From 6b27b1e189eeaa743d3599c7b411552ff6566bde Mon Sep 17 00:00:00 2001 From: Seungsu Lim Date: Fri, 24 May 2019 19:23:47 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A8=ED=8E=B8=ED=99=94=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c | 4 +- Drivers/CC2530/CC2530_MAC/Src/mac_interface.c | 6 +- Drivers/INTEG_MAC/Inc/integ_mac.h | 75 ++++---- Drivers/INTEG_MAC/Inc/mem_pool.h | 10 ++ Drivers/INTEG_MAC/Src/integ_mac.c | 163 ++++++++++++++---- Drivers/INTEG_MAC/Src/mem_pool.c | 43 +++++ Drivers/LIFI/LIFI_MAC/Inc/lifi.h | 15 ++ Drivers/LIFI/LIFI_MAC/Src/lifi.c | 8 + Inc/list.h | 20 +++ Src/display.c | 2 +- Src/list.c | 88 ++++++++++ Src/main.c | 109 ++++++++++-- Src/stm32f4xx_hal_msp.c | 7 +- Src/task.c | 42 +++-- Src/timer.c | 5 +- Src/uart.c | 24 ++- 16 files changed, 519 insertions(+), 102 deletions(-) create mode 100644 Drivers/INTEG_MAC/Inc/mem_pool.h create mode 100644 Drivers/INTEG_MAC/Src/mem_pool.c create mode 100644 Inc/list.h create mode 100644 Src/list.c diff --git a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c index 04dcf6c..6f2fa58 100644 --- a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c +++ b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c @@ -39,7 +39,9 @@ unsigned char bluetooth_init(unsigned char deviceType) unsigned char bluetooth_send(unsigned char* dest_addr, unsigned char* data, int data_length) { //printf("[BLUETOOTH] ���� �õ�\r\n"); - HAL_UART_Transmit(&huart2, data, data_length, 1000); + memcpy(btBuf, data, INTEG_FRAME_HEADER_LEN); + memcpy(btBuf + INTEG_FRAME_HEADER_LEN, ((INTEG_FRAME*) data)->data, data_length - INTEG_FRAME_HEADER_LEN); + HAL_UART_Transmit(&huart2, btBuf, data_length, 1000); return 0; } diff --git a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c index e578c40..80d35a6 100644 --- a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c +++ b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c @@ -452,7 +452,11 @@ unsigned char macDataReq(unsigned char* dest_addr, unsigned char* data, int data macBuf[30] = data_length; // MSDU - memcpy(macBuf+31, data, data_length); + //memcpy(macBuf+31, data, data_length); + + memcpy(macBuf+31, data, INTEG_FRAME_HEADER_LEN); + memcpy(macBuf+31 + INTEG_FRAME_HEADER_LEN, ((INTEG_FRAME*) data)->data, data_length - INTEG_FRAME_HEADER_LEN); + uartSreq(STATE_SREQ); diff --git a/Drivers/INTEG_MAC/Inc/integ_mac.h b/Drivers/INTEG_MAC/Inc/integ_mac.h index 0157191..873ddc1 100644 --- a/Drivers/INTEG_MAC/Inc/integ_mac.h +++ b/Drivers/INTEG_MAC/Inc/integ_mac.h @@ -4,6 +4,10 @@ */ + +// ����ȭ �׽�Ʈ �� ������ +extern unsigned char testBuf_2[120]; + #define MEDIA_NUM 3 // ��� ��ü �� #define LIFI 0 // Media Type #define BLUETOOTH 1 @@ -16,8 +20,8 @@ static char *media_name[MEDIA_NUM] = {"LI-FI", "BLUETOOTH", "CC2530"}; extern unsigned char integ_init_state; // ���� MAC �ʱ�ȭ ���� // ���� ���� ���� ���̺� -#define STATUS_NUM 2 -#define INIT_STATUS 0 +#define STATUS_NUM 2 // ���� ���� +#define INIT_STATUS 0 #define CONNECT_STATUS 1 #define CON 1 #define DISCON 0 @@ -27,9 +31,9 @@ extern unsigned char STATUS_TABLE[STATUS_NUM][MEDIA_NUM]; #define FIND_OPT_PERIOD 5 // ���� ��� �˻� �ֱ� 500ms #define RETRANSMIT_TIME 3 // ������ �ֱ� 300ms -#define RETRANSMIT_NUM 3 // ������ Ƚ�� -#define R_SUCCESS 1 -#define R_FAIL 0 +#define RETRANSMIT_NUM 3 // 3�� ACK �ȿ��� ��� ������ +#define R_SUCCESS 1 // ���� ��� : ���� +#define R_FAIL 0 // ���� ��� : ���� static char *result_string[2] = {"FAIL", "SUCCESS"}; #define INTEG_ADDR_LEN 6 // ���� �� �ּ� ���� @@ -37,59 +41,68 @@ static char *result_string[2] = {"FAIL", "SUCCESS"}; #define BLUETOOTH_ADDR_LEN 6 // BLUETOOTH �� �ּ� ���� #define CC2530_ADDR_LEN 8 // CC2530 �� �ּ� ���� #define MEDIA_ADDR_LEN_MAX 8 // �� ��ü �ּ��� ���̰��� �� �� -static unsigned char media_addr_len[MEDIA_NUM] = {LIFI_ADDR_LEN, BLUETOOTH_ADDR_LEN, CC2530_ADDR_LEN}; +static unsigned char media_addr_len[MEDIA_NUM] = {LIFI_ADDR_LEN, BLUETOOTH_ADDR_LEN, CC2530_ADDR_LEN}; /// �� ��ü �ּ� ���� �ε����� ���� �� -#define INTEG_FRAME_HEADER_LEN 17 // ���� �� ������ ��� ���� -#define INTEG_FRAME_DATA_LEN 40 -#define INTEG_FRAME_TOTAL_LEN 57 +#define INTEG_FRAME_HEADER_LEN 19 // ���� �� ������ ��� ���� +#define INTEG_FRAME_DATA_LEN 39 // ���� �� ������ ������ ���� +#define INTEG_FRAME_TOTAL_LEN 58 + 1 // ���� �� ������ ��� + ������ ���� -#define INTEG_FRAME_LEN_FIELD 0 +#define INTEG_FRAME_LEN_FIELD 0 // ������ ���� �ʵ�� ���� �������� 0�� // messageType -#define DATA_MSG 0x01 -#define ACK_MSG 0x02 -#define ADV_MSG 0x04 -#define ADV_IND 0x05 -#define PASS_MSG 0xFF +#define DATA_MSG 0x01 // �Ϲ� �����͸� ���� �޽��� +#define ACK_MSG 0x02 // ���� �޽��� +#define ADV_MSG 0x04 // ��� �ڽ��� ���縦 ��ε�ij���� �Ҷ� +#define ADV_IND 0x05 // ADV_MSG�� ���� ���� +#define PASS_MSG 0xFF // �ƹ��͵� ���� �޽��� // deviceType #define MASTER 0x00 #define SLAVE 0x01 +// fragmentaion ���� +static int media_mtu_size[MEDIA_NUM] = {20, 43, 91}; +extern unsigned char fragment_id; +#define DEFAULT_FRAGMENT_ID 0 // ����ȭ �ĺ��� �ʱⰪ +#define MIN_MTU_SIZE 48 // ��ü�� MTU ũ�� �� ���� ���� �� + -extern unsigned char my_integ_address[INTEG_ADDR_LEN]; -#define HOOD_HASH_ID 0x10 -extern unsigned char hood_integ_address[INTEG_ADDR_LEN]; +// SEQ #define MAX_SEQ_NUMBER 10 // ���� ��ȣ �ִ� #define DEFAULT_SEQ_NUMBER 0 // ���� ��ȣ �ʱⰪ extern unsigned char seqNumber; // ���� ��ȣ -#define STATIC_ADDR 0 -#define DYNAMIC_ADDR 1 -static char *addr_type_name[2] = {"STATIC", "DYNAMIC"}; +#define STATIC_ADDR 0 // �������� ���� �ּ� (�ڽ��� �ּ�, ��ε�ij��Ʈ) +#define DYNAMIC_ADDR 1 // �ܺη� ���� ������ ���� +static char *addr_type_name[2] = {"STATIC", "DYNAMIC"}; +extern unsigned char my_integ_address[INTEG_ADDR_LEN]; +extern unsigned char hood_integ_address[INTEG_ADDR_LEN]; // ���� MAC ���̺� ����ü typedef struct integ_table { - unsigned char integ_addr[INTEG_ADDR_LEN]; + unsigned char integ_addr[INTEG_ADDR_LEN]; // ���� MAC �ּ� unsigned char addr_type; // static : 0, dynamic : 1 - unsigned char media_addr[MEDIA_NUM][MEDIA_ADDR_LEN_MAX]; + unsigned char media_addr[MEDIA_NUM][MEDIA_ADDR_LEN_MAX]; // �� ��ü �ּ� } INTEG_TABLE; // ���� MAC ������ ����ü typedef struct integ_frame { - unsigned char frame_length; - unsigned char message_type; - unsigned char src_address[INTEG_ADDR_LEN]; - unsigned char dest_address[INTEG_ADDR_LEN]; - unsigned char media_type; - unsigned char seqNumber; - unsigned char ackNumber; - unsigned char data[INTEG_FRAME_DATA_LEN]; + unsigned char frame_length; // ������ ���� + unsigned char message_type; // �޽��� ���� + unsigned char src_address[INTEG_ADDR_LEN]; // �ٿ��� �ּ� + unsigned char dest_address[INTEG_ADDR_LEN]; // ������ �ּ� + unsigned char media_type; // ��ü ���� + unsigned char seqNumber; // ���� ��ȣ + unsigned char ackNumber; // ���� ��ȣ + unsigned char fragment_id; // ����ȭ �ĺ��� + unsigned char fragment_offset; // ������ ��Ʈ ������ + unsigned char *data;// ���̷ε� } INTEG_FRAME; + extern INTEG_FRAME advertising_frame; unsigned char get_seq_number(void); diff --git a/Drivers/INTEG_MAC/Inc/mem_pool.h b/Drivers/INTEG_MAC/Inc/mem_pool.h new file mode 100644 index 0000000..5bdd766 --- /dev/null +++ b/Drivers/INTEG_MAC/Inc/mem_pool.h @@ -0,0 +1,10 @@ +/* + mem_pool.h +*/ + +#define MAX_MEM_POOL_SIZE 30 +#define MEM_SIZE 100 + +void mem_pool_init(void); +unsigned char *get_mem(void); +unsigned char return_mem(unsigned char *mem); \ No newline at end of file diff --git a/Drivers/INTEG_MAC/Src/integ_mac.c b/Drivers/INTEG_MAC/Src/integ_mac.c index f4e4e10..deeddca 100644 --- a/Drivers/INTEG_MAC/Src/integ_mac.c +++ b/Drivers/INTEG_MAC/Src/integ_mac.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "integ_mac.h" #include "frame_queue.h" #include "task.h" @@ -11,16 +12,25 @@ #include "mac_interface.h" // CC2530 #include "uart.h" #include "display.h" +#include "mem_pool.h" #define STM32_UUID ((uint32_t *)0x1FFF7A10) +unsigned char testBuf_2[120] = {'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1', +'2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2', +'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1', +'2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2','2', +'1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'}; + +unsigned char testBuf_recv[120]; + // dispaly �� ���� char message_buffer[COL_NUMS]; // �� ��ü �� �Լ� ������ -unsigned char (*fun_init[MEDIA_NUM])(unsigned char) = {lifi_init, bluetooth_init, startMac}; // �ʱ�ȭ -unsigned char (*fun_send[MEDIA_NUM])(unsigned char* , unsigned char* , int ) = {lifi_send, bluetooth_send, macDataReq}; // ������ ���� -unsigned char* (*fun_get_addr[MEDIA_NUM])(unsigned char) = {lifi_get_mac_addr, bt_get_mac_addr, cc2530_get_mac_addr}; // ��ü �ּ� ��� +unsigned char (*fun_init[MEDIA_NUM])(unsigned char) = {lifi_init, bluetooth_init, startMac}; // �� ��ü �ʱ�ȭ �Լ� ������ +unsigned char (*fun_send[MEDIA_NUM])(unsigned char* , unsigned char* , int ) = {lifi_send, bluetooth_send, macDataReq}; // �� ��ü ������ ���� �Լ� ������ +unsigned char* (*fun_get_addr[MEDIA_NUM])(unsigned char) = {lifi_get_mac_addr, bt_get_mac_addr, cc2530_get_mac_addr}; // �� ��ü �ּ� ��� �Լ� ������ // �̿� �ּ� @@ -42,6 +52,7 @@ unsigned char my_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x67, 0x11, 0x11, 0x11 unsigned char integ_broadcast_addr[INTEG_ADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; INTEG_FRAME advertising_frame; +INTEG_FRAME t_frame; // �ӽÿ� ������ ���� unsigned char seqNumber; // ���� ��ȣ unsigned char cur_media; // ���� ����ϴ� ��ü @@ -49,8 +60,12 @@ INTEG_FRAME advertising_frame; unsigned char opt_media; // ������ ��ü unsigned char deviceType; // ��ġ ���� +// ��ü ���� ���̺� unsigned char STATUS_TABLE[STATUS_NUM][MEDIA_NUM] = {{R_FAIL, R_FAIL, R_FAIL}, {DISCON, DISCON, DISCON}}; + +// ���� MAC �ʱ�ȭ ���� (1 : �ʱ�ȭ �Ϸ�) unsigned char integ_init_state = 0; +unsigned char fragment_id; #define TRANSMIT_FRAME 1 #define RECEIVE_FRAME 0 @@ -58,13 +73,12 @@ void integ_mac_handler(void * arg) { struct task task, retrans_task; struct node *table = NULL; // MAC ���̺� ������ ���� - INTEG_FRAME *frame = NULL; - INTEG_FRAME t_frame; - unsigned char message_type; + INTEG_FRAME *frame = NULL; // ���� ������ ť���� ������ �������� ����Ű�� ������ + unsigned char message_type; // �޽��� ���� unsigned char result; // �Լ� ���� ��� ����� ���� unsigned char frame_state; // �۽ſ� ���ſ� ���� unsigned char mac_table_key; // �����̺� ���� �� Ű - int i; + int i; // for �ݺ��� �� while((frame = frame_queue_delete()) != NULL) { //integ_print_frame(frame); @@ -119,17 +133,55 @@ void integ_mac_handler(void * arg) //insert_display_message(message_buffer); } - sprintf(message_buffer, "[SEQ : %d] ������ ������ (�� ������ : %02X) : %s\r\n", frame->seqNumber, frame->dest_address[0], frame->data); + sprintf(message_buffer, "[SEQ : %d] ������ ������ (�� ������ : %02X)\r\n", frame->seqNumber, frame->dest_address[0]); + // sprintf(message_buffer, "[SEQ : %d] ������ ������ (�� ������ : %02X) : %s\r\n", frame->seqNumber, frame->dest_address[0], frame->data); insert_display_message(cur_media, message_buffer); } // ó�� ������ ��� else { - frame->media_type ^= OPT_MEDIA; - re_frame_queue_insert((unsigned char *)frame); - frame->media_type = cur_media; - - sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� ������ : %02X) : %s\r\n", frame->seqNumber, frame->dest_address[0], frame->data); - insert_display_message(cur_media, message_buffer); + // �����Ϸ��� �������� �� ��ü �ּ� MTU ũ�⺸�� ū ��� + if(frame->frame_length > MIN_MTU_SIZE) { + + // ����ȭ �غ� + int i; + int total_data_len = frame->frame_length - INTEG_FRAME_HEADER_LEN; + + int fragment_count = ceil((total_data_len / (double) (MIN_MTU_SIZE - INTEG_FRAME_HEADER_LEN))); + + //printf("%d %d %d", fragment_count, frame->frame_length, MIN_MTU_SIZE); + + memcpy(&t_frame, frame, INTEG_FRAME_HEADER_LEN); + t_frame.fragment_id = DEFAULT_FRAGMENT_ID; + t_frame.fragment_offset = 0; + t_frame.media_type = opt_media; + + int max_octet_length = (MIN_MTU_SIZE - INTEG_FRAME_HEADER_LEN) / 8; + for (i = 0; i < fragment_count; i++) { + t_frame.frame_length = INTEG_FRAME_HEADER_LEN + max_octet_length * 8; + if (i >= 1) { + t_frame.seqNumber = get_seq_number(); + } + + t_frame.fragment_offset = i * max_octet_length; + if (i != (fragment_count - 1)) { // MF ���� + t_frame.fragment_offset |= 0x80; + } + + t_frame.data = get_mem(); + memcpy(t_frame.data, frame->data + ((t_frame.fragment_offset & 0x7F) * 8), max_octet_length * 8); + frame_queue_insert((unsigned char *)&t_frame); + } + } + // �����Ϸ��� �������� �� ��ü �ּ� MTU ũ�⺸�� ���� ��� ����ȭ ���� �ٷ� ���� + else { + frame->media_type ^= OPT_MEDIA; + re_frame_queue_insert((unsigned char *)frame); + frame->media_type = cur_media; + + sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� ������ : %02X) \r\n", frame->seqNumber, frame->dest_address[0]); + // sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� ������ : %02X) : %s\r\n", frame->seqNumber, frame->dest_address[0], frame->data); + insert_display_message(cur_media, message_buffer); + } } // ������ Task �߰� @@ -149,17 +201,33 @@ void integ_mac_handler(void * arg) else if(frame_state == RECEIVE_FRAME) { //printf("** Data ����\r\n"); + // ����ȭ ������ ���� �� + // MF�� ���õǾ� �ְų�, fragment_offset�� 0�� �ƴ� ��� + unsigned char more_flag = frame->fragment_offset & 0x80; + unsigned char offset = frame->fragment_offset & 0x7F; + + if ((more_flag == 0x80 )|| (offset != 0)){ + memcpy(testBuf_recv + (offset * 8), frame->data, frame->frame_length - INTEG_FRAME_HEADER_LEN); + } + + // ACK ��Ŷ ���� t_frame.frame_length = frame->frame_length; t_frame.message_type = ACK_MSG; t_frame.media_type = frame->media_type & 0x0F; t_frame.ackNumber = frame->seqNumber + 1; + t_frame.data = NULL; memcpy(t_frame.dest_address, frame->src_address, INTEG_ADDR_LEN); memcpy(t_frame.src_address, my_integ_address, INTEG_ADDR_LEN); - sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� �ٿ��� : %02X) : %s\r\n", frame->seqNumber, frame->src_address[0], frame->data); + sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� �ٿ��� : %02X) \r\n", frame->seqNumber, frame->src_address[0]); + // sprintf(message_buffer, "[SEQ : %d] ������ ���� ( �� �ٿ��� : %02X) : %s\r\n", frame->seqNumber, frame->src_address[0], frame->data); insert_display_message(t_frame.media_type, message_buffer); + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; + // ���� ��ü ���� ���� ���� STATUS_TABLE[CONNECT_STATUS][t_frame.media_type] = CON; @@ -184,6 +252,7 @@ void integ_mac_handler(void * arg) sprintf(message_buffer, "[ACK : %d] ACK �۽� ( �� ������ : %02X) \r\n", frame->ackNumber, frame->dest_address[0]); insert_display_message(cur_media, message_buffer); + } // ACK ���� �� else if(frame_state == RECEIVE_FRAME) { @@ -198,6 +267,10 @@ void integ_mac_handler(void * arg) sprintf(message_buffer, "[ACK : %d] ACK ���� ( ��ٿ��� : %02X) \r\n", frame->ackNumber, frame->src_address[0]); insert_display_message(frame->media_type, message_buffer); + + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; } break; case ADV_MSG: @@ -206,7 +279,7 @@ void integ_mac_handler(void * arg) // INTEG ADDR -> MAC ADDR ��ȯ if(table != NULL) { // �۽� - + for(i = 0; i < MEDIA_NUM; i++) { frame->media_type = i; //printf("%s ADV_MSG �۽�\r\n", media_name[frame->media_type]); @@ -214,6 +287,7 @@ void integ_mac_handler(void * arg) HAL_Delay(30); } } + frame->data = NULL; //frame_queue_insert((unsigned char *)frame); } // ADV_MSG ���� ���� ��� @@ -240,6 +314,7 @@ void integ_mac_handler(void * arg) } // ADV_MSG �۽��ڿ��� MAC ���̺��� �����ؼ� ADV_IND ���� + t_frame.data = get_mem(); t_frame.frame_length = frame->frame_length; t_frame.message_type = ADV_IND; t_frame.media_type = frame->media_type; @@ -247,6 +322,10 @@ void integ_mac_handler(void * arg) memcpy(t_frame.dest_address, frame->src_address, INTEG_ADDR_LEN); memcpy(t_frame.data, advertising_frame.data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); frame_queue_insert((unsigned char *)&t_frame); + + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; } break; @@ -261,6 +340,9 @@ void integ_mac_handler(void * arg) HAL_Delay(30); fun_send[frame->media_type](table->data.media_addr[frame->media_type], (unsigned char *)frame, frame->frame_length); } + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; } // ADV_IND ���� ���� ��� else if(frame_state == RECEIVE_FRAME) { @@ -283,11 +365,23 @@ void integ_mac_handler(void * arg) sprintf(message_buffer, "���ο� �̿���� (���� MAC �ּ� : %02X) �߰� MAC TABLE �߰�\r\n", table->data.integ_addr[0]); insert_display_message(INTEG_MSG, message_buffer); } + + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; } break; case PASS_MSG: //printf("������ ���\r\n"); + + // �޸� -> Ǯ ��ȯ + return_mem(frame->data); + frame->data = NULL; + break; + default: + sprintf(message_buffer, "�߸��� ���� MAC ������ (Error Type : %02X)\r\n", frame->message_type); + insert_display_message(INTEG_MSG, message_buffer); break; } } @@ -318,11 +412,14 @@ void integ_mac_init(void) insert_display_message(INTEG_MSG, "���� MAC �ʱ�ȭ ����\r\n"); + fragment_id = DEFAULT_FRAGMENT_ID; seqNumber = DEFAULT_SEQ_NUMBER; // ������ȣ �ʱ�ȭ frame_queue_init(); // ���� ������ ť �ʱ�ȭ re_frame_queue_init(); // ������ ������ ť �ʱ�ȭ + advertising_frame.data = get_mem(); + // �ӽ� if (LSB(STM32_UUID[0]) == 0x2c) { hood_integ_address[0] = 0x2E; @@ -355,10 +452,10 @@ void integ_mac_init(void) } // �� ��ü �ּ� �������� - memcpy(my_integ_address, integ_get_mac_addr(MAC_ADDR), INTEG_ADDR_LEN); - memcpy(my_cc2530_address, cc2530_get_mac_addr(MAC_ADDR), CC2530_ADDR_LEN); - memcpy(my_bluetooth_address, bt_get_mac_addr(MAC_ADDR), BLUETOOTH_ADDR_LEN); - memcpy(my_lifi_address, lifi_get_mac_addr(MAC_ADDR), LIFI_ADDR_LEN); + memcpy(my_integ_address, integ_get_mac_addr(MAC_ADDR), INTEG_ADDR_LEN); // ���� + memcpy(my_cc2530_address, cc2530_get_mac_addr(MAC_ADDR), CC2530_ADDR_LEN); // CC2530 + memcpy(my_bluetooth_address, bt_get_mac_addr(MAC_ADDR), BLUETOOTH_ADDR_LEN); // BT + memcpy(my_lifi_address, lifi_get_mac_addr(MAC_ADDR), LIFI_ADDR_LEN); // LI-FI // advertising frame ���� advertising_frame.frame_length = INTEG_FRAME_HEADER_LEN + MEDIA_NUM * MEDIA_ADDR_LEN_MAX; @@ -369,9 +466,18 @@ void integ_mac_init(void) memcpy(advertising_frame.data + (i * MEDIA_ADDR_LEN_MAX), fun_get_addr[i](MAC_ADDR), MEDIA_ADDR_LEN_MAX); } - // advertising frame ���� + // advertising �۽� frame ���� frame_queue_insert((unsigned char *)&advertising_frame); + // �ڽ��� �� ���̺� ���� + table = get_hashNode(); + table->id = LSB(STM32_UUID[0]); + + table->data.addr_type = STATIC_ADDR; + memcpy(table->data.integ_addr, my_integ_address, INTEG_ADDR_LEN); + memcpy(table->data.media_addr, advertising_frame.data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); + AddHashData(table->id, table); + // Boradcast MAC table ���� table = get_hashNode(); table->id = 0xFF; @@ -384,15 +490,6 @@ void integ_mac_init(void) AddHashData(table->id, table); - // �ڽ��� �� ���̺� ���� - table = get_hashNode(); - table->id = LSB(STM32_UUID[0]); - - table->data.addr_type = STATIC_ADDR; - memcpy(table->data.integ_addr, my_integ_address, INTEG_ADDR_LEN); - memcpy(table->data.media_addr, advertising_frame.data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); - AddHashData(table->id, table); - /* // �̿� �� ���̺� ���� table = get_hashNode(); @@ -406,13 +503,13 @@ void integ_mac_init(void) AddHashData(table->id, table); */ + // ���� ��ü ���� + integ_find_opt_link(NULL); + // �ʱ�ȭ �Ϸ� ���� integ_init_state = 1; insert_display_message(INTEG_MSG, "���� MAC �ʱ�ȭ �Ϸ�\r\n"); - // ���� ��ü ���� - integ_find_opt_link(NULL); - // ù ��� ������ ���� ��ü ���� cur_media = opt_media; diff --git a/Drivers/INTEG_MAC/Src/mem_pool.c b/Drivers/INTEG_MAC/Src/mem_pool.c new file mode 100644 index 0000000..601ac42 --- /dev/null +++ b/Drivers/INTEG_MAC/Src/mem_pool.c @@ -0,0 +1,43 @@ +/* + mem_pool.c +*/ +#include +#include +#include +#include "mem_pool.h" +#include "stm32f4xx_hal.h" + + +unsigned char *mem_pool[MAX_MEM_POOL_SIZE]; +unsigned char f_pool, r_pool; + + +// �޸� Ǯ �ʱ�ȭ +void mem_pool_init(void) { + int i; + f_pool = r_pool = 0; + + for( i = 0; i < MAX_MEM_POOL_SIZE; i++) { + return_mem((unsigned char *)malloc(sizeof(char) * MEM_SIZE)); + } +} + +// �޸� ��û +unsigned char *get_mem(void) { + if (r_pool == f_pool) // empty + return(0); + f_pool = (f_pool + 1) % MAX_MEM_POOL_SIZE; + return(mem_pool[f_pool]); +} + +// �޸� ��ȯ +unsigned char return_mem(unsigned char *mem) { + if ((r_pool + 1) % MAX_MEM_POOL_SIZE == f_pool) // full + return(0); + r_pool = (r_pool + 1) % MAX_MEM_POOL_SIZE; + + // �޸� Clean + memset(mem, '\0', MEM_SIZE); + mem_pool[r_pool] = mem; + return(1); +} \ No newline at end of file diff --git a/Drivers/LIFI/LIFI_MAC/Inc/lifi.h b/Drivers/LIFI/LIFI_MAC/Inc/lifi.h index 100f22e..100bd69 100644 --- a/Drivers/LIFI/LIFI_MAC/Inc/lifi.h +++ b/Drivers/LIFI/LIFI_MAC/Inc/lifi.h @@ -2,6 +2,21 @@ lifi.h */ +extern unsigned char rx3_data[10]; +static unsigned char tx5_data[22]="i can speak english \r\n"; +static unsigned char testBuf[100] = {100, '1', '1', '1', '1', '1', '1', '1', '\r', '\n', +'2', '2', '2', '2', '2', '2', '2', '2', '\r', '\n', +'3', '3', '3', '3', '3', '3', '3', '3', '\r', '\n', +'4', '4', '4', '4', '4', '4', '4', '4', '\r', '\n', +'5', '5', '5', '5', '5', '5', '5', '5', '\r', '\n', +'6', '6', '6', '6', '6', '6', '6', '6', '\r', '\n', +'7', '7', '7', '7', '7', '7', '7', '7', '\r', '\n', +'8', '8', '8', '8', '8', '8', '8', '8', '\r', '\n', +'9', '9', '9', '9', '9', '9', '9', '9', '\r', '\n', +'0', '0', '0', '0', '0', '0', '0', '0', '\r', '\n'}; +extern int index; +volatile extern int l_flag; + unsigned char lifi_init(unsigned char deviceType); unsigned char lifi_send(unsigned char* dest_addr, unsigned char* data, int data_length); unsigned char* lifi_get_mac_addr(unsigned char addr_type); \ No newline at end of file diff --git a/Drivers/LIFI/LIFI_MAC/Src/lifi.c b/Drivers/LIFI/LIFI_MAC/Src/lifi.c index 81a091b..2f0c8a5 100644 --- a/Drivers/LIFI/LIFI_MAC/Src/lifi.c +++ b/Drivers/LIFI/LIFI_MAC/Src/lifi.c @@ -2,7 +2,14 @@ lifi.c */ #include +#include "stm32f4xx_hal.h" #include "integ_mac.h" +#include "uart.h" +#include "lifi.h" + +unsigned char rx3_data[10]; +int index = 0; +int volatile l_flag; unsigned char lifi_mac_addr[8]; unsigned char lifi_broadcast_addr[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; @@ -13,6 +20,7 @@ unsigned char lifi_init(unsigned char deviceType) unsigned char lifi_send(unsigned char* dest_addr, unsigned char* data, int data_length) { + HAL_UART_Transmit(&huart5,data,data_length,100); return 0; } diff --git a/Inc/list.h b/Inc/list.h new file mode 100644 index 0000000..e0792d1 --- /dev/null +++ b/Inc/list.h @@ -0,0 +1,20 @@ +/* + +list.h + +*/ + +struct node { + int data; + struct node *link; +}; + +extern struct node *Head; + +void insert_node_head(struct node *np); +void insert_node_tail(struct node *np); +void insert_node_ascn(struct node *np); +void free_node(struct node *np); +void tour_list(); +void free_list(); +struct node *get_node(); diff --git a/Src/display.c b/Src/display.c index 6c7b8f6..c51f58a 100644 --- a/Src/display.c +++ b/Src/display.c @@ -95,7 +95,7 @@ void insert_display_message(int message_type, char *message) void print_message(void *arg) { - int row, col; + int row; printf(" ** �޽��� ���� **\r\n"); diff --git a/Src/list.c b/Src/list.c new file mode 100644 index 0000000..6ec09aa --- /dev/null +++ b/Src/list.c @@ -0,0 +1,88 @@ +/* + +list.c + +*/ + +#include +#include +#include "list.h" + +struct node *Head = NULL; + +struct node *get_node() +{ + struct node *cp; + cp = (struct node *)malloc(sizeof(struct node)); + return(cp); +} + +void free_node(struct node *np) +{ + free(np); +} + +void insert_node_head(struct node *np) +{ + if (!Head) { + Head = np; + np->link = NULL; + } + else { + np->link = Head; + Head = np; + } +} + +void insert_node_tail(struct node *np) +{ + struct node *cp; + if (!Head) + Head = np; + else { + for (cp = Head; cp->link != NULL; cp = cp->link) + ; + cp->link = np; + } + np->link = NULL; +} + +void insert_node_ascn(struct node *np) +{ + struct node *cp, *pp; + if (!Head) { + Head = np; + np->link = NULL; + } + else { + for (cp = Head, pp = NULL; cp != NULL && cp->data < np->data; pp = cp, cp = cp->link) + ; + if (pp == NULL) { + np->link = Head; + Head = np; + } else { + np->link = pp->link; + pp->link = np; + } + } +} + +void tour_list() +{ + struct node *cp; + printf("\n"); + for (cp = Head; cp != NULL; cp = cp->link) + printf("-->%c ", cp->data); + printf("\n"); +} + +void free_list() +{ + struct node *cp; + + for ( ; Head != NULL; ) { + cp = Head; + Head = cp->link; + free_node(cp); + } +} diff --git a/Src/main.c b/Src/main.c index 74e2798..d28af52 100644 --- a/Src/main.c +++ b/Src/main.c @@ -46,6 +46,8 @@ #include "timer.h" #include "integ_mac.h" #include "display.h" +#include "lifi.h" +#include "mem_pool.h" void SystemClock_Config(void); @@ -54,6 +56,10 @@ int main(void) int tag; struct task task; + //NVIC_SystemReset(); + + mem_pool_init(); + HAL_Init(); SystemClock_Config(); GPIO_Init(); @@ -61,13 +67,36 @@ int main(void) UART2_Init(); // BT UART3_Init(); // PC UART4_Init(); // CC2530 - UART5_Init(); // LIFI + //UART5_Init(); // LIFI HAL_Delay(500); - + init_display_buffer(); integ_mac_init(); - + + /* + while(1) { + //HAL_UART_Transmit(&huart5,&testBuf[index],1,100); + //HAL_UART_Transmit(&huart5,&tx5_data[index++],1,1); + HAL_Delay(1); + + index = (index +1 ) % 100; + //index=index%sizeof(tx5_data); + //HAL_UART_Receive_IT(&huart5,rx3_data,1); + if(l_flag) + { + + //printf("%c", rx3_data[1]); + //HAL_Delay(100); + //HAL_UART_Transmit(&huart3,rx3_data,1,1); + + l_flag=0; + //continue; + } + } + */ + + while(1) { __disable_interrupt(); tag = task_delete(&task); @@ -79,9 +108,41 @@ int main(void) } /** - * @brief System Clock Configuration - * @retval None - */ +* @brief System Clock Configuration +* @retval None +*/ +/* +void SystemClock_Config(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); + + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } + + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) + { + Error_Handler(); + } +} +*/ + void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; @@ -90,32 +151,44 @@ void SystemClock_Config(void) /**Configure the main internal regulator output voltage */ __HAL_RCC_PWR_CLK_ENABLE(); - __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = 8; + RCC_OscInitStruct.PLL.PLLN = 180; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 4; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } + /**Activate the Over-Drive mode + */ + if (HAL_PWREx_EnableOverDrive() != HAL_OK) + { + Error_Handler(); + } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK) { Error_Handler(); } } + void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ @@ -126,12 +199,12 @@ void Error_Handler(void) #ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ +* @brief Reports the name of the source file and the source line number +* where the assert_param error has occurred. +* @param file: pointer to the source file name +* @param line: assert_param error line source number +* @retval None +*/ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ diff --git a/Src/stm32f4xx_hal_msp.c b/Src/stm32f4xx_hal_msp.c index db9b2b7..3d9af90 100644 --- a/Src/stm32f4xx_hal_msp.c +++ b/Src/stm32f4xx_hal_msp.c @@ -219,7 +219,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USER CODE BEGIN UART5_MspInit 1 */ - + /* UART5 interrupt Init */ + HAL_NVIC_SetPriority(UART5_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(UART5_IRQn); /* USER CODE END UART5_MspInit 1 */ } } @@ -362,6 +364,9 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); + /* UART5 interrupt DeInit */ + HAL_NVIC_DisableIRQ(UART5_IRQn); + /* USER CODE BEGIN UART5_MspDeInit 1 */ /* USER CODE END UART5_MspDeInit 1 */ diff --git a/Src/task.c b/Src/task.c index 9615b80..26e1786 100644 --- a/Src/task.c +++ b/Src/task.c @@ -44,13 +44,14 @@ int task_delete(struct task *tskp) void task_cmd(void *arg) { char buf[64], *cp0, *cp1; - int deviceType = 0; + int deviceType = 0, msg_len = 0; + INTEG_FRAME frame; if (fgets(buf, 64, stdin) == NULL) { display(); return; } cp0 = strtok(buf, " \t\n\r"); - cp1 = strtok(NULL, " \t\n\r"); + cp1 = strtok(NULL, "\t\n\r"); // �ƹ��͵� �Է¾��� ��� if (cp0 == NULL) { @@ -60,32 +61,51 @@ void task_cmd(void *arg) return; } else if(!strcmp(cp0, "t")) { // test - frame_queue_insert((unsigned char *)&advertising_frame); + frame.frame_length = INTEG_FRAME_HEADER_LEN + 0x78; + memcpy(frame.src_address, my_integ_address, INTEG_ADDR_LEN); + memcpy(frame.dest_address, hood_integ_address, INTEG_ADDR_LEN); + integ_find_opt_link(NULL); + frame.media_type = opt_media; + frame.message_type = DATA_MSG; + + frame.ackNumber = 0; + frame.seqNumber = get_seq_number(); + frame.data = testBuf_2; + frame_queue_insert((unsigned char *)&frame); } else if(!strcmp(cp0, "info")) { PrintAllHashData(); HAL_Delay(3000); } else if(!strcmp(cp0, "s")) { // send - INTEG_FRAME frame; - frame.frame_length = INTEG_FRAME_HEADER_LEN + 0x06; + frame.frame_length = INTEG_FRAME_HEADER_LEN; memcpy(frame.src_address, my_integ_address, INTEG_ADDR_LEN); memcpy(frame.dest_address, hood_integ_address, INTEG_ADDR_LEN); integ_find_opt_link(NULL); //frame.media_type = cur_media; frame.media_type = opt_media; frame.message_type = DATA_MSG; - frame.data[0] = 0x48; - frame.data[1] = 0x65; - frame.data[2] = 0x6c; - frame.data[3] = 0x6c; - frame.data[4] = 0x6f; + frame.ackNumber = 0; frame.seqNumber = get_seq_number(); - frame.data[5] = frame.seqNumber + 0x30; + frame.data = testBuf_2; frame_queue_insert((unsigned char *)&frame); //macDataReq(broadcast_addr, &frame, frame.frame_length); } + else if (!strcmp(cp0, "send")) { + msg_len = strlen(cp1); + frame.frame_length = INTEG_FRAME_HEADER_LEN + msg_len; + memcpy(frame.src_address, my_integ_address, INTEG_ADDR_LEN); + memcpy(frame.dest_address, hood_integ_address, INTEG_ADDR_LEN); + integ_find_opt_link(NULL); + //frame.media_type = cur_media; + frame.media_type = opt_media; + frame.message_type = 0X45; + memcpy(frame.data, cp1, msg_len); + frame.ackNumber = 0; + frame.seqNumber = get_seq_number(); + frame_queue_insert((unsigned char *)&frame); + } else if (!strcmp(cp0, "init")) { // �߰� ���� �Է����� ���� ��� if (cp1 == NULL) { diff --git a/Src/timer.c b/Src/timer.c index 80cddd3..779c513 100644 --- a/Src/timer.c +++ b/Src/timer.c @@ -25,9 +25,10 @@ void MX_TIM6_Init(void) /* USER CODE END TIM6_Init 1 */ htim6.Instance = TIM6; - htim6.Init.Prescaler = 16000 - 1; + //htim6.Init.Prescaler = 16000 - 1; + htim6.Init.Prescaler = 45000 - 1; htim6.Init.CounterMode = TIM_COUNTERMODE_UP; - htim6.Init.Period = 100 - 1; + htim6.Init.Period = 200 - 1; if (HAL_TIM_Base_Init(&htim6) != HAL_OK) { //Error_Handler(); diff --git a/Src/uart.c b/Src/uart.c index 4c8883c..45b760d 100644 --- a/Src/uart.c +++ b/Src/uart.c @@ -16,6 +16,8 @@ uart.c #include "frame_queue.h" #include "display.h" #include "timer.h" +#include "lifi.h" +#include "mem_pool.h" #define ETX 0x04 @@ -33,6 +35,8 @@ UART_HandleTypeDef huart3; // <---> PC UART_HandleTypeDef huart4; // <---> CC2530 UART_HandleTypeDef huart5; // <---> LIFI +INTEG_FRAME uart_frame; + uint8_t rxData; uint8_t rxData_b; uint8_t txData; @@ -149,7 +153,7 @@ void UART3_Init(void) q_init(); /* USART3 Init */ huart3.Instance = USART3; - huart3.Init.BaudRate = 921600; + huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; @@ -197,6 +201,7 @@ void UART5_Init(void) { // Error_Handler(); } + HAL_UART_Receive_IT(&huart5, rx3_data,1); } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) @@ -220,7 +225,10 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) if(t_char == 'O') { bt_state = 1; bt_index++; } else if(t_char == 'A') {bt_state = 1; bt_index++; } else{ bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, t_char - 1, 1000); bt_index = 0; - frame_queue_insert(btBuf); + memcpy((unsigned char *)&uart_frame, btBuf, INTEG_FRAME_HEADER_LEN); + uart_frame.data = get_mem(); + memcpy(uart_frame.data, btBuf + INTEG_FRAME_HEADER_LEN, uart_frame.frame_length - INTEG_FRAME_HEADER_LEN); + frame_queue_insert((unsigned char *)&uart_frame); } break; case 1: @@ -330,6 +338,13 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } } + // LI-FI + else if (huart->Instance == huart5.Instance) { + l_flag = 1; + //HAL_UART_Transmit(&huart3, (uint8_t *)rx3_data,1,1); + HAL_UART_Receive_IT(&huart5,rx3_data,1); + } + // CC2530 else if (huart->Instance == huart4.Instance) { @@ -355,7 +370,10 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } else if(macBuf[3] == 0x85) { // MAC_DATA_IND #define DATA_FIELD 48 - frame_queue_insert(macBuf + 48); + memcpy((unsigned char *)&uart_frame, macBuf + 48, INTEG_FRAME_HEADER_LEN); + uart_frame.data = get_mem(); + memcpy(uart_frame.data, macBuf + 48 + INTEG_FRAME_HEADER_LEN, uart_frame.frame_length - INTEG_FRAME_HEADER_LEN); + frame_queue_insert((unsigned char *)&uart_frame); } else { if(macBuf[3] == 0x8C) { // MAC_SCAN_CNF