diff --git a/mesht_protobuf_extra.py b/mesht_protobuf_extra.py index fccf43a..58c572b 100644 --- a/mesht_protobuf_extra.py +++ b/mesht_protobuf_extra.py @@ -1,3 +1,6 @@ +from protobufs_extra.position_proto import * +from protobufs_extra.telemetry_proto import * + LOG_RECORD = [ ("string", "message", 1), ("fixed32", "time", 2), @@ -45,76 +48,3 @@ FILE_INFO = [ ("string", "file_name", 1), ("uint32", "size_bytes", 2) ] - -######### - -DEVICE_METRICS_SCHEME = [ - ("uint32", "battary_level", 1), - ("float", "voltage", 2), - ("float", "channel_utilization", 3), - ("float", "air_util_tx", 4), - ("uint32", "uptime_seconds", 5) -] - -ENVIRONMENT_METRICS_SCHEME = [ - ("float", "temperature", 1) - ##and moreeee -] - -AIR_QUALITY_METRICS_SCHEME = [ - ("uint32", "pm10_standard", 1) - #and moreee -] - -POWER_METRICS_SCHEME = [ - ("float", "ch1_voltage", 1) - #and moreee -] - -LOCAL_STATS_SCHEME = [ - ("uint32", "uptime_seconds", 1), - ("float", "channel_utilization", 2), - ("float", "air_util_tx", 3), - ("uint32", "num_packets_tx", 4), - ("uint32", "num_packets_rx", 5), - ("uint32", "num_packets_rx_bad", 6), - ("uint32", "num_online_nodes", 7), - ("uint32", "num_total_nodes", 8), - ("uint32", "num_rx_dupe", 9), - ("uint32", "num_tx_relay", 10), - ("uint32", "num_tx_relay_canceled", 11), - ("uint32", "heap_total_bytes", 12), - ("uint32", "heap_free_bytes", 13), - ("uint32", "num_tx_dropped", 14), - ("int32", "noise_floor", 15) -] - -HEALTH_METRICS_SCHEME = [ - ("uint32", "heart_bpm", 1), - ("uint32", "spO2", 2), - ("float", "temperature", 3) -] - -HOST_METRICS_SCHEME = [ - ("uint32", "uptime_seconds", 1) - #and moooore -] - -TRAFFIC_MANAGEMENT_SCHEME = [ - ("uint32", "packets_inspected", 1) - #AnD MOREEE -] - -TELEMETRY_SCHEME = [ - ("fixed32", "time", 1), - ("oneof", "variant", [ - (DEVICE_METRICS_SCHEME, "device_metrics", 2), - (ENVIRONMENT_METRICS_SCHEME, "environment_metrics", 3), - (AIR_QUALITY_METRICS_SCHEME, "air_quality_metrics", 4), - (POWER_METRICS_SCHEME, "power_metrics", 5), - (LOCAL_STATS_SCHEME, "local_stats", 6), - (HEALTH_METRICS_SCHEME, "health_metrics", 7), - (HOST_METRICS_SCHEME, "host_metrics", 8), - (TRAFFIC_MANAGEMENT_SCHEME, "traffic_management_stats", 9) - ]) -] diff --git a/protobufs_extra/__init__.py b/protobufs_extra/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/protobufs_extra/position_proto.py b/protobufs_extra/position_proto.py new file mode 100644 index 0000000..8e3cc47 --- /dev/null +++ b/protobufs_extra/position_proto.py @@ -0,0 +1,40 @@ +LOC_SOURCE_ENUM = { + 0:"LOC_UNSET", + 1:"LOC_MANUAL", + 2:"LOC_INTERNAL", + 3:"LOC_EXTERNAL" +} + +ALT_SOURCE_ENUM = { + 0:"ALT_UNSET", + 1:"ALT_MANUAL", + 2:"ALT_INTERNAL", + 3:"ALT_EXTERNAL", + 4:"ALT_BAROMETRIC" +} + +POSITION_SCHEME = [ + ("sfixed32", "latitude_i", 1), + ("sfixed32", "longitude_i", 2), + ("int32", "altitude", 3), + ("float32", "time", 4), + ("int32", "location_source", 5), + ("int32", "altitude_source", 6), + ("fixed32", "timestamp", 7), + ("int32", "timestamp_millis_adjust", 8), + ("sint32", "altitude_hae", 9), + ("sint32", "altitude_geoidal_separation", 10), + ("uint32", "PDOP", 11), + ("uint32", "HDOP", 12), + ("uint32", "VDOP", 13), + ("uint32", "gps_accuracy", 14), + ("uint32", "ground_speed", 15), + ("uint32", "ground_track", 16), + ("uint32", "fix_quality", 17), + ("uint32", "fix_type", 18), + ("uint32", "sats_in_view", 19), + ("uint32", "sensor_id", 20), + ("uint32", "next_update", 21), + ("uint32", "seq_number", 22), + ("uint32", "precision_bits", 23) +] \ No newline at end of file diff --git a/protobufs_extra/telemetry_proto.py b/protobufs_extra/telemetry_proto.py new file mode 100644 index 0000000..feb3f3d --- /dev/null +++ b/protobufs_extra/telemetry_proto.py @@ -0,0 +1,71 @@ + +DEVICE_METRICS_SCHEME = [ + ("uint32", "battary_level", 1), + ("float", "voltage", 2), + ("float", "channel_utilization", 3), + ("float", "air_util_tx", 4), + ("uint32", "uptime_seconds", 5) +] + +ENVIRONMENT_METRICS_SCHEME = [ + ("float", "temperature", 1) + ##and moreeee +] + +AIR_QUALITY_METRICS_SCHEME = [ + ("uint32", "pm10_standard", 1) + #and moreee +] + +POWER_METRICS_SCHEME = [ + ("float", "ch1_voltage", 1) + #and moreee +] + +LOCAL_STATS_SCHEME = [ + ("uint32", "uptime_seconds", 1), + ("float", "channel_utilization", 2), + ("float", "air_util_tx", 3), + ("uint32", "num_packets_tx", 4), + ("uint32", "num_packets_rx", 5), + ("uint32", "num_packets_rx_bad", 6), + ("uint32", "num_online_nodes", 7), + ("uint32", "num_total_nodes", 8), + ("uint32", "num_rx_dupe", 9), + ("uint32", "num_tx_relay", 10), + ("uint32", "num_tx_relay_canceled", 11), + ("uint32", "heap_total_bytes", 12), + ("uint32", "heap_free_bytes", 13), + ("uint32", "num_tx_dropped", 14), + ("int32", "noise_floor", 15) +] + +HEALTH_METRICS_SCHEME = [ + ("uint32", "heart_bpm", 1), + ("uint32", "spO2", 2), + ("float", "temperature", 3) +] + +HOST_METRICS_SCHEME = [ + ("uint32", "uptime_seconds", 1) + #and moooore +] + +TRAFFIC_MANAGEMENT_SCHEME = [ + ("uint32", "packets_inspected", 1) + #AnD MOREEE +] + +TELEMETRY_SCHEME = [ + ("fixed32", "time", 1), + ("oneof", "variant", [ + (DEVICE_METRICS_SCHEME, "device_metrics", 2), + (ENVIRONMENT_METRICS_SCHEME, "environment_metrics", 3), + (AIR_QUALITY_METRICS_SCHEME, "air_quality_metrics", 4), + (POWER_METRICS_SCHEME, "power_metrics", 5), + (LOCAL_STATS_SCHEME, "local_stats", 6), + (HEALTH_METRICS_SCHEME, "health_metrics", 7), + (HOST_METRICS_SCHEME, "host_metrics", 8), + (TRAFFIC_MANAGEMENT_SCHEME, "traffic_management_stats", 9) + ]) +] diff --git a/service.py b/service.py index fb7a017..2332a75 100644 --- a/service.py +++ b/service.py @@ -13,7 +13,8 @@ from logger import logger from mesht_device import MeshtDevice from mesht_models import _wait_for_config_complete, PUB_CH from mesht_models import NOT_CONNECTED, WAIT_CONFIG, AVAILABLE, ERR, RECONNECT -from mesht_protobuf_extra import * +from protobufs_extra.telemetry_proto import * +from protobufs_extra.position_proto import * import pb #fs imports @@ -151,6 +152,8 @@ class MongoDriver(MeshArgsParse): try: if v.get("portnum", 0) == 67: v["decoded_payload_object"] = pb.decode(v["payload"], TELEMETRY_SCHEME) + elif v.get("portnum", 0) == 3: + print(pb.decode(v["payload"], POSITION_SCHEME)) except: traceback.print_exc() pass