asd
parent
c60c5d2da4
commit
dd493fa1d6
73
bluetooth.m
73
bluetooth.m
|
@ -13,10 +13,10 @@ global total_len_dec = -1; # total len int
|
|||
global preamble = -1; # preamble 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 pdu = -1; # pdu array
|
||||
global crc = -1; # crc array
|
||||
global pduArray = -1; # pdu array
|
||||
global crcArray = -1; # crc array
|
||||
# PDU
|
||||
global header_struct = -1; # header Struct
|
||||
global payload_struct = -1; # payload Struct
|
||||
|
@ -26,6 +26,7 @@ global crc_struct = -1; # crc struct
|
|||
## Functions
|
||||
#############################################
|
||||
## Helper Functions
|
||||
# Flips every octect in array
|
||||
function arr = flipOctects(arr)
|
||||
for i = 1:8:length(arr)
|
||||
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, ";"));
|
||||
endfunction
|
||||
|
||||
# Extracts preamble from data
|
||||
## Extracts preamble from data
|
||||
function getPreamble()
|
||||
global data;
|
||||
global preamble;
|
||||
|
@ -53,7 +54,7 @@ function getPreamble()
|
|||
endfor
|
||||
endfunction
|
||||
|
||||
# Extracts Access Address
|
||||
## Extracts Access Address
|
||||
function getAccessAddress()
|
||||
global data;
|
||||
addrArray = data(9:40);
|
||||
|
@ -65,7 +66,7 @@ function getAccessAddress()
|
|||
endfunction
|
||||
|
||||
|
||||
# deWhiten PDU and split up pdu & crc arrays
|
||||
## deWhiten PDU and split up pdu & crc arrays
|
||||
function deWhitenPDUCRC()
|
||||
global data;
|
||||
global channel;
|
||||
|
@ -82,18 +83,17 @@ function deWhitenPDUCRC()
|
|||
lfsr = bitset(lfsr, 1, bitget(lfsr, 8));
|
||||
lfsr = bitset(lfsr, 5, bitxor(bitget(lfsr, 5), bitget(lfsr, 8)));
|
||||
endfor
|
||||
global pdu;
|
||||
global crc;
|
||||
pdu = pduCrcArray(1:length(pduCrcArray) - 24);
|
||||
crc = pduCrcArray(length(pduCrcArray) - 23:length(pduCrcArray));
|
||||
global pduArray;
|
||||
global crcArray;
|
||||
pduArray = pduCrcArray(1:length(pduCrcArray) - 24);
|
||||
crcArray = pduCrcArray(length(pduCrcArray) - 23:length(pduCrcArray));
|
||||
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()
|
||||
global pdu;
|
||||
global pduArray;
|
||||
global header_struct;
|
||||
header = pdu(1:16);
|
||||
header = pduArray(1:16);
|
||||
reserved_1 = header(5:6);
|
||||
tx_add = uint8(0);
|
||||
rx_add = uint8(0);
|
||||
|
@ -133,19 +133,19 @@ function getPDUHeader()
|
|||
pdutype = "Reserved";
|
||||
endif
|
||||
# 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
|
||||
|
||||
# Sets pdu struct to correct vars and store payload
|
||||
## Sets pdu struct to correct vars and store payload
|
||||
function setPayloadFields()
|
||||
global pdu;
|
||||
global pduArray;
|
||||
global header_struct;
|
||||
global payload_struct;
|
||||
|
||||
field2_len = header_struct.length - 6;
|
||||
pdutype_dec = header_struct.pdutype_dec;
|
||||
payload_len = length(pdu) - 16;
|
||||
payload = pdu(17:length(pdu));
|
||||
field2_len = header_struct.length - 6;
|
||||
pdutype_dec = header_struct.pdutype_dec;
|
||||
payload_len = length(pduArray) - 16;
|
||||
payload = pduArray(17:length(pduArray));
|
||||
|
||||
# ADV_IND, ADV_NONNCONN_IND, ADV_SCAN_IND
|
||||
if pdutype_dec == 0 || pdutype_dec == 2 || pdutype_dec == 6
|
||||
|
@ -234,12 +234,17 @@ function setPDUField_5()
|
|||
endfunction
|
||||
|
||||
## Calculates crc & sets up struct
|
||||
# crc_rx_dec is calculated crc, crc is transmitted
|
||||
function setCRC()
|
||||
global crc;
|
||||
global crcArray;
|
||||
global crc_struct;
|
||||
|
||||
crc_dec = -1;
|
||||
crc = flipOctects(crcArray)
|
||||
## CONVERT crc to crc_dec
|
||||
## CALC CRC
|
||||
crc_dec = 0x555555;
|
||||
crc_rx_dec = -1;
|
||||
## COMPARE crc_dec, crc_rx_dec
|
||||
crc_flag = -1;
|
||||
crc_struct = struct("crc", crc, "crc_dec", crc_dec, "crc_rx_dec", crc_rx_dec, "crc_flag", crc_flag);
|
||||
endfunction
|
||||
|
@ -251,22 +256,24 @@ function printAll()
|
|||
global header_struct;
|
||||
global crc_struct;
|
||||
|
||||
printf("Preamble: 0x%X\n", preamble);
|
||||
printf("Access Address: 0x%X\n", access_address);
|
||||
printf("Preamble: 0x%X\n", preamble);
|
||||
printf("Access Address: 0x%X\n", access_address);
|
||||
|
||||
printf("PDU Type: %s\n", header_struct.pdutype);
|
||||
printf("PDU Dec: %s\n", header_struct.pdutype_dec);
|
||||
printf("PDU Type: %s\n", header_struct.pdutype);
|
||||
printf("PDU Dec: %s\n", header_struct.pdutype_dec);
|
||||
printf("Reserved 1: ");
|
||||
disp(header_struct.reserved_1);
|
||||
printf("Tx_Add: %d\n", header_struct.tx_add);
|
||||
printf("Rx_Add: %d\n", header_struct.rx_add);
|
||||
printf("Payload Length: %d\n", header_struct.length);
|
||||
printf("Tx_Add: %d\n", header_struct.tx_add);
|
||||
printf("Rx_Add: %d\n", header_struct.rx_add);
|
||||
printf("Payload Length: %d\n", header_struct.length);
|
||||
printf("Reserved 2: ");
|
||||
disp(header_struct.reserved_2);
|
||||
|
||||
printf("CRC_DEC: %X\n", crc_struct.crc_dec);
|
||||
printf("CRC_RX_DEC: %X\n", crc_struct.crc_rx_dec);
|
||||
printf("CRC_FLAG: %X\n", crc_struct.crc_flag);
|
||||
printf("CRC_DEC: %X\n", crc_struct.crc_dec);
|
||||
printf("CRC_RX_DEC: %X\n", crc_struct.crc_rx_dec);
|
||||
printf("CRC_FLAG: %X\n", crc_struct.crc_flag);
|
||||
printf("CRC_ARRAY: \n");
|
||||
disp(crc_struct.crc);
|
||||
endfunction
|
||||
|
||||
## Actually call functions
|
||||
|
|
BIN
octave-workspace
BIN
octave-workspace
Binary file not shown.
Loading…
Reference in New Issue