#ifndef __IKONKE_MODULE_FACTORY_TEST_H_______________________
#define __IKONKE_MODULE_FACTORY_TEST_H_______________________

#include "ikk-debug.h"
#include "../driver/ikk-uart.h"
#include "ikk-command.h"
// 定义是否需要产测
#define FACTORY_TEST_ENABLE 					true
//使能debug快速测试老化
#define AGING_DEBUG                 			false
//可以最多两个按钮可以退出老化
#define AGING_EXIT_MAX_BTN_NUM					2


//按键强制退老化时，长按次数，比如铂金10A/16A插座的触摸按键长按5S两次退老化，轻触机械按键只要1次20S
#define LONG_PRESS_1_TIMES						1
#define LONG_PRESS_2_TIMES						2
//强制退老化时间
#define TOUCH_KEY_LONG_PRESS_TIME_MS			(5 * 1000)
#define MECHANICAL_KEY_LONG_PRESS_TIME_MS		(20 * 1000)

#define FIRST_BTN_LONG_PRESSED_VALIED_TIME_MS	(10 * 1000)

#define FACTORY_TEST_POLL_TTME_1S				(1 * 1000)
#define FACTORY_TEST_POLL_TTME_10S				(10 * 1000)
#define FACTORY_TEST_POLL_TIMES					(FACTORY_TEST_POLL_TTME_10S / FACTORY_TEST_POLL_TTME_1S)
#if AGING_DEBUG
#define FACTORY_TEST_15MIN_MS					(2 * 60 * 1000)
#define FACTORY_TEST_4HOU_MS					(1 * 15 * 60 * 1000)
#else
#define FACTORY_TEST_15MIN_MS					(15 * 60 * 1000)
#define FACTORY_TEST_4HOU_MS					(4 * 60 * 60 * 1000)
#endif
#define FACTORY_TEST_1S							(1000)

//初始值
#define TEST_INIT_VALUE							0xFF
typedef enum{
	FTS_NORMAL=0,
	FTS_START,
	FTS_AGING_15MIN,
	FTS_AGING_4HOU_START,
	FTS_AGING_4HOU,
	FTS_AGING_DONE,
	FTS_FORCE_EXIT,
	FTS_WAITING_RELEASED,//waiting key released
	FTS_FORCE_REBOOT,
	FTS_FIRST_LONG_PRESSED,
	FTS_WAITING_SECOND_PRESS,
	FTS_SINGLE_BOARD_TEST,
	FTS_FULL_DEVICE_TEST,
	FTS_SINGLE_BOARD_TEST_DONE,
	FTS_FULL_DEVICE_TEST_DONE,
}FactoryTestStatusEnum;

typedef struct{
	uint8_t u8BtnId;
	uint8_t u8BtnLongPressTimes; //touch keys must be long pressed 2 times, mechanical keys is pressed 1 time
	uint32_t u32AgingForceExitTimeMs;  //key long pressed time for  exit aging test
}FactoryTestConfSt;

//10S轮询操作函数，可根据不同长供电产品自定义实现
typedef void (*pFactoryTestPollCallback)(FactoryTestStatusEnum status);
nv_sts_t General_Set_Factory_Test(nv_item_t items,uint8_t value);
uint8_t General_Get_Factory_Test(nv_item_t items,uint8_t default_value);

#define kSetSingleBoardValue(value)			General_Set_Factory_Test(NV_SINGLE_BOARD_TEST_FLG,value)
#define kSetFullDeviceValue(value)			General_Set_Factory_Test(NV_FULL_DEVICE_TEST_FLG,value)
#define kSetAgingTestValue(value)			General_Set_Factory_Test(NV_AGE_TEST_STEP,value)

#define kGetSingleBoardValue()				General_Get_Factory_Test(NV_SINGLE_BOARD_TEST_FLG,TEST_INIT_VALUE)
#define kGetFullDeviceValue()				General_Get_Factory_Test(NV_FULL_DEVICE_TEST_FLG,TEST_INIT_VALUE)
#define kGetAgingTestValue()				General_Get_Factory_Test(NV_AGE_TEST_STEP,0)

uint8_t kGetFactoryTestValueStatus(void);
uint32_t kGetAgingMaxTime(void);
void kSetAgingMaxTime(uint16_t value);
//获取当前产测状态
FactoryTestStatusEnum kGetFactoryTestStatus(void);
//void  kGetFactoryTestBtnAction(uint8_t btn_id, BtnActionEnum action);
void kFactoryTestInit(pFactoryTestPollCallback callback, FactoryTestConfSt conf_list[], uint8_t btn_num,uint8_t led_id);

void kSetNetworkSteeringInfo(uint8_t channel, uint16_t PanId);

//Auth: han_frc.20220105.
void kSetAgingTestDone(void);

kk_err_t kkFactoryMsgInComingPaser(UMsgNodeSt *pMsgNode, ComPortEm port, DataField_st *pDataOut);
#endif

