#include "bleInstruct.h"
#endif
+
#include "custom_utils.h"
#include "custom_runtime.h"
#include "bleANCS.h"
{
if(input_filename == NULL || output_file_path == NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_file_recv_file_path: NULL pointer detected - input_filename=%p, output_file_path=%p",
+ input_filename, output_file_path);
+ return ERRCODE_FAIL;
+ }
+
+ if(input_size == 0 || max_output_size == 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_file_recv_file_path: Invalid size parameters - input_size=%u, max_output_size=%u",
+ input_size, max_output_size);
return ERRCODE_FAIL;
}
int ret = sprintf_s(output_file_path,max_output_size,"/user/userdata/%s",input_filename);
if (ret < 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_file_recv_file_path: sprintf_s failed - ret=%d, filename='%s', max_size=%u",
+ ret, input_filename, max_output_size);
return ERRCODE_FAIL;
+ }
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] get_file_recv_file_path: Success - input='%s', output='%s'",
+ input_filename, output_file_path);
return ERRCODE_SUCC;
}
static errcode_t get_app_file_path(char* input_filename ,uint32_t input_size, char* output_file_path , uint32_t max_output_size)
{
if(input_filename == NULL || output_file_path == NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_app_file_path: NULL pointer detected - input_filename=%p, output_file_path=%p",
+ input_filename, output_file_path);
+ return ERRCODE_FAIL;
+ }
+
+ if(input_size == 0 || max_output_size == 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_app_file_path: Invalid size parameters - input_size=%u, max_output_size=%u",
+ input_size, max_output_size);
return ERRCODE_FAIL;
}
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] get_app_file_path: Creating app_store directory");
uapi_create_dir("/user/app_store");
int ret = sprintf_s(output_file_path,max_output_size,"/user/app_store/%s",input_filename);
if (ret < 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_app_file_path: sprintf_s failed - ret=%d, filename='%s', max_size=%u",
+ ret, input_filename, max_output_size);
return ERRCODE_FAIL;
+ }
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] get_app_file_path: Success - input='%s', output='%s'",
+ input_filename, output_file_path);
return ERRCODE_SUCC;
}
static errcode_t get_custom_dial_file_path(uint16_t id,char *filename,uint32_t input_size, char* output_file_path , uint32_t max_output_size)
{
if( id >=5 || output_file_path == NULL || filename == NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_custom_dial_file_path: Invalid parameters - id=%u, output_file_path=%p, filename=%p",
+ id, output_file_path, filename);
+ return ERRCODE_FAIL;
+ }
+
+ if(input_size == 0 || max_output_size == 0)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] get_custom_dial_file_path: Invalid size parameters - input_size=%u, max_output_size=%u",
+ input_size, max_output_size);
return ERRCODE_FAIL;
}
char name[64]={0};
if(fp==NULL)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"fopen fail %s\r\n",file_path);
- return 0;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] calculate_lrc_file: Failed to open file - path='%s', errno=%d",
+ file_path, errno);
+ return 0;
}
do
{
buf = ym_malloc(17 + datalen + 1);
memset_s(buf,ble_nus_max_data_len,0,17 + datalen + 1);
if (buf == NULL && datalen!=0) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"内存分配失败\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] sendBleData: Memory allocation failed - requested_size=%u, datalen=%u",
+ 17 + datalen + 1, datalen);
return;
}
if(type.Packet_id>=2)
}
fclose(file);
}
- // ym_free(jsonString);
cJSON_free(jsonString);
cJSON_Delete(dataJSON);
// 读取JSON文件
static uint8_t jsonCheck_time(uint8_t *buf)//json 格式解析
{
if (buf == NULL) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Input buffer is NULL");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_time: Input buffer is NULL");
return 2;
}
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] jsonCheck_time: Parsing JSON data, length=%zu", strlen((char*)buf));
+
cJSON* root = cJSON_Parse((const char *)buf);
if (root == NULL) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JSON解析错误");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_time: JSON parse failed - data='%s'", (char*)buf);
return 2;
}
// 验证必需字段
cJSON* time = cJSON_GetObjectItem(root, "time");
if (!time || !cJSON_IsNumber(time)) {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Missing or invalid 'time' field");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_time: Missing or invalid 'time' field - time=%p, isNumber=%d",
+ time, time ? cJSON_IsNumber(time) : 0);
cJSON_Delete(root);
return 2;
}
json = buf;
cJSON* root = cJSON_Parse((const char *)json);
if (root == NULL) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"时间 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_targetparam: JSON parse failed");
return 2;
}
cJSON* root = cJSON_Parse((const char *)json);
if (root == NULL) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"闹钟 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_alarm: Alarm JSON parse failed");
return;
}
else
cJSON* alarms = cJSON_GetObjectItem(root, "alarms");
if(alarms==NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_alarm: Missing 'alarms' field in JSON");
+ cJSON_Delete(root);
return;
}
int alarmCount = cJSON_GetArraySize(alarms);
cJSON *data=cJSON_GetArrayItem(alarms,i);
if(data==NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_alarm: Failed to get alarm item at index %d", i);
+ cJSON_Delete(root);
return;
}
cJSON *json_data = ble_get_Trainingdata_by_timetamp(timetamp);
if(json_data==NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] Failed to get training data by timestamp - timestamp=%u", timetamp);
ble_data_type type_={0x02,0x19,0,1,1};
send_big_data(type_,NULL,0);
return;
uint32_t file_size=0;
if(fp==NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"打开文件失败 %s \r\n",path);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"打开文件失败 %s \r\n",path);
ble_data_type type_={0x02,0x4b,0,1,1};
send_big_data(type_,NULL,0);
int num_check=file_size%5;//心率数据 5个字节
if(num_check!=0)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"数据有误 %d \r\n",cmd);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"数据有误 %d \r\n",cmd);
ble_data_type type_={0x02,0x4b,0,1,1};
send_big_data(type_,NULL,0);
}
char* buf = (char *)ym_malloc(sizeof(char)*num+1);
- if(buf==NULL){fclose(fp); return ;}
+ if(buf==NULL){
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] Memory allocation failed for file data - requested_size=%u", num+1);
+ fclose(fp);
+ return ;
+ }
uint32_t pack=1;
uint32_t file_size=0;
if(fp==NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"打开文件失败 %s \r\n",path);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"打开文件失败 %s \r\n",path);
ble_data_type type_={0x02,0x18,0,1,1};
send_big_data(type_,NULL,0);
int num_check=file_size%6;
if(num_check!=0)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"数据有误 %d \r\n",cmd);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"数据有误 %d \r\n",cmd);
ble_data_type type_={0x02,0x18,0,1,1};
send_big_data(type_,NULL,0);
}
char* buf = (char *)ym_malloc(sizeof(char)*num+1);
- if(buf==NULL){fclose(fp); return ;}
+ if(buf==NULL){
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] Memory allocation failed for file data - requested_size=%u", num+1);
+ fclose(fp);
+ return ;
+ }
uint32_t pack=1;
if(file_size%num==0)
uint8_t vibration=data[5];
uint8_t notify=data[6];
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"设置步数:%d %d %d %d \r\n",targetStep,ringOn,vibration,notify);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"设置步数:%d %d %d %d \r\n",targetStep,ringOn,vibration,notify);
set_goal_stepcount(targetStep);
FILE *fp=fopen("/user/userdata/weather.json","wb+");
if(fp != NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"jsonCheck_weather len %d",strlen((char *)buf)+1);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] jsonCheck_weather: Writing weather data to file, length=%zu", strlen((char *)buf)+1);
//fwrite((void*)buf,1,strlen((char *)buf)+1,fp);
- fputs((char *)buf,fp);
+ if(fputs((char *)buf,fp) == EOF) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_weather: Failed to write weather data to file");
+ }
fclose(fp);
+ } else {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jsonCheck_weather: Failed to open weather file for writing - errno=%d", errno);
}
return parse_jsonCheck_weather(buf,check);
}
// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json));
cJSON* root = cJSON_Parse((const char *)json);
if (root == NULL) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"天气 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] parse_jsonCheck_weather_post: Weather JSON parse failed");
return ;
}
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"开始解析天气 JSON\n");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"开始解析天气 JSON\n");
cJSON *now_cjson = cJSON_GetObjectItem(root, "now");
if(now_cjson == NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"天气 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] parse_jsonCheck_weather_post: Missing 'now' field in weather JSON");
+ cJSON_Delete(root);
return ;
}
int humidity=0;
uint8_t *json;
json = buf;
// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json));
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] parse_jsonCheck_weather: Parsing weather JSON, length=%zu", strlen((char*)json));
+
cJSON* root = cJSON_Parse((const char *)json);
if (root == NULL) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"天气 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] parse_jsonCheck_weather: JSON parse failed - data='%s'", (char*)json);
flag = 2;
memcpy(check,&flag,1);
return 0;
}
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"开始解析天气 JSON\n");
+
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_DEBUG] parse_jsonCheck_weather: Starting weather JSON parsing");
cJSON *now_cjson = cJSON_GetObjectItem(root, "now");
if(now_cjson == NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"天气 JSON解析错误\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] parse_jsonCheck_weather: Missing 'now' field in weather JSON");
+ cJSON_Delete(root);
return 0;
}
int humidity=0;
FILE *fp=fopen("/user/userdata/weather.json","rb");
if(fp == NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"read_jsonHistory_weather:fopen error\r\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] read_jsonHistory_weather: Failed to open weather file - errno=%d", errno);
return 0;
}
fseek(fp, 0, SEEK_END);
fseek(fp, 0, SEEK_SET);
if (size == 0)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] read_jsonHistory_weather: Weather file is empty");
fclose(fp);
return 0;
}
buf = (uint8_t*)malloc(size + 1);
if(buf == NULL)
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] read_jsonHistory_weather: Memory allocation failed - requested_size=%ld", size + 1);
fclose(fp);
return 0;
}
value[18] = lrc;
sendBleData(value,19);
}
+
cJSON_free(json_format);
}
//查找手表 01 04
break;
}
- if(json_format == NULL) return ;
+ if(json_format == NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] JSON format generation failed - json_format is NULL");
+ return ;
+ }
uint32_t data_len = strlen(json_format);
uint32_t surplus_len=data_len;
}
buf = (char *)ym_malloc(sizeof(char)*num+1);
- if(buf==NULL){fclose(fp); return false;}
+ if(buf==NULL){
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] Memory allocation failed for file data - requested_size=%u", num+1);
+ fclose(fp);
+ return false;
+ }
uint32_t pack=1;
if(file_size%num==0)
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"lrc:%d",lrc);
value[data_len+18] = lrc;
sendBleData(value,data_len+18);
+
+ cJSON_free(json_format);
*/
// uint8_t value[128];
json = data;
cJSON* root = cJSON_Parse((const char *)json);
if (root == NULL) {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"信息解析 JSON解析 失败\n");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jscheck_ancs: Message JSON parse failed");
return 2;
}
msgBuf = ym_malloc(MSG_BUF_LEN+1);
if(titleBuf == NULL || msgBuf == NULL)//申请内存失败不在申请
{
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] jscheck_ancs: Memory allocation failed - titleBuf=%p, msgBuf=%p", titleBuf, msgBuf);
+ if(titleBuf) ym_free(titleBuf);
+ if(msgBuf) ym_free(msgBuf);
+ cJSON_Delete(root);
return 2;
}
memset(titleBuf,0,TITLE_BUF_LEN+1);
errcode_t handle_recv_file(ble_read_data *buffer_handle,uint8_t *data, uint16_t event_size)
{
- if( event_size == 0 || data == NULL ) return ERRCODE_FAIL;
+ if( event_size == 0 || data == NULL ) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BLE_EVENT_ERROR] handle_recv_file: Invalid parameters - event_size=%u, data=%p",
+ event_size, data);
+ return ERRCODE_FAIL;
+ }
if (buffer_handle->last_data_size == event_size)
{