#include "SetDialModel.h"
+#include "AiVoiceModel.h"
#include "SleepModel.h"
//#include "AlarmClockModel.h"
#ifdef __cplusplus
#include <dirent.h>
+void ble_set_ai_Question_str(char *buf)
+{
+ OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf));
+}
+
+void ble_set_ai_Answer_str(char *buf)
+{
+ OHOS::AiVoiceModel::GetInstance().SetaiAnswerStrStr(std::string(buf));
+}
+
+
+char * dir_to_json_buf_malloc_(uint8_t type)
+{
+ char dir_path[128]={0};
+ switch (type)
+ {
+ case 0x43: //同步步数历史数据
+ sprintf_s(dir_path,64,"%s","user/userdata/music");
+ break;
+ default:
+ break;
+ }
+ cJSON *dataJSON = cJSON_CreateObject();
+ cJSON* data_arryJSON = cJSON_CreateArray();
+
+ struct DIR *dir;
+ struct dirent *ent;
+ uint32_t file_size=0;
+ if ((dir = opendir(dir_path)) != NULL)
+ {
+ while ((ent = readdir(dir)) != NULL)
+ {
+ std::string fileName = ent->d_name;
+
+ if (fileName != "." && fileName != "..")
+ {
+ //std::string filePath = directory + fileName;
+
+
+ if (ent->d_type == DT_REG || ent->d_type == DT_UNKNOWN ) // 普通文件
+ {
+
+ //*file_size=ent->d_reclen;
+ // char file_path[128]={0};
+ // sprintf_s(file_path,128,"%s/%s",TAR_PATH,ent->d_name);
+
+ // FILE * fp = fopen(file_path,"rb+");
+ // if(fp==NULL)
+ // {
+ // printf(" fopen fail %s\r\n",file_path);
+ // return NULL;
+ // }
+ // if (fp != NULL)
+ // {
+ // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾
+ // file_size = ftell(fp); // 获取当前文件指针位置,即文件大小
+ // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头
+ // }
+ // fclose(fp);
+
+ // cJSON* itemJSON = cJSON_CreateObject();
+
+ // cJSON_AddNumberToObject(itemJSON,"index",file_index);
+ // cJSON_AddNumberToObject(itemJSON,"count",file_count);
+
+ // cJSON_AddNumberToObject(itemJSON,"crc",crc);
+
+ // cJSON_AddStringToObject(itemJSON,"name",fileName.c_str());
+ // cJSON_AddNumberToObject(itemJSON,"size",file_size);
+
+ // char *json_format = cJSON_PrintUnformatted(itemJSON);
+
+ // int pSize = cJSON_GetArraySize(dataJSON);
+ // printf("文件数据:%s\r\n",json_format);
+ // cJSON_Delete(dataJSON);
+ // file_index++;
+
+ // return json_format;
+
+ //cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON);
+
+ }
+ else if (ent->d_type == DT_DIR) // 目录
+ {
+ continue;
+ }
+
+ }
+
+ }
+ closedir(dir);
+ }
+ else
+ {
+ printf("opendir fail\r\n");
+ }
+ return NULL;
+}
+
+
+
+
uint8_t ble_AT_add_nap_data(uint16_t time)
{
OHOS::NAP_T data;
cJSON_AddNumberToObject(itemJSON,"di",data->di);
cJSON_AddNumberToObject(itemJSON,"hr",data->hr);
cJSON_AddNumberToObject(itemJSON,"stp",data->stp);
+ cJSON_AddNumberToObject(itemJSON,"ti",data->ti);
+ cJSON_AddNumberToObject(itemJSON,"cir",data->cir);
+ cJSON_AddNumberToObject(itemJSON,"alt",data->alt);
+ cJSON_AddNumberToObject(itemJSON,"fpc",data->fpc);
+ cJSON_AddNumberToObject(itemJSON,"spc",data->spc);
+ cJSON_AddNumberToObject(itemJSON,"std",data->std);
+ cJSON_AddNumberToObject(itemJSON,"cdc",data->cdc);
cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON);
free(data);
uint8_t flag = 0;\r
// printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json));\r
#if 0\r
- FILE *fp=fopen("user/weather.json","wb+");\r
- printf("jsonCheck_weather len %d",strlen((char *)buf)+1);\r
- //fwrite((void*)buf,1,strlen((char *)buf)+1,fp);\r
- fputs((char *)buf,fp);\r
+ FILE *fp=fopen("user/AI.txt","wb+");\r
+ printf("binCheck_AI len %d\r\n",len);\r
+ fwrite((void*)buf,1,len,fp);\r
+ //fputs((char *)buf,fp);\r
fclose(fp);\r
- 1+1+2\r
#endif\r
+\r
uint16_t offset=0;\r
\r
while (len>offset)\r
if(buf[offset]==1)\r
{\r
offset++;\r
- uint16_t txt_len=buf[offset];\r
- offset++;\r
- char buf[128]={0};\r
- memcpy_s(buf,128,buf[offset],txt_len);\r
- printf("%s\r\n",buf);\r
+ uint16_t txt_len;\r
+ memcpy_s(&txt_len,2,&buf[offset],2);\r
+\r
+ offset+=2;\r
+ char txt_buf[128]={0};\r
+ memcpy_s(txt_buf,128,&buf[offset],txt_len);\r
+ printf("binCheck_AI txtbuf:%s %d\r\n",txt_buf,txt_len);\r
+ ble_set_ai_Question_str(txt_buf);\r
offset+=txt_len;\r
offset+=1;\r
}\r
else if(buf[offset]==2)\r
{\r
offset++;\r
- uint16_t txt_len=buf[offset];\r
- offset++;\r
- char buf[128]={0};\r
- memcpy_s(buf,128,buf[offset],txt_len);\r
- printf("%s\r\n",buf);\r
+ uint16_t txt_len=buf[offset]+buf[offset+1]*256;\r
+ offset+=2;\r
+\r
+ char txt_buf[128]={0};\r
+ memcpy_s(txt_buf,128,&buf[offset],txt_len);\r
+ printf("%s %d\r\n",txt_buf,txt_len);\r
+ ble_set_ai_Answer_str(txt_buf);\r
offset+=txt_len;\r
offset+=1;\r
}\r
}\r
\r
\r
-void GetAiResultCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//获取天气数据\r
+void GetAiResultCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)\r
{\r
uint32_t tmp = 1;\r
uint16_t tmp_data = 1;\r
memset(sendBuf,0,19);\r
sendBuf[0] = 0x72;\r
sendBuf[1] = 0x02;\r
- sendBuf[2] = 0x20;\r
+ sendBuf[2] = 0x1f;\r
memcpy(sendBuf+3,&tmp,4);\r
memcpy(sendBuf+7,&tmp,4);\r
memcpy(sendBuf+11,&tmp,4);\r
void type2AE4Data(ble_read_data *buffer_handle,uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *totalData,uint8_t crcvalue)\r
{\r
uint16_t typeID = buf_cmd[1]*256+buf_cmd[2];\r
- #ifdef BLE_LOG\r
+\r
printf("type2AE4Data typeID:0x%04X\r\n",typeID);\r
- #endif\r
switch (typeID) //ID\r
{\r
case USER_INFOR_CMD://app下发的获取用户信息\r
printf("fopen fail %s\r\n",file_name);\r
goto GetAiRecordFail;\r
}\r
+\r
do\r
{\r
memset_s(data,num+1,0,num+1);\r
\r
send_big_data(1,data,read_size,file_size,pack_id,pack,0x34,1);\r
pack_id++;\r
- msleep(50);\r
+ msleep(20);\r
\r
} while (read_size==num);\r
free(data);\r
case GET_PASSWORD_CMD: //获取手表密码\r
GetPasswordCmd(cmd,data,datalen,totaldata,crcvalue);\r
break;\r
- case AI_IS_READ_DATA_CMD:\r
+ case APP_GET_AI_PCM_DATA_CMD:\r
GetAiRecordCmd(cmd,data,datalen,totaldata,crcvalue);\r
break;\r
- case APP_GET_AI_PCM_DATA_CMD://获取手表闹钟//同步闹钟\r
+ case AI_IS_READ_DATA_CMD:\r
case SYN_HEART_HISTORY_DATA_CMD://同步心率历史数据\r
//heartDataCmd(cmd,data,datalen,totaldata,crcvalue);\r
case SYN_SPO2_HISTORY_DATA_CMD://同步血氧历史数据\r