/*
 * PCTools.h
 *
 *  Created on: Oct 16, 2020
 *      Author: yang_p1
 */

#ifndef APP_PCTOOLS_PCTOOLS_H_
#define APP_PCTOOLS_PCTOOLS_H_

#ifdef MCU_SYSTEM_VERSION
# define MCU_VERSION_SW					MCU_SYSTEM_VERSION
#else
# define MCU_VERSION_SW					"SAJ.00.00.0000.00"
#endif

#define PCTOOLS_RX_MSG_ID              (0x4E8)
#define PCTOOLS_RX_MSG_DLC             (8u)

typedef struct {
	uint16_t	event_code;
	uint32_t  	data_size;
	void *      data_buff;
} PCToolsMsg_st;

#define JTOOLS_CMD_ALL_LEN (8)
#define JTOOLS_CMD_SYNC_LEN (2)
#define JTOOLS_CMD_DLC_LEN (2)
#define JTOOLS_CMD_SID_LEN (1)
#define JTOOLS_CMD_TYPE_LEN (1)
#define JTOOLS_CMD_HEADER_LEN (JTOOLS_CMD_SYNC_LEN+JTOOLS_CMD_DLC_LEN+JTOOLS_CMD_SID_LEN+JTOOLS_CMD_TYPE_LEN)

#define JTOOLS_CMD_SYNC_POS (0)
#define JTOOLS_CMD_DLC_POS (2)
#define JTOOLS_CMD_SID_POS (4)
#define JTOOLS_CMD_TYPE_POS (5)
#define JTOOLS_CMD_DATA_POS (6)
#define JTOOLS_CMD_SYNC_H (0xFF)
#define JTOOLS_CMD_SYNC_L (0xEE)

#define JTOOLS_CMD_TYPE_COMMAND (0)
#define JTOOLS_CMD_TYPE_RESULT (2)

#define JTOOLS_CMD_OK (0)
#define JTOOLS_CMD_NG (1)
#define JTOOLS_CMD_SYNC_ERR (1)
#define JTOOLS_CMD_SID_ERR (1)
#define JTOOLS_CMD_TYPE_ERR (1)

#define JTOOLS_DTC_ONE_SIZE (4)
#define JTOOLS_DTC_ABAIL_MASK (0x09)


/*
#define JTOOLS_SF_CMD_DLC_POS (1)
#define JTOOLS_SF_CMD_SID_POS (2)
#define JTOOLS_SF_CMD_SUBID_POS (3)
#define JTOOLS_SF_CMD_DATA_POS (4)

#define JTOOLS_FF_CMD_DLC_POS (1)
#define JTOOLS_FF_CMD_SID_POS (3)
#define JTOOLS_FF_CMD_SUBID_POS (4)
#define JTOOLS_FF_CMD_DATA_POS (5)

#define JTOOLS_CF_CMD_SN_POS (1)
#define JTOOLS_CF_CMD_DATA_POS (2)

#define JTOOLS_CMD_DLC_POS (0)
#define JTOOLS_CMD_SID_POS (1)
#define JTOOLS_CMD_SUBID_POS (2)
#define JTOOLS_CMD_DATA_POS (3)
*/

#define JTOOLS_TIMER_BASE (10)
#define JTOOLS_TIMER_WAITCF_TIMEOUT (50u)
#define JTOOLS_TIMER_SEND_REP_INTERVAL (30u)

#define JTOOLS_FUNC_ON (1u)
#define JTOOLS_FUNC_OFF (0u)
#define JTOOLS_FUNC_PERMIT (1u)
#define JTOOLS_FUNC_PROHIBIT (0u)

#define JTOOLS_RESP_OK (0u)
#define JTOOLS_RESP_NG (1u)
#define JTOOLS_RESP_MUTIL_ID_POS (0u)
#define JTOOLS_RESP_MULTI_ALL_LEN_POS (1u) // total length
#define JTOOLS_RESP_MULTI_OFFSET_POS (3u)
#define JTTOLS_RESP_MULTI_LEN_POS (5u) // valid data length in one message
#define JTTOLS_RESP_MULTI_DATA_POS (6u) //

