171 lines
5.0 KiB
C
171 lines
5.0 KiB
C
/*----------------------------------------------------------------------------
|
|
* Copyright (c) Fenda Technologies Co., Ltd. 2021. All rights reserved.
|
|
*
|
|
* Description: user_collect_data_server.c
|
|
*
|
|
* Author: shey.tanxiaoyu
|
|
*
|
|
* Create: 2022-04-20
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "ble_collect_data_server.h"
|
|
#include "ble_data_transmission.h"
|
|
#include "task_alg.h"
|
|
#include "alg_proc.h"
|
|
|
|
enum {
|
|
COLLECT_DATA_CMD_APP_START = 0x01, // 3.3.1.1
|
|
COLLECT_DATA_CMD_DEV_START = 0x02, // 3.3.1.2
|
|
COLLECT_DATA_CMD_DEV_STOP = 0x03, // 3.3.2.1
|
|
COLLECT_DATA_CMD_APP_STOP = 0x04, // 3.3.2.2
|
|
COLLECT_DATA_CMD_GET_HISTORY = 0x05, // 3.3.3
|
|
COLLECT_DATA_CMD_HISTORY_FINISH = 0x06, // 3.3.4
|
|
COLLECT_DATA_CMD_CLEAR_HISTORY = 0x07, // 3.3.5
|
|
};
|
|
|
|
enum {
|
|
COLLECT_DATA_ACK_SUCCESS,
|
|
COLLECT_DATA_ACK_FAILURE,
|
|
};
|
|
|
|
/* 数采规范 3.3.1 开始采集 */
|
|
static void collect_start(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
uint8_t out_data[TEMP_NUM_MAX];
|
|
uint16_t out_len = 0;
|
|
uint8_t packet_index = 0;
|
|
uint8_t cmd_id = 0;
|
|
uint8_t suffix = 0;
|
|
collect_data_switch_config_t collect_data_sw_cfg;
|
|
|
|
packet_index = in_data[1]; // 序号
|
|
cmd_id = in_data[3]; // 指令编号
|
|
suffix = in_data[4]; // 包尾识别码
|
|
|
|
collect_data_sw_cfg.power = 1;
|
|
collect_data_sw_cfg.collect_type = (collect_type_e)suffix;
|
|
|
|
task_alg_notify_ext(ALG_MSG_COLLECT_MODE, &collect_data_sw_cfg, sizeof(collect_data_switch_config_t));
|
|
|
|
out_data[out_len++] = 0xFD;
|
|
out_data[out_len++] = packet_index;
|
|
out_data[out_len++] = 0x03;
|
|
out_data[out_len++] = cmd_id;
|
|
out_data[out_len++] = suffix;
|
|
out_data[out_len++] = COLLECT_DATA_ACK_SUCCESS;
|
|
|
|
BLE_SendFrameById(COLLECT_DATA_SERVER, SET_COLLECT_DATA_COMMAND_ID, out_data, out_len);
|
|
}
|
|
|
|
/* 数采规范 3.3.2 结束采集 */
|
|
static void collect_stop(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
uint8_t out_data[TEMP_NUM_MAX];
|
|
uint16_t out_len = 0;
|
|
uint8_t packet_index = 0;
|
|
uint8_t cmd_id = 0;
|
|
uint8_t suffix = 0;
|
|
collect_data_switch_config_t collect_data_sw_cfg;
|
|
|
|
packet_index = in_data[1]; // 序号
|
|
cmd_id = in_data[3]; // 指令编号
|
|
suffix = in_data[4]; // 包尾识别码
|
|
|
|
collect_data_sw_cfg.power = 0;
|
|
collect_data_sw_cfg.collect_type = (collect_type_e)suffix;
|
|
|
|
task_alg_notify_ext(ALG_MSG_COLLECT_MODE, &collect_data_sw_cfg, sizeof(collect_data_switch_config_t));
|
|
|
|
out_data[out_len++] = 0xFD;
|
|
out_data[out_len++] = packet_index;
|
|
out_data[out_len++] = 0x03;
|
|
out_data[out_len++] = cmd_id;
|
|
out_data[out_len++] = suffix;
|
|
out_data[out_len++] = COLLECT_DATA_ACK_SUCCESS;
|
|
|
|
BLE_SendFrameById(COLLECT_DATA_SERVER, SET_COLLECT_DATA_COMMAND_ID, out_data, out_len);
|
|
}
|
|
|
|
/* 数采规范 3.3.3 获取历史数据 */
|
|
static void get_history(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
|
|
}
|
|
|
|
/* 数采规范 3.3.4 历史数据结束 */
|
|
static void history_finish(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
|
|
}
|
|
|
|
/* 数采规范 3.3.5 历史数据清除 */
|
|
static void clear_history(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
|
|
}
|
|
|
|
/* 数采规范 3.3.6 拓展编号 */
|
|
static void expand_command(uint8_t *in_data, uint16_t in_len)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/* 4.26.3 指令交互 */
|
|
static void ble_set_collect_data_command(uint8_t *in_data, uint16_t in_len, uint8_t *out_data, uint16_t *out_len)
|
|
{
|
|
uint8_t packet_head = 0; // 包头
|
|
uint8_t cmd_id = 0; // 指令编号
|
|
|
|
// am_util_stdio_printf("len = %d\n", in_len);
|
|
// for (uint32_t i = 0; i < in_len; i++) {
|
|
// am_util_stdio_printf("[%02d]%02X\n", i, in_data[i]);
|
|
// }
|
|
|
|
packet_head = in_data[0];
|
|
cmd_id = in_data[3];
|
|
|
|
if (packet_head == 0xFD) {
|
|
if (cmd_id >= 0x80 && cmd_id <= 0xFF) {
|
|
expand_command(in_data, in_len);
|
|
} else {
|
|
switch (cmd_id) {
|
|
case COLLECT_DATA_CMD_APP_START:
|
|
case COLLECT_DATA_CMD_DEV_START:
|
|
collect_start(in_data, in_len);
|
|
break;
|
|
|
|
case COLLECT_DATA_CMD_DEV_STOP:
|
|
case COLLECT_DATA_CMD_APP_STOP:
|
|
collect_stop(in_data, in_len);
|
|
break;
|
|
|
|
case COLLECT_DATA_CMD_GET_HISTORY:
|
|
get_history(in_data, in_len);
|
|
break;
|
|
|
|
case COLLECT_DATA_CMD_HISTORY_FINISH:
|
|
history_finish(in_data, in_len);
|
|
break;
|
|
|
|
case COLLECT_DATA_CMD_CLEAR_HISTORY:
|
|
clear_history(in_data, in_len);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
*out_len = 0;
|
|
}
|
|
|
|
const p_func_t collect_data_server_func[COLLECT_DATA_SERVERE_MAX_ID] = {
|
|
user_null_func,
|
|
user_null_func, //4.26.1
|
|
user_null_func, //4.26.2
|
|
ble_set_collect_data_command, //4.26.3
|
|
};
|
|
|