master
Paul Walko 2017-02-23 14:24:59 +00:00
parent c60c5d2da4
commit dd493fa1d6
2 changed files with 41 additions and 34 deletions

View File

@ -13,10 +13,10 @@ global total_len_dec = -1; # total len int
global preamble = -1; # preamble int global preamble = -1; # preamble int
global access_address = -1; # acc addr int global access_address = -1; # acc addr int
### PDU / CRC vars ### PDU / CRC vars # Holds raw dewhitened data
global pduCrcArray = -1; # pdu + crc array global pduCrcArray = -1; # pdu + crc array
global pdu = -1; # pdu array global pduArray = -1; # pdu array
global crc = -1; # crc array global crcArray = -1; # crc array
# PDU # PDU
global header_struct = -1; # header Struct global header_struct = -1; # header Struct
global payload_struct = -1; # payload Struct global payload_struct = -1; # payload Struct
@ -26,6 +26,7 @@ global crc_struct = -1; # crc struct
## Functions ## Functions
############################################# #############################################
## Helper Functions ## Helper Functions
# Flips every octect in array
function arr = flipOctects(arr) function arr = flipOctects(arr)
for i = 1:8:length(arr) for i = 1:8:length(arr)
arr(i:i + 7) = flip(arr(i:i + 7)); arr(i:i + 7) = flip(arr(i:i + 7));
@ -43,7 +44,7 @@ function loadFile(fileName = "frames.mat", dataName = "advertising_data_known",
eval (strcat("channel = ", channelName, ";")); eval (strcat("channel = ", channelName, ";"));
endfunction endfunction
# Extracts preamble from data ## Extracts preamble from data
function getPreamble() function getPreamble()
global data; global data;
global preamble; global preamble;
@ -53,7 +54,7 @@ function getPreamble()
endfor endfor
endfunction endfunction
# Extracts Access Address ## Extracts Access Address
function getAccessAddress() function getAccessAddress()
global data; global data;
addrArray = data(9:40); addrArray = data(9:40);
@ -65,7 +66,7 @@ function getAccessAddress()
endfunction endfunction
# deWhiten PDU and split up pdu & crc arrays ## deWhiten PDU and split up pdu & crc arrays
function deWhitenPDUCRC() function deWhitenPDUCRC()
global data; global data;
global channel; global channel;
@ -82,18 +83,17 @@ function deWhitenPDUCRC()
lfsr = bitset(lfsr, 1, bitget(lfsr, 8)); lfsr = bitset(lfsr, 1, bitget(lfsr, 8));
lfsr = bitset(lfsr, 5, bitxor(bitget(lfsr, 5), bitget(lfsr, 8))); lfsr = bitset(lfsr, 5, bitxor(bitget(lfsr, 5), bitget(lfsr, 8)));
endfor endfor
global pdu; global pduArray;
global crc; global crcArray;
pdu = pduCrcArray(1:length(pduCrcArray) - 24); pduArray = pduCrcArray(1:length(pduCrcArray) - 24);
crc = pduCrcArray(length(pduCrcArray) - 23:length(pduCrcArray)); crcArray = pduCrcArray(length(pduCrcArray) - 23:length(pduCrcArray));
endfunction endfunction
# deWhitenPDUCRC MUST be run before this function ## Extract header and store values in header_struct
# Extract header and store values in header_struct
function getPDUHeader() function getPDUHeader()
global pdu; global pduArray;
global header_struct; global header_struct;
header = pdu(1:16); header = pduArray(1:16);
reserved_1 = header(5:6); reserved_1 = header(5:6);
tx_add = uint8(0); tx_add = uint8(0);
rx_add = uint8(0); rx_add = uint8(0);
@ -133,19 +133,19 @@ function getPDUHeader()
pdutype = "Reserved"; pdutype = "Reserved";
endif endif
# Set header values # Set header values
header_struct = struct("pdutype", pdutype, "pdutype_dec", pdutype_dec, "reserved_1", reserved_1, "tx_add", tx_add, "rx_add", rx_add, "length", payload_len_dec, "reserved_2", reserved_2); header_struct = struct("header", header, "pdutype", pdutype, "pdutype_dec", pdutype_dec, "reserved_1", reserved_1, "tx_add", tx_add, "rx_add", rx_add, "length", payload_len_dec, "reserved_2", reserved_2);
endfunction endfunction
# Sets pdu struct to correct vars and store payload ## Sets pdu struct to correct vars and store payload
function setPayloadFields() function setPayloadFields()
global pdu; global pduArray;
global header_struct; global header_struct;
global payload_struct; global payload_struct;
field2_len = header_struct.length - 6; field2_len = header_struct.length - 6;
pdutype_dec = header_struct.pdutype_dec; pdutype_dec = header_struct.pdutype_dec;
payload_len = length(pdu) - 16; payload_len = length(pduArray) - 16;
payload = pdu(17:length(pdu)); payload = pduArray(17:length(pduArray));
# ADV_IND, ADV_NONNCONN_IND, ADV_SCAN_IND # ADV_IND, ADV_NONNCONN_IND, ADV_SCAN_IND
if pdutype_dec == 0 || pdutype_dec == 2 || pdutype_dec == 6 if pdutype_dec == 0 || pdutype_dec == 2 || pdutype_dec == 6
@ -234,12 +234,17 @@ function setPDUField_5()
endfunction endfunction
## Calculates crc & sets up struct ## Calculates crc & sets up struct
# crc_rx_dec is calculated crc, crc is transmitted
function setCRC() function setCRC()
global crc; global crcArray;
global crc_struct; global crc_struct;
crc_dec = -1; crc = flipOctects(crcArray)
## CONVERT crc to crc_dec
## CALC CRC
crc_dec = 0x555555;
crc_rx_dec = -1; crc_rx_dec = -1;
## COMPARE crc_dec, crc_rx_dec
crc_flag = -1; crc_flag = -1;
crc_struct = struct("crc", crc, "crc_dec", crc_dec, "crc_rx_dec", crc_rx_dec, "crc_flag", crc_flag); crc_struct = struct("crc", crc, "crc_dec", crc_dec, "crc_rx_dec", crc_rx_dec, "crc_flag", crc_flag);
endfunction endfunction
@ -251,22 +256,24 @@ function printAll()
global header_struct; global header_struct;
global crc_struct; global crc_struct;
printf("Preamble: 0x%X\n", preamble); printf("Preamble: 0x%X\n", preamble);
printf("Access Address: 0x%X\n", access_address); printf("Access Address: 0x%X\n", access_address);
printf("PDU Type: %s\n", header_struct.pdutype); printf("PDU Type: %s\n", header_struct.pdutype);
printf("PDU Dec: %s\n", header_struct.pdutype_dec); printf("PDU Dec: %s\n", header_struct.pdutype_dec);
printf("Reserved 1: "); printf("Reserved 1: ");
disp(header_struct.reserved_1); disp(header_struct.reserved_1);
printf("Tx_Add: %d\n", header_struct.tx_add); printf("Tx_Add: %d\n", header_struct.tx_add);
printf("Rx_Add: %d\n", header_struct.rx_add); printf("Rx_Add: %d\n", header_struct.rx_add);
printf("Payload Length: %d\n", header_struct.length); printf("Payload Length: %d\n", header_struct.length);
printf("Reserved 2: "); printf("Reserved 2: ");
disp(header_struct.reserved_2); disp(header_struct.reserved_2);
printf("CRC_DEC: %X\n", crc_struct.crc_dec); printf("CRC_DEC: %X\n", crc_struct.crc_dec);
printf("CRC_RX_DEC: %X\n", crc_struct.crc_rx_dec); printf("CRC_RX_DEC: %X\n", crc_struct.crc_rx_dec);
printf("CRC_FLAG: %X\n", crc_struct.crc_flag); printf("CRC_FLAG: %X\n", crc_struct.crc_flag);
printf("CRC_ARRAY: \n");
disp(crc_struct.crc);
endfunction endfunction
## Actually call functions ## Actually call functions

Binary file not shown.