#include "stdafx.h" #include "alchemy_internal.h" #include #include "cli.h" #define ENABLE_BHJDEBUG #include "bhjdebug.h" typedef enum { FACTORY_ID = 0x001, GPIO_TEST = 0x003, REGISTER_TEST = 0x004, ADC_TEST = 0x005, REBOOT_TEST = 0x006, CAMERA_TEST = 0x007, BLUETOOTH_TEST = 0x008, TESTINFO = 0x009, ATPARSER_TEST = 0x00a, VIBRATOR_TEST = 0x00b, POWERREASON_TEST=0x00c, VOLTAGE_TEST = 0x00d, /*get real voltage by ADC */ TEMPRATURE_TEST = 0x00e, /*get real temprature by ADC */ CHARGETYPE_TEST =0x00f, GSENSOR_TEST = 0x010, MICCO_TEST = 0x011, LCDBACK_TEST = 0x012, KEYBACK_TEST = 0x013, TOUCH_POINT =0x014, KEY_INPUT = 0x015, ONLY_Key = 0x031, LGSENSOR_TEST = 0x01c, GSENSOR_INFO = 0x01d, /* DDR test commands */ Ddr_TEST = 0x01f, /* LCD test commands */ LCD_TEST = 0x20, /* T-FLASH card detect*/ CARD_TEST =0x021, /* charge status */ CHARGESTATUS_TEST = 0x022, /* MAT FILE Read AND write */ MAT_TEST = 0x023 , /*audio hardware test */ AUDIO_TEST = 0x024, /* ADC calibration &NVM block operation related test commands*/ CALI_TEMP = 0x016, /*only operation on filesystem file*/ CALI_VOLT = 0x017, /*only operation on filesystem file*/ NVM_TEST = 0X018, VOLT_TEST = 0x019, /*read /write from filesystem to NVM block*/ TEMP_TEST = 0x01a, /*read /write from filesystem to NVM block*/ RF_TEST = 0x01b, /*read /write from filesystem to NVM block*/ TESTINFO_TEST =0x025,/*read /write from filesystem to NVM block*/ FACTORYID_TEST=0x026,/*read /write from filesystem to NVM block*/ MATFLAG_TEST=0x027,/*read /write from filesystem to NVM block*/ /*touch panel test */ PANEL_TEST = 0x028, /*empty test */ EMPTY_TEST = 0x029, /* bluetooth test commands */ BT_TEST = 0x050, BTNVM_TEST= 0x051, BT_INQUIRE= 0x052, BT_TESTMODE =0x053, BT_KILL=0x054,//kill the "/system/bin/hciattach" process after enter into BT Test Mode /BTINQUIRE /*camera test commands */ CAMERA_PREVIEW = 0x060, LAUNCH_CAMERA = 0x61, I2C_TEST = 0x01e, /*CMMB test commands */ IF101_TEST= 0x070, INNO_DEVICE= 0x071, /*enter or exit CMMB test mode*/ Signallock_TEST = 0x72, Sensitive_TEST = 0x73, IF101_SPI_TEST = 0x74, IF101_SET_FREQ = 0x75, LAUNCH_TV = 0x76, /* GPS test commands */ GPS_TEST = 0x80, GPS_LOCATION=0x81, GPS_MESSAGE=0x82,/*only get NEMA Message*/ GPS_LOCA_MESSAGE=0x83,/*only get Location Message*/ GPS_CHANGE_MODE=0x84,/*Change between hot mode and code mode*/ /* SPARK */ SPARK_KEY=0x90,/*TEST KEY INPUT*/ /* Key Monitor */ KEY_MONITOR=0x91, /* Sensor Monitor */ SENSOR_MONITOR=0x92, /* Set/Get LPR SMS report flag */ SMS_FLAG =0x93, /* Set/Get LPR livetime period */ LIVETIME_PERIOD = 0x94, /* Set/Get EFEM feature flag */ EFEM_FLAG =0x95, DIAG_LAUNCH=0x96, GET_RDNVM =0x9a, DIAG_EXT_INTERFACE=0x9b, /*to set /get element config value */ NVM_Element=0x9c, /*to set /get phase data : */ NVM_PHASE =0x9d, /*Common set/get Bit config element value*/ NVM_BITCONFIG =0x9e, /* Version */ VERSION = 0x039, /* bp only handler */ BP_ONLY = 0xFFFF } TC_AP_FSM_EVENT_OPCODE_T; typedef unsigned char u8; typedef unsigned short u16; typedef struct{ const char *cmdName; int opCode; const char *inputSpec; // datatype: BHIOoF, how: <>*! const char *fixedInput; const char *description; } testCmd_T; //< means from the fixedInput, //> means from user provided input, //! means arbitrary value is acceptable, so we just use 0, //* means fill with a string static testCmd_T cmdMap[] = { {"version", VERSION, "B<", "0x12", "Read software version of the phone"}, {"get factory_id", FACTORY_ID, "B<", "0x11", "Read FactoryId of the phone"}, {"set factory_id", FACTORY_ID, "BB!", "0x1", "Get GPIO, the u16 argument is the GPIO number"}, {"set gpio", GPIO_TEST, "BB>", "0x2", "Set GPIO, the u16 is GPIO number, the u8 is GPIO setting\n" "the meaning of bit 7-0:\n" " level : 1, //0:low,1:High\n" " in_out: 1, //0:input, 1:output\n" " pullup: 1, //0:no pullup,1:pullup\n" " pulldown: 1, //0:no pulldown,1:pulldown\n" " tri_state: 1, //0:anit_tristate,1:tristate\n" " reserved: 3;\n" }, {"get register", REGISTER_TEST, "BI!", "0x1", "Read register value, u32 is register number. Use with caution!"}, {"set register", REGISTER_TEST, "BI>", "0x2", "Write register, first u32 is register number, second is value"}, {"get adc", ADC_TEST, "B>H!", "", "Read A/D converter value, u8 is AD number" }, {"reboot poweroff", REBOOT_TEST, "B<", "0x0", "reboot to poweroff mode"}, {"reboot factory", REBOOT_TEST, "B<", "0x1" "reboot to factory mode (minimal applications will start, so boot/test is faster)"}, {"reboot normal", REBOOT_TEST, "B<", "0x2", "reboot, the `Normal' reboot"}, {"reboot flash", REBOOT_TEST, "B<", "0x3", "reboot to flash mode"}, //{"camera test", //??? {"launch camera", LAUNCH_CAMERA, "", "", "lauch camera"}, //{"bluetooth test", //??? //{"get info", TESTINFO, "B<", "0x11"}, //??? //{"set info", TESTINFO, "BB!", "0x1", "get gravity sensor value, u8 is the gsensor number"}, {"set gsensor", GSENSOR_TEST, "BB>", "0x2", "set gsensor value, first u8 is the gsensor number, second is value"}, {"get micco", MICCO_TEST, "BB>", "0x1", "}, {"set micco", MICCO_TEST, "BB>", "0x2"}, {"vibrator on", VIBRATOR_TEST, "B<", "0x1"}, {"vibrator off", VIBRATOR_TEST, "B<", "0x2"}, //{"at test" //bhj: don't know what this means {"get power reason", POWERREASON_TEST, "", ""}, {"get chargetype", CHARGETYPE_TEST, "B<", "0x1"}, {"set chargetype", CHARGETYPE_TEST, "B", "0x2"}, {"get manual voltage", VOLTAGE_TEST, "B<", "0x0"}, {"get auto voltage", VOLTAGE_TEST, "B<", "0x4"}, {"get manual temperature", TEMPRATURE_TEST, "B<", "0x1"},//0x0? {"get auto temperature", TEMPRATURE_TEST, "B<", "0x5"}, {"get lcdbl", LCDBACK_TEST, "B", "0x1"}, {"set lcdbl", LCDBACK_TEST, "B", "0x2"}, {"get keybl", KEYBACK_TEST, "B", "0x1"}, {"set keybl", KEYBACK_TEST, "B", "0x2"}, {"test touch", TOUCH_POINT, "", ""}, {"test keyinput",ONLY_Key,"",""}, {"get lprflag", SMS_FLAG, "B<", "0x1"}, {"set lprflag", SMS_FLAG, "B", "0x2"}, {"get lprtime", LIVETIME_PERIOD, "B<", "0x1"}, {"set lprtime", LIVETIME_PERIOD, "B", "0x2"}, {"get efemflag", EFEM_FLAG, "B<", "0x1"}, {"set efemflag", EFEM_FLAG, "B", "0x2"}, {"get cali temperature",CALI_TEMP,"B<","0x1"},//add by Jason from here {"get cali voltage",CALI_VOLT,"B<","0x1"}, {"set cali voltage",CALI_VOLT,"B",""}, {"lcd test",LCD_TEST,"B>",""}, {"card detect",CARD_TEST,"B>",""}, {"charge status",CHARGESTATUS_TEST,"B>",""}, {"audio test",AUDIO_TEST,"B>",""}, //data: 0x01: AUDIO_SD_PLAY // 0x02: AUDIO_MICRO_TEST // 0x03: AUDIO_EAR_TEST {"save rd",GET_RDNVM,"B","0x1"}, {"get diag_en",DIAG_LAUNCH,"B<","0x1"}, {"set diag_en",DIAG_LAUNCH,"B","0x2"}, {"get diag_intf",DIAG_EXT_INTERFACE,"B<","0x1"}, {"set diag_intf",DIAG_EXT_INTERFACE,"B","0x2"}, {"get element",NVM_Element,"I>B<","0x1"}, {"set element",NVM_Element,"I>BB<","0x1"}, {"set phase",NVM_PHASE,"I>B","0x2"}, {"get ap_panic_report",NVM_BITCONFIG,"I>B<","0x1"}, {"set ap_panic_report",NVM_BITCONFIG,"I>B","0x2"}, {"opcode", -1, "o>", ""}, {"reliable data", 0x97, "F>", ""}, {NULL, 0, NULL, NULL}, }; static BOOL notOptionalCode(char c) { return (c!='*' && c!='?'); } static BOOL isOptionalCode(char c) { return !notOptionalCode(c); } static BOOL isSingleOptional(char c) { return c=='?'; } static BOOL isMultiOptional(char c) { return c=='*'; } static unsigned long getLong(CString& strInput) { const char *s = strInput.GetBufferSetLength(strInput.GetLength()); char *firstInvalid = NULL; long dataH = strtol(s, &firstInvalid, 0); strInput.ReleaseBuffer(); strInput.Delete(0, firstInvalid-s); strInput.TrimLeft(); return (unsigned long) dataH; } static int getLongCheck(CString& strInput, unsigned long& outLong) { outLong = 0; strInput.TrimLeft(); strInput.TrimRight(); if (strInput.IsEmpty()) { return -1; } int len = strInput.GetLength(); outLong = (unsigned long)getLong(strInput); if (len == strInput.GetLength()) { return -1; } return 0; } static int getB(CString& strInput, CU8Array& dataArr) { unsigned long outLong = 0; if (getLongCheck(strInput, outLong) < 0) { return -1; } unsigned char data = (unsigned char)outLong; dataArr.Add(data); return 0; } //'H' stands for a short static int getH(CString& strInput, CU8Array& dataArr) { unsigned long outLong = 0; if (getLongCheck(strInput, outLong) < 0) { return -1; } unsigned short data = (unsigned short) outLong; //big endian or little endian? dataArr.Add(data&0xff); dataArr.Add(data>>8); return 0; } static int getI(CString& strInput, CU8Array& dataArr) { unsigned long outLong = 0; if (getLongCheck(strInput, outLong) < 0) { return -1; } unsigned int data = (unsigned int)outLong; dataArr.Add(data&0xff); //获取int的低位字节 dataArr.Add((data>>8) & 0xff); //获取int的第二个字节 dataArr.Add((data>>16) & 0xff); //获取int的第三个字节 dataArr.Add((data>>24) &0xff); //获取int的第四个字节 return 0; } static int getF(CString& strInput, CU8Array& dataArr) { strInput.TrimLeft(); strInput.TrimRight(); FILE* fp = fopen(strInput, "rb"); if (fp == NULL) { urgTrace("Error: %s open failed", (const char *)strInput); return -1; } fseek(fp, 0, SEEK_END); DWORD dwLength = ftell(fp); rewind(fp); char *buff = (char *)calloc(dwLength, 1); DWORD numRead = 0; for (;;) { numRead += fread(buff+numRead, 1, dwLength, fp); if (numRead == dwLength) break; } ASSERT(numRead == dwLength); for (DWORD i=0; i'; } static BOOL isFromFixed(char where) { return where == '<'; } static BOOL isArbitrary(char where) { return where == '!'; } static BOOL isMultiple(char where) { return where == '*'; } static int getArg(CU8Array& dataArr, CString& strUserInput, CString& strFixedInput, char dataType, char where) { if (dataType == 'B') { if (isFromUser(where)) { return getB(strUserInput, dataArr); } else if (isFromFixed(where)) { return getB(strFixedInput, dataArr); } else if (isArbitrary(where)) { return getB(CString("0"), dataArr); } else if (isMultiple(where)) { //the rest of the user-input is consumed for (int k=0; k10) { sendTrace+="..."; } dbgTrace("%s", sendTrace); int ret = getConnection()->UC_Do3rdCommand(opcode, dataArr, result, cmdMap[i].cmdName); printResult(result); if (ret < 0) { infoTrace("`%s`: failed!", cmdMap[i].cmdName); return -1; } else { infoTrace("`%s`: success!", cmdMap[i].cmdName); return 0; } } } if (sCommand.Find("help") == 0) { help(); } else if (sCommand.Find("todo") == 0) { todo(); } else if (sCommand.Find("bugs") == 0) { bugs(); } else if (sCommand.Find("commands") == 0) { commands(); } else { urgTrace("%s", sCommand+=": unknown command"); } return 0; }