123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #include "common.h"
- #include "ql_type.h"
- unsigned long htoi(char s[])
- {
- int i = 0;
- unsigned long long n = 0;
- if (s[0] == '0' && (s[1]=='x' || s[1]=='X')) i = 2;
- else i = 0;
- for (; (s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >='A' && s[i] <= 'Z');++i){
- if (tolower(s[i]) > '9') n = 16 * n + (10 + tolower(s[i]) - 'a');
- else n = 16 * n + (tolower(s[i]) - '0');
- }
- return n;
- }
- int GetParaFromStr(char *Str,char *Para,char *Value){
- int ValueLen=0,ParaLen=0;
- char ParaTemp[22];
- char *p;
- char d;
- int i=0;
- if(0==*Str || 0==*Para)return 0;
- while(0!=(d=*Para) && ParaLen<20){
- ParaTemp[i++]=d;
- if(d=='=' || d==';')return 0;
- Para++;
- ParaLen++;
- }
- ParaTemp[ParaLen++]='=';
- ParaTemp[ParaLen]=0;
- p=strstr(Str,ParaTemp);
- p+=ParaLen;
- //--
- while(*p>0x20 && ';'!=*p && ValueLen<=80){
- *Value=*p;
- p++;
- Value++;
- ValueLen++;
- }
- *Value=0;
- return ValueLen;
- }
- char msgCmp(char *msg, char *target){
- char *p1=target, *p2=msg;
- while(*p1 != 0){
- if(*p1 != *p2) return 0;
- p1++;p2++;
- }
- return 1;
- }
- // '56'->0X56
- unsigned char charStrToHex(char d1, char d2){
- unsigned char p1=d1;
- unsigned char p2=d2;
- if(p1>='0' && p1 <='9') p1 -= 0x30;
- else if(p1>='a' && p1 <='f') p1 -= 0x57;
- else if(p1>='A' && p1 <='F') p1 -= 0x37;
- else return 0;
- p1<<=4;p1&=0xF0;
-
- if(p2>='0' && p2 <='9') p2 -= 0x30;
- else if(p2>='a' && p2 <='f') p2 -= 0x57;
- else if(p2>='A' && p2 <='F') p2 -= 0x37;
- else return 0;
- return (p1|p2);
- }
- /*
- restoreDataFormatByHex
- "313233"=>{0x31,0x32,0x33}
- */
- unsigned char restoreDataFormatByHex(unsigned char *src, unsigned short len)
- {
- unsigned short i,j,k;
- unsigned char temp[2];
- if(0==src) return 1;
- j=0;
- for(i=0;i<len/2;i++){
- temp[0]=src[2*i];
- temp[1]=src[2*i+1];
- for(k=0;k<2;k++){
- if(temp[k]>='0' && temp[k]<='9') temp[k] -= 0x30;
- else if(temp[k]>='a' && temp[k]<='f') temp[k] -= 0x57;
- else if(temp[k]>='A' && temp[k]<='F') temp[k] -= 0x37;
- else return 2;
- }
- temp[0] <<= 4;
- temp[0] &= 0xF0;
- src[j++] = temp[0] | temp[1];
- }
- return 0;
- }
- /*
- 从长度为len的src缓存中查找第index个target,并返回下一个字节的索引
- src:缓存
- len:缓存长度
- target:要匹配的字节内容
- index:第几个target, 1,2,3,4.....
- return: < 0 失败,else, target后面一个字节的索引
- */
- int findByteFromStr(unsigned char *src, int len,unsigned char target,unsigned char index){
- int i;
- unsigned char num=0;
- for(i=0;i<len;i++){
- if(src[i]==target){
- if(++num==index) return i+1;
- }
- }
- return -1;
- }
- unsigned char AscToHex(unsigned char aHex)
- {
- if((aHex>=0)&&(aHex<=9))
- aHex += 0x30;
- else if((aHex>=10)&&(aHex<=15))//A-F
- //aHex += 0x37;
- aHex += 0x57;
- else aHex = 0xff;
- return aHex;
- }
- void AscStrTurnHexStr(char *AscStr, char *HexStr)
- {
- char *pAscStr=AscStr;
- unsigned char d,h,l;
- while(0!=(d=(unsigned char)*pAscStr++)){
- l=d&0x0f;
- h=d>>4;
- *HexStr++=AscToHex(h);
- *HexStr++=AscToHex(l);
- }
- *HexStr=0;
- }
- void LwEndingToBiEndingStr(char *data, int len){
- char tt[2];
- int i;
- for(i=0;i<len/4;i++){
- tt[0]=data[4*i];
- tt[1]=data[4*i+1];
- data[4*i]=data[4*i+2];
- data[4*i+1]=data[4*i+3];
- data[4*i+2]=tt[0];
- data[4*i+3]=tt[1];
- }
- }
- #include "ohpoc.h"
- MY_CLOCK poc_clock;
- char *ohpocGetICCID(void){
- static char ICCID[21];
- if(0==ql_sim_get_iccid(ICCID,sizeof(ICCID))){
- return &ICCID[0];
- }
- return NULL;
- //if(sutApp.ICCID[0]==0)return NULL;
- //return &sutApp.ICCID[0];
- };
- char *ohpocGetIMEI(void){
- static char IMEI[16];
- if(0==ql_dev_get_imei(IMEI,sizeof(IMEI))){
- return &IMEI[0];
- }
- return NULL;
-
- };
- void getMyClock(MY_CLOCK *myclock){
- myclock->year=poc_clock.year;
- myclock->month=poc_clock.month;
- myclock->day=poc_clock.day;
- myclock->hour=poc_clock.hour;
- myclock->min=poc_clock.min;
- myclock->sec=poc_clock.sec;
- }
- void ohpocGetClock(MY_CLOCK *myclock){
- //getMyClock(myclock);
- current_zone_time(myclock);
-
- };
|