#define JTOOLS_SW_LEN (4u)
#define JTOOLS_RTC_LEN (11u)


/*error code*/
#define JTOOLS_ERR_CA_BUFFER (0xFF)

/*EEPROM Address*/
#define JTOOLS_EEPROM_TEST_ADDR 0x1FFD
#define JTOOLS_EEPROM_TEST_DATA 0x55






/*
enum JToolsServiceID
{
	SupplyVoltageControl=0x01,
	TerminalInfoWrite,
	TerminalInforRead,
	FuncTest
};
*/
enum JToolsServiceSubID
{
	/*0x80*/CANSleep=0x80,
	/*0x81*/ElectricInspectionON,
	/*0x82*/ElectricInspectionOFF,

	/*0x01*/SNWriteIn=0x01,
	/*0x02*/WorkScheduleWriteIn,
	/*0x03*/HWWriteIn,
	/*0x04*/HSM_Key_WriteIn,
	/*0x05*/SysNameWriteIn,
	/*0x06*/SysSupIDWriteIn,
	/*0x07*/ManufactureDataWriteIn,
	/*0x08*/SwNmAlphaCodeWritenIn,
	/*0x09*/HwNmAlphaCodeWriteIn,
	/*0x0A*/CA_Install,

	/*0x11*/SNReadOut=0x11,
	/*0x12*/ICCIDReadOut,
	/*0x13*/IMEIReadOut,
	/*0x14*/HWVerReadOut,
	/*0x15*/SWVerReadOut,
	/*0x16*/StandbyBatteryVolReadOut,
	/*0x17*/StandbyBatteryTempReadOut,
	/*0x18*/WorkScheduleReadOut,
	/*0x19*/IMSIReadOut,
	/*0x1A*/TerminalRTCReadOut,
	/*0x1B*/SysSupIDReadOut,
	/*0x1C*/ManufactureDataReadOut,
	/*0x1D*/SwNmAlphaCodeReadOut,
	/*0x1E*/HwNmAlphaCodeReadOut,
	/*0x1F*/BTMACReadOut,


	/*0x21*/EMMCFuncDetect=0x21,
	/*0x22*/ESDDetect,
	/*0x23*/ServerCommDetect,
	/*0x24*/RESERV1,
	/*0x25*/RESERV2,
	/*0x26*/RESERV3,
	/*0x27*/RESERV4,
	/*0x28*/RESERV5,
	/*0x29*/VolDetect,
	/*0x2A*/GPSPlugDetect,

	/*0x2B*/_4GAntennaPlugDetect,
	/*0x2C*/MicDetect,
	/*0x2D*/SpeakerDetect,
	/*0x2E*/BTTest,
	/*0x2F*/WIFITest,
	/*0x30*/CrashDetect,
	/*0x31*/GSensorDetectStart,
	/*0x32*/V2XDetect,
	/*0x33*/GPSDetect,
	/*0x34*/CommSigIntensityTest,
	/*0x35*/EthernetTestStart,
	/*0x36*/StandbyBatteryLifeTimeDetect,
    /*0x37*/StandbyBatteryStsDetect,
	/*0x38*/SOSKeyDetect,
	/*0x39*/EthernetTestStop,
	/*0x3A*/GSensorDetectStop,
	/*0x3B*/BeaconDetect,
	/*0x3C*/BLEConnectStsDetect,
	/*0x3D*/GPSLocationDetect,
	/*0x3E*/V2XCommDetect,
	/*0x3F*/ExternalEEPROMDetect,

	/*0x51*/RestoreFactorySetting_ReadDTC=0x51,
	/*0x52*/RestoreFactorySetting_ClearDTC,
	/*0x53*/StorageFormatting,
	/*0x54*/TerminalDiag,
	/*0x55*/DataExport,
	/*0x56*/Ecall_Press,
	/*0x57*/Ecall_Hangup,
	/*0x58*/StandbyBatteryDisable,

	Reserve
};

enum CA_Install
{
    Install_Root_Key,
    CA_Request,
    Install_CA,
};

