/* Show the result of the CLASS/COMMAND statistics */ void t0ShowStatistics(int cardType, int *claInsStatistics, int *fileStatistics, int *swStatistics) { int i; int highByte; int lowByte; int framecount = 0; char outputBuffer[1024]; sprintf(outputBuffer,"\r\n"); logfilePut(outputBuffer); printf("%s",outputBuffer); sprintf(outputBuffer,"CLA/INS statistics:\r\n"); logfilePut(outputBuffer); printf("%s",outputBuffer); sprintf(outputBuffer," CLA: INS: QTY:\r\n"); logfilePut(outputBuffer); printf("%s",outputBuffer); for(i=0; i<0x10000;i++) { if(claInsStatistics[i] != 0) { highByte = (i >> 8) & 0xFF; lowByte = i & 0xFF; sprintf(outputBuffer," %02hhx %02hhx %-10i\r\n",highByte, lowByte, claInsStatistics[i]); logfilePut(outputBuffer); printf("%s",outputBuffer); decodeCommand(highByte, lowByte, cardType, 0); framecount+=claInsStatistics[i]; } }
WL_API int decodeIR(struct ir_remote *remotes, char *out) { //wait till data is ready if(receive) { if(!receive->waitTillDataIsReady(0)) { return 0; } last = end; gettimeofday(&start,NULL); receive->getData(&irCode); gettimeofday(&end,NULL); if(decodeCommand(remotes,out)) { ResetEvent(dataReadyEvent); return 1; } ResetEvent(dataReadyEvent); } return 0; }
/** * @brief bossTask * @param argument */ void StartBossTask(void const * argument) { // Start receiving data via USB UART cHAL_UART_TermReceive_IT(&huart1, 512); cHAL_UART_TermReceive_IT(&huart2, 512); msg_genericMessage_t rxMessage; // If in AUTO mode, set off a WIFI startup // if (globalFlags.states.commState == COMM_STATE_AUTO) { // sendCommand(msgQBoss, MSG_SRC_BOSS_TASK, MSG_CMD_WIFI_INIT, // osWaitForever); // } /* Infinite loop */ for (;;) { fetchMessage(msgQBoss, &rxMessage, 0); switch (rxMessage.messageType) { case MSG_TYPE_NO_MESSAGE: break; case MSG_TYPE_COMMAND: interpretCommand(decodeCommand(&rxMessage)); break; default: break; } } }
static void ICACHE_FLASH_ATTR processRxFunc(RcvMsgBuff *rxBfr) { char *bfr = readRx(rxBfr); while (bfr != NULL) { // TESTP("bfr: %s\n", bfr); decodeCommand(bfr); bfr = readRx(rxBfr); } }
WL_API int decodeIR(struct ir_remote *remotes, char *out) { if(sendReceiveData) { if(!sendReceiveData->waitTillDataIsReady(0)) { return 0; } clear_rec_buffer(&hw); if(decodeCommand(&hw,remotes,out)) { return 1; } } return 0; }
static void commandDecoder() { decoderCurrBufferPos = 0; char com2Name[] = IOSERVERCOM2_NAME; com2 = WhoIs(com2Name); char randomName[] = RANDOM_CONTROL_NAME; randomController = WhoIs(randomName); char trainControllerName[] = TRAIN_CONTROLLER_NAME; trainController = WhoIs(trainControllerName); char trackControllerName[] = TRACK_NAME; trackController = WhoIs(trackControllerName); char uiName[] = UI_TASK_NAME; ui = WhoIs(uiName); char sensorServerName[] = SENSOR_NAME; sensorServer = WhoIs(sensorServerName); char timeServerName[] = TIMESERVER_NAME; timeServer = WhoIs(timeServerName); char snakeDirectorName[] = SNAKE_DIRECTOR_NAME; snakeDirector = WhoIs(snakeDirectorName); UiMsg msg; msg.type = PROMPT_CHAR; for (;;) { char c = Getc(com2); msg.data3 = c; if (c == RETURN) { decodeCommand(); msg.data2 = 1; // Move cursor to clear line. Send(ui, (char*)&msg, sizeof(UiMsg), (char*)1, 0); } else { if (decoderCurrBufferPos > 0 && c == BACKSPACE) { --decoderCurrBufferPos; msg.data2 = decoderCurrBufferPos+1; Send(ui, (char*)&msg, sizeof(UiMsg), (char*)1, 0); } else if (decoderCurrBufferPos < DECODER_BUFFER_SIZE) { if (( c >= '0' && c <= '9' ) || ( c >= 'a' && c <= 'z' ) || ( c >= 'A' && c <= 'Z' ) || c == ' ') { decoderBuffer[decoderCurrBufferPos] = c; ++decoderCurrBufferPos; msg.data2 = decoderCurrBufferPos; Send(ui, (char*)&msg, sizeof(UiMsg), (char*)1, 0); } } } } }
WL_API int decodeIR( struct ir_remote *remotes, char *out ) { if(sendReceiveData) { if(!sendReceiveData->waitTillDataIsReady(0)) { return 0; } if(decodeCommand(&hw,remotes,out)) { ResetEvent(dataReadyEvent); return 1; } ResetEvent(dataReadyEvent); } return 0; }
int main(void) { bool isRunning = true; char* pUserInput; char* userInput = NULL; item* it = NULL; userInput = malloc(sizeof(char)*1024); assert(userInput != NULL); pUserInput = userInput; performRotCheck(); system(CALL_DOWNLOAD_SCRIPT); while(isRunning) { printf(">>"); char command = 0; fgets(userInput, MAX_COMMAND_LEN-1, stdin); if(!decodeCommand(userInput, &command)) { printf("\tCommand error.\n"); continue; } else if(command != 0) { it = parseItem(userInput); if(it == NULL) { printf("The creation of item you provided was not successful.\n"); continue; } if(!performCommand(command, it)) { fprintf(stderr, "Error.\n"); } } else { isRunning = false; } releaseItem(&it); } free(pUserInput); }
/* Analyse T=0 Protocol traffic */ bool t0Analysis(const int byte, const int offset, int *errorCounter, int *claInsStatistics, int *fileStatistics, int *swStatistics, int cardtype) { static int i_offsetCount = 0; static int i_byteCount = 0; static int i_bodyLength = 0; static int i_statusLength = 0; static int if_dataHistroy[257]; static int i_commandType = 0; bool statusReport; char outputBuffer[1000]; memset(outputBuffer,0,sizeof(outputBuffer)); if(i_offsetCount == offset) { i_byteCount++; if_dataHistroy[i_byteCount] = byte & 0xFF; /* Store data for later use */ if((i_byteCount == 5)&&(i_bodyLength == 0)) /* Header complete */ { sprintf(outputBuffer,"\r\n" " ==> Header: Class Byte (CLA) = %02hhx\r\n" " Instruction Byte (INS) = %02hhx\r\n" " Parameter (P1) = %02hhx\r\n" " Parameter (P2) = %02hhx\r\n" " Parameter (P3/LE) = %02hhx\r\n", if_dataHistroy[1], if_dataHistroy[2], if_dataHistroy[3], if_dataHistroy[4], if_dataHistroy[5]); printf("%s", outputBuffer); logfilePut(outputBuffer); /* Try to decode CLA/INS bytes */ i_commandType = decodeCommand(if_dataHistroy[1],if_dataHistroy[2],cardtype,claInsStatistics); sprintf(outputBuffer,"\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); i_byteCount = 0; i_bodyLength = byte; if(byte == 0) i_statusLength = 2; /* defined by ISO7816 */ statusReport = true; } else if((i_byteCount == 1)&&(i_bodyLength != 0)&&(i_statusLength == 0)&&(i_bodyLength != 0)) { sprintf(outputBuffer,"\r\n ==> ACK (should be lways the same as the INS byte!)\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); if(if_dataHistroy[2] != if_dataHistroy[1]) { sprintf(outputBuffer," Transmission or analysis error, INS byte is not equal to ACK byte!\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); } sprintf(outputBuffer,"\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); if(if_dataHistroy[2] != if_dataHistroy[1]) { i_byteCount = 0; i_bodyLength = 0; i_statusLength = 0; statusReport = true; sprintf(outputBuffer,"\r\n==> TRANSMISSION OR ANALYSIS FAILED!\r\n\r\n\r\n\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); (*errorCounter)++; } statusReport = true; } else if((i_byteCount == i_bodyLength+1)&&(i_bodyLength != 0)&&(i_statusLength == 0)) { sprintf(outputBuffer,"\r\n ==> Body (Contains the transmitted data)\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); /* If the current command is a select command, try to decode the meaning of the file */ if(i_commandType == COMMAND_TYPE_SELECT) decodeFile(if_dataHistroy[2],if_dataHistroy[3],cardtype,fileStatistics); sprintf(outputBuffer,"\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); i_byteCount = 0; i_bodyLength = 0; i_statusLength = 2; /* defined by ISO7816 */ statusReport = true; }else if((i_byteCount == i_statusLength)&&(i_statusLength != 0)) { sprintf(outputBuffer,"\r\n" " ==> Status: status word 1 = (SW1) %02hhx\r\n" " status word 2 = (SW2) %02hhx\r\n", if_dataHistroy[1],if_dataHistroy[2]); printf("%s",outputBuffer); logfilePut(outputBuffer); decodeStatusword(if_dataHistroy[1],if_dataHistroy[2], cardtype, swStatistics); i_byteCount = 0; i_bodyLength = 0; i_statusLength = 0; statusReport = true; sprintf(outputBuffer,"\r\n==> TRANSMISSION COMPLETE!\r\n\r\n\r\n\r\n"); printf("%s",outputBuffer); logfilePut(outputBuffer); } else statusReport = false; } else { i_offsetCount++; statusReport = false; } return statusReport; }