From dd493fa1d6d2cd551c0ae96399bd52056bd116c0 Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Thu, 23 Feb 2017 14:24:59 +0000 Subject: [PATCH] asd --- bluetooth.m | 75 ++++++++++++++++++++++++++--------------------- octave-workspace | Bin 48 -> 14361 bytes 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/bluetooth.m b/bluetooth.m index 2089921..6ab4bb0 100755 --- a/bluetooth.m +++ b/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("PDU Type: %s\n", header_struct.pdutype); - printf("PDU Dec: %s\n", header_struct.pdutype_dec); + 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("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 diff --git a/octave-workspace b/octave-workspace index 078a6070db60d3b398e4ee05631b38ab6b9bbe67..df4b51feb91caed4d6d3ab7301e5096ebee6af33 100644 GIT binary patch literal 14361 zcmeI3%T60-7>3=0+O$;XV**WCG?WG zg1Y~2^K|fwU;pEQWh24k_wao)*hGwc_<1nRuZx%Mmp`_?ZM9nY@VY3c=acjC+x{@0 z=KbHt7dPV&v|95|!nb$%v^<~vGoQ~t2KxkjoX;GjhlcnNAL2V|&uQngmmK0N$(63BzG~frriV_EKBSL^_)vYcQu|GF z_Bgt|^fgCoj#g@)93QHWPEqIS<3oI?eoE_{_Q|2i`{+UK zJ70Tf?W?8-$(5R;w^)W9Id1eUH(*l>NuLCm3lsCdMQm$$($p7a;Md&4>d>EC3_s%Lym^(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