//===================================================================== //====== The Following functions are used to read 7K AI modules. === //====== You can copy the following functions to your own program. === //===================================================================== int Read7K87KAI_Config(int iComPort, int iAddress, int iCheckSum, int iTimeout, int *iRangeCode_Original, int *iFilter_Original, int *iDataFormat_Original) { /* DCON protocol to read the AI Configuration Send command: $AA2 valid Response: !AATTCCFF iComPort: 1~8 iAddress: 0 ~ 255 iCheckSum: 0=Disable or 1=Enable iTimeout: unit=ms *iRangeCode_Original: pointer to record original range code For detailed specifications, refer to CD:8000\Napdos\DCON\IO_Module\hw_dcon_on_87kUnit CD:8000\Napdos\7000\Manual *iFilter_Original: pointer to record original filter setting 0 = 60Hz rejection 1 = 50Hz rejection This setting is reserved for the I-87015/I-87015T and should be zero. *iDataFormat_Original: pointer to record original data format 0 = Engineer Unit Format 1 = % of FSR Format 2 = 2's Complement Hexdecimal Format 3 = Ohms in Engineer Unit Format For I-87013 Only */ unsigned char InBuf[20],OutBuf[20]; int iRet; sprintf(OutBuf,"$%02X2",iAddress); iRet=SendCmdTo7000(iComPort,OutBuf,iCheckSum); iRet=ReceiveResponseFrom7000_ms(iComPort ,InBuf,iTimeout,iCheckSum); if(iRet==NoError) { if(InBuf[0]== '!') //Valid response first character: ! { *iRangeCode_Original= ((ascii_to_hex(InBuf[3])<<4)&0xF0) +(ascii_to_hex(InBuf[4])&0xF); *iFilter_Original=((ascii_to_hex(InBuf[7])&0xF)>>3); *iDataFormat_Original= (ascii_to_hex(InBuf[8])&0xF); return NoError; } else return -1; //Response string error.
// Key reader function to turn key into hex so we can use it void readKey(char* key,char* output){ //printf("Key: %s\n",key); unsigned char firstBit,secondBit; unsigned char sum,hexOutput[16]; int i,j; for(j = 0; j < 8; j++) { for(i = j*2;i < (j*2) + 1;i++) { firstBit = ascii_to_hex((unsigned char)key[i]); secondBit = ascii_to_hex((unsigned char)key[i+1]); sum = firstBit<<4 | secondBit; hexOutput[j] = sum; //printf("%02x\n",finalHex[j]); } } memcpy(output,hexOutput,8); }//end keyRead
int main(int argc, char *argv[]) { char str[256]; int i=0; unsigned char val; int offset; while(argc != 3){ return 0; } memcpy(str, argv[1], strlen(argv[1])); str[strlen(argv[1])] = '\0'; memcpy(filename, argv[2], strlen(argv[2])); filename[strlen(argv[2])] = '\0'; //printf("Please enter file name\n"); //scanf("%s",filename); //printf("Please enter byte pattern to match\n"); //scanf("%s",str); length = strlen(str); if(length %2 != 0) { //printf("invalid pattern length\n"); goto DONE; } /*Convert ascii to hex, check for invalid characters*/ for(i=0;i<length;i++) { val = ascii_to_hex(str[i]); if(val == 0xff) { //printf("Invalid character\n"); goto DONE; } else { if((i&1) == 0) val <<= 4; pattern[i>>1] |= val; } } length = length/2; offset = findOffset(); if(offset != -1) printf("%d\n",offset); DONE: if(buffer) free(buffer); return 0;
/* * Letters (A–Z and a–z), numbers (0–9) and the characters '.','-','~' and '_' are left as-is * SPACE is encoded as '+' or "%20" [8] * All other characters are encoded as %HH hex representation with any non-ASCII characters * first encoded as UTF-8 (or other specified encoding) * The octet corresponding to the tilde ("~") character is often encoded as "%7E" by older * URI processing implementations; the "%7E" can be replaced by "~" without changing its interpretation. * * The encoding of SPACE as '+' and the selection of "as-is" characters distinguishes this encoding from RFC 1738. */ static char * url_decode(char * encoded, const size_t length) { char * decoded = malloc(sizeof(char) * length + 1); size_t decoded_index = 0; size_t encoded_index = 0; while (encoded_index < length) { unsigned char c = encoded[encoded_index++]; if (c == '+') { decoded[decoded_index++] = ' '; } else if (c == '%' && encoded_index + 2 <= length) { unsigned char digit1 = ascii_to_hex(encoded[encoded_index++]); unsigned char digit2 = ascii_to_hex(encoded[encoded_index++]); unsigned char decimal = (digit1 << 4) | digit2; decoded[decoded_index++] = decimal; } else { decoded[decoded_index++] = c; } } decoded[decoded_index] = '\0'; return decoded; }
static void select_miu(U8 u8MiuIdx, const char* cStr) { if (cStr) { int i = 0; int j = 0; int length = 0; for (;;) { if (':' == cStr[i]) { ++length; } if ('\0' == cStr[i]) { ++length; // length is ':' number and priority number need add one more. break; } ++i; } i = 0; j = 0; U16 au16SelMiu[MIU_MAX_GP_NUM] = {0}; for (;;) { au16SelMiu[j++] = ascii_to_hex(&cStr[i], 4); i += 5; if (length == j) { break; } } MDrv_MIU_SelectMIU_UBoot (u8MiuIdx, au16SelMiu, length); } }
fm_s32 cfg_item_match(fm_s8 *src_key, fm_s8 *src_val, fm_s8 *dst_key, fm_s32 *dst_val) { fm_s32 ret = 0; fm_u16 tmp_hex; fm_s32 tmp_dec; /* WCN_DBG(FM_NTC|MAIN,"src_key=%s,src_val=%s\n", src_key,src_val); */ /* WCN_DBG(FM_NTC|MAIN,"dst_key=%s\n", dst_key); */ if (strcmp(src_key, dst_key) == 0) { if (strncmp(src_val, "0x", strlen("0x")) == 0) { src_val += strlen("0x"); /* WCN_DBG(FM_NTC|MAIN,"%s\n", src_val); */ ret = ascii_to_hex(src_val, &tmp_hex); if (!ret) { *dst_val = tmp_hex; /* WCN_DBG(FM_NTC|MAIN, "%s 0x%04x\n", dst_key, tmp_hex); */ return 0; } else { /* WCN_DBG(FM_ERR | MAIN, "%s format error\n", dst_key); */ return 1; } } else { ret = ascii_to_dec(src_val, &tmp_dec); if (!ret /*&& ((0 <= tmp_dec) && (tmp_dec <= 0xFFFF)) */) { *dst_val = tmp_dec; /* WCN_DBG(FM_NTC|MAIN, "%s %d\n", dst_key, tmp_dec); */ return 0; } else { /* WCN_DBG(FM_ERR | MAIN, "%s format error\n", dst_key); */ return 1; } } } /* else */ /* { */ /* WCN_DBG(FM_ERR | MAIN, "src_key!=dst_key\n"); */ /* } */ return -1; }
/****************************************************************************** 函数名称:TimeModify 功能描述:要求输入时间,进行修改 参数描述: 参数名称: 输入/输出? 类型 描述 返 回 值:无 作 者 :许岩 日 期:2004-09-02 修改历史: 日期 修改人 修改描述 ------ --------- ------------- ******************************************************************************/ void TimeModify(void) { INT8U i = 0; INT8U input[50]; INT8U buf[50]; BUS_TIME ltime; for (;;) { EA_vCls(); Get_Time(<ime); EA_vDisp(1, 1, "当前时间:"); sprintf((void *)buf, "%02X%02X-%02X-%02X-%02X:%02X:%02X", ltime.century, ltime.year, ltime.month, ltime.day, ltime.hour, ltime.minute, ltime.second); EA_vDisp(2, 1, (void *)buf); EA_vDisp(3, 1, "请输入新的时间:"); (void)EA_ucClrKeyBuf(); strcpy((void *)input, ""); i = EA_ucGetInputStr(4, 1, 20, EM_BIG_FONT | EM_MODE_NUMBER | EM_ALIGN_LEFT | EM_SHOW_ORIGINALLY , 14, 14, 0, (void *)input); // sprintf(dbuf, "%s", input); // EA_vDisp(3, 1, dbuf); // sprintf(dbuf, "result:%02X", i); // EA_vDisp(4, 1, dbuf); if ( i == EM_ABOLISH ) return; if ( i != EM_SUCCESS ) continue; ltime.century = (ascii_to_hex(input[0]) << 4) | ascii_to_hex(input[1]); ltime.year = (ascii_to_hex(input[2]) << 4) | ascii_to_hex(input[3]); ltime.month = (ascii_to_hex(input[4]) << 4) | ascii_to_hex(input[5]); ltime.day = (ascii_to_hex(input[6]) << 4) | ascii_to_hex(input[7]); ltime.hour = (ascii_to_hex(input[8]) << 4) | ascii_to_hex(input[9]); ltime.minute = (ascii_to_hex(input[10]) << 4) | ascii_to_hex(input[11]); ltime.second = (ascii_to_hex(input[12]) << 4) | ascii_to_hex(input[13]); i = CheckTimeFormat(<ime); if ( i != ok ) { EA_vCls(); EA_vDisp(4, 1, "时间格式错误"); SleepMs(1500); // EA_vCls(); continue; } Modify_Time(<ime); EA_vCls(); EA_vDisp(4, 1, "时间修改成功"); SleepMs(1500); break; } }
int uri_decoding(request *req, char *data) { static char *zero = "\0"; char *buf, *buf_end; register char chbuf; if (data == NULL) return -1; boa_dbg("req->query = %s\n", data); req->cmd_string = buf = (char *) malloc(MAX_CMD_LENGTH); if (buf == NULL) return -1; buf_end = buf+MAX_CMD_LENGTH-1; req->cmd_count = 0; req->cmd_arg[0].name = buf; req->cmd_arg[0].value = zero; do { int hex; chbuf = *data++; switch ( chbuf ) { case '+': chbuf = ' '; break; case '%': hex = ascii_to_hex((const unsigned char *)data); if ( hex > 0 ) { chbuf = (char)hex; data += 2; } break; case '\0': case '\n': case '\r': case ' ': *buf = '\0'; req->cmd_count++; return 0; } switch ( chbuf ) { case '&': req->cmd_count++; *buf++ = '\0'; req->cmd_arg[req->cmd_count].name = buf; req->cmd_arg[req->cmd_count].value = zero; break; case '=': *buf++ = '\0'; req->cmd_arg[req->cmd_count].value = buf; break; default: *buf++ = chbuf; break; } } while (buf < buf_end); *buf = '\0'; req->cmd_count++; return 0; }
/****************************************************************************** 函数名称:TimeModify 功能描述:要求输入时间,进行修改 参数描述: 参数名称: 输入/输出? 类型 描述 返 回 值:无 作 者 :许岩 日 期:2004-09-02 修改历史: 日期 修改人 修改描述 ------ --------- ------------- ******************************************************************************/ void TimeModify(void) { INT8U i = 0; INT8U input[50]; INT8U buf[50]; BUS_TIME ltime; for ( ;; ) { EA_vCls(); // Get_Time(<ime); EA_vDisp(1, 1, "当前生效时间:"); sprintf((void *)buf, " %02X:%02X ", DevStat.effect_time.hour, DevStat.effect_time.minute); EA_vDisp(2, 1, (void *)buf); EA_vDisp(3, 1, "请输入新的时间:"); (void)EA_ucClrKeyBuf(); strcpy((void *)input, ""); i = EA_ucGetInputStr(4, 8, 20, EM_BIG_FONT | EM_MODE_NUMBER | EM_ALIGN_LEFT | EM_SHOW_ORIGINALLY , 2, 2, 0, (void *)input); if ( i == EM_ABOLISH ) return; if ( i != EM_SUCCESS ) continue; i = EA_ucGetInputStr(4, 11, 20, EM_BIG_FONT | EM_MODE_NUMBER | EM_ALIGN_LEFT | EM_SHOW_ORIGINALLY , 2, 2, 0, (void *)input); if ( i == EM_ABOLISH ) return; if ( i != EM_SUCCESS ) continue; // sprintf(dbuf, "%s", input); // EA_vDisp(3, 1, dbuf); // sprintf(dbuf, "result:%02X", i); // EA_vDisp(4, 1, dbuf); ltime.hour = (ascii_to_hex(input[8]) << 4) | ascii_to_hex(input[9]); ltime.minute = (ascii_to_hex(input[11]) << 4) | ascii_to_hex(input[12]); if ( ltime.hour > 0x23 ) //小时应在0-23之间 return ; if ( ltime.minute > 0x59 ) //分钟应在0-59之间 return ; if ( (ltime.hour > 0x23) || (ltime.minute > 0x59) ) { EA_vCls(); EA_vDisp(4, 1, "时间格式错误"); SleepMs(1500); continue; } DevStat.effect_time.hour = ltime.hour; DevStat.effect_time.minute = ltime.minute; WriteParam(); EA_vCls(); EA_vDisp(4, 1, "生效时间修改成功"); SleepMs(1500); break; } }