-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_2fsk_packet_decode.sh
executable file
·104 lines (80 loc) · 3.81 KB
/
1_2fsk_packet_decode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Wisun 2-FSK packet decode test scripts
# qianfan Zhao <[email protected]>
# Preamble + sfd + phr + payload
# 10001000 <=> 10000111
# 1000100001000100 <=> 1000011100110100
simple_2fsk_packet="
01010101-1001000001001110-0000100000000001-10000111
01010101-1001000001001110-0000100000000001-10001000
0101010101010101-1001000001001110-0000100000000001-10000111
0101010101010101-1001000001001110-0000100000000001-10001000
01010101010101010101010101010101-1001000001001110-0000100000000001-10000111
01010101010101010101010101010101-1001000001001110-0000100000000001-10001000
01010101-1001000001001110-0000100000000010-1000011100110100
01010101-1001000001001110-0000100000000010-1000100001000100
011001-01010101-1001000001001110-0000100000000010-1000011100110100
01010101-1001000001001110-0000100000000010-1000100001000100
011001-01010101-101010-0101010101010101-1001000001001110-0000100000000010-1000011100110100
0101010101010101-1001000001001110-0000100000000010-1000100001000100
"
# $1: the raw binary string bits
# $2: the expected binary string bits result after encoding
decode_2fsk_packet_test() {
local decode raw=$1 expected=$(echo $2 | tr -d '-')
printf "P: ${raw}\nE: ${expected}\n"
decode=$(./urh_wisun_fsk.debug --skip-verify --decode "${raw}")
if [ X"${expected}" != X"${decode}" ] ; then
printf "R: ${decode}\nx\n"
return 1
fi
}
decode_test () {
local retval=0
echo "urh_wisun_fsk packet decode testing..."
while [ $# -gt 0 ] ; do
local raw=$1 expected=$2
shift 2
if ! decode_2fsk_packet_test "${raw}" "${expected}" ; then
let retval++
fi
done
return ${retval}
}
decode_hexo_test () {
local raw=$1 expected=$2
local decode
printf "urh_wisun_fsk packet decode ${expected}... "
decode=$(./urh_wisun_fsk.debug --human --hexo --decode ${raw})
if [ X"${decode}" != X"${expected}" ] ; then
printf "\nE: ${expected}\nR: ${decode}\n"
printf "failed\n"
return 1
else
printf "pass\n"
fi
}
# A packet copied from urh when RAILtest follow this configurations:
# > settxlength 4
# {{(settxlength)}{TxLength:4}{TxLength Written:4}}
# > set802154phr 1 0 1
# {{(set802154phr)}{PhrSize:2}{PHR:0x6010}}
# {{(set802154phr)}{len:4}{payload: 0x10 0x60 0x11 0x22}}
rf_1122="010101010101010101010101010101010101010101010101010101010101010110010000010011100000100000000110100001110011010010100101110100010101011111010111"
rf_1122_decode="aaaaaaaaaaaaaaaa-7209-6010-1122-687d28f2"
# > settxlength 5
# {{(settxlength)}{TxLength:5}{TxLength Written:5}}
# > set802154phr 1 0 1
# {{(set802154phr)}{PhrSize:2}{PHR:0xe010}}
# {{(set802154phr)}{len:5}{payload: 0x10 0xe0 0x11 0x22 0x33}}
rf_112233="01010101010101010101010101010101010101010101010101010101010101011001000001001110000010000000011110000111001101000111111101110101010110110101101000101000"
rf_112233_decode="aaaaaaaaaaaaaaaa-7209-e010-112233-58184306"
rf_11223344="1000000000000001010101010101010101010101010101010101010101010101010101010101011001000001001110000010000000100010000111001101000111111101001101110010000010000100000111010000000000000000"
rf_11223344_decode="aaaaaaaaaaaaaaaa-7209-1010-11223344-d19df277"
rf_1122334455="00000000101010101010101010101010101010101010101010101010101010101010101100100000100111000001000000010011000011100110100011111110100110111101001000011000001001010101011101000001"
rf_1122334455_decode="aaaaaaaaaaaaaaaa-7209-9010-1122334455-295aa038"
decode_test ${simple_2fsk_packet} || exit $?
decode_hexo_test ${rf_1122} ${rf_1122_decode} || exit $?
decode_hexo_test ${rf_112233} ${rf_112233_decode} || exit $?
decode_hexo_test "${rf_112233}01010101" ${rf_112233_decode} || exit $? # garbage in the tail
decode_hexo_test ${rf_11223344} ${rf_11223344_decode} || exit $?
decode_hexo_test ${rf_1122334455} ${rf_1122334455_decode} || exit $?