int handleBatCmd(char* line, int cmdId) { int result = -1; int param = -1; char response[MAX_AT_RESPONSE]; LOGATCI(LOG_DEBUG, "line: %s", line); switch(cmdId) { case 0: result = AT_get_charging_state_flag(); break; case 1: result = AT_get_bat_voltage(); break; case 2: result = AT_set_Charger_Current(CUT_CHARGER_CURRENT); break; default: LOGATCI(LOG_DEBUG, "atcid not support this at command: %s", line); } if(result != -1) { sprintf(response, "%d\r\nOK\r\n\0", result); writeDataToSerial(response, strlen(response)); } else { sprintf(response, "ERROR\r\n\0"); writeDataToSerial(response, strlen(response)); } return result; }
// Writes image data to a file on the non-temporary storage (ie. HDD or flash // memory) of the device running this sofware. void* writeImageContentToFile(void* args) { struct threadArgs* inputs = (struct threadArgs*)args; int nodeCtr = 0; struct lstnode* node = inputs->cNode; pthread_mutex_t* mutex = inputs->mutex; free(args); int fd = openPort(); // open the serial port while(TRUE) { byte* buf = (byte*)malloc(6); // allocate buffer for meta data if(read(fd, buf, 6) == 6) // read meta data { pthread_mutex_lock(mutex); // lock so other thread can't change ptrs printf("Received: %s\n", buf); struct telpkt* tp = decode(buf, 5); // create telemetry pkt if(node->size > 0) node = writeDataToSerial(tp, fd, node, nodeCtr); free(tp); pthread_mutex_unlock(mutex); } free(buf); } free(inputs); pthread_exit(NULL); }
int custom_command_hdlr(char* line){ int i = 0, ret = 0; int table_size = 0; char response[MAX_AT_RESPONSE]; char* line_cut = cut_cmd_line(line); memset(response, 0, sizeof(response)); table_size = (sizeof(custom_cmd_table)/sizeof(customcmd_type)); for(i = 0; i < table_size;i++){ LOGATCI(LOG_DEBUG, "custom_cmd_table[%d].cmdName = %s", i, custom_cmd_table[i].cmdName); if(strcmp(line_cut, custom_cmd_table[i].cmdName) == 0){ ATOP_t at_op = getAtOp(&line); LOGATCI(LOG_DEBUG, "The command op is %d; Support op is %d", at_op, custom_cmd_table[i].opType); if((at_op & custom_cmd_table[i].opType) == 0){ writeDataToserialByResponseType(AT_NOT_IMPL); }else{ ret = custom_cmd_table[i].cmd_handle_func(line, at_op, response); if(strlen(response) > 0){ writeDataToSerial(response, strlen(response)); } if(ret != AT_NONE_OP){ writeDataToserialByResponseType(ret); } } free(line_cut); return 1; //The command is handled here } } free(line_cut); return 0; }
int handleBspCmd(char* cmdData, int cmdId){ cmd_data_type cmd_data; int fd = -1, result = -1; ATOP_t at_op; char response[MAX_AT_RESPONSE]; LOGATCI(LOG_DEBUG,"Enter with cmdId:%d", cmdId); at_op = getAtOp(&cmdData); LOGATCI(LOG_DEBUG, "The command op is %d; Support op is %d", at_op, bsp_cmd_table[cmdId].opType); memset(response, 0, sizeof(response)); if((at_op & bsp_cmd_table[cmdId].opType) != 0){ //Open the FD to handle LOGATCI(LOG_DEBUG, "Open FD: %s", bsp_cmd_table[cmdId].devPath); fd = open(bsp_cmd_table[cmdId].devPath, O_RDWR); if(fd < 0){ LOGATCI(LOG_ERR, "Fail to open FD with errno:%d", errno); writeDataToserialByResponseType(AT_ERROR); return 0; } //Initalize the cmd data structure memset(cmd_data.cmdDataRequest, 0, sizeof(cmd_data.cmdDataRequest)); memset(cmd_data.cmdDataResponse, 0, sizeof(cmd_data.cmdDataResponse)); strcpy(cmd_data.cmdDataRequest, cmdData); cmd_data.opType = at_op; //Send IOControl to device driver result = ioctl(fd, bsp_cmd_table[cmdId].cmdId, &cmd_data); if(result < 0){ LOGATCI(LOG_ERR, "Fail to IO Control[%d] with errno:%d", bsp_cmd_table[cmdId].cmdId, errno); writeDataToserialByResponseType(AT_ERROR); return 0; } if(strlen(cmd_data.cmdDataResponse) > 0){ sprintf(response, "\r\n%s\r\n", cmd_data.cmdDataResponse); writeDataToSerial(response, strlen(response)); } }else{ writeDataToserialByResponseType(AT_NOT_IMPL); } return 0; }
ATRESPONSE_t pas_esuo_handler(char* cmdline, ATOP_t opType, char* response){ int err = 0, cmdID = 0; char simIDProperty[PROPERTY_VALUE_MAX]; int simID = 0; LOGATCI(LOG_DEBUG, "pas_esuo_handler enter with opType: %d", opType); switch(opType){ case AT_SET_OP: err = at_tok_nextint(&cmdline, &cmdID); if (err < 0) return -1; if(cmdID == 4){ //Configure the default SIM to SIM1 property_set(ATCI_SIM, "0"); LOGATCI(LOG_DEBUG, "Set default to SIM1"); return AT_OK; }else if(cmdID == 5){ //Configure the default SIM to SIM2 property_set(ATCI_SIM, "1"); LOGATCI(LOG_DEBUG, "Set default to SIM2"); return AT_OK; } break; case AT_TEST_OP: writeDataToSerial("+ESUO: (4-5)", strlen("+ESUO: (4-5)")); return AT_OK; break; case AT_READ_OP: property_get(ATCI_SIM, simIDProperty, "0"); simID = atoi(simIDProperty); if(simID == 1){ strcpy(response, "+ESUO:5\r\n"); }else{ strcpy(response, "+ESUO:4\r\n"); } return AT_OK; break; default: break; } return AT_ERROR; }