271 lines
10 KiB
C
271 lines
10 KiB
C
/**************************************************************************************************
|
||
* Copyright (c) Fenda Technologies Co., Ltd. 2020-2021. All rights reserved.
|
||
* Description: 消息接口
|
||
* Author: ball.caojianguang
|
||
* Create: 2020-5-21
|
||
**************************************************************************************************/
|
||
|
||
#include "FreeRTOS.h"
|
||
|
||
#include "sys_config.h"
|
||
|
||
#include "ble_message_server.h"
|
||
#include "task_ble.h"
|
||
//#include "user_message_notify.h"
|
||
#include "sql_setting.h"
|
||
#include "ui_port_fw.h"
|
||
#include "sql_message.h"
|
||
#include "ui_event.h"
|
||
|
||
|
||
|
||
|
||
/**************************************************************************************************
|
||
设置消息提醒(设置服务端消息提示信息)--4.17.1
|
||
***************************************************************************************************/
|
||
void Ble_SetMessageRemind(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
uint8_t textType;
|
||
protocol_data_info_t data_info = {0};
|
||
MessageInfo_t message = {0};
|
||
char* message_content_temp = NULL;
|
||
|
||
// ------TO BE ADDED 待添加消息提醒log打点 -------
|
||
if(sql_setting_get_ble_switch_message_notify() == 0)
|
||
{// app关闭了消息通知总开关
|
||
ble_printf("****** Message Notify Switch Is Turn off. ******\r\n");
|
||
return;
|
||
}
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
switch(data_info.type & 0x7f) { //无子节点
|
||
case MES_MESSAGE_ID_TYPE:
|
||
message.id = (*data_info.p_data++) * 0x100;
|
||
message.id += *data_info.p_data++;
|
||
break;
|
||
|
||
case MES_MESSAGE_TYPE:
|
||
message.msgType = (MessageType)(*data_info.p_data);
|
||
break;
|
||
|
||
case MES_MOTOR_ENABLE_TYPE:
|
||
message.motorEnable = *data_info.p_data++;
|
||
break;
|
||
|
||
case MES_TEXT_LIST_TYPE:
|
||
break;
|
||
|
||
case MES_TEXT_TYPE:
|
||
textType = *data_info.p_data++;
|
||
break;
|
||
case MES_TEXT_FORMAT_TYPE:
|
||
message.encoderType = (TextEncodeType)(*data_info.p_data);
|
||
break;
|
||
|
||
case MES_TEXT_CONTENT_TYPE:
|
||
message_content_temp = pvPortMalloc(data_info.len + 1);
|
||
if(message_content_temp == NULL) {
|
||
ble_printf("Ble_SetMessageRemind memalloc message_content_temp fail.\r\n");
|
||
break;
|
||
}
|
||
memset(message_content_temp, 0, data_info.len + 1);
|
||
memcpy(message_content_temp, in_data, data_info.len);
|
||
ble_printf("message Reveice DataLen = %d.\r\n", data_info.len);
|
||
if(textType == TEXT_MESSAGE_CONTENT_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TEXT_LENGTH) {
|
||
memcpy(message.text, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.text, message_content_temp, MESSAGE_TEXT_LENGTH - 1);
|
||
}
|
||
|
||
} else if(textType == TEXT_CONTACT_NAME_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TITLE_LENGTH) {
|
||
memcpy(message.contactName, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.contactName, message_content_temp, MESSAGE_TITLE_LENGTH - 1);
|
||
}
|
||
|
||
} else if(textType == TEXT_TITLE_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TITLE_LENGTH) {
|
||
memcpy(message.title, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.title, message_content_temp, MESSAGE_TITLE_LENGTH - 1);
|
||
}
|
||
} else if(textType == TEXT_APP_NAME_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TITLE_LENGTH) {
|
||
memcpy(message.appName, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.appName, message_content_temp, MESSAGE_TITLE_LENGTH - 1);
|
||
}
|
||
} else if(*data_info.p_data == TEXT_YELLOW_PAGE_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TITLE_LENGTH) {
|
||
memcpy(message.yellowPage, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.yellowPage, message_content_temp, MESSAGE_TITLE_LENGTH - 1);
|
||
}
|
||
} else if(textType == TEXT_PHONE_NUM_MARK_TYPE) {
|
||
if(strlen(message_content_temp) < MESSAGE_TITLE_LENGTH) {
|
||
memcpy(message.phoneNumMark, message_content_temp, strlen(message_content_temp));
|
||
} else {
|
||
memcpy(message.phoneNumMark, message_content_temp, MESSAGE_TITLE_LENGTH - 1);
|
||
}
|
||
}
|
||
|
||
if(message_content_temp != NULL) {
|
||
vPortFree(message_content_temp);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
|
||
}
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
|
||
} while(in_len);
|
||
|
||
if(message.msgType != 0){
|
||
sql_message_new_message(&message);
|
||
// ------TO BE ADDED 待添加消息通知UI -------
|
||
ui_port_send_sys_remind_event(EVENT_REMIND_MESSAGE, 0, &message, sizeof(MessageInfo_t));
|
||
task_ble_notify(BLE_MESSAGE_LIST_STORAGE_MSG, 0); // 异步存储消息列表
|
||
}
|
||
write_idx = user_set_protocol_error(out_data, MESSAGE_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
|
||
}
|
||
|
||
/***************************************************************************************************
|
||
设置通知提醒总开关--4.17.2 (IOS手机)
|
||
***************************************************************************************************/
|
||
void Ble_SetMessageRemindSwitch_IOS(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
protocol_data_info_t data_info = {0};
|
||
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
|
||
switch(data_info.type & 0x7f) { //无子节点
|
||
case NOTIFY_ENABLE_TYPE:
|
||
ble_printf("NOTIFY_ENABLE_TYPE(IOS) = %d\r\n", *data_info.p_data);
|
||
sql_setting_set_ble_switch_message_notify(*data_info.p_data);
|
||
task_ble_notify(BLE_SAVE_SETTINGS_MSG, 0); // 异步存储通知开关
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
|
||
} while(in_len);
|
||
|
||
write_idx = user_set_protocol_error(out_data, MESSAGE_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
}
|
||
|
||
|
||
/***************************************************************************************************
|
||
消息已读--4.17.3
|
||
***************************************************************************************************/
|
||
void Ble_SendMessageHaveReadInfo(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
uint16_t temp_msgid_buff = 0;
|
||
protocol_data_info_t data_info = {0};
|
||
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
switch(data_info.type & 0x7f) {
|
||
case MES_MESSAGE_ID_TYPE: {
|
||
temp_msgid_buff = (data_info.p_data[0]) * 0x100 + data_info.p_data[1];
|
||
ble_printf("have read message id=%d\r\n ", temp_msgid_buff);
|
||
//temp_msgid_buff = temp_msgid_buff+(*data_info.p_data);
|
||
//printf("have read message_id=%x\n ",temp_msgid_buff);
|
||
//ADPTDeleteMessageById((unsigned int)(&temp_msgid_buff));
|
||
}
|
||
break;
|
||
case MES_MESSAGE_TYPE: {
|
||
ble_printf("have read message type=%d\r\n", *data_info.p_data);
|
||
sql_message_delete_same_type_message((MessageType)*data_info.p_data);
|
||
// ------TO BE ADDED 待添加通知UI此类消息已读 -------
|
||
task_ble_notify(BLE_MESSAGE_LIST_STORAGE_MSG, 0); // 异步存储消息列表
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
in_data = data_info.p_data;
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
} while(in_len);
|
||
write_idx = user_set_protocol_error(out_data, MESSAGE_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
}
|
||
|
||
/***************************************************************************************************
|
||
设置通知提醒总开关--4.17.4 (安卓手机)
|
||
***************************************************************************************************/
|
||
void Ble_SetMessageRemindSwitch_Android(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
||
{
|
||
uint16_t write_idx = 0;
|
||
protocol_data_info_t data_info = {0};
|
||
|
||
data_info.error = FENDA_SUCCESS;
|
||
|
||
do {
|
||
user_get_data_info(&data_info, &in_data, &in_len);
|
||
|
||
switch(data_info.type & 0x7f) { //无子节点
|
||
case NOTIFY_ENABLE_TYPE:
|
||
ble_printf("NOTIFY_ENABLE_TYPE(Android) = %d\r\n", *data_info.p_data);
|
||
sql_setting_set_ble_switch_message_notify(*data_info.p_data);
|
||
task_ble_notify(BLE_SAVE_SETTINGS_MSG, 0); // 异步存储通知开关
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
|
||
}
|
||
|
||
in_data = in_data + (data_info.len);
|
||
in_len = in_len - (2 + data_info.len);
|
||
if(in_len > FRAM_MAX_SIZ) {
|
||
in_len = 0;
|
||
}
|
||
|
||
} while(in_len);
|
||
|
||
write_idx = user_set_protocol_error(out_data, MESSAGE_SERVER, data_info.error);
|
||
*out_len = write_idx;
|
||
}
|
||
|
||
// 所有涉及到消息的函数指针,这里的顺序和common id 顺序相同
|
||
const p_func_t MessageServerFunc[MESSAGE_SERVERE_MAX_ID] = {
|
||
user_null_func,
|
||
Ble_SetMessageRemind, //4.17.1
|
||
Ble_SetMessageRemindSwitch_IOS, //4.17.2
|
||
Ble_SendMessageHaveReadInfo, //4.17.3
|
||
Ble_SetMessageRemindSwitch_Android, //4.17.4
|
||
};
|
||
|