feat: add the decode_start_data_char_notify() & stop_data_char_notify() function for dev_mode

This commit is contained in:
Roy_01
2024-12-10 10:08:04 +08:00
parent 4abf04c08d
commit d6fa983da5
+162 -12
View File
@@ -21,9 +21,22 @@ typedef struct
uint32_t mask;
} input_pin_t;
TaskHandle_t test_gpio_task_Handle = NULL;
typedef struct
{
uint16_t pattern_id;
uint32_t pattern;
} resistor_combination_t;
static pel_output_t output_data = { 0 };
typedef struct __PACKED
{
uint32_t notify_period;
uint32_t total_notify_count;
} characteristic_param_t;
static bool data_char_notify_running;
TaskHandle_t test_gpio_task_Handle = NULL;
static pel_output_t output_data = { 0 };
static resistor_combination_t global_resis = { 0 };
const input_pin_t input_pin_tab[] = {
{ 0.5, INPUT_1_PIN, PEL_0P5R_MASK},
@@ -42,7 +55,9 @@ const input_pin_t input_pin_tab[] = {
static float _load_set(uint32_t mask)
{
float ohms = 0;
float ohms = 0;
global_resis.pattern = mask;
for (int32_t i = COUNTOF(input_pin_tab) - 1; i >= 0; i--)
{
if (input_pin_tab[i].mask & mask)
@@ -67,12 +82,6 @@ void set_high_z_state(void)
void set_pattern_resistor(uint16_t pattern_id)
{
typedef struct
{
uint16_t pattern_id;
uint32_t pattern;
} resistor_combination_t;
const resistor_combination_t pattern_tab[] = {
{ 1, 0b111},
{ 2, 0b011},
@@ -119,6 +128,8 @@ void set_pattern_resistor(uint16_t pattern_id)
{43, 0b1 << 11},
};
global_resis.pattern_id = pattern_id;
for (int32_t i = 0; i < ARRAY_SIZE(pattern_tab); i++)
{
if (pattern_tab[i].pattern_id == pattern_id)
@@ -278,9 +289,9 @@ pel_output_t pel_smaple_and_convt_all(uint32_t measure_out, uint32_t load_mask)
#define VERSION_DATE_YEAR 24
#define VERSION_DATE_MONTH 12
#define VERSION_DATE_DAY 4
#define VERSION_DATE_HOUR 11
#define VERSION_DATE_MINUTE 33
#define VERSION_DATE_DAY 10
#define VERSION_DATE_HOUR 10
#define VERSION_DATE_MINUTE 8
static void cis_version(uint8_t *ins, uint16_t size)
{
NRF_LOG_INFO("%s", __FUNCTION__);
@@ -475,6 +486,137 @@ static void data_char_update_once(void)
data.val_10_f += 0.01;
}
static ret_code_t _send_data_char_notify_start_packet(void *p_buf, uint16_t p_buf_size, uint32_t loops)
{
memset(p_buf, 0x00, sizeof(p_buf));
for (uint32_t i = 0; i < loops; i++)
{
ret_code_t le_data_notify(uint8_t * p_value, uint16_t len);
ret_code_t ret = le_data_notify((void *)p_buf, p_buf_size);
if (ret != NRF_SUCCESS)
{
return ret;
}
}
return NRF_SUCCESS;
}
static void start_data_char_notify_task(void *p_arg)
{
typedef struct __PACKED
{
uint8_t mem_board_id;
uint32_t notify_time;
uint8_t packet_seq;
int32_t val_1;
int32_t val_2;
int32_t val_3;
int32_t val_4;
int32_t val_5;
float val_6_f;
float val_7_f;
float val_8_f;
float val_9_f;
float val_10_f;
uint16_t pattern_id;
uint32_t pattern;
} data_char_packet_t;
bool first_data = true;
data_char_packet_t packet_buf;
characteristic_param_t *data_char_notify_param = (characteristic_param_t *)p_arg;
data_char_notify_running = true;
memset(&packet_buf, 0x00, sizeof(packet_buf));
_send_data_char_notify_start_packet(&packet_buf, sizeof(packet_buf), 4);
for (;;)
{
if (data_char_notify_running)
{
if (first_data)
{
packet_buf.mem_board_id = 5;
packet_buf.notify_time = xTaskGetTickCount();
packet_buf.packet_seq = 0;
packet_buf.val_1 = 0;
packet_buf.val_2 = 100;
packet_buf.val_3 = 1000;
packet_buf.val_4 = 10000;
packet_buf.val_5 = 100000;
packet_buf.val_6_f = 1.0;
packet_buf.val_7_f = 5.0;
packet_buf.val_8_f = 10.0;
packet_buf.val_9_f = 15.0;
packet_buf.val_10_f = 20.0;
packet_buf.pattern_id = global_resis.pattern_id;
packet_buf.pattern = global_resis.pattern;
first_data = false;
}
else
{
packet_buf.mem_board_id = 5;
packet_buf.notify_time = xTaskGetTickCount();
packet_buf.packet_seq += 1;
packet_buf.val_1 += 1;
packet_buf.val_2 += 1;
packet_buf.val_3 += 1;
packet_buf.val_4 += 1;
packet_buf.val_5 += 1;
packet_buf.val_6_f += 0.01;
packet_buf.val_7_f += 0.01;
packet_buf.val_8_f += 0.01;
packet_buf.val_9_f += 0.01;
packet_buf.val_10_f += 0.01;
packet_buf.pattern_id = global_resis.pattern_id;
packet_buf.pattern = global_resis.pattern;
}
ret_code_t le_data_notify(uint8_t * p_value, uint16_t len);
ret_code_t ret = le_data_notify((void *)&packet_buf, sizeof(packet_buf));
{
char str[128];
snprintf(str, sizeof(str), "{%d, %d, %d, %d, %d, %d, %d, %d, %.7f, %.7f, %.7f, %.7f, %.7f, %d, 0x%08X}", packet_buf.mem_board_id, packet_buf.notify_time, packet_buf.packet_seq, packet_buf.val_1, packet_buf.val_2, packet_buf.val_3, packet_buf.val_4, packet_buf.val_5, packet_buf.val_6_f, packet_buf.val_7_f, packet_buf.val_8_f, packet_buf.val_9_f, packet_buf.val_10_f, packet_buf.pattern_id, packet_buf.pattern);
NRF_LOG_INFO("%s", str);
}
vTaskDelay(pdMS_TO_TICKS(data_char_notify_param->notify_period));
}
else // stop data update process
{
free(data_char_notify_param);
vTaskDelete(NULL);
}
}
}
static void decode_start_data_char_notify(uint8_t *param)
{
characteristic_param_t *data_char_notify_param = malloc(sizeof(characteristic_param_t));
if (data_char_notify_param == NULL)
{
NRF_LOG_ERROR("Failed to allocate memory for data_char_notify_param");
return;
}
data_char_notify_param->notify_period = u8_to_u32(param[0], param[1], param[2], param[3]);
data_char_notify_param->total_notify_count = u8_to_u32(param[0], param[1], param[2], param[3]);
data_char_notify_param->notify_period = 100;
data_char_notify_param->total_notify_count = 5;
xTaskCreate(start_data_char_notify_task, "start_data_char_notify_task", 2048, (void *)data_char_notify_param, 3, NULL);
}
static void stop_data_char_notify(void)
{
data_char_notify_running = false;
}
static void dev_mode_characteristic(uint8_t *ins)
{
NRF_LOG_INFO("[DEV MODE] %s", __FUNCTION__);
@@ -496,6 +638,14 @@ static void dev_mode_characteristic(uint8_t *ins)
data_char_update_once();
break;
case 0x01:
decode_start_data_char_notify(p_ins->param);
break;
case 0x02:
stop_data_char_notify();
break;
default:
break;
}