A59 -V1.1版本提交
This commit is contained in:
162
app/moto/protocol/Bt_Interaction_protocol.c
Normal file
162
app/moto/protocol/Bt_Interaction_protocol.c
Normal file
@ -0,0 +1,162 @@
|
||||
#include "awtk.h"
|
||||
#include "conversation_protocol.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "chip.h"
|
||||
#include "board.h"
|
||||
#include "serial.h"
|
||||
#include "sysinfo.h"
|
||||
#include "user_data.h"
|
||||
#include "data_port.h"
|
||||
#include "universal.h"
|
||||
|
||||
|
||||
#define MAX_ENTRIES 100 // 假设最大条目数为100
|
||||
|
||||
// 定义电话本条目结构体
|
||||
typedef struct {
|
||||
char name[50];
|
||||
char phone[20];
|
||||
} PhoneBookEntry;
|
||||
|
||||
PhoneBookEntry phoneBook[MAX_ENTRIES]; // 存储电话本信息的数组
|
||||
int numEntries = 0; // 当前电话本条目数量
|
||||
|
||||
void Phone_book_analysis(void){
|
||||
/*int numEntries = 0; // 当前电话本条目数量
|
||||
|
||||
// 模拟收到的电话本信息字符串
|
||||
char data[] = "+PBDATA=1<FF>JACK<FF>12345678911";
|
||||
|
||||
// 解析字符串并提取姓名和电话号码
|
||||
char *token = strtok(data, "<FF>"); // 使用<FF>作为分隔符
|
||||
if (token != NULL) {
|
||||
token = strtok(NULL, "<FF>"); // 跳过第一个分隔符
|
||||
if (token != NULL) {
|
||||
strcpy(phoneBook[numEntries].name, token);
|
||||
token = strtok(NULL, "<FF>");
|
||||
if (token != NULL) {
|
||||
strcpy(phoneBook[numEntries].phone, token);
|
||||
numEntries++;
|
||||
printf("Phone book entry stored successfully.\n");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
// 打印存储的电话本信息
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
printf("Entry %d: Name - %s, Phone - %s\n", i+1, phoneBook[i].name, phoneBook[i].phone);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Call_analysis(){
|
||||
|
||||
}
|
||||
|
||||
void parseBtATCommand(char* cAtCmd,int cATLen) {
|
||||
uint8_t str[64];
|
||||
static uint8_t flag = 0;
|
||||
uint8_t j=0;
|
||||
uint32_t num = 0;
|
||||
|
||||
printf(">>");
|
||||
for(uint16_t i =0;i<cATLen;i++){
|
||||
printf("%c",cAtCmd[i]);
|
||||
}
|
||||
|
||||
if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+A2DPDEV",8))//蓝牙连接设备信息 远端设备信息 蓝牙连接
|
||||
{
|
||||
Set_sys_bt_connect_state(1);
|
||||
}else if(strlen(cAtCmd) > 8 && !memcmp(cAtCmd,"+A2DPDEV",8)){
|
||||
|
||||
}else if(strlen(cAtCmd) > 9 && !memcmp(cAtCmd,"+A2DPLOST",9)){//远距离断开 设备丢失
|
||||
|
||||
}else if(strlen(cAtCmd) > 12 && !memcmp(cAtCmd,"+AVRCPSTAT=1",12)){//AVRCP状态 1是配对状态 蓝牙断开
|
||||
Set_sys_bt_connect_state(0);
|
||||
}else if(strlen(cAtCmd) > 6 && !memcmp(cAtCmd,"+PBCNT",6)){//电话本数量
|
||||
num = atoi(cAtCmd + 7); //从数字的起始位置开始转换为整数
|
||||
printf("Extracted number from command: %d\n", num);
|
||||
}else if(strlen(cAtCmd) > 7 && !memcmp(cAtCmd,"+PBDATA",7)){//电话号码
|
||||
printf("----------------------------\r\n");
|
||||
// 解析字符串并提取姓名和电话号码
|
||||
// char *token = strtok(cAtCmd, "<FF>"); // 使用<FF>作为分隔符
|
||||
/*char *token = strtok(cAtCmd, 0x3F); // 使用<FF>作为分隔符
|
||||
printf("token1 > %s .\r\n",token);
|
||||
if (token != NULL) {
|
||||
// token = strtok(NULL, "<FF>"); // 跳过第一个分隔符
|
||||
token = strtok(NULL, 0x3F); // 跳过第一个分隔符
|
||||
printf("token2 > %s .\r\n",token);
|
||||
if (token != NULL) {
|
||||
strcpy(phoneBook[numEntries].name, token);
|
||||
printf("token3 > %s .\r\n",token);
|
||||
// token = strtok(NULL, "<FF>");
|
||||
token = strtok(NULL, 0x3F); // 跳过第一个分隔符
|
||||
if (token != NULL) {
|
||||
strcpy(phoneBook[numEntries].phone, token);
|
||||
printf("token4 > %s .\r\n",token);
|
||||
numEntries++;
|
||||
printf("Phone book entry stored successfully.\n");
|
||||
}
|
||||
}
|
||||
}*/
|
||||
printf(">>");
|
||||
for(uint16_t i =0;i<cATLen;i++){
|
||||
printf("%02X ",cAtCmd[i]);
|
||||
}
|
||||
|
||||
char call_num[20];
|
||||
char call_name[20];
|
||||
uint16_t len1=0;
|
||||
uint16_t len2=0;
|
||||
for(uint16_t i=0;i<cATLen;i++){
|
||||
if(cAtCmd[i] == 0xFF){
|
||||
if(!len1)
|
||||
len1 = i;
|
||||
else
|
||||
len2 = i;
|
||||
}
|
||||
}
|
||||
printf("len1 = %d,len2 = %d.\r\n",len1,len2);
|
||||
char *start;
|
||||
char *start2;
|
||||
char *start3;
|
||||
char *start4 = cAtCmd + len2 +1;//call number
|
||||
printf("start4 >%s.\r\n",start4);
|
||||
|
||||
strncpy(start2, (cAtCmd + len2), len2);//number
|
||||
printf("start2 >%s.\r\n",start2);
|
||||
strncpy(start, (cAtCmd + 10), len2-len1);//name
|
||||
printf("start >%s, start2 >%s .\r\n",start,start2);
|
||||
|
||||
|
||||
// char *start = cAtCmd + 10;
|
||||
// char *start2;
|
||||
// strncpy(start2, start, len1);
|
||||
// char *start3 = start + len1;
|
||||
|
||||
// // char *end = strchr(start, 0x3F);
|
||||
// // char *end2 = strchr(end, 0x3F);
|
||||
// printf("start >%s, end >%s, end2 >%s .\r\n",start,start2,start3);
|
||||
|
||||
|
||||
|
||||
|
||||
// if (end) {
|
||||
// *end = '\0';
|
||||
// strncpy(call_num, start, 19);
|
||||
// call_num[19] = '\0'; // 确保字符串以null结尾
|
||||
// printf("call_num > %s .\r\n",call_num);
|
||||
// }
|
||||
// if (end2) {
|
||||
// *end2 = '\0';
|
||||
// strncpy(call_name, end, 19);
|
||||
// call_name[19] = '\0'; // 确保字符串以null结尾
|
||||
// printf("call_name > %s .\r\n",call_name);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user