-
Notifications
You must be signed in to change notification settings - Fork 16
/
toa.py
executable file
·52 lines (50 loc) · 2.83 KB
/
toa.py
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
#!/usr/bin/env python
from lorawan_toa_cal import get_toa, parse_args
if __name__ == "__main__" :
opt = parse_args()
if opt.sf != "FSK":
ret = get_toa(opt.n_size, opt.n_sf, n_bw=opt.n_bw,
enable_auto_ldro=opt.enable_auto_ldro,
enable_ldro=opt.enable_ldro,
enable_eh=opt.enable_eh, enable_crc=opt.enable_crc,
n_cr=opt.n_cr, n_preamble=opt.n_preamble)
ret["duty_cycle"] = opt.n_duty_cycle
ret["t_cycle"] = (ret["t_packet"]/1000.)*(100./ret["duty_cycle"])
ret["max_packets_day"] = 86400./ret["t_cycle"]
if opt.f_verbose:
print("PHY payload size : %d Bytes" % ret["phy_pl_size"])
print("MAC payload size : %d Bytes" % ret["mac_pl_size"])
print("Spreading Factor : %d" % ret["sf"])
print("Band width : %d kHz" % ret["bw"])
print("Low data rate opt. : %s" % ret["ldro"])
print("Explicit header : %s" % ret["eh"])
print("CR (coding rate) : %d (4/%d)" % (ret["cr"], 4+ret["cr"]))
print("Symbol Rate : %.3f symbol/s" % ret["r_sym"])
print("Symbol Time : %.3f msec/symbol" % ret["t_sym"])
print("Preamble size : %d symbols" % ret["n_preamble"])
print("Packet symbol size : %d symbols" % ret["n_sym_payload"])
print("Preamble ToA : %.3f msec" % ret["t_preamble"])
print("Payload ToA : %.3f msec" % ret["t_payload"])
print("Time on Air : %.3f msec" % ret["t_packet"])
print("RAW data rate : %.3f bps" % ret["raw_datarate"])
print("Duty Cycle : %d %%" % ret["duty_cycle"])
print("Min span of a cycle : %.3f sec" % ret["t_cycle"])
print("Max Frames per day : %d frames" % ret["max_packets_day"])
if opt.debug_level:
ret0 = get_toa(0, opt.n_sf, n_bw=opt.n_bw,
enable_auto_ldro=opt.enable_auto_ldro,
enable_ldro=opt.enable_ldro,
enable_eh=opt.enable_eh, enable_crc=opt.enable_crc,
n_cr=opt.n_cr, n_preamble=opt.n_preamble)
print("PHY PL=0 ToA : %.3f msec" % (ret0["t_packet"]))
# preamble=8 cr=1? payload-len=7? crc=16 (payload) payload-crc=16
# =? 48 ==> 6 bytes ?
t0 = (ret["t_packet"]-ret0["t_packet"])/1000.
print("PHY fr.dr.(48b) 7:15: %.3f bps" % ((8.*opt.n_size+48)/t0))
print("MAC frame DR : %.3f bps" % ((8.*(opt.n_size))/t0))
print("before ceil(x) : %.3f" % ret["v_ceil"])
else:
print("%.3f" % ret["t_packet"])
else: # FSK
raise NotImplementedError
pass