first init
This commit is contained in:
123
has_project/has_app/acm/has_acm.c
Normal file
123
has_project/has_app/acm/has_acm.c
Normal file
@@ -0,0 +1,123 @@
|
||||
#include "has_platform.h"
|
||||
static OS_THREAD_ID protocol_tid;
|
||||
static OS_THREAD_ID send_test_tid;
|
||||
static unsigned char *read_buffer;
|
||||
|
||||
#define REC_BUFFER_LEN_MAX 1024
|
||||
#define PROCESS_MSG_PERIOD 3000
|
||||
#define TEST_EVENT 0
|
||||
#define TEST_EVENT1 1
|
||||
#define TEST_EVENT2 2
|
||||
|
||||
static has_ptcl_handler *g_handler = NULL;
|
||||
|
||||
static void has_receive_from_mcu(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
}
|
||||
static void has_receive_from_mcu_1(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
}
|
||||
static void has_receive_from_mcu_2(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int acm_hal_send(uint8_t *buff, uint32_t len)
|
||||
{
|
||||
return has_dev_write(UART, 0, buff, len);
|
||||
}
|
||||
|
||||
void resend_callback(has_tlv_t *p_tlv, uint8_t resend_cnt)
|
||||
{
|
||||
printf("retry to send msg event:%d cnt:%d\n", p_tlv->event, resend_cnt);
|
||||
}
|
||||
|
||||
void send_success_callback(has_tlv_t *p_tlv)
|
||||
{
|
||||
printf("event %x send successfully\n", p_tlv->event);
|
||||
}
|
||||
|
||||
void send_fail_callback(has_tlv_t *p_tlv)
|
||||
{
|
||||
printf("event %x send fail\n", p_tlv->event);
|
||||
}
|
||||
|
||||
void *protocol_task(void *param)
|
||||
{
|
||||
int actuall_len;
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* reads */
|
||||
actuall_len = has_dev_read(UART, 0, read_buffer, REC_BUFFER_LEN_MAX);
|
||||
if (actuall_len > 0)
|
||||
{
|
||||
has_protocol_recv_process(g_handler, read_buffer, actuall_len);
|
||||
}
|
||||
has_sleep_ms(PROCESS_MSG_PERIOD);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void msg_handle_cb(unsigned char module_id, const unsigned char *buf, unsigned int len)
|
||||
{
|
||||
if (has_protocol_send(g_handler, module_id, buf, 1, need_confirm) != 0) {
|
||||
printf("send err module:%x\n", module_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *send_test_task(void *param)
|
||||
{
|
||||
unsigned char data = 3;
|
||||
while (1)
|
||||
{
|
||||
/* write */
|
||||
has_msg_handle(ACM, msg_handle_cb, PROCESS_MSG_PERIOD);
|
||||
/* 重发,发送失败需要publish,注册发送的硬件接口 */
|
||||
// has_protocol_send(g_handler, TEST_EVENT2, &data, sizeof(data), need_confirm);
|
||||
}
|
||||
}
|
||||
|
||||
int example_protocol_init(void)
|
||||
{
|
||||
has_protocol_attr attr;
|
||||
kbox_event uart_list[] =
|
||||
{
|
||||
{TEST_EVENT, has_receive_from_mcu},
|
||||
{TEST_EVENT1, has_receive_from_mcu_1},
|
||||
{TEST_EVENT2, has_receive_from_mcu_2},
|
||||
};
|
||||
attr.ev_list = uart_list;
|
||||
attr.ev_list_sz = sizeof(uart_list) / sizeof(uart_list[0]);
|
||||
attr.hal_send_cb = acm_hal_send;
|
||||
attr.resend_cb = resend_callback;
|
||||
attr.retry_max_cnt = 1;
|
||||
attr.wait_period = 500;
|
||||
attr.success_cb = send_success_callback;
|
||||
attr.fail_cb = send_fail_callback;
|
||||
|
||||
g_handler = has_protocol_create(&attr);
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
printf("create ACM handler err!\n");
|
||||
return NULL;
|
||||
}
|
||||
printf("module:ACM\n");
|
||||
/* 创建线程 */
|
||||
if (has_task_create("read_test", TASK_PRIORITY_NORMAL, 1024, protocol_task, NULL, &protocol_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
return -1;
|
||||
}
|
||||
if (has_task_create("send_test", TASK_PRIORITY_NORMAL, 1024, send_test_task, NULL, &send_test_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
HAS_DECLARE_MODULE(ACM, example_protocol_init)
|
||||
Reference in New Issue
Block a user