From 09cd981711dc1cf44877ac7ece51e26071da97ec Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sat, 21 Dec 2024 17:39:20 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0pud=E8=A7=A3=E7=A0=81=E6=94=AF?= =?utf8?q?=E6=8C=81=E9=95=BF=E7=9F=AD=E4=BF=A1=E8=A7=A3=E7=A0=81=E5=8F=8A?= =?utf8?q?=E8=8B=B1=E6=96=87=E7=9F=AD=E4=BF=A1=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/drivers/peripheral/utils/pdu.c | 234 +++++++++++++++++++++--- 1 file changed, 206 insertions(+), 28 deletions(-) diff --git a/code/sdk/drivers/peripheral/utils/pdu.c b/code/sdk/drivers/peripheral/utils/pdu.c index cff60cbb9..f793b1a0f 100644 --- a/code/sdk/drivers/peripheral/utils/pdu.c +++ b/code/sdk/drivers/peripheral/utils/pdu.c @@ -161,6 +161,42 @@ int strHex2bytearray(char *inputHexstr, char *output_bytes, int *max_output_byte } +void GetASCIICode7Bit(uint8_t*pTempInt, int nlen,char *out_char) +{ + int i=0, j=0; + int Point=0;//每7次就转换出8个ASCII码 + for(i=0; j>(8-Point)) & 0x7F; + } + + + out_char[j]=nRet; + printf("GetASCIICode7Bit:%c %02X\r\n",nRet,nRet); + if(Point==6)//每7位可以多转换一个ASCII码 + { + j++; + nRet = (pTempInt[i]>>1)&(0x7F); + out_char[j]=nRet; + } + + Point=(Point+1)%7; + } + + return ; +} + + int pdu_decode(unsigned char* buffer, int buffer_length, struct tm* output_sms_time, int* output_sms_zone,time_t *output_sms_timestamp, char* output_sender_phone_number, int sender_phone_number_size, @@ -178,12 +214,24 @@ int pdu_decode(unsigned char* buffer, int buffer_length, printf("delive_start +1 > buffer_len\n"); return -2; } + //0000 00100 + // + uint8_t have_sms_head=0; + if ((buffer[sms_deliver_start] & SMS_DELIVER_ONE_MESSAGE) != SMS_DELIVER_ONE_MESSAGE) { - printf("buffer[%d]=%02X",sms_deliver_start,buffer[sms_deliver_start]); - return -3; + printf("buffer[%d]=%02X\r\n",sms_deliver_start,buffer[sms_deliver_start]); + //return -3; + } + //如果bit6为1则表示后面有消息头 + if((buffer[sms_deliver_start] & 0b01000000)) + { + have_sms_head++; + printf("have have_sms_head\r\n"); } + + const int sender_number_length = buffer[sms_deliver_start + 1]; if (sender_number_length + 1 > sender_phone_number_size) { @@ -194,6 +242,13 @@ int pdu_decode(unsigned char* buffer, int buffer_length, DecodePhoneNumber(buffer + sms_deliver_start + 3, sender_number_length, output_sender_phone_number); const int sms_pid_start = sms_deliver_start + 3 + (buffer[sms_deliver_start + 1] + 1) / 2; + + uint8_t is_uint8_bit=0; + + if(buffer[sms_pid_start+1]==0) + { + is_uint8_bit++; + } #if 0 // Decode timestamp. struct tm sms_broken_time; @@ -220,22 +275,41 @@ int pdu_decode(unsigned char* buffer, int buffer_length, (*output_sms_timestamp) = mktime(output_sms_time) ; #endif - const int sms_start = sms_pid_start + 2 + 7; + int sms_start = sms_pid_start + 2 + 7; if (sms_start + 1 > buffer_length) return -5; // Invalid input buffer. const int output_sms_text_length = buffer[sms_start]; if (sms_text_size < output_sms_text_length) return -6; // Cannot hold decoded buffer. // printf("output_sms_text_length %d, index %d\n",output_sms_text_length,sms_start + 1); - + + if(have_sms_head) + { + //有消息头 + sms_start=sms_start+buffer[sms_pid_start+2+7+1]+1; + + } unsigned char * unicodebuf=buffer+sms_start+1; int unicodebuflen=buffer_length-(sms_start+1); char * utf8p=output_sms_text; - int jj; - for(jj=0; jj < unicodebuflen/2;jj++){ - uni2utf8((const uint8_t *)(unicodebuf+jj*2),&utf8p); + + //if() + int decoded_sms_text_size; + if(is_uint8_bit==0) + { + int jj; + for(jj=0; jj < unicodebuflen/2;jj++){ + uni2utf8((const uint8_t *)(unicodebuf+jj*2),&utf8p); + } + decoded_sms_text_size = (utf8p - output_sms_text); } - int decoded_sms_text_size = (utf8p - output_sms_text); + else + { + printf("GetASCIICode7Bit %d\r\n",output_sms_text_length); + GetASCIICode7Bit((uint8_t *)unicodebuf,output_sms_text_length,utf8p); + decoded_sms_text_size=output_sms_text_length; + } + // const int decoded_sms_text_size = DecodePDUMessage(buffer + sms_start + 1, buffer_length - (sms_start + 1), // output_sms_text, output_sms_text_length); @@ -247,6 +321,17 @@ int pdu_decode(unsigned char* buffer, int buffer_length, else output_sms_text[sms_text_size-1] = 0; + // if() + // { + // printf("长短信\r\n"); + // // output_sms_text[0]=output_sms_text[0]<<1; + // // if (decoded_sms_text_size < sms_text_size) + // // memmove(&output_sms_text[0],&output_sms_text[9],decoded_sms_text_size-6); + // // else + // // memmove(&output_sms_text[0],&output_sms_text[9],decoded_sms_text_size-7); + + // } + return decoded_sms_text_size; } @@ -299,15 +384,19 @@ pdustr len 45,phonenumb:8615521469561 ,text:计划的好好的基金 ,txtlen:24, static uint32_t ancs_msg_index =0; -// typedef struct -// { -// uint32_t ref; -// uint16_t num; -// char *phone_number; -// char *text; -// }pdu_data; - -// static pdu_data[20]={0}; +typedef struct +{ + uint32_t ref; + uint16_t total_num; + uint16_t num; + uint16_t seq; + char *phone_number; + char *text; +}pdu_data; + +#define PDU_DATA_MAX 20 +static uint8_t pdu_flag=0; +static pdu_data pdu_data_t[PDU_DATA_MAX]={0}; int pdu_decode_example(const char *inpdustr, uint32_t ref,uint16_t num, uint16_t seq) { @@ -320,24 +409,113 @@ int pdu_decode_example(const char *inpdustr, uint32_t ref,uint16_t num, uint16_ int text_size=256; ret = pdu_decode_hexstr(inpdustr,&sms_broken_timestamp,phone_number,phone_number_size,text,text_size); - + if (ret <= 0) { printf("pdu_decode_hexstr Error %d",ret); - }else{ - printf(" recv sms phonenumber %s len %d, timestamp %d , smstxt %s len %d , pdu_decode_hexstr ret %d\n",phone_number,strlen(phone_number),sms_broken_timestamp,text,strlen(text),ret); - struct tm * timenow =localtime(&sms_broken_timestamp); - printf("receive timenow %04d-%02d-%02d %02d:%02d:%02d \n", - timenow->tm_year+1900, - timenow->tm_mon+1, - timenow->tm_mday, - timenow->tm_hour, - timenow->tm_min, - timenow->tm_sec); + return -1; + } + + pdu_data_t[pdu_flag].ref=ref; + pdu_data_t[pdu_flag].total_num=num; + if(pdu_data_t[pdu_flag].phone_number) + { + free(pdu_data_t[pdu_flag].phone_number); + pdu_data_t[pdu_flag].phone_number=NULL; + } + pdu_data_t[pdu_flag].phone_number=malloc(strlen(phone_number)+1); + memset(pdu_data_t[pdu_flag].phone_number,0,strlen(phone_number)+1); + memcpy(pdu_data_t[pdu_flag].phone_number,phone_number,strlen(phone_number)); + + if(pdu_data_t[pdu_flag].text) + { + free(pdu_data_t[pdu_flag].text); + pdu_data_t[pdu_flag].text=NULL; + } + + pdu_data_t[pdu_flag].text=malloc(strlen(text)+1); + memset(pdu_data_t[pdu_flag].text,0,strlen(text)+1); + memcpy(pdu_data_t[pdu_flag].text,text,strlen(text)); + + pdu_data_t[pdu_flag].seq=seq; + + if(pdu_data_t[pdu_flag].total_num==1) + { message_data(0,0,phone_number,text,0); + + free(pdu_data_t[pdu_flag].phone_number); + free(pdu_data_t[pdu_flag].text); + pdu_data_t[pdu_flag].ref=0; + + } + else + { + for(int i=0;i