enum JTools_CMD
{
	EV_RESP_FROM_MCU,
	EV_RESP_FROM_MPU,
	EV_REQ_FROM_JTOOLS,
	EV_RESP_FROM_SOSKey,
	EV_RESP_FROM_Crash,
	EV_STANDBYIN,
	EV_STANDBYOUT
};


enum EV_JTools_TO_MPU/*SPI : MCU->MPU */
{

	/*0xA200*/EV_JTOOLS_TO_MPU_READ_ICCID=0xA200,
	/*0xA201*/EV_JTOOLS_TO_MPU_READ_IMEI,
	/*0xA202*/EV_JTOOLS_TO_MPU_READ_SIMCARD_STATUS,
	/*0xA203*/EV_JTOOLS_TO_MPU_READ_SIM_SIGNAL_STRENGTH,
	/*0xA204*/EV_JTOOLS_TO_MPU_READ_SIM_CARD_MODE,
	/*0xA205*/EV_JTOOLS_TO_MPU_READ_SIM_CARD_NETWORK_STATUS,
	/*0xA206*/EV_JTOOLS_TO_MPU_IO_SRS_NORMAL_ECALL_PRESS,
	/*0xA207*/EV_JTOOLS_TO_MPU_IO_SRS_CRASH_ECALL_PRESS,
	/*0xA208*/EV_JTOOLS_TO_MPU_IO_SRS_NORMAL_ECALL_HANGUP,
	/*0xA209*/EV_JTOOLS_TO_MPU_IO_SRS_CRASH_ECALL_HANGUP,
	/*0xA20A*/EV_JTOOLS_TO_MPU_IO_SRS_NORMAL,
	/*0xA20B*/EV_JTOOLS_TO_MPU_IO_SRS_CRASH,
	/*0xA20C*/EV_JTOOLS_TO_MPU_IO_ECALL_PRESS,
	/*0xA20D*/EV_JTOOLS_TO_MPU_IO_ECALL_HANGUP,
	/*0xA20E*/EV_JTOOLS_TO_MPU_IO_RETURN_TO_NORMAL,
	/*0xA20F*/EV_JTOOLS_TO_MPU_ROUTINE_V2X_FUNC_TEST,
	/*0xA210*/EV_JTOOLS_TO_MPU_ROUTINE_4G5G_ANTENNA_TEST,
	/*0xA211*/EV_JTOOLS_TO_MPU_ROUTINE_SERVER_TEST,
	/*0xA212*/EV_JTOOLS_TO_MPU_ROUTINE_GPS_TEST,
	/*0xA213*/EV_JTOOLS_TO_MPU_ROUTINE_ETHERNET_TEST_START,
	/*0xA214*/EV_JTOOLS_TO_MPU_ROUTINE_ETHERNET_TEST_STOP,
	/*0xA215*/EV_JTOOLS_TO_MPU_ROUTINE_G_SENSOR_TEST_START,
	/*0xA216*/EV_JTOOLS_TO_MPU_ROUTINE_G_SENSOR_TEST_STOP,
	/*0xA217*/EV_JTOOLS_TO_MPU_ROUTINE_EMMC_TEST,
	/*0xA218*/EV_JTOOLS_TO_MPU_CA_REQUEST,
	/*0xA219*/EV_JTOOLS_TO_MPU_GPS_Location_REQUEST,
	/*0xA21A*/EV_JTOOLS_TO_MPU_V2X_COMM_REQUEST,
	/*0xA21B*/EV_JTOOLS_TO_MPU_ROUTINE_WRITE_SN_RESULT,
	/*0xA21C*/EV_JTOOLS_TO_MPU_ROUTINE_WRITE_HSM_KEY_RESULT,
	/*0xA21D*/EV_JTOOLS_TO_MPU_ROUTINE_WRITE_TBOX_SK_RESULT,
	/*0xA21E*/EV_JTOOLS_TO_MPU_ROUTINE_WRITE_VIN_RESULT,
	/*0xA21F*/EV_JTOOLS_TO_MPU_ROUTINE_BLE_TEST,
	/*0xA220*/EV_JTOOLS_TO_MPU_ROUTINE_WIFI_TEST,

	EV_TO_MPU_CNT
};


enum EV_JTools_MPU_TO_MCU //MPU->MCU
{
	EV_MPU_TO_JTOOLS_UPPER=0x21FF,

	/*0x2200*/EV_MPU_TO_JTOOLS_ICCID_READ_DATA,
	/*0x2201*/EV_MPU_TO_JTOOLS_IMEI_READ_DATA,
	/*0x2202*/EV_MPU_TO_JTOOLS_READ_SIMCARD_STATUS,
	/*0x2203*/EV_MPU_TO_JTOOLS_READ_SIM_SIGNAL_STRENGTH,
	/*0x2204*/EV_MPU_TO_JTOOLS_READ_SIM_CARD_MODE,
	/*0x2205*/EV_MPU_TO_JTOOLS_READ_SIM_CARD_NETWORK_STATUS,
	/*0x2206*/RESERVE1,
	/*0x2207*/RESERVE2,
	/*0x2208*/RESERVE3,
	/*0x2209*/RESERVE4,
	/*0x220A*/RESERVE5,
	/*0x220B*/RESERVE6,
	/*0x220C*/RESERVE7,
	/*0x220D*/RESERVE8,
	/*0x220E*/RESERVE9,
	/*0x220F*/RESERVE10,
	/*0x2210*/RESERVE11,
	/*0x2211*/RESERVE12,
	/*0x2212*/RESERVE13,
	/*0x2213*/RESERVE14,
	/*0x2214*/RESERVE15,
	/*0x2215*/RESERVE16,
	/*0x2216*/RESERVE17,
	/*0x2217*/RESERVE18,
	/*0x2218*/EV_MPU_TO_JTOOLS_ROUTINE_V2X_FUNC_TEST,
	/*0x2219*/EV_MPU_TO_JTOOLS_ROUTINE_4G5G_ANTENNA_TEST,
	/*0x221A*/EV_MPU_TO_JTOOLS_ROUTINE_SERVER_TEST,
	/*0x221B*/EV_MPU_TO_JTOOLS_ROUTINE_GPS_TEST,
	/*0x221C*/EV_MPU_TO_JTOOLS_ROUTINE_ETHERNET_TEST,
	/*0x221D*/EV_MPU_TO_JTOOLS_ROUTINE_G_SENSOR_TEST,
	/*0x221E*/EV_MPU_TO_JTOOLS_ROUTINE_EMMC_TEST,
	/*0x221F*/EV_MPU_TO_JTOOLS_CA_REQUEST,
	/*0x2220*/EV_MPU_TO_JTOOLS_ROUTINE_GPS_Location_TEST,
	/*0x2221*/EV_MPU_TO_JTOOLS_ROUTINE_C2X_COMM_TEST,
	/*0x2222*/EV_MPU_TO_JTOOLS_ROUTINE_WRITE_SN_REQUEST,
	/*0x2223*/EV_MPU_TO_JTOOLS_ROUTINE_WRTIE_HSM_KEY_REQUEST,
	/*0x2224*/EV_MPU_TO_JTOOLS_ROUTINE_WRTIE_TBOX_SK_REQUEST,
	/*0x2225*/EV_MPU_TO_JTOOLS_ROUTINE_WRTIE_VIN_REQUEST,
	/*0x2226*/EV_MPU_TO_JTOOLS_ROUTINE_BLE_TEST_RESULT,
	/*0x2227*/EV_MPU_TO_JTOOLS_ROUTINE_WIFI_TEST_RESULT,

	EV_MPU_TO_JTOOLS_Bottom
};



enum EV_MPU_TO_JTools/*SPI : MPU->MCU */
{
	EV_FROM_MPU_ICCID_READ_DATA=0x2200,

};


extern uint8_t nubJTools_SendMessage(uint16_t auhEventCode, void * avdDate_p, uint32_t auwSize);

#endif /* APP_PCTOOLS_PCTOOLS_H_ */
