std::vector<unsigned char> OK5553ReaderUnit::rats() { std::vector<unsigned char> answer; // Sending two RATS is not supported without a new Select. Doesn't send another one if the first successed. if (d_successedRATS.size() == 0) { LOG(LogLevel::INFOS) << "Sending a RATS"; answer = getDefaultOK5553ReaderCardAdapter()->sendAsciiCommand("t020FE020"); answer = asciiToHex(answer); if (answer.size() > 1) { if (answer[0] == answer.size() - 1) { answer.erase(answer.begin()); } else answer.clear(); } else { answer.clear(); THROW_EXCEPTION_WITH_LOG(std::invalid_argument, "No tag present in rfid field"); } d_successedRATS = answer; } else { answer = d_successedRATS; } return answer; }
std::shared_ptr<Chip> OK5553ReaderUnit::getChipInAir(unsigned int maxwait) { LOG(LogLevel::INFOS) << "Starting get chip in air..."; std::shared_ptr<Chip> chip; std::vector<unsigned char> buf; unsigned int currentWait = 0; while (!chip && (maxwait == 0 || currentWait < maxwait)) { try { buf = getDefaultOK5553ReaderCardAdapter()->sendAsciiCommand("s"); } catch (std::exception&) { buf.clear(); } d_successedRATS.clear(); if (buf.size() > 0) { buf = asciiToHex(buf); if (buf[0] == ChipType::MIFARE) { chip = createChip("Mifare"); buf.erase(buf.begin()); chip->setChipIdentifier(buf); } else if (buf[0] == ChipType::DESFIRE) { chip = createChip("DESFire"); buf.erase(buf.begin()); chip->setChipIdentifier(buf); std::dynamic_pointer_cast<DESFireISO7816Commands>(chip->getCommands())->getCrypto()->setCryptoContext(std::dynamic_pointer_cast<DESFireProfile>(chip->getProfile()), chip->getChipIdentifier()); } else if (buf[0] == ChipType::MIFAREULTRALIGHT) { chip = createChip("MifareUltralight"); buf.erase(buf.begin()); chip->setChipIdentifier(buf); } } if (!chip) { std::this_thread::sleep_for(std::chrono::milliseconds(250)); currentWait += 250; } } return chip; }
std::vector<unsigned char> OK5553ReaderUnit::reqA() { std::vector<unsigned char> answer = getDefaultOK5553ReaderCardAdapter()->sendAsciiCommand("t01E326"); answer = asciiToHex(answer); if (answer.size() > 1) { if (answer[0] == answer.size() - 1) { answer.erase(answer.begin()); } else answer.clear(); } else { answer.clear(); } return answer; }
static int DAPLUGCALL addAsciiText(Keyboard *k, char *text){ int text_len = strlen(text); char text_hex[text_len*2+1]; strcpy(text_hex,""); asciiToHex(text,text_hex); int added_len = strlen(text_hex); added_len = added_len/2; if(k->currentContentSize+added_len <= MAX_KB_CONTENT_SIZE){ strcat(k->content,text_hex); k->currentContentSize = k->currentContentSize+added_len; }else{ fprintf(stderr,"\nkeyboard_addOSProbe(): Keyboard maximum content size exceeded !\n"); return 0; } return 1; }
int main(int argc,char *argv[]){ #ifdef _DEBUG_ //调试时启用内存泄露检测工具 printf("DEBUG !!!!!!!!!!!!!!!!!!!!!!!\n\n\n"); atexit(report_mem_leak); // #endif // //UI start //------------------------------------------------------------------- //初始化------------------------------------------------------------- //------------------------------------------------------------------- //1.将发送的命令转换成正确的格式 asciiToHex(UPS_COMMUNICATION_INI,UPS_COMMUNICATION_INI_DECODE); asciiToHex(UPS_CMD_ACCEPT,UPS_CMD_ACCEPT_DECODE); asciiToHex(UPS_CMD_01,UPS_CMD_01_DECODE); asciiToHex(UPS_CMD_02,UPS_CMD_02_DECODE); asciiToHex(UPS_CMD_03,UPS_CMD_03_DECODE); asciiToHex(UPS_CMD_06,UPS_CMD_06_DECODE); asciiToHex(UPS_CMD_07,UPS_CMD_07_DECODE); asciiToHex(UPS_CMD_24,UPS_CMD_24_DECODE); asciiToHex(UPS_CMD_27,UPS_CMD_27_DECODE); asciiToHex(UPS_CMD_31,UPS_CMD_31_DECODE); asciiToHex(UPS_CMD_32,UPS_CMD_32_DECODE); asciiToHex(UPS_CMD_3B,UPS_CMD_3B_DECODE); asciiToHex(UPS_CMD_42,UPS_CMD_42_DECODE); //UI show "ok" //2.读取配置文件参数 char *value_buf = (char*) malloc(MAX_CHAR_PER_PARA); //临时变量 char *key_buf = (char*) malloc(MAX_CHAR_PER_CONF); //临时变量 KEY_VAL config_file, *config_file_ptr1=&config_file, *config_file_ptr2=NULL; if(analyzeConfFile("config",&config_file)){ //read file successfully } else{ //file not existed } errorReport(); // for(int i=0;i<NUM_OF_UPS;i++){ //读取配置文件参数的设定值 sprintf(key_buf,"com_num_%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].LINK_COM_NUM=atoi(value_buf);// } else{ } sprintf(key_buf,"READ_INTERVAL_UPS%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].READ_INTERVAL=atoi(value_buf);// } else{ } sprintf(key_buf,"READ_MULTIPLIER_UPS%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].READ_MULTIPLIER=atoi(value_buf);// } else{ } sprintf(key_buf,"READ_CONSTANT_UPS%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].READ_CONSTANT=atoi(value_buf);// } else{ } sprintf(key_buf,"WRITE_MULTIPLIER_UPS%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].WRITE_MULTIPLIER=atoi(value_buf);// } else{ } sprintf(key_buf,"WRITE_CONSTANT_UPS%d",i+1); if(getValue(&config_file,key_buf,value_buf)){ _2023ups[i].WRITE_CONSTANT=atoi(value_buf);// } else{ } } #ifdef _DEBUG_ printf("%d %d %d %d\n\n",_2023ups[0].LINK_COM_NUM,_2023ups[1].LINK_COM_NUM,_2023ups[2].LINK_COM_NUM,_2023ups[3].LINK_COM_NUM); for(int i=0;i<NUM_OF_UPS;i++){ printf("%d %d %d %d %d\n",_2023ups[i].READ_INTERVAL,_2023ups[i].READ_MULTIPLIER,_2023ups[i].READ_CONSTANT,\ _2023ups[i].WRITE_MULTIPLIER,_2023ups[i].WRITE_CONSTANT); } #endif free(value_buf); free(key_buf); while(config_file_ptr1!=NULL){ config_file_ptr2=config_file_ptr1; config_file_ptr1=config_file_ptr1->next; free(config_file_ptr2); } //3.初始化相应串口 char com[20]; for(int i=0;i<NUM_OF_UPS;i++){ //打开串口,配置相应参数 memset(com,0,20); if(_2023ups[i].LINK_COM_NUM > 0){ // _2023ups[i].LINK_COM_NUM从配置文件读取,>0有效 _2023ups[i].UPS_SET_ACTIVE=TRUE; //gtk_switch_set_active(itemValue[i][9],TRUE); //_2023ups[i].UPS_ALARM_ENABLE=TRUE; #ifdef _DEBUG_ printf("start com%d communication\n",_2023ups[i].LINK_COM_NUM); #endif sprintf(com,"\\\\.\\COM%d",_2023ups[i].LINK_COM_NUM); _2023ups[i].UPS_COM_HANDLE=initialCom(com,1024); if(_2023ups[i].UPS_COM_HANDLE == INVALID_HANDLE_VALUE){ //需要加入异常处理及日志记录 errorReport(); printf("Open Com%d Error shit\n",_2023ups[i].LINK_COM_NUM); // exit(0); } COMMTIMEOUTS timeouts={_2023ups[i].READ_INTERVAL,_2023ups[i].READ_MULTIPLIER,\ _2023ups[i].READ_CONSTANT,_2023ups[i].WRITE_MULTIPLIER,_2023ups[i].WRITE_CONSTANT}; if(setComTimeout(_2023ups[i].UPS_COM_HANDLE,timeouts)) printf("set com timeout ok\n"); //需要加入异常处理及日志记录 if(setComPara(_2023ups[i].UPS_COM_HANDLE,_24_N_8_1)) printf("set com parameter ok\n"); //需要加入异常处理及日志记录 } else { _2023ups[i].UPS_SET_ACTIVE=FALSE; } } GtkApplication *app; app = gtk_application_new ("org.gtk.ups_monitor_v3", G_APPLICATION_FLAGS_NONE); int status; g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); g_signal_connect (app, "startup", G_CALLBACK (startup), NULL); //5.创建一个线程,用来发送接收串口数据 // #ifndef NO_DATA_THREAD HANDLE sendDataThreadProc=CreateThread(NULL,0,sendDataViaCom,NULL,0,NULL); printf("Start data transmision\n"); // #endif status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return 0; }
void XQAccessPointManagerPrivate::storeWEPDataL(const TInt aIapId, const TDesC& aPresharedKey) { CCommsDbTableView* wLanServiceTable; CApUtils* apUtils = CApUtils::NewLC(*ipCommsDB); TUint32 iapId = apUtils->IapIdFromWapIdL(aIapId); CleanupStack::PopAndDestroy(apUtils); TUint32 serviceId; CCommsDbTableView* iapTable = ipCommsDB->OpenViewMatchingUintLC(TPtrC(IAP), TPtrC(COMMDB_ID), iapId); User::LeaveIfError(iapTable->GotoFirstRecord()); iapTable->ReadUintL(TPtrC(IAP_SERVICE), serviceId); CleanupStack::PopAndDestroy(iapTable); wLanServiceTable = ipCommsDB->OpenViewMatchingUintLC(TPtrC(XQ_WLAN_SERVICE), TPtrC(XQ_WLAN_SERVICE_ID), serviceId); TInt errorCode = wLanServiceTable->GotoFirstRecord(); if (errorCode == KErrNone) { User::LeaveIfError(wLanServiceTable->UpdateRecord()); } else { TUint32 dummyUid = 0; User::LeaveIfError(wLanServiceTable->InsertRecord(dummyUid)); wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_SERVICE_ID), aIapId); } CleanupCancelPushL(*wLanServiceTable); // Save index of key in use TUint32 keyInUse(KFirstWepKey); wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_INDEX), keyInUse); // Save authentication mode TUint32 auth(0); // set to open... if (isS60VersionGreaterThan3_1()) { //TODO: wLanServiceTable->WriteUintL(TPtrC(NU_WLAN_AUTHENTICATION_MODE), auth); } else { wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_AUTHENTICATION_MODE), auth); } // not we need to convert the key.... to 8bit and to hex... and again detect the required bits.. TBuf8<KMaxWepKeyLen> key; //convert to 8 bit key.Copy(aPresharedKey); TBool useHex(EFalse); TWepKeyLength keyLength; TBool validKey = validWepKeyLength(aPresharedKey, useHex, keyLength); if (!useHex) { // Must be converted to hexa and stored as a hexa // Ascii key is half the length of Hex HBufC8* buf8Conv = HBufC8::NewLC(key.Length() * 2); asciiToHex(key, buf8Conv); if (isS60VersionGreaterThan3_1()) { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY1), buf8Conv->Des()); } else { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY1), buf8Conv->Des()); } CleanupStack::PopAndDestroy(buf8Conv); } else if (isHex(aPresharedKey)) { //already in hexa format if (isS60VersionGreaterThan3_1()) { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY1), key); } else { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY1), key); } } wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY1_FORMAT), useHex); key.Zero(); // write default values to the rest of the columns if (isS60VersionGreaterThan3_1()) { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY2), key); } else { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY2), key ); } // Save third WEP key if (isS60VersionGreaterThan3_1()) { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_HEX_WEP_KEY3), key); } else { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY3), key); } // Save fourth WEP key if (isS60VersionGreaterThan3_1()) { //TODO: wLanServiceTable->WriteTextL(TPtrC(NU_WLAN_WEP_KEY4), // key); } else { wLanServiceTable->WriteTextL(TPtrC(XQ_WLAN_WEP_KEY4), key); } wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY2_FORMAT), (TUint32&)useHex); wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY3_FORMAT), (TUint32&)useHex); wLanServiceTable->WriteUintL(TPtrC(XQ_WLAN_WEP_KEY4_FORMAT), (TUint32&)useHex); wLanServiceTable->PutRecordChanges(); CleanupStack::Pop(wLanServiceTable); // table rollback... CleanupStack::PopAndDestroy(wLanServiceTable); }
void cmd_dataHandler(u08 input) { uart_send_char (input); if (command) { parameter[paramIndex++] = input; paramsRemaining--; if (paramsRemaining == 0) { u08 which = (parameter[0] == '0' ? 0 : 1); switch (command) { /* Set display 0 character - a<char> */ case 'a': dm_setChar(0, parameter[0]); break; /* Set display 1 character - A<char> */ case 'A': dm_setChar(1, parameter[0]); break; /* Blank character - b<01> */ case 'b': dm_blank(which); break; /* Unblank character - b<01> */ case 'B': dm_unBlank(which); break; /* Enable Custom character - c<01> */ case 'c': dm_displayProgrammed(which, 1); break; /* Disable Custom character - C<01> */ case 'C': dm_displayProgrammed(which, 0); break; /* Dim display - d<01> */ case 'd': dm_setDim(which, 1); break; /* Undim display - D<01> */ case 'D': dm_setDim(which, 0); break; /* Flip display - f<01> */ case 'f': dm_setFlip(which, 1); break; /* Unflip display - F<01> */ case 'F': dm_setFlip(which, 0); break; /* Invert display bits - i<01> */ case 'i': dm_setReverse(which, 1); break; /* Uninvert display bits - I<01> */ case 'I': dm_setReverse(which, 0); break; /* Set Pallete Index for display 0- l<index> */ /* This is ignored for single-color displays */ case 'l': dm_setPalette(0, asciiToHex(parameter[0], parameter[1])); break; /* Set Pallete Index for display 1- L<HH> */ /* This is ignored for single-color displays */ case 'L': dm_setPalette(1, asciiToHex(parameter[0], parameter[1])); break; /* Mirror display - m<01> */ case 'm': dm_setMirror(which, 1); break; /* Unmirror display M<01> */ case 'M': dm_setMirror(which, 0); break; /* Copy character to custom character 0 - p<hex> */ case 'p': dm_copyToCustom(0, asciiToHex(parameter[0], parameter[1])); break; /* Copy character to custom character 1 - P<hex> */ case 'P': dm_copyToCustom(1, asciiToHex(parameter[0], parameter[1])); break; /* Roll matrix n row<s> - r<01><udlr><n> */ case 'r': dm_roll(which, parameter[1], parameter[2] - '0'); break; /* Shift matrix <n> rows - s<01><udlr><n> */ case 's': dm_shift(which, parameter[1], parameter[2] - '0'); break; /* Turn on pixel in custom character - t<01><row><column> */ case 't': dm_pixel(which, 1, parameter[1] - '0', parameter[2] - '0'); break; /* Turn off pixel in custom character - T<01><row><column> */ case 'T': dm_pixel(which, 0, parameter[1] - '0', parameter[2] - '0'); break; /* Reset all transforms - !<01> */ case '!': dm_reset(which); break; /* Program custom character columns, display 0 - [01234]<HexHex> */ case '0': case '1': case '2': case '3': case '4': dm_progColumn(0, command - '0', asciiToHex(parameter[0], parameter[1])); break; /* Program custom character columns, display 1 - [56789]<data> */ case '5': case '6': case '7': case '8': case '9': dm_progColumn(1, command -'5', asciiToHex(parameter[0], parameter[1])); break; } command = 0; paramIndex = 0; } return; } paramsRemaining = 0; paramIndex = 0; switch (input) { case 'a': case 'A': case 'b': case 'B': case 'c': case 'C': case 'd': case 'D': case 'f': case 'F': case 'i': case 'I': case 'm': case 'M': case 'R': case '!': command = input; paramsRemaining = 1; break; case 'p': case 'P': case 'l': case 'L': command = input; paramsRemaining = 2; break; case 'r': case 's': case 't': case 'T': command = input; paramsRemaining = 3; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': command = input; paramsRemaining = 2; break; case '*': _wdt_write(1); break; case '?': dm_dumpdisp(0); dm_dumpdisp(1); break; default: command = 0; break; } }