wiliot-certificate 1.3.0a1__py3-none-any.whl → 1.4.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. brg_certificate/__init__.py +0 -0
  2. brg_certificate/ag/energous_v0_defines.py +925 -0
  3. brg_certificate/ag/energous_v1_defines.py +931 -0
  4. brg_certificate/ag/energous_v2_defines.py +925 -0
  5. brg_certificate/ag/energous_v3_defines.py +925 -0
  6. brg_certificate/ag/energous_v4_defines.py +925 -0
  7. brg_certificate/ag/fanstel_lan_v0_defines.py +925 -0
  8. brg_certificate/ag/fanstel_lte_v0_defines.py +925 -0
  9. brg_certificate/ag/fanstel_wifi_v0_defines.py +925 -0
  10. brg_certificate/ag/minew_lte_v0_defines.py +925 -0
  11. brg_certificate/ag/wlt_cmd_if.html +102 -0
  12. brg_certificate/ag/wlt_types.html +6114 -0
  13. brg_certificate/ag/wlt_types_ag.py +7840 -0
  14. brg_certificate/ag/wlt_types_ag_jsons/brg2brg_ota.json +142 -0
  15. brg_certificate/ag/wlt_types_ag_jsons/brg2gw_hb.json +785 -0
  16. brg_certificate/ag/wlt_types_ag_jsons/brg2gw_hb_sleep.json +139 -0
  17. brg_certificate/ag/wlt_types_ag_jsons/calibration.json +394 -0
  18. brg_certificate/ag/wlt_types_ag_jsons/custom.json +515 -0
  19. brg_certificate/ag/wlt_types_ag_jsons/datapath.json +672 -0
  20. brg_certificate/ag/wlt_types_ag_jsons/energy2400.json +550 -0
  21. brg_certificate/ag/wlt_types_ag_jsons/energySub1g.json +595 -0
  22. brg_certificate/ag/wlt_types_ag_jsons/externalSensor.json +598 -0
  23. brg_certificate/ag/wlt_types_ag_jsons/interface.json +938 -0
  24. brg_certificate/ag/wlt_types_ag_jsons/powerManagement.json +1234 -0
  25. brg_certificate/ag/wlt_types_ag_jsons/side_info_sensor.json +105 -0
  26. brg_certificate/ag/wlt_types_ag_jsons/signal_indicator_data.json +77 -0
  27. brg_certificate/ag/wlt_types_ag_jsons/unified_echo_ext_pkt.json +61 -0
  28. brg_certificate/ag/wlt_types_ag_jsons/unified_echo_pkt.json +110 -0
  29. brg_certificate/brg_certificate.py +191 -0
  30. brg_certificate/brg_certificate_cli.py +47 -0
  31. brg_certificate/cert_common.py +828 -0
  32. brg_certificate/cert_config.py +395 -0
  33. brg_certificate/cert_data_sim.py +188 -0
  34. brg_certificate/cert_defines.py +337 -0
  35. brg_certificate/cert_gw_sim.py +285 -0
  36. brg_certificate/cert_mqtt.py +373 -0
  37. brg_certificate/cert_prints.py +181 -0
  38. brg_certificate/cert_protobuf.py +88 -0
  39. brg_certificate/cert_results.py +300 -0
  40. brg_certificate/cert_utils.py +358 -0
  41. brg_certificate/certificate_sanity_test_list.txt +36 -0
  42. brg_certificate/certificate_test_list.txt +43 -0
  43. brg_certificate/config/eclipse.json +10 -0
  44. brg_certificate/config/hivemq.json +10 -0
  45. brg_certificate/config/mosquitto.json +10 -0
  46. brg_certificate/config/mosquitto.md +95 -0
  47. brg_certificate/config/wiliot-dev.json +10 -0
  48. brg_certificate/restore_brg.py +59 -0
  49. brg_certificate/tests/calibration/interval_test/interval_test.json +13 -0
  50. brg_certificate/tests/calibration/interval_test/interval_test.py +28 -0
  51. brg_certificate/tests/calibration/output_power_test/output_power_test.json +13 -0
  52. brg_certificate/tests/calibration/output_power_test/output_power_test.py +28 -0
  53. brg_certificate/tests/calibration/pattern_test/pattern_test.json +13 -0
  54. brg_certificate/tests/calibration/pattern_test/pattern_test.py +70 -0
  55. brg_certificate/tests/datapath/adaptive_pacer_algo_test/adaptive_pacer_algo_test.json +13 -0
  56. brg_certificate/tests/datapath/adaptive_pacer_algo_test/adaptive_pacer_algo_test.py +76 -0
  57. brg_certificate/tests/datapath/num_of_tags_test/num_of_tags_test.json +13 -0
  58. brg_certificate/tests/datapath/num_of_tags_test/num_of_tags_test.py +83 -0
  59. brg_certificate/tests/datapath/output_power_test/output_power_test.json +13 -0
  60. brg_certificate/tests/datapath/output_power_test/output_power_test.py +27 -0
  61. brg_certificate/tests/datapath/pacer_interval_ble5_test/pacer_interval_ble5_test.json +13 -0
  62. brg_certificate/tests/datapath/pacer_interval_ble5_test/pacer_interval_ble5_test.py +43 -0
  63. brg_certificate/tests/datapath/pacer_interval_tags_count_test/pacer_interval_tags_count_test.json +13 -0
  64. brg_certificate/tests/datapath/pacer_interval_tags_count_test/pacer_interval_tags_count_test.py +63 -0
  65. brg_certificate/tests/datapath/pacer_interval_test/pacer_interval_test.json +13 -0
  66. brg_certificate/tests/datapath/pacer_interval_test/pacer_interval_test.py +50 -0
  67. brg_certificate/tests/datapath/pattern_test/pattern_test.json +13 -0
  68. brg_certificate/tests/datapath/pattern_test/pattern_test.py +28 -0
  69. brg_certificate/tests/datapath/pkt_filter_ble5_test/pkt_filter_ble5_test.json +13 -0
  70. brg_certificate/tests/datapath/pkt_filter_ble5_test/pkt_filter_ble5_test.py +51 -0
  71. brg_certificate/tests/datapath/pkt_filter_gen3_test/pkt_filter_gen3_test.json +13 -0
  72. brg_certificate/tests/datapath/pkt_filter_gen3_test/pkt_filter_gen3_test.py +54 -0
  73. brg_certificate/tests/datapath/pkt_filter_test/pkt_filter_test.json +13 -0
  74. brg_certificate/tests/datapath/pkt_filter_test/pkt_filter_test.py +55 -0
  75. brg_certificate/tests/datapath/rssi_threshold_test/rssi_threshold_test.json +13 -0
  76. brg_certificate/tests/datapath/rssi_threshold_test/rssi_threshold_test.py +73 -0
  77. brg_certificate/tests/datapath/rx_channel_test/rx_channel_test.json +13 -0
  78. brg_certificate/tests/datapath/rx_channel_test/rx_channel_test.py +41 -0
  79. brg_certificate/tests/datapath/rx_rate_gen2_test/rx_rate_gen2_test.json +21 -0
  80. brg_certificate/tests/datapath/rx_rate_gen2_test/rx_rate_gen2_test.py +184 -0
  81. brg_certificate/tests/datapath/rx_rate_gen3_test/rx_rate_gen3_test.json +21 -0
  82. brg_certificate/tests/datapath/rx_rate_gen3_test/rx_rate_gen3_test.py +210 -0
  83. brg_certificate/tests/datapath/stress_gen3_test/stress_gen3_test.json +30 -0
  84. brg_certificate/tests/datapath/stress_gen3_test/stress_gen3_test.py +203 -0
  85. brg_certificate/tests/datapath/stress_test/stress_test.json +30 -0
  86. brg_certificate/tests/datapath/stress_test/stress_test.py +210 -0
  87. brg_certificate/tests/datapath/tx_repetition_algo_test/tx_repetition_algo_test.json +13 -0
  88. brg_certificate/tests/datapath/tx_repetition_algo_test/tx_repetition_algo_test.py +113 -0
  89. brg_certificate/tests/datapath/tx_repetition_test/tx_repetition_test.json +13 -0
  90. brg_certificate/tests/datapath/tx_repetition_test/tx_repetition_test.py +79 -0
  91. brg_certificate/tests/edge_mgmt/actions_test/actions_test.json +13 -0
  92. brg_certificate/tests/edge_mgmt/actions_test/actions_test.py +432 -0
  93. brg_certificate/tests/edge_mgmt/brg2brg_ota_ble5_test/brg2brg_ota_ble5_test.json +13 -0
  94. brg_certificate/tests/edge_mgmt/brg2brg_ota_ble5_test/brg2brg_ota_ble5_test.py +94 -0
  95. brg_certificate/tests/edge_mgmt/brg2brg_ota_test/brg2brg_ota_test.json +13 -0
  96. brg_certificate/tests/edge_mgmt/brg2brg_ota_test/brg2brg_ota_test.py +87 -0
  97. brg_certificate/tests/edge_mgmt/leds_test/leds_test.json +13 -0
  98. brg_certificate/tests/edge_mgmt/leds_test/leds_test.py +210 -0
  99. brg_certificate/tests/edge_mgmt/ota_test/ota_test.json +13 -0
  100. brg_certificate/tests/edge_mgmt/ota_test/ota_test.py +83 -0
  101. brg_certificate/tests/edge_mgmt/stat_test/stat_test.json +13 -0
  102. brg_certificate/tests/edge_mgmt/stat_test/stat_test.py +48 -0
  103. brg_certificate/tests/energy2400/duty_cycle_test/duty_cycle_test.json +13 -0
  104. brg_certificate/tests/energy2400/duty_cycle_test/duty_cycle_test.py +26 -0
  105. brg_certificate/tests/energy2400/output_power_test/output_power_test.json +13 -0
  106. brg_certificate/tests/energy2400/output_power_test/output_power_test.py +27 -0
  107. brg_certificate/tests/energy2400/pattern_test/pattern_test.json +13 -0
  108. brg_certificate/tests/energy2400/pattern_test/pattern_test.py +28 -0
  109. brg_certificate/tests/energy2400/signal_indicator_ble5_test/signal_indicator_ble5_test.json +13 -0
  110. brg_certificate/tests/energy2400/signal_indicator_ble5_test/signal_indicator_ble5_test.py +398 -0
  111. brg_certificate/tests/energy2400/signal_indicator_sub1g_2_4_test/signal_indicator_sub1g_2_4_test.json +13 -0
  112. brg_certificate/tests/energy2400/signal_indicator_sub1g_2_4_test/signal_indicator_sub1g_2_4_test.py +153 -0
  113. brg_certificate/tests/energy2400/signal_indicator_test/signal_indicator_test.json +13 -0
  114. brg_certificate/tests/energy2400/signal_indicator_test/signal_indicator_test.py +264 -0
  115. brg_certificate/tests/energy_sub1g/duty_cycle_test/duty_cycle_test.json +13 -0
  116. brg_certificate/tests/energy_sub1g/duty_cycle_test/duty_cycle_test.py +27 -0
  117. brg_certificate/tests/energy_sub1g/pattern_test/pattern_test.json +13 -0
  118. brg_certificate/tests/energy_sub1g/pattern_test/pattern_test.py +26 -0
  119. brg_certificate/tests/energy_sub1g/signal_indicator_functionality_test/signal_indicator_functionality_test.json +13 -0
  120. brg_certificate/tests/energy_sub1g/signal_indicator_functionality_test/signal_indicator_functionality_test.py +397 -0
  121. brg_certificate/tests/energy_sub1g/signal_indicator_test/signal_indicator_test.json +13 -0
  122. brg_certificate/tests/energy_sub1g/signal_indicator_test/signal_indicator_test.py +27 -0
  123. brg_certificate/wltPb_pb2.py +72 -0
  124. brg_certificate/wltPb_pb2.pyi +227 -0
  125. brg_certificate/wlt_types.py +114 -0
  126. gw_certificate/api/extended_api.py +7 -1531
  127. gw_certificate/api_if/200/data.json +106 -0
  128. gw_certificate/api_if/200/logs.json +12 -0
  129. gw_certificate/api_if/200/status.json +47 -0
  130. gw_certificate/api_if/201/data.json +98 -0
  131. gw_certificate/api_if/201/logs.json +12 -0
  132. gw_certificate/api_if/201/status.json +53 -0
  133. gw_certificate/api_if/202/data.json +83 -0
  134. gw_certificate/api_if/202/logs.json +12 -0
  135. gw_certificate/api_if/202/status.json +60 -0
  136. gw_certificate/api_if/203/data.json +85 -0
  137. gw_certificate/api_if/203/logs.json +12 -0
  138. gw_certificate/api_if/203/status.json +63 -0
  139. gw_certificate/api_if/204/data.json +85 -0
  140. gw_certificate/api_if/204/logs.json +12 -0
  141. gw_certificate/api_if/204/status.json +63 -0
  142. gw_certificate/api_if/205/data.json +85 -0
  143. gw_certificate/api_if/205/logs.json +12 -0
  144. gw_certificate/api_if/205/status.json +63 -0
  145. gw_certificate/api_if/api_validation.py +0 -2
  146. gw_certificate/common/analysis_data_bricks.py +18 -1413
  147. gw_certificate/common/debug.py +0 -21
  148. gw_certificate/common/utils.py +1 -212
  149. gw_certificate/common/utils_defines.py +0 -87
  150. gw_certificate/gw_certificate.py +9 -7
  151. gw_certificate/gw_certificate_cli.py +39 -23
  152. gw_certificate/interface/4.4.52_app.zip +0 -0
  153. gw_certificate/interface/4.4.52_sd_bl_app.zip +0 -0
  154. gw_certificate/interface/ble_simulator.py +0 -32
  155. gw_certificate/interface/if_defines.py +1 -0
  156. gw_certificate/interface/mqtt.py +96 -19
  157. gw_certificate/interface/nrfutil-linux +0 -0
  158. gw_certificate/interface/nrfutil-mac +0 -0
  159. gw_certificate/interface/nrfutil.exe +0 -0
  160. gw_certificate/interface/pkt_generator.py +0 -82
  161. gw_certificate/interface/uart_if.py +73 -43
  162. gw_certificate/templates/results.html +1 -1
  163. gw_certificate/tests/__init__.py +1 -2
  164. gw_certificate/tests/actions.py +134 -9
  165. gw_certificate/tests/connection.py +10 -5
  166. gw_certificate/tests/downlink.py +2 -4
  167. gw_certificate/tests/generic.py +62 -12
  168. gw_certificate/tests/registration.py +78 -27
  169. gw_certificate/tests/static/generated_packet_table.py +12 -48
  170. gw_certificate/tests/static/packet_table.csv +10048 -10048
  171. gw_certificate/tests/static/references.py +2 -1
  172. gw_certificate/tests/static/uplink_defines.py +0 -7
  173. gw_certificate/tests/throughput.py +7 -12
  174. gw_certificate/tests/uplink.py +83 -43
  175. {wiliot_certificate-1.3.0a1.dist-info → wiliot_certificate-1.4.0a1.dist-info}/METADATA +59 -8
  176. wiliot_certificate-1.4.0a1.dist-info/RECORD +198 -0
  177. {wiliot_certificate-1.3.0a1.dist-info → wiliot_certificate-1.4.0a1.dist-info}/WHEEL +1 -1
  178. wiliot_certificate-1.4.0a1.dist-info/entry_points.txt +3 -0
  179. wiliot_certificate-1.4.0a1.dist-info/top_level.txt +2 -0
  180. gw_certificate/interface/packet_error.py +0 -22
  181. wiliot_certificate-1.3.0a1.dist-info/RECORD +0 -51
  182. wiliot_certificate-1.3.0a1.dist-info/entry_points.txt +0 -2
  183. wiliot_certificate-1.3.0a1.dist-info/top_level.txt +0 -1
  184. {wiliot_certificate-1.3.0a1.dist-info → wiliot_certificate-1.4.0a1.dist-info}/LICENSE +0 -0
@@ -0,0 +1,337 @@
1
+ # Files
2
+ import os
3
+ # BASE_DIR should be initiated in the same dir as brg_certificate.py
4
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
5
+ CERT_MQTT_LOG_FILE = "cert_mqtt_log.json"
6
+ DATA_SIM_LOG_FILE = "data_sim_log.txt"
7
+ UT_RESULT_FILE_HTML = "results.html"
8
+ UT_RESULT_FILE_PDF = "results.pdf"
9
+ UT_RESULT_FILE = "results.html"
10
+ UTILS_BASE_REL_PATH = "../../../utils"
11
+
12
+ # GW defines
13
+ GW_ID = "gatewayId"
14
+ ADDITIONAL = "additional"
15
+ REPORTED_CONF = "reportedConf"
16
+ GW_CONF = "gatewayConf"
17
+ GW_NAME = "gatewayName"
18
+ GW_API_VERSION = "apiVersion"
19
+ LAT = "lat"
20
+ LNG = "lng"
21
+ WLT_SERVER = "wiliotServer"
22
+ PACER_INTERVAL = "pacerInterval"
23
+ PKT_TYPES_MASK = "packetTypesMask"
24
+ RX_TX_PERIOD = "rxTxPeriodMs"
25
+ TX_PERIOD = "txPeriodMs"
26
+ OUTPUT_POWER_2_4 = "2.4GhzOutputPower"
27
+ NFPKT = "nfpkt"
28
+ TBC = "tbc"
29
+ RSSI = "rssi"
30
+ SRC_ID = "src_id"
31
+
32
+ INTERNAL_BRG_RSSI = 1
33
+ BRIDGE_ID = "bridgeId"
34
+ ALIAS_BRIDGE_ID = "aliasBridgeId"
35
+ GROUP_ID = "group_id"
36
+ BRG_ACTION = "bridgeAction"
37
+
38
+ GW_DATA_MODE = "gwDataMode"
39
+ TAGS_AND_BRGS = "Tags & Bridges"
40
+ TAGS_ONLY = "Tags only"
41
+ BRGS_ONLY_37 = "Bridges only (ch37)"
42
+ BRGS_ONLY_38 = "Bridges only (ch38)"
43
+ BRGS_ONLY_39 = "Bridges only (ch39)"
44
+ HIBERNATE = "Hibernate"
45
+
46
+ BLE_WIFI = "ble_wifi"
47
+ BLE_LAN = "ble_lan"
48
+
49
+ WLT_SERVER = "wiliotServer"
50
+ PACER_INTERVAL = "pacerInterval"
51
+ OUTPUT_POWER_2_4 = "2.4GhzOutputPower"
52
+ USE_STAT_LOC = "useStaticLocation"
53
+ GW_ENERGY_PATTERN = "energizingPattern"
54
+ VERSION = "version"
55
+ WIFI_VERSION = "interfaceChipSwVersion"
56
+ BLE_VERSION = "bleChipSwVersion"
57
+ BLE_MAC_ADDR = "bleChipMacAddress"
58
+ GW_MODE = "gwMode"
59
+ PROD = "prod"
60
+ SERIALIZATION_FORMAT = "serializationFormat"
61
+ PROTOBUF = "Protobuf"
62
+ JSON = "JSON"
63
+
64
+ GET_INFO_ACTION = "getGwInfo"
65
+ REBOOT_GW_ACTION = "rebootGw"
66
+ LOG_PERIOD_ACTION = "LogPeriodSet"
67
+ GET_LOGS = "getLogs"
68
+ GW_INFO = "gatewayInfo"
69
+ GW_LOGS = "gatewayLogs"
70
+ LOGS = "logs"
71
+ GW_LATITUDE = "Latitude"
72
+ GW_LONGITUDE = "Longitude"
73
+ GW_LOG_PERIOD = 30
74
+
75
+ # Thin gw defines
76
+ THIN_GW_PROTOCOL_VERSION = "protocolVersion"
77
+ TX_PKT = "txPacket"
78
+ TX_MAX_DURATION_MS = "txMaxDurationMs"
79
+ TX_MAX_RETRIES = "txMaxRetries"
80
+ TRANPARENT_PKT_LEN = 31 * 2
81
+
82
+ # Simulator defines
83
+ GW_SIM_BLE_MAC_ADDRESS = 'GW_SIM_BLE_MAC_ADDRESS'
84
+ GW_SIM_PREFIX = 'SIM'
85
+ DATA_SIMULATION = 'sim'
86
+ DATA_REAL_TAGS = 'tags'
87
+ GEN2 = 2
88
+ GEN3 = 3
89
+ GEN3_EXTENDED = 4
90
+
91
+ # Configurable brg fields' names by modules
92
+ # common #
93
+ BRG_OUTPUT_POWER = "output_power"
94
+ BRG_PATTERN = "pattern"
95
+ BRG_DUTY_CYCLE = "duty_cycle"
96
+ BRG_SIGNAL_INDICATOR_CYCLE = "signal_indicator_cycle"
97
+ BRG_SIGNAL_INDICATOR_REP = "signal_indicator_rep"
98
+ # Datapath #
99
+ BRG_UNIFIED_ECHO_PKT = "unified_echo_pkt"
100
+ BRG_ADAPTIVE_PACER = "adaptive_pacer"
101
+ BRG_PACER_INTERVAL = "pacer_interval"
102
+ BRG_RSSI_THRESHOLD = "rssi_threshold"
103
+ BRG_SUB1G_RSSI_THRESHOLD = "sub1g_rssi_threshold"
104
+ BRG_TX_REPETITION = "tx_repetition"
105
+ BRG_PKT_FILTER = "pkt_filter"
106
+ BRG_RX_CHANNEL = "rx_channel"
107
+ # Calibration #
108
+ BRG_CALIB_INTERVAL = "interval"
109
+ # Energy Sub1g #
110
+ BRG_CYCLE = "cycle"
111
+ # 3rd party sensors #
112
+ BRG_SENSOR0 = "sensor0"
113
+ BRG_SENSOR1 = "sensor1"
114
+
115
+ # Common defines
116
+ PACKETS = "packets"
117
+ TIMESTAMP = "timestamp"
118
+ ACTION = "action"
119
+ ACTION_STATUS = "actionStatus" # Protobuf
120
+ PAYLOAD = "payload"
121
+ SEQUENCE_ID = "sequenceId"
122
+ MODULE_IF = "module IF"
123
+ HB = "HB"
124
+ DATETIME = "datetime"
125
+ TIME = "time"
126
+ TIMESTAMP_DELTA = "timestamp_delta"
127
+ TAGS_COUNT = "tags_count"
128
+ NEW_TAGS = "new_tags"
129
+ TTFP = "ttfp"
130
+
131
+ # Protobuf related
132
+ ENTRIES = "entries"
133
+ STR_VAL = "stringValue"
134
+ NUM_VAL = "numberValue"
135
+ GW_STATUS = "gatewayStatus"
136
+ BRG_UPGRADE = "bridgeUpgrade"
137
+ REBOOT_PKT = "rebootPacket"
138
+
139
+ # Custom broker
140
+ CUSTOM_BROKER_ENABLE = "customBroker"
141
+ CUSTOM_BROKER_PORT = "port"
142
+ CUSTOM_BROKER_BROKER_URL = "brokerUrl"
143
+ CUSTOM_BROKER_USERNAME = "username"
144
+ CUSTOM_BROKER_PASSWORD = "password"
145
+ CUSTOM_BROKER_UPDATE_TOPIC = "updateTopic"
146
+ CUSTOM_BROKER_STATUS_TOPIC = "statusTopic"
147
+ CUSTOM_BROKER_DATA_TOPIC = "dataTopic"
148
+
149
+ # External Sensors
150
+ IS_SENSOR = "isSensor"
151
+ IS_EMBEDDED = "isEmbedded"
152
+ IS_SCRAMBLED = "isScrambled"
153
+ SENSOR_UUID = "sensorServiceId"
154
+ SENSOR_ID = "sensorId"
155
+ PKT_ID_CTR = "pkt_id_ctr"
156
+
157
+ # OTA
158
+ STATUS_CODE_STR = "statusCode"
159
+ STATUS_CODE = "status" # Protobuf
160
+ IMG_DIR_URL = "imageDirUrl"
161
+ UPGRADE_BLSD = "upgradeBlSd"
162
+ VER_UUID_STR = "versionUUID"
163
+ VER_MAX_LEN = 31
164
+
165
+ # Versions
166
+ VERSIONS = {
167
+ "1.5.0" : {WIFI_VERSION: "3.5.32", BLE_VERSION: "3.7.25"},
168
+ "1.5.2" : {WIFI_VERSION: "3.5.132", BLE_VERSION: "3.7.25"},
169
+ "1.6.1" : {WIFI_VERSION: "3.5.51", BLE_VERSION: "3.8.18"},
170
+ "1.7.0" : {WIFI_VERSION: "3.9.8", BLE_VERSION: "3.9.24"},
171
+ "1.7.1" : {WIFI_VERSION: "3.10.6", BLE_VERSION: "3.10.13"},
172
+ "1.8.0" : {WIFI_VERSION: "3.11.36", BLE_VERSION: "3.11.40"},
173
+ "1.8.2" : {WIFI_VERSION: "3.11.36", BLE_VERSION: "3.11.42"},
174
+ "1.9.0" : {WIFI_VERSION: "3.12.10", BLE_VERSION: "3.12.36"},
175
+ "1.10.1" : {WIFI_VERSION: "3.13.29", BLE_VERSION: "3.13.25"},
176
+ "3.14.0" : {WIFI_VERSION: "3.14.33", BLE_VERSION: "3.14.64"},
177
+ "3.15.0" : {WIFI_VERSION: "3.15.38", BLE_VERSION: "3.15.72"},
178
+ "3.16.3" : {WIFI_VERSION: "3.16.20", BLE_VERSION: "3.16.96"},
179
+ "3.17.0" : {WIFI_VERSION: "3.17.25", BLE_VERSION: "3.17.90"},
180
+ "4.0.0" : {WIFI_VERSION: "4.0.8", BLE_VERSION: "4.0.65"},
181
+ "4.1.0" : {WIFI_VERSION: "4.1.8", BLE_VERSION: "4.1.33"},
182
+ "4.1.2" : {WIFI_VERSION: "4.1.11", BLE_VERSION: "4.1.35"},
183
+ "4.2.0" : {WIFI_VERSION: "4.2.22", BLE_VERSION: "4.2.115"},
184
+ "4.2.5" : {WIFI_VERSION: "4.2.26", BLE_VERSION: "4.2.125"},
185
+ "4.3.0" : {WIFI_VERSION: "4.3.24", BLE_VERSION: "4.3.96"},
186
+ "4.3.1" : {WIFI_VERSION: "4.3.24", BLE_VERSION: "4.3.98"},
187
+ "4.3.2" : {WIFI_VERSION: "4.3.24", BLE_VERSION: "4.3.100"},
188
+ }
189
+
190
+ # Tests defines
191
+ DEFAULT_GW_FIELD_UPDATE_TIMEOUT = 10
192
+ DEFAULT_BRG_FIELD_UPDATE_TIMEOUT = 10
193
+ HB_PERIOD = 30
194
+ VER_UPDATE_TIMEOUT = 400
195
+ GW_LATITUDE_DEFAULT = 33.0222
196
+ GW_LONGITUDE_DEFAULT = -117.0839
197
+ # Set to work with default when versions tests only pass through new api ver
198
+ GW_API_VER_DEFAULT = "201"
199
+ GW_API_VER_OLD = "200"
200
+ BRG_CFG_HAS_LEN = 2
201
+ CLEAR_DATA_PATH_TIMEOUT = 10
202
+ ACTION_LONG_TIMEOUT = 120
203
+ ACTION_SI_PKT_TIMEOUT = 10
204
+ ACTION_SHORT_TIMEOUT = 5
205
+
206
+ # Internal python ut defines - used only in ut
207
+ PACER_INTERVAL_MIN_TAGS_COUNT = 20
208
+ PACER_INTERVAL_MAX_FAILED_TAGS = 2
209
+ PACER_INTERVAL_THRESHOLD_HIGH = 0.90
210
+ PACER_INTERVAL_CEIL_THRESHOLD = 1.1
211
+ PACER_INTERVAL_THRESHOLD = 0.80
212
+ PACKETS_ECHO_OFF = 16
213
+ TEST_PASSED = 0
214
+ TEST_FAILED = -1
215
+ TEST_SKIPPED = 1
216
+ TEST_INIT = 2
217
+ NO_RESPONSE = "NO_RESPONSE"
218
+ DONE = "DONE"
219
+ TEST_SUCCESS = ":)"
220
+ MGMT_PKT = "mgmt_pkt"
221
+ UNIFIED_PKT = "unified_pkt"
222
+ SIDE_INFO_SENSOR_PKT = "side_info_sensor_pkt"
223
+ SENSOR_PKT = "sensor_pkt"
224
+ DECODED_DATA = "decoded_data"
225
+ TAG_ID = "tag_id"
226
+ BRG_LATENCY = "brg_latency"
227
+ PACKET_CNTR = "packet_cntr"
228
+ PACKET_TYPE = "packet_type"
229
+ PACKET_DATA = "packet_data"
230
+ PKTS = "pkts"
231
+ MQTT_LOG_PRE_STR = "mqtt_log_"
232
+ GW_DATA = "gw_data"
233
+ GW_ID = "gw_id"
234
+ CER = "cer"
235
+ PKT_CNTR_DIFF = "packet_cntr_diff"
236
+ AVG = "avg_"
237
+ CER_PER_TAG = "cer_per_tag"
238
+ AWS = "aws"
239
+ TEST = "test"
240
+ MULTI_BRG_TEST = "multiBridgeTest" # used for multi brg tests
241
+ GW_ONLY_TEST = "gwOnlyTest" # used for gw only tests
242
+ ALL_SUPPORTED_VALUES = "allSupportedValues"
243
+ PROLOG = "Prolog"
244
+ TEST_BODY = "Test Body"
245
+ EPILOG = "Epilog"
246
+
247
+ # test reasons
248
+ NO_PARAMS_GIVEN = "No parameters given!"
249
+ BRG_VER_SUCCESS = "SUCCESS - BRG version matches expected version!"
250
+ BRG_BL_VER_SUCCESS = "SUCCESS - BRG Bootloader version matches expected version!"
251
+ WANTED_VER_SAME = "Wanted version is same as original one!"
252
+ WANTED_VER_SAME_MUL = "Wanted versions are same as original ones!"
253
+ VER_UPDATE_PASSED = "Version Update Ran Successfully!"
254
+ VER_UPDATE_FAILED = "The Update Process Has Been Interrupted!"
255
+
256
+ # ---------------------------------------------------RTSA defines---------------------------------------------------
257
+ # common defines
258
+ TRACE_LOG_FILE_NAME = "TRACELOG"
259
+ TRACE_LOG_FILE_PATH = "C:/SignalVu-PC Files/" + TRACE_LOG_FILE_NAME + ".TOV"
260
+
261
+ # freq defines
262
+ FREQ_2_4_GHZ = {'37':2.402, '38':2.426, '39':2.480}
263
+ FREQ_SUB1G_MHZ = {'865_7':865.700, '915':915.000, '916_3':916.300, '917_5':917.500, '918':918.000, '919_1':919.100}
264
+
265
+ # SignalVu API commands defines
266
+ TRACE_DETECTION = {'average':'AVERage', 'positive':'POSitive', 'negative':'NEGative', 'positive-negative':'POSNegative', 'sample':'SAMPle'}
267
+ MAX_TRACE_POINTS = {'1K':'ONEK', '10K':'TENK', '100K':'HUNDredk', 'never_decimate':'NEVerdecimate' }
268
+
269
+ # default values
270
+ DEFAULT_LENGTH_MS = 30
271
+ DEFAULT_TIME_PER_DIVISION_SEC = 5
272
+ DEFAULT_RX_TX_PERIOD_SEC = 0.015
273
+ BEACON_MIN_LENGTH_SEC = 375e-6
274
+ BEACON_MAX_LENGTH_SEC = 500e-6
275
+ ENERGIZING_TIME_THRESHOLD = 0.3
276
+ BEACON_POWER_THRESHOLD = 0.9
277
+ BEACON_POWER_CURVE_38 = 0.7
278
+ BEACON_POWER_CURVE_39 = 0.625
279
+ DEFAULT_SPAN_MHZ = 5
280
+ RXTX_MAX_CFG = 255
281
+ RXTX_CFG_DEFAULT = 100
282
+
283
+ # test times
284
+ FREQ_BEACONS_ANALYSIS_TIME_DELTA = 10
285
+
286
+ # structured energizing patterns information
287
+ class energizingPattern:
288
+ def __init__(self, ble_calibration_beacons = [], ble_energy = {}, ble_post_energy_beacons = [], sub1G_energy = False, info = ""):
289
+ self.ble_calibration_beacons = ble_calibration_beacons
290
+ self.ble_energy = ble_energy
291
+ self.ble_post_energy_beacons = ble_post_energy_beacons
292
+ self.sub1G_energy = sub1G_energy
293
+ self.info = info
294
+
295
+ EP_INFO = {
296
+ '17' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']]),
297
+ '18' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['39'] : 1.0}),
298
+ '20' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['37'] : 0.2, FREQ_2_4_GHZ['39'] : 0.8}),
299
+ '24' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['37'] : 1.0}),
300
+ '25' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['38'] : 1.0}),
301
+ '26' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={2.454 : 1.0}),
302
+ '27' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39'], FREQ_2_4_GHZ['39']]),
303
+ '29' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['38'] : 0.3333, 2.454 : 0.3333, FREQ_2_4_GHZ['39'] : 0.3333}),
304
+ '36' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'],FREQ_2_4_GHZ['38'],FREQ_2_4_GHZ['39']], info="idle"),
305
+ '37' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], 2.415, FREQ_2_4_GHZ['39'], 2.441, 2.428, 2.454, 2.467], ble_energy={2.450 : 1.0}, info="euro"),
306
+ '50' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], sub1G_energy=True),
307
+ '51' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['39'] : 1.0}, sub1G_energy=True),
308
+ '52' : energizingPattern(sub1G_energy=True),
309
+ '55' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['37'] : 1.0}, sub1G_energy=True),
310
+ '56' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={FREQ_2_4_GHZ['38'] : 1.0}, sub1G_energy=True),
311
+ '57' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], FREQ_2_4_GHZ['38'], FREQ_2_4_GHZ['39']], ble_energy={2.454 : 1.0}, sub1G_energy=True),
312
+ '61' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], 2.415, FREQ_2_4_GHZ['39'], 2.441, 2.428, 2.454, 2.467], sub1G_energy=True, info="euro"),
313
+ '62' : energizingPattern(ble_calibration_beacons=[FREQ_2_4_GHZ['37'], 2.415, FREQ_2_4_GHZ['39'], 2.441, 2.428, 2.454, 2.467], ble_energy={2.475 : 1.0}, sub1G_energy=True, info="euro"),
314
+ '99' : energizingPattern(ble_calibration_beacons=[i/1000.0 for i in range(2402, 2481, 2)])
315
+ }
316
+
317
+ EP_FREQ_BREAKDOWN_COUNTER_SETUP = {
318
+ 2.402 : {'beacons':0, 'energy_in_ms': 0.0},
319
+ 2.426 : {'beacons':0, 'energy_in_ms': 0.0},
320
+ 2.480 : {'beacons':0, 'energy_in_ms': 0.0},
321
+ 2.403 : {'beacons':0, 'energy_in_ms': 0.0},
322
+ 2.427 : {'beacons':0, 'energy_in_ms': 0.0},
323
+ 2.483 : {'beacons':0, 'energy_in_ms': 0.0},
324
+ 2.454 : {'beacons':0, 'energy_in_ms': 0.0},
325
+ 2.481 : {'beacons':0, 'energy_in_ms': 0.0},
326
+ 2.415 : {'beacons':0, 'energy_in_ms': 0.0},
327
+ 2.441 : {'beacons':0, 'energy_in_ms': 0.0},
328
+ 2.428 : {'beacons':0, 'energy_in_ms': 0.0},
329
+ 2.467 : {'beacons':0, 'energy_in_ms': 0.0},
330
+ 2.475 : {'beacons':0, 'energy_in_ms': 0.0},
331
+ 0.8657 : {'beacons':0, 'energy_in_ms': 0.0},
332
+ 0.915 : {'beacons':0, 'energy_in_ms': 0.0},
333
+ 0.9163 : {'beacons':0, 'energy_in_ms': 0.0},
334
+ 0.9175 : {'beacons':0, 'energy_in_ms': 0.0},
335
+ 0.918 : {'beacons':0, 'energy_in_ms': 0.0},
336
+ 0.9191 : {'beacons':0, 'energy_in_ms': 0.0}
337
+ }
@@ -0,0 +1,285 @@
1
+ import time
2
+ import os
3
+ import re
4
+ import paho.mqtt.client as mqtt
5
+ import serial
6
+ import serial.tools.list_ports
7
+ from brg_certificate.cert_mqtt import *
8
+ from brg_certificate.cert_defines import *
9
+ from brg_certificate.cert_prints import *
10
+ import brg_certificate.cert_common as cert_common
11
+ from brg_certificate.cert_data_sim import PIXEL_SIM_INDICATOR, write_to_data_sim_log_file
12
+ import brg_certificate.cert_utils as cert_utils
13
+
14
+ # Generic Defines
15
+ SERIAL_TIMEOUT = 0.1 # TODO decide about the right value
16
+ GW_APP_VERSION_HEADER = 'WILIOT_GW_BLE_CHIP_SW_VER'
17
+ STOP_ADVERTISING = '!stop_advertising'
18
+ RESET_GW = '!reset'
19
+ DEDUPLICATION_PKTS = '!deduplication_pkts'
20
+ SET_RX_CHANNEL = '!set_rx_channel'
21
+ VERSION = '!version'
22
+ CONNECTIVITY_STATUS = '!connectivity_status'
23
+
24
+ # Interference Analysis Defines
25
+ DEFAULT_LOOKOUT_TIME = 2
26
+ GET_LOGGER_COUNTERS = '!get_logger_counters'
27
+ CHANNELS_TO_ANALYZE = [(37, 2402), (38, 2426), (39, 2480)]
28
+ CNTRS_LISTEN_TIME_SEC = 30
29
+ MAX_UNSIGNED_32_BIT = 0xFFFFFFFF
30
+ INCONCLUSIVE_MINIMUM = 70
31
+ NON_WLT_RX = 'non_wlt_rx'
32
+ WLT_RX = 'wlt_rx'
33
+ BAD_CRC = 'bad_crc'
34
+ CNTRS_KEYS = [NON_WLT_RX, WLT_RX, BAD_CRC]
35
+
36
+ GW_STATUS_MESSAGES = []
37
+
38
+ ##############################################
39
+ # UART PKT TYPES
40
+ ##############################################
41
+ class UplinkPkt(): # p6
42
+ def __init__(self, gw, seq_id, raw):
43
+ self.gw = gw
44
+ self.seq_id = seq_id
45
+ self.alias_brg_id = raw[0:12]
46
+ self.payload = raw[12:74]
47
+ self.rssi = int(raw[74:76], 16)
48
+ def dump(self):
49
+ return {
50
+ GW_ID: self.gw, TIMESTAMP: time.time()*1000,
51
+ "packets": [{ALIAS_BRIDGE_ID: self.alias_brg_id,
52
+ TIMESTAMP: time.time()*1000,
53
+ SEQUENCE_ID: self.seq_id,
54
+ RSSI: self.rssi,
55
+ PAYLOAD: self.payload}]
56
+ }
57
+
58
+ class UplinkExtendedPkt(): # p7
59
+ def __init__(self, gw, seq_id, raw):
60
+ self.gw = gw
61
+ self.seq_id = seq_id
62
+ self.alias_brg_id = raw[0:12]
63
+ self.payload = raw[12:96] # 39 payload + 3 side info
64
+ self.rssi = int(raw[96:98], 16)
65
+ def dump(self):
66
+ return {
67
+ GW_ID: self.gw, TIMESTAMP: time.time()*1000,
68
+ "packets": [{ALIAS_BRIDGE_ID: self.alias_brg_id,
69
+ TIMESTAMP: time.time()*1000,
70
+ SEQUENCE_ID: self.seq_id,
71
+ RSSI: self.rssi,
72
+ PAYLOAD: self.payload}]
73
+ }
74
+
75
+ ##############################################
76
+ # UT HELPER FUNCTIONS
77
+ ##############################################
78
+ def prep_gw(args, mqttc, start_time):
79
+ # Check GW is online and configure to defaults
80
+ utPrint(SEP)
81
+ utPrint("Checking UART response and configure internal brg to defaults", "BLUE")
82
+ gw = args.gw
83
+ protobuf = False
84
+ internal_brg_mac_addr = os.getenv(GW_SIM_BLE_MAC_ADDRESS)
85
+ if not internal_brg_mac_addr:
86
+ cert_utils.handle_error(f"ERROR: Didn't receive {GW_SIM_BLE_MAC_ADDRESS} response!", start_time)
87
+ internal_brg = cert_utils.ut_prep_brg(args, mqttc, start_time, gw, internal_brg_mac_addr, "prod", protobuf)
88
+ if internal_brg.api_version != ag.API_VERSION_LATEST:
89
+ cert_utils.handle_error(f"ERROR: Certificate FW api_version={internal_brg.api_version} instead of api_version={ag.API_VERSION_LATEST}! Please upgrade the FW!", start_time)
90
+ return gw, internal_brg, "prod", {BLE_VERSION:"0.0.0", WIFI_VERSION:"0.0.0"}, protobuf
91
+
92
+ ##############################################
93
+ # UART FUNCTIONS
94
+ ##############################################
95
+ def write_to_ble(ble_serial, txt, print_enable=True, sleep=0):
96
+ if print_enable:
97
+ print('\n' + txt)
98
+ ble_serial.write(bytes(txt, encoding='utf-8') + b'\r\n')
99
+ if sleep:
100
+ cert_common.wait_time_n_print(sleep)
101
+
102
+ def read_from_ble(ble_serial):
103
+ ble_serial_bytes = ble_serial.readline()
104
+ input = ble_serial_bytes.decode("utf-8", "ignore").strip()
105
+ # if input:
106
+ # print(input)
107
+ return input
108
+
109
+ def gw_app_reponse(ble_serial):
110
+ write_to_ble(ble_serial, txt=VERSION, print_enable=True)
111
+ start_time = datetime.datetime.now()
112
+ while (datetime.datetime.now() - start_time).seconds < 2:
113
+ input = read_from_ble(ble_serial)
114
+ if GW_APP_VERSION_HEADER in input:
115
+ print(input)
116
+ ble_mac_address = re.search('WILIOT_GW_BLE_CHIP_MAC_ADDRESS=([0-9A-F]{12})', input).group(1)
117
+ print("success!")
118
+ return TEST_PASSED, ble_mac_address
119
+ print("failure!")
120
+ return TEST_FAILED, ''
121
+
122
+ def cur_time():
123
+ return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
124
+
125
+ # Packet Counters
126
+ def get_pkts_cntrs(ble_serial, channel, set_rx_ch=False):
127
+ print(f'\n{cur_time()} | Getting pkt counters for CH{channel}')
128
+ if set_rx_ch:
129
+ write_to_ble(ble_serial, f"{SET_RX_CHANNEL} {channel}", sleep=1)
130
+ pkt_cntrs = None
131
+ write_to_ble(ble_serial, GET_LOGGER_COUNTERS)
132
+ start_time = datetime.datetime.now()
133
+ while (datetime.datetime.now() - start_time).seconds < DEFAULT_LOOKOUT_TIME:
134
+ input = read_from_ble(ble_serial)
135
+ if input and f"'{BAD_CRC}'" in input:
136
+ start_of_cntr_index = input.find('{')
137
+ pkt_cntrs = input[start_of_cntr_index:]
138
+ print(f"pkt_cntrs: {pkt_cntrs}")
139
+ return eval(pkt_cntrs)
140
+ print(f"No counter received within the time limit of {DEFAULT_LOOKOUT_TIME} seconds")
141
+ return pkt_cntrs
142
+
143
+ # Interference Analysis
144
+ def interference_analysis(ble_serial):
145
+ """Analyze the interference level (PER) before the test begins"""
146
+
147
+ def handle_wrap_around(a):
148
+ "handle a wrap around of the counter"
149
+ if a < 0:
150
+ a = a + MAX_UNSIGNED_32_BIT
151
+ return a
152
+
153
+ for channel in CHANNELS_TO_ANALYZE:
154
+ print('\n' + '#' * 30 + f'\nAnalyzing channel {channel[0]}\n' + '#' * 30)
155
+ # Send the sniffer a command to retrieve the counters and convert them to dict
156
+ start_cntrs = get_pkts_cntrs(ble_serial, channel[0], set_rx_ch=True)
157
+ cert_common.wait_time_n_print(CNTRS_LISTEN_TIME_SEC)
158
+ end_cntrs = get_pkts_cntrs(ble_serial, channel[0])
159
+
160
+ if start_cntrs is None or end_cntrs is None:
161
+ print(color('RED', f'Channel {channel[0]} ({channel[1]} MHz) interference analysis was skipped because at least one counter is missing.'))
162
+ print(color('RED', f'Channel {channel[0]} ({channel[1]} MHz) Ambient Interference was not calculated, missing at least one counter.'))
163
+ continue
164
+
165
+ # Calculate the bad CRC percentage
166
+ diff_dict = dict()
167
+ for key in CNTRS_KEYS:
168
+ diff_dict[key] = handle_wrap_around(end_cntrs[key] - start_cntrs[key])
169
+ bad_crc_percentage = round((diff_dict[BAD_CRC] / (diff_dict[WLT_RX] + diff_dict[NON_WLT_RX])) * 100)
170
+ print(color('WARNING', f'Channel {channel[0]} ({channel[1]} MHz) Ambient Interference (bad CRC percentage) is: {bad_crc_percentage}%'))
171
+ print(f'Good CRC packets = {diff_dict[NON_WLT_RX] + diff_dict[WLT_RX] - diff_dict[BAD_CRC]}, bad CRC packets: {diff_dict[BAD_CRC]}')
172
+
173
+ ##############################################
174
+ # MQTT FUNCTIONS
175
+ ##############################################
176
+
177
+ def on_connect(mqttc, userdata, flags, rc):
178
+ print("python_gw_sim_connect, rc: " + str(rc))
179
+
180
+ def on_disconnect(mqttc, userdata, rc):
181
+ txt = f"ERROR: python_gw_sim_disconnect, rc: {rc} {mqtt.error_string(rc)}"
182
+ print(txt)
183
+ write_to_mqtt_log_file(txt)
184
+ write_to_data_sim_log_file(txt)
185
+
186
+ def on_subscribe(mqttc, userdata, mid, granted_qos):
187
+ print("python_gw_sim_subscribe, " + str(mid) + " " + str(granted_qos))
188
+
189
+ def on_unsubscribe(mqttc, userdata, mid):
190
+ print("ERROR: python_gw_sim_unsubscribe, " + str(mid))
191
+
192
+ def on_message(client, userdata, message):
193
+ data = json.loads(message.payload.decode("utf-8"))
194
+ print_enable = True if not PIXEL_SIM_INDICATOR in str(message.payload.decode("utf-8")) else False
195
+ if print_enable:
196
+ print("##########\n// Message received at {}, topic={}:\n{}\n".format(datetime.datetime.now().strftime("%d/%m/%Y, %H:%M:%S"), message.topic, str(message.payload.decode("utf-8"))))
197
+ # Send packet to UART
198
+ if TX_PKT in data:
199
+ # Downlink packet
200
+ cmd = f"!sp {data[TX_PKT]} {data[TX_MAX_RETRIES]}"
201
+ write_to_ble(userdata['serial'], cmd, print_enable=print_enable)
202
+ if GW_CONF in data:
203
+ # GW configuration
204
+ cfg = data[GW_CONF][ADDITIONAL]
205
+ GW_STATUS_MESSAGES.append(data)
206
+ if ACTION in data and len(data) == 1:
207
+ # GW actions
208
+ if data[ACTION].startswith("!"):
209
+ write_to_ble(userdata['serial'], data[ACTION], print_enable=print_enable)
210
+
211
+ ##############################################
212
+ # GW SIMULATOR
213
+ ##############################################
214
+ def parse_uart_pkts(input, mqttc, custom_broker, gw_id, seq_id):
215
+ if input.startswith("p6 "):
216
+ # p6 1234567898761E16C6FC0000EE02093E3C71BF6DFA3C006648001CB8003A730160000E010031
217
+ pkt = UplinkPkt(gw_id, seq_id, input.split()[1])
218
+ mqttc.publish(custom_broker[CUSTOM_BROKER_DATA_TOPIC], payload=json.dumps(pkt.dump(), indent=4))
219
+ return True
220
+ elif input.startswith("p7 "):
221
+ # p7 1234567898762616C6FC05000002093E3C71BF6DFA3C006648001CB8003A730160000E0100112233445566778831
222
+ pkt = UplinkExtendedPkt(gw_id, seq_id, input.split()[1])
223
+ mqttc.publish(custom_broker[CUSTOM_BROKER_DATA_TOPIC], payload=json.dumps(pkt.dump(), indent=4))
224
+ return True
225
+ elif GW_STATUS_MESSAGES:
226
+ pkt = GW_STATUS_MESSAGES.pop(0)
227
+ mqttc.publish(custom_broker[CUSTOM_BROKER_STATUS_TOPIC], payload=json.dumps(pkt, indent=4))
228
+ return False
229
+
230
+ def gw_sim_run(port, gw_id, analyze_interference=False):
231
+
232
+ print(f"###>>> GW SIM STARTED WITH PORT {port}")
233
+
234
+ # Init serial side
235
+ print("\nAvailable ports:")
236
+ for port, desc, hwid in sorted(serial.tools.list_ports.comports()):
237
+ print("{}: {} [{}]".format(port, desc, hwid))
238
+ ble_serial = serial.Serial(port=port, baudrate=921600, timeout=SERIAL_TIMEOUT)
239
+ ble_serial.flushInput()
240
+
241
+ # Init mqtt side
242
+ custom_broker = load_custom_broker(gw_id)
243
+ client_id = '{}-republish2'.format(gw_id)
244
+ userdata = {'serial': ble_serial}
245
+ mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, client_id, userdata=userdata)
246
+ mqttc.username_pw_set(custom_broker[CUSTOM_BROKER_USERNAME], custom_broker[CUSTOM_BROKER_PASSWORD])
247
+ mqttc.on_message = on_message
248
+ mqttc.on_connect = on_connect
249
+ mqttc.on_disconnect = on_disconnect
250
+ mqttc.on_subscribe = on_subscribe
251
+ mqttc.on_unsubscribe = on_unsubscribe
252
+ if not 1883 == custom_broker[CUSTOM_BROKER_PORT]:
253
+ mqttc.tls_set(tls_version=ssl.PROTOCOL_TLSv1_2)
254
+ mqttc.connect(custom_broker[CUSTOM_BROKER_BROKER_URL].replace("mqtts://", ""), port=custom_broker[CUSTOM_BROKER_PORT], keepalive=60)
255
+ mqttc.loop_start()
256
+
257
+ mqttc.update_topic = custom_broker[CUSTOM_BROKER_UPDATE_TOPIC]
258
+ mqttc.subscribe(mqttc.update_topic)
259
+
260
+ # Run BLE
261
+ write_to_ble(ble_serial, RESET_GW, sleep=5)
262
+ gw_app_res = gw_app_reponse(ble_serial)
263
+ if gw_app_res[0] == TEST_FAILED:
264
+ print("ERROR: didn't get version response!")
265
+ return
266
+ os.environ[GW_SIM_BLE_MAC_ADDRESS] = gw_app_res[1]
267
+ write_to_ble(ble_serial, STOP_ADVERTISING, sleep=2)
268
+ write_to_ble(ble_serial, f"{CONNECTIVITY_STATUS} 1 1")
269
+
270
+ # Run interference analysis
271
+ if analyze_interference:
272
+ print(color("BLUE", f"\nStarting interference analysis for channels {[ch[0] for ch in CHANNELS_TO_ANALYZE]}. This will take {30 * len(CHANNELS_TO_ANALYZE)} seconds (total)"))
273
+ interference_analysis(ble_serial)
274
+
275
+ # Run infinte loop reading from UART
276
+ seq_id = 100
277
+ while True:
278
+ input = read_from_ble(ble_serial)
279
+ if input and input[0] == "p" and input[2] == " ":
280
+ seq_id += 1
281
+ # input = ""
282
+ if not parse_uart_pkts(input, mqttc, custom_broker, gw_id, seq_id):
283
+ # if input:
284
+ if 0:
285
+ print(f"###>>> IGNORED: {input}")