Skip to content

Commit

Permalink
MAC 테이블 구성 부분 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
imsoo committed May 14, 2019
1 parent 3415f27 commit 0f20cfa
Show file tree
Hide file tree
Showing 17 changed files with 422 additions and 130 deletions.
1 change: 1 addition & 0 deletions Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
75 changes: 55 additions & 20 deletions Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
bluetooth.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h> //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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);

Expand All @@ -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()
Expand All @@ -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);

Expand All @@ -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 커맨더 진입
Expand Down
3 changes: 2 additions & 1 deletion Drivers/CC2530/CC2530_MAC/Inc/mac_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
void mtUtilGetPrimaryIEEE();
unsigned char* cc2530_get_mac_addr(unsigned char addr_type);
43 changes: 33 additions & 10 deletions Drivers/CC2530/CC2530_MAC/Src/mac_interface.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <string.h> //for memcpy()
#include "mac_interface.h"
#include "mac_interface_uart.h"
#include "stm32f4xx_hal.h"
#include <string.h> //for memcpy()
#include "integ_mac.h"

/** Get the Least Significant Byte (LSB) of an unsigned int*/
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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$ ");
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions Drivers/INTEG_MAC/Inc/integ_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand All @@ -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 // 통합 맥 프레임 헤더 길이
Expand All @@ -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
Expand All @@ -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;


Expand All @@ -85,13 +90,19 @@ 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);
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)

Expand Down
2 changes: 1 addition & 1 deletion Drivers/INTEG_MAC/Src/frame_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 0f20cfa

Please sign in to comment.