From 0f20cfaabd5ed1540d62188f2a85202d092b8edf Mon Sep 17 00:00:00 2001 From: Seungsu Lim Date: Tue, 14 May 2019 19:23:02 +0900 Subject: [PATCH] =?UTF-8?q?MAC=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1=20=EB=B6=80=EB=B6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h | 1 + .../BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c | 75 +++-- Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h | 3 +- Drivers/CC2530/CC2530_MAC/Src/mac_interface.c | 43 ++- Drivers/INTEG_MAC/Inc/integ_mac.h | 15 +- Drivers/INTEG_MAC/Src/frame_queue.c | 2 +- Drivers/INTEG_MAC/Src/integ_mac.c | 308 ++++++++++++++---- Drivers/LIFI/LIFI_MAC/Inc/lifi.h | 3 +- Drivers/LIFI/LIFI_MAC/Src/lifi.c | 12 +- Inc/display.h | 13 +- README.md | 15 +- Src/display.c | 14 +- Src/gpio.c | 14 +- Src/hash.c | 4 +- Src/stm32f4xx_hal_msp.c | 6 +- Src/task.c | 21 +- Src/uart.c | 3 +- 17 files changed, 422 insertions(+), 130 deletions(-) diff --git a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h index 48676ee..aab5481 100644 --- a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h +++ b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h @@ -14,6 +14,7 @@ void BT_M_Init(); void BT_S_Init(); void task_bt_update(void *arg); void task_connect(void *arg); +unsigned char* bt_get_mac_addr(unsigned char addr_type); // AT Ŀ�Ǵ� ���� void BT_AT(); diff --git a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c index b930104..04dcf6c 100644 --- a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c +++ b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c @@ -2,11 +2,16 @@ bluetooth.c */ #include +#include #include //for strncmp #include "stm32f4xx_hal.h" #include "integ_mac.h" #include "uart.h" #include "bluetooth.h" +#include "display.h" + +unsigned char bt_mac_addr[8]; +unsigned char bt_broadcast_addr[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned char bt_state; unsigned char bt_index; unsigned char bt_count; @@ -108,11 +113,15 @@ void task_bt_update(void *arg) { // AT if(strncmp((char*)arg, "1", 1)) { - insert_display_message("* [BLUETOOTH] ���� ��\r\n"); + insert_display_message(INTEG_MSG, "[BLUETOOTH] ���� ��\r\n"); + STATUS_TABLE[CONNECT_STATUS][BLUETOOTH] = CON; } else { - insert_display_message("* [BLUETOOTH] ���� ����\r\n"); + insert_display_message(INTEG_MSG, "[BLUETOOTH] ���� ����\r\n"); + STATUS_TABLE[CONNECT_STATUS][BLUETOOTH] = DISCON; } + display(); + integ_find_opt_link(NULL); } void task_connect(void *arg) @@ -125,16 +134,16 @@ void task_connect(void *arg) // BlueTooth Init // Master void BT_M_Init() -{ +{ // BAUD HAL_UART_Transmit(&huart2, SET_BAUD, 8, 1000); HAL_Delay(100); // AT - //HAL_UART_Transmit(&huart2, AT, 2, 1000); + HAL_UART_Transmit(&huart2, AT, 2, 1000); HAL_Delay(100); - // MODE 2 + // MODE 0 HAL_UART_Transmit(&huart2, SET_MODE, 8, 1000); HAL_Delay(100); @@ -158,23 +167,28 @@ void BT_M_Init() HAL_UART_Transmit(&huart2, BT_START1, 8, 1000); HAL_Delay(100); - // DISC - HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); + // QR_MAC + HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); HAL_Delay(100); - memcpy(SAVE_ADDRESS, MAC1, 20); - // QR_MAC - //HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); - HAL_Delay(10); - - // BT_CONNET() - HAL_UART_Transmit(&huart2, CON_MAC2, 18, 1000); + // �ּ� ���� + char temp[2]; + int index; + for (index = 0; index < BLUETOOTH_ADDR_LEN; index++) { + memcpy(temp, btBuf + (index * 2) + 8, 2); + bt_mac_addr[index] = strtol(temp, NULL, 16); + } HAL_Delay(100); - //HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); + + // DISC + HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); HAL_Delay(100); + // BT_CONNET() + HAL_UART_Transmit(&huart2, CON_MAC2, 18, 1000); + HAL_Delay(100); } //Slave void BT_S_Init() @@ -188,10 +202,10 @@ void BT_S_Init() HAL_Delay(100); // AT - //HAL_UART_Transmit(&huart2, AT, 2, 1000); + HAL_UART_Transmit(&huart2, AT, 2, 1000); HAL_Delay(100); - // MODE 2 + // MODE 0 HAL_UART_Transmit(&huart2, SET_MODE, 8, 1000); HAL_Delay(300); @@ -211,15 +225,36 @@ void BT_S_Init() HAL_UART_Transmit(&huart2, SET_RESET, 8, 1000); HAL_Delay(10); + // SET START + //HAL_UART_Transmit(&huart2, BT_START1, 8, 1000); + HAL_Delay(100); + // DISC - //HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); + // HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); HAL_Delay(100); // QR_MAC HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); - HAL_Delay(10); + HAL_Delay(100); - memcpy(SAVE_ADDRESS, MAC2, 20); + + // �ּ� ���� + char temp[2]; + int index; + for (index = 0; index < BLUETOOTH_ADDR_LEN; index++) { + memcpy(temp, btBuf + (index * 2) + 8, 2); + bt_mac_addr[index] = strtol(temp, NULL, 16); + } + HAL_Delay(100); +} + +unsigned char* bt_get_mac_addr(unsigned char addr_type) { + if (addr_type == BROADCAST_ADDR) { + return bt_broadcast_addr; + } + else { + return bt_mac_addr; + } } // AT Ŀ�Ǵ� ���� diff --git a/Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h b/Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h index 3156656..7c54ff3 100644 --- a/Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h +++ b/Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h @@ -14,4 +14,5 @@ void macSetReq(unsigned char attr, unsigned char *attrValue); void macScanReq(unsigned char scanType); void printMacBuf(); void utilCallbackSubCmd(); -void getMacAddr_CC2530(unsigned char * addr); \ No newline at end of file +void mtUtilGetPrimaryIEEE(); +unsigned char* cc2530_get_mac_addr(unsigned char addr_type); \ No newline at end of file diff --git a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c index 09d0c54..e578c40 100644 --- a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c +++ b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c @@ -1,7 +1,7 @@ +#include //for memcpy() #include "mac_interface.h" #include "mac_interface_uart.h" #include "stm32f4xx_hal.h" -#include //for memcpy() #include "integ_mac.h" /** Get the Least Significant Byte (LSB) of an unsigned int*/ @@ -17,7 +17,8 @@ #define PAN_COORDINATOR 0x00 -unsigned char macAddr[8]; +unsigned char cc2530_mac_addr[8]; +unsigned char cc2530_broadcast_addr[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned char startMac(unsigned char deviceType) { @@ -51,13 +52,14 @@ unsigned char startMac(unsigned char deviceType) utilCallbackSubCmd(); HAL_Delay(100); + // mtUtilGetPrimaryIEEE + mtUtilGetPrimaryIEEE(); + if(deviceType == PAN_COORDINATOR) { // MAC_SET_REQ [SHORT ADDRESS, EXT ADDRESS] // set the parameter - attrValue[0] = LSB(STM32_UUID[0]); - macSetReq(ZMAC_SHORT_ADDRESS, attrValue); - macSetReq(ZMAC_EXTENDED_ADDRESS, attrValue); - memcpy(macAddr, attrValue, 8); + macSetReq(ZMAC_SHORT_ADDRESS, cc2530_mac_addr); + macSetReq(ZMAC_EXTENDED_ADDRESS, cc2530_mac_addr); // auto request false; attrValue[0] = 0x00; @@ -281,7 +283,7 @@ void macAssociateRsp(void *arg) // wait MAC_COMM_STATUS_IND sreqFlag = STATE_ASSOCIATE_RSP_CNF; while(sreqFlag != STATE_IDLE); - + printf("AssociateRsp\r\n$ "); } @@ -405,7 +407,7 @@ unsigned char macDataReq(unsigned char* dest_addr, unsigned char* data, int data macBuf[12] = 0x2E; macBuf[13] = 0x2E; } - + /* macBuf[12] = 0xFF; macBuf[13] = 0xFF; @@ -617,9 +619,30 @@ void macScanReq(unsigned char scanType) stateFlag = STATE_SYNC; } -void getMacAddr_CC2530(unsigned char * addr) + +#define MT_UTIL_GET_PRIMARY_IEEE 0x27EF +#define MT_UTIL_GET_PRIMARY_IEEE_PAYLOAD_LEN 0x01; +void mtUtilGetPrimaryIEEE() { - memcpy(addr, macAddr, 8); + macBuf[0] = MT_UTIL_GET_PRIMARY_IEEE_PAYLOAD_LEN; + macBuf[1] = MSB(MT_UTIL_GET_PRIMARY_IEEE); + macBuf[2] = LSB(MT_UTIL_GET_PRIMARY_IEEE); + + macBuf[3] = 0x00; + + uartSreq(STATE_SREQ); + memcpy(cc2530_mac_addr, macBuf + 1, 8); + cc2530_mac_addr[0] = LSB(STM32_UUID[0]); +} + +unsigned char* cc2530_get_mac_addr(unsigned char addr_type) { + + if (addr_type == BROADCAST_ADDR) { + return cc2530_broadcast_addr; + } + else { + return cc2530_mac_addr; + } } void printMacBuf() diff --git a/Drivers/INTEG_MAC/Inc/integ_mac.h b/Drivers/INTEG_MAC/Inc/integ_mac.h index 190e0ec..0157191 100644 --- a/Drivers/INTEG_MAC/Inc/integ_mac.h +++ b/Drivers/INTEG_MAC/Inc/integ_mac.h @@ -27,6 +27,7 @@ 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 static char *result_string[2] = {"FAIL", "SUCCESS"}; @@ -35,6 +36,7 @@ static char *result_string[2] = {"FAIL", "SUCCESS"}; #define LIFI_ADDR_LEN 6 // lifi �� �ּ� ���� #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}; #define INTEG_FRAME_HEADER_LEN 17 // ���� �� ������ ��� ���� @@ -46,6 +48,8 @@ static unsigned char media_addr_len[MEDIA_NUM] = {LIFI_ADDR_LEN, BLUETOOTH_ADDR_ // messageType #define DATA_MSG 0x01 #define ACK_MSG 0x02 +#define ADV_MSG 0x04 +#define ADV_IND 0x05 #define PASS_MSG 0xFF // deviceType @@ -58,18 +62,19 @@ extern unsigned char my_integ_address[INTEG_ADDR_LEN]; extern unsigned char hood_integ_address[INTEG_ADDR_LEN]; #define MAX_SEQ_NUMBER 10 // ���� ��ȣ �ִ� -#define DEFAULT_SEQ_NUMBER 1 // ���� ��ȣ �ʱⰪ +#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"}; + // ���� MAC ���̺� ����ü typedef struct integ_table { unsigned char integ_addr[INTEG_ADDR_LEN]; unsigned char addr_type; // static : 0, dynamic : 1 - unsigned char *media_addr[MEDIA_NUM]; + unsigned char media_addr[MEDIA_NUM][MEDIA_ADDR_LEN_MAX]; } INTEG_TABLE; @@ -85,6 +90,8 @@ typedef struct integ_frame { unsigned char data[INTEG_FRAME_DATA_LEN]; } INTEG_FRAME; +extern INTEG_FRAME advertising_frame; + unsigned char get_seq_number(void); void integ_mac_handler(void * arg); void integ_retransmit_handler(void * arg); @@ -92,6 +99,10 @@ void integ_find_opt_link(void *); void integ_mac_init(void); void integ_print_frame(INTEG_FRAME *frame); +#define MAC_ADDR 0x00 +#define BROADCAST_ADDR 0xFF +unsigned char* integ_get_mac_addr(unsigned char addr_type); + /** Get the Least Significant Byte (LSB) of an unsigned int*/ #define LSB(num) ((num) & 0xFF) diff --git a/Drivers/INTEG_MAC/Src/frame_queue.c b/Drivers/INTEG_MAC/Src/frame_queue.c index f86f225..e76127d 100644 --- a/Drivers/INTEG_MAC/Src/frame_queue.c +++ b/Drivers/INTEG_MAC/Src/frame_queue.c @@ -47,7 +47,7 @@ void re_frame_queue_remove(unsigned char index) int i; // �ӽ� - for(i = 1; i < RE_FRAME_QUEUE_SIZE; i++) { + for(i = 0; i < RE_FRAME_QUEUE_SIZE; i++) { if(re_frame_queue[i].seqNumber == index) { re_frame_queue[i].message_type = PASS_MSG; } diff --git a/Drivers/INTEG_MAC/Src/integ_mac.c b/Drivers/INTEG_MAC/Src/integ_mac.c index 0035c6d..f4e4e10 100644 --- a/Drivers/INTEG_MAC/Src/integ_mac.c +++ b/Drivers/INTEG_MAC/Src/integ_mac.c @@ -15,23 +15,33 @@ #define STM32_UUID ((uint32_t *)0x1FFF7A10) // dispaly �� ���� -unsigned char message_buffer[COL_NUMS]; +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 hood_integ_address[INTEG_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +/* unsigned char hood_lifi_address[LIFI_ADDR_LEN] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; unsigned char hood_bluetooth_address[BLUETOOTH_ADDR_LEN] = {0x33, 0x33, 0x33, 0x33, 0x33, 0x33}; -unsigned char hood_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}; +unsigned char hood_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x67, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}; +*/ // �� �ּ� +unsigned char integ_macAddr[INTEG_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char my_integ_address[INTEG_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char my_lifi_address[LIFI_ADDR_LEN] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55}; unsigned char my_bluetooth_address[BLUETOOTH_ADDR_LEN] = {0x33, 0x33, 0x33, 0x33, 0x33, 0x33}; -unsigned char my_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}; +unsigned char my_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x67, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}; + +// ��ε�ij��Ʈ �� ���� MAC �ּ� +unsigned char integ_broadcast_addr[INTEG_ADDR_LEN] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + +INTEG_FRAME advertising_frame; unsigned char seqNumber; // ���� ��ȣ unsigned char cur_media; // ���� ����ϴ� ��ü @@ -47,11 +57,14 @@ unsigned char integ_init_state = 0; 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; - unsigned char result; - unsigned char frame_state; // �۽ſ� ���ſ� + unsigned char result; // �Լ� ���� ��� ����� ���� + unsigned char frame_state; // �۽ſ� ���ſ� ���� + unsigned char mac_table_key; // �����̺� ���� �� Ű + int i; while((frame = frame_queue_delete()) != NULL) { //integ_print_frame(frame); @@ -66,38 +79,48 @@ void integ_mac_handler(void * arg) frame_state = RECEIVE_FRAME; } + // �����̺� ���� �� Ű �ּ� ù����Ʈ + mac_table_key = frame->dest_address[0]; + + // �����̺� �������� + table = FindHashData(mac_table_key); + switch(message_type) { case DATA_MSG: // ������ �۽� ���� if(frame_state == TRANSMIT_FRAME) { - //sprintf(message_buffer, "* [INTEG] ������ �۽� ������ (������ : %02x)\r\n", frame->dest_address[0]); - //insert_display_message(message_buffer); - //printf("** Data �۽� seqNum %d\r\n", frame->seqNumber); cur_media = frame->media_type; // ������ �������� ��� ������ ��ü�� ���� if((cur_media & OPT_MEDIA) == OPT_MEDIA) { prev_media = cur_media & 0x0F; - // ���� ���� ��ü ���� ���� ���� - STATUS_TABLE[CONNECT_STATUS][prev_media] = DISCON; - - integ_find_opt_link(NULL); - cur_media = opt_media; - frame->media_type = OPT_MEDIA | cur_media; + // ackNumber �ʵ� �� �������� Ƚ���� ����Ѵ�. (�ӽ�) + frame->ackNumber++; // ������ ��⿭�� ������ �߰� re_frame_queue_insert((unsigned char *)frame); - sprintf(message_buffer, "* [%s] ������ ���� ���� \r\n", media_name[prev_media]); - insert_display_message(message_buffer); + sprintf(message_buffer, "%d �� ������ ���� ���� \r\n", frame->ackNumber); + insert_display_message(prev_media, message_buffer); + + cur_media = prev_media; + // ������ Ƚ���� 3ȸ�̸� ��ü ���� ���� �������� ���� + if(frame->ackNumber >= RETRANSMIT_NUM) { + // ���� ���� ��ü ���� ���� ���� + STATUS_TABLE[CONNECT_STATUS][prev_media] = DISCON; + integ_find_opt_link(NULL); + cur_media = opt_media; + } + frame->media_type = OPT_MEDIA | cur_media; + if(prev_media != cur_media) { - sprintf(message_buffer, "* [%s] ���� [%s] ���� ��ü ���� \r\n", media_name[prev_media], media_name[cur_media]); - insert_display_message(message_buffer); + //sprintf(message_buffer, "* [INTEG][%s] ���� [%s] ���� ��ü ���� \r\n", media_name[prev_media], media_name[cur_media]); + //insert_display_message(message_buffer); } - sprintf(message_buffer, "* [%s][SEQ : %d] ������ ������ (�� ������ : %02x) : %s\r\n", media_name[cur_media], frame->seqNumber, frame->dest_address[0], frame->data); - insert_display_message(message_buffer); + 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 { @@ -105,8 +128,8 @@ void integ_mac_handler(void * arg) re_frame_queue_insert((unsigned char *)frame); frame->media_type = cur_media; - sprintf(message_buffer, "* [%s][SEQ : %d] ������ ���� ( �� ������ : %02x) : %s\r\n", media_name[cur_media], frame->seqNumber, frame->dest_address[0], frame->data); - insert_display_message(message_buffer); + 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 �߰� @@ -115,7 +138,6 @@ void integ_mac_handler(void * arg) insert_timer(&retrans_task, RETRANSMIT_TIME); // INTEG ADDR -> MAC ADDR ��ȯ - struct node *table = FindHashData(HOOD_HASH_ID); if(table != NULL) { // �۽� @@ -126,7 +148,7 @@ void integ_mac_handler(void * arg) // ������ ���� �� ACK ���� else if(frame_state == RECEIVE_FRAME) { //printf("** Data ����\r\n"); - + // ACK ��Ŷ ���� t_frame.frame_length = frame->frame_length; t_frame.message_type = ACK_MSG; @@ -135,8 +157,8 @@ void integ_mac_handler(void * arg) 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, "* [%s][SEQ : %d] ������ ���� ( �� �ٿ��� : %02x) : %s\r\n", media_name[t_frame.media_type], frame->seqNumber, frame->src_address[0], frame->data); - insert_display_message(message_buffer); + 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); // ���� ��ü ���� ���� ���� STATUS_TABLE[CONNECT_STATUS][t_frame.media_type] = CON; @@ -154,15 +176,14 @@ void integ_mac_handler(void * arg) cur_media = frame->media_type; // INTEG ADDR -> MAC ADDR - struct node *table = FindHashData(HOOD_HASH_ID); if(table != NULL) { // �۽� //printf("cur_media = %d\r\n", cur_media); fun_send[cur_media](table->data.media_addr[cur_media], (unsigned char *)frame, frame->frame_length); } - sprintf(message_buffer, "* [%s][ACK : %d] ACK �۽� ( �� ������ : %02x) \r\n", media_name[cur_media], frame->ackNumber, frame->dest_address[0]); - insert_display_message(message_buffer); + 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) { @@ -172,14 +193,99 @@ void integ_mac_handler(void * arg) STATUS_TABLE[CONNECT_STATUS][frame->media_type] = CON; ackNumber = frame->ackNumber - 1; - //printf("** ACK ���� ackNum : %d\r\n", ackNumber + 1); // ������ ��⿭�� ������ ���� re_frame_queue_remove(ackNumber % MAX_SEQ_NUMBER); - sprintf(message_buffer, "* [%s][ACK : %d] ACK ���� ( ��ٿ��� : %02x) \r\n", media_name[frame->media_type], frame->ackNumber, frame->src_address[0]); - insert_display_message(message_buffer); + sprintf(message_buffer, "[ACK : %d] ACK ���� ( ��ٿ��� : %02X) \r\n", frame->ackNumber, frame->src_address[0]); + insert_display_message(frame->media_type, message_buffer); + } + break; + case ADV_MSG: + // ADV_MSG �۽� ������ + if(frame_state == TRANSMIT_FRAME) { + // 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]); + fun_send[i](table->data.media_addr[i], (unsigned char *)frame, frame->frame_length); + HAL_Delay(30); + } + } + //frame_queue_insert((unsigned char *)frame); + } + // ADV_MSG ���� ���� ��� + else if(frame_state == RECEIVE_FRAME) { + //printf("%s ADV ����\r\n", media_name[frame->media_type]); + + // ADV_MSG �۽����� �����̺� �������� + mac_table_key = frame->src_address[0]; + table = FindHashData(mac_table_key); + + // ���ο� �̿��� �����̺��� �߰� + if(table == NULL) { + // �̿� �� ���̺� ���� + table = get_hashNode(); + table->id = mac_table_key; + table->data.addr_type = DYNAMIC_ADDR; + memcpy(table->data.integ_addr, frame->src_address, INTEG_ADDR_LEN); + memcpy(table->data.media_addr, frame->data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); + AddHashData(table->id, table); + + + sprintf(message_buffer, "���ο� �̿���� (���� MAC �ּ� : %02X) �߰� MAC TABLE �߰�\r\n", table->data.integ_addr[0]); + insert_display_message(INTEG_MSG, message_buffer); + } + + // ADV_MSG �۽��ڿ��� MAC ���̺��� �����ؼ� ADV_IND ���� + t_frame.frame_length = frame->frame_length; + t_frame.message_type = ADV_IND; + t_frame.media_type = frame->media_type; + memcpy(t_frame.src_address, my_integ_address, INTEG_ADDR_LEN); + 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); } break; + + case ADV_IND: + // ADV_IND �۽� ������ + if(frame_state == TRANSMIT_FRAME) { + //printf("%s ADV_IND �۽�\r\n", media_name[frame->media_type]); + + // INTEG ADDR -> MAC ADDR ��ȯ + if(table != NULL) { + // �۽� + HAL_Delay(30); + fun_send[frame->media_type](table->data.media_addr[frame->media_type], (unsigned char *)frame, frame->frame_length); + } + } + // ADV_IND ���� ���� ��� + else if(frame_state == RECEIVE_FRAME) { + //printf("%s ADV_IND ����\r\n", media_name[frame->media_type]); + + // ADV_IND �۽����� �����̺� �������� + mac_table_key = frame->src_address[0]; + table = FindHashData(mac_table_key); + + // ���ο� �̿��� �����̺��� �߰� + if(table == NULL) { + // �̿� �� ���̺� ���� + table = get_hashNode(); + table->id = mac_table_key; + table->data.addr_type = DYNAMIC_ADDR; + memcpy(table->data.integ_addr, frame->src_address, INTEG_ADDR_LEN); + memcpy(table->data.media_addr, frame->data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); + AddHashData(table->id, table); + + sprintf(message_buffer, "���ο� �̿���� (���� MAC �ּ� : %02X) �߰� MAC TABLE �߰�\r\n", table->data.integ_addr[0]); + insert_display_message(INTEG_MSG, message_buffer); + } + } + break; + case PASS_MSG: //printf("������ ���\r\n"); break; @@ -210,59 +316,99 @@ void integ_mac_init(void) int i, result; struct node *table; // MAC Table ���� - insert_display_message("* [INTEG] ���� MAC �ʱ�ȭ ����\r\n"); + insert_display_message(INTEG_MSG, "���� MAC �ʱ�ȭ ����\r\n"); + + seqNumber = DEFAULT_SEQ_NUMBER; // ������ȣ �ʱ�ȭ + frame_queue_init(); // ���� ������ ť �ʱ�ȭ + re_frame_queue_init(); // ������ ������ ť �ʱ�ȭ - seqNumber = DEFAULT_SEQ_NUMBER; - frame_queue_init(); - re_frame_queue_init(); - my_integ_address[0] = LSB(STM32_UUID[0]); - my_cc2530_address[0] = LSB(STM32_UUID[0]); - my_lifi_address[0] = LSB(STM32_UUID[0]); - my_bluetooth_address[0] = LSB(STM32_UUID[0]); + // �ӽ� if (LSB(STM32_UUID[0]) == 0x2c) { hood_integ_address[0] = 0x2E; + /* hood_cc2530_address[0] = 0x2E; hood_lifi_address[0] = 0x2E; hood_bluetooth_address[0] = 0x2E; + */ deviceType = MASTER; } else { hood_integ_address[0] = 0x2c; + /* hood_cc2530_address[0] = 0x2c; hood_lifi_address[0] = 0x2c; hood_bluetooth_address[0] = 0x2c; + */ deviceType = SLAVE; } + // MCU <---> ��ü ��� �ʱ�ȭ + + // ��ü �ʱ�ȭ + for(i = 0; i < MEDIA_NUM; i++) { + result = fun_init[i](deviceType); + STATUS_TABLE[INIT_STATUS][i] = result; + STATUS_TABLE[CONNECT_STATUS][i] = result; + sprintf(message_buffer, "�ʱ�ȭ %s \r\n", result_string[result]); + insert_display_message(i, message_buffer); + } + + // �� ��ü �ּ� �������� + 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); + + // advertising frame ���� + advertising_frame.frame_length = INTEG_FRAME_HEADER_LEN + MEDIA_NUM * MEDIA_ADDR_LEN_MAX; + advertising_frame.message_type = ADV_MSG; + memcpy(advertising_frame.src_address, my_integ_address, INTEG_ADDR_LEN); + memcpy(advertising_frame.dest_address, integ_broadcast_addr, INTEG_ADDR_LEN); + for(i = 0; i < MEDIA_NUM; i++) { + memcpy(advertising_frame.data + (i * MEDIA_ADDR_LEN_MAX), fun_get_addr[i](MAC_ADDR), MEDIA_ADDR_LEN_MAX); + } + + // advertising frame ���� + frame_queue_insert((unsigned char *)&advertising_frame); + + // Boradcast MAC table ���� + table = get_hashNode(); + table->id = 0xFF; + + table->data.addr_type = STATIC_ADDR; + memcpy(table->data.integ_addr, integ_broadcast_addr, INTEG_ADDR_LEN); + for(i = 0; i < MEDIA_NUM; i++) { + memcpy(table->data.media_addr[i], fun_get_addr[i](BROADCAST_ADDR), MEDIA_ADDR_LEN_MAX); + } + 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); - table->data.media_addr[LIFI] = my_lifi_address; - table->data.media_addr[BLUETOOTH] = my_bluetooth_address; - table->data.media_addr[CC2530] = my_cc2530_address; + memcpy(table->data.media_addr, advertising_frame.data, MEDIA_ADDR_LEN_MAX * MEDIA_NUM); AddHashData(table->id, table); + /* + // �̿� �� ���̺� ���� table = get_hashNode(); table->id = HOOD_HASH_ID; table->data.addr_type = DYNAMIC_ADDR; memcpy(table->data.integ_addr, hood_integ_address, INTEG_ADDR_LEN); - table->data.media_addr[LIFI] = hood_lifi_address; - table->data.media_addr[BLUETOOTH] = hood_bluetooth_address; - table->data.media_addr[CC2530] = hood_cc2530_address; - AddHashData(table->id, table); - // MCU <---> ��ü ��� �ʱ�ȭ + memcpy(table->data.media_addr[LIFI], hood_lifi_address, MEDIA_ADDR_LEN_MAX); + memcpy(table->data.media_addr[BLUETOOTH], hood_bluetooth_address, MEDIA_ADDR_LEN_MAX); + memcpy(table->data.media_addr[CC2530], hood_cc2530_address, MEDIA_ADDR_LEN_MAX); + AddHashData(table->id, table); + */ - // ��ü �ʱ�ȭ - for(i = 0; i < MEDIA_NUM; i++) { - result = fun_init[i](deviceType); - STATUS_TABLE[INIT_STATUS][i] = result; - STATUS_TABLE[CONNECT_STATUS][i] = result; - sprintf(message_buffer, "* [%s] �ʱ�ȭ %s \r\n", media_name[i], result_string[result]); - insert_display_message(message_buffer); - } + // �ʱ�ȭ �Ϸ� ���� + integ_init_state = 1; + insert_display_message(INTEG_MSG, "���� MAC �ʱ�ȭ �Ϸ�\r\n"); // ���� ��ü ���� integ_find_opt_link(NULL); @@ -272,38 +418,55 @@ void integ_mac_init(void) // ���� MAC Handler TASK ���� integ_mac_handler(""); - integ_init_state = 1; - insert_display_message("* [INTEG] ���� MAC �ʱ�ȭ �Ϸ�\r\n"); + /* struct task task; task.fun = integ_find_opt_link; strcpy(task.arg, ""); insert_timer(&task, FIND_OPT_PERIOD); + */ } void integ_find_opt_link(void * arg) { struct task task; - int i; + int i,prev_media; + + + prev_media = opt_media; - // �ֱ����� TASK ���� + // �ֱ����� TASK ���� task.fun = integ_find_opt_link; strcpy(task.arg, ""); - insert_timer(&task, FIND_OPT_PERIOD); - + //insert_timer(&task, FIND_OPT_PERIOD); + for(i = 0; i < MEDIA_NUM; i++) { if(STATUS_TABLE[INIT_STATUS][i] && STATUS_TABLE[CONNECT_STATUS][i]) { - //opt_media = BLUETOOTH; opt_media = i; + break; //printf("������ü : %s\r\n", media_name[opt_media]); - return; } } - //opt_media = (rand() % 2) + 1; - opt_media = (opt_media + 1) % 2 + 1; - + + // ����� ��ü�� ���� ��� + if(i == MEDIA_NUM) { + opt_media = rand() % MEDIA_NUM; + sprintf(message_buffer, "���� ���� ��ü ����. [%s] ���� ��ü ���� \r\n", media_name[opt_media]); + insert_display_message(INTEG_MSG, message_buffer); + } + // ����� ��ü�� �ִ� ��� + // ���ο� ������ü �� ��� ���� �˸� + else if (prev_media != opt_media) { + sprintf(message_buffer, "[%s] ���� [%s] ���� ���� ��ü ���� \r\n", media_name[prev_media], media_name[opt_media]); + insert_display_message(INTEG_MSG, message_buffer); + return; + } + // ���� ������ü�� ���� ��ü�� ���� ��� PASS + else { + + } } @@ -326,6 +489,17 @@ void integ_print_frame(INTEG_FRAME *frame) } +// ���� MAC �ּ� GET +unsigned char* integ_get_mac_addr(unsigned char addr_type) { + if (addr_type == BROADCAST_ADDR) { + return integ_broadcast_addr; + } + else { + integ_macAddr[0] = LSB(STM32_UUID[0]); + return integ_macAddr; + } +} + unsigned char get_seq_number(void) { unsigned char return_value = seqNumber; diff --git a/Drivers/LIFI/LIFI_MAC/Inc/lifi.h b/Drivers/LIFI/LIFI_MAC/Inc/lifi.h index 6365bbb..100f22e 100644 --- a/Drivers/LIFI/LIFI_MAC/Inc/lifi.h +++ b/Drivers/LIFI/LIFI_MAC/Inc/lifi.h @@ -3,4 +3,5 @@ */ unsigned char lifi_init(unsigned char deviceType); -unsigned char lifi_send(unsigned char* dest_addr, unsigned char* data, int data_length); \ No newline at end of file +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 2bbb562..81a091b 100644 --- a/Drivers/LIFI/LIFI_MAC/Src/lifi.c +++ b/Drivers/LIFI/LIFI_MAC/Src/lifi.c @@ -4,6 +4,8 @@ #include #include "integ_mac.h" +unsigned char lifi_mac_addr[8]; +unsigned char lifi_broadcast_addr[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; unsigned char lifi_init(unsigned char deviceType) { return R_FAIL; @@ -11,6 +13,14 @@ unsigned char lifi_init(unsigned char deviceType) unsigned char lifi_send(unsigned char* dest_addr, unsigned char* data, int data_length) { - printf("LIFI_SEND_����_�õ�\r\n"); return 0; +} + +unsigned char* lifi_get_mac_addr(unsigned char addr_type) { + if (addr_type == BROADCAST_ADDR) { + return lifi_broadcast_addr; + } + else { + return lifi_mac_addr; + } } \ No newline at end of file diff --git a/Inc/display.h b/Inc/display.h index 5e9d433..6ba256a 100644 --- a/Inc/display.h +++ b/Inc/display.h @@ -1,6 +1,15 @@ /* display.h */ +#define MSG_HEADER_LENGTH 16 +#define MSG_NUM 0x05 +#define LIFI_MSG 0x00 +#define BT_MSG 0x01 +#define CC2530_MSG 0x02 +#define INTEG_MSG 0x03 +#define SYSTEM_MSG 0x04 + + #define ROW_LINES 12 #define FIRST_ROW 0 #define LAST_ROW ROW_LINES - 1 @@ -14,9 +23,11 @@ display.h #define RECT_CHAR_LEN 10 #define RECT_FIRST_CON_START RECT_CHAR_START - 6 #define RECT_SECOND_CON_START (RECT_CHAR_START + RECT_CHAR_LEN + 4) + +static char *str_message[MSG_NUM] = {" LI-FI ", "BLUETOOTH", " CC2530 ", "INTEG-MAC", " SYSTEM "}; void init_display_buffer(); -void insert_display_message(unsigned char *message); +void insert_display_message(int message_type, char *message); void print_info(void *arg); void print_message(void *arg); void display(); \ No newline at end of file diff --git a/README.md b/README.md index d4b8bf3..c37ad10 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -# ---- \ No newline at end of file +# --- + +**GPIO** +------------------------------ + PC9 CC2530 RESET PIN + PC10 BLUETOOTH STATE PIN + +**UART** +------------------------------ + UART TX RX + BLUETOOTH USART2 PD5 PD6 + PC USART3 PD8 PD9 + CC2530 UART4 PC10 PC11 + LI-FI UART5 PC12 PD2 diff --git a/Src/display.c b/Src/display.c index ab406a1..6c7b8f6 100644 --- a/Src/display.c +++ b/Src/display.c @@ -9,7 +9,7 @@ display.c unsigned char display_buffer_index = 0; unsigned char new_line[2] = {'\r', '\n'}; -unsigned char display_buffer[ROW_LINES][COL_NUMS]; +char display_buffer[ROW_LINES][COL_NUMS]; unsigned char *media_name_for_display[MEDIA_NUM] = {" LI-FI ", "BLUETOOTH ", " CC2530 "}; unsigned char rectange1[COL_NUMS] = {"�������������� �������������� ��������������\r\n"}; unsigned char rectange1_1[COL_NUMS] = {"�� �� �������������� ��������������\r\n"}; @@ -38,7 +38,7 @@ void print_info(void *arg) int i; printf("\033[2J"); //printf("\033[%d;%dH\r\n", 0, 0); - printf(" ** ��ü ���� ���� ** ** ���� ���� ��ü **\r\n"); + printf(" ** ��ü ���� ���� ** \r\n"); for(i = 0; i < MEDIA_NUM; i++) { if(i == 0) { printf("%s", rectange1); @@ -82,9 +82,13 @@ void print_info(void *arg) } } -void insert_display_message(unsigned char *message) +void insert_display_message(int message_type, char *message) { - strcpy(display_buffer[display_buffer_index], message); + char message_buffer[MSG_HEADER_LENGTH]; + sprintf(message_buffer, "* [%s] : ", str_message[message_type]); + + strncpy(display_buffer[display_buffer_index], message_buffer, MSG_HEADER_LENGTH); + strcpy(display_buffer[display_buffer_index] + MSG_HEADER_LENGTH, message); display_buffer_index = (display_buffer_index + 1) % ROW_LINES; display(); } @@ -94,6 +98,7 @@ void print_message(void *arg) int row, col; printf(" ** �޽��� ���� **\r\n"); + /* for(row = ROW_LINES - 1; row > display_buffer_index; row--) { printf("%s", display_buffer[row]); @@ -103,6 +108,7 @@ void print_message(void *arg) } */ + for(row = display_buffer_index; row < ROW_LINES; row++) { printf("%s", display_buffer[row]); } diff --git a/Src/gpio.c b/Src/gpio.c index 858d862..b5a00c2 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -14,14 +14,14 @@ gpio.c void GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - + /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); - + // CC2530 RESET_PIN /*Configure GPIO pin : PC9 */ GPIO_InitStruct.Pin = GPIO_PIN_9; @@ -55,11 +55,11 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) //printf("BT disconnected\r\n"); // BT �翬�� if(bt_dis_count > 4) { - struct task task; - task.fun = task_connect; - strcpy(task.arg, ""); - task_insert(&task); - bt_dis_count = 0; + struct task task; + task.fun = task_connect; + strcpy(task.arg, ""); + task_insert(&task); + bt_dis_count = 0; } } } diff --git a/Src/hash.c b/Src/hash.c index c2d04e4..0ce29cd 100644 --- a/Src/hash.c +++ b/Src/hash.c @@ -112,7 +112,7 @@ void PrintAllHashData() void PrintHashData(struct node *t_node) { int i, j; - printf("\r\n** Integ Addr : "); + printf("** Integ Addr : "); for(i = 0; i < INTEG_ADDR_LEN; i++) { printf("%02X ", (t_node->data).integ_addr[i]); } @@ -125,5 +125,5 @@ void PrintHashData(struct node *t_node) } printf("\r\n"); } - printf("\r\n-----------\r\n"); + printf("-----------\r\n"); } \ No newline at end of file diff --git a/Src/stm32f4xx_hal_msp.c b/Src/stm32f4xx_hal_msp.c index 18c4c3d..db9b2b7 100644 --- a/Src/stm32f4xx_hal_msp.c +++ b/Src/stm32f4xx_hal_msp.c @@ -129,7 +129,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USART2 interrupt Init */ - HAL_NVIC_SetPriority(USART2_IRQn, 0, 2); + HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ @@ -156,7 +156,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* USART3 interrupt Init */ - HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); + HAL_NVIC_SetPriority(USART3_IRQn, 1, 0); HAL_NVIC_EnableIRQ(USART3_IRQn); /* USER CODE BEGIN USART3_MspInit 1 */ @@ -184,7 +184,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* UART4 interrupt Init */ - HAL_NVIC_SetPriority(UART4_IRQn, 0, 3); + HAL_NVIC_SetPriority(UART4_IRQn, 2, 0); HAL_NVIC_EnableIRQ(UART4_IRQn); /* USER CODE BEGIN UART4_MspInit 1 */ diff --git a/Src/task.c b/Src/task.c index 3ae2482..9615b80 100644 --- a/Src/task.c +++ b/Src/task.c @@ -43,7 +43,7 @@ int task_delete(struct task *tskp) void task_cmd(void *arg) { - char buf[64], *cp0, *cp1, *cp2; + char buf[64], *cp0, *cp1; int deviceType = 0; if (fgets(buf, 64, stdin) == NULL) { display(); @@ -55,27 +55,32 @@ void task_cmd(void *arg) // �ƹ��͵� �Է¾��� ��� if (cp0 == NULL) { //printf("$ "); - insert_display_message("* [SYSTEM] \r\n"); + insert_display_message(SYSTEM_MSG, "!!!-Usage : \r\n"); display(); return; } + else if(!strcmp(cp0, "t")) { // test + frame_queue_insert((unsigned char *)&advertising_frame); + } else if(!strcmp(cp0, "info")) { - //PrintAllHashData(); - //print_uart_state(); - BT_CONNET(); + PrintAllHashData(); + HAL_Delay(3000); } - else if(!strcmp(cp0, "s")) { + else if(!strcmp(cp0, "s")) { // send INTEG_FRAME frame; frame.frame_length = INTEG_FRAME_HEADER_LEN + 0x06; memcpy(frame.src_address, my_integ_address, INTEG_ADDR_LEN); memcpy(frame.dest_address, hood_integ_address, INTEG_ADDR_LEN); - frame.media_type = cur_media; + 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_queue_insert((unsigned char *)&frame); @@ -97,7 +102,7 @@ void task_cmd(void *arg) } // �߸��� ���ɾ� �Է��� ��� else { - insert_display_message("* [SYSTEM] !!!-Wrong command\r\n"); + insert_display_message(SYSTEM_MSG, "!!!-Wrong command\r\n"); //printf("* [SYSTEM] !!!-Wrong command\r\n"); } display(); diff --git a/Src/uart.c b/Src/uart.c index 5652bb7..4c8883c 100644 --- a/Src/uart.c +++ b/Src/uart.c @@ -310,7 +310,6 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) */ } - // CC2530 else if (huart->Instance == huart3.Instance) { if (rxData != ETX) { @@ -330,6 +329,8 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) task_insert(&task); } } + + // CC2530 else if (huart->Instance == huart4.Instance) { if(macBuf[1] != 0x00)