"proto_name",
"DecodeError",
"Respond",
- "LK",
)
PROTO_PREFIX = "BS:"
self.latitude = p.lat * p.nors
self.longitude = p.lon * p.eorw
+ def rectified(self) -> Dict[str, Any]: # JSON-able dict
+ if self.gps_valid:
+ return {
+ "type": "location",
+ "devtime": str(self.devtime),
+ "battery_percentage": self.battery_percentage,
+ "accuracy": self.positioning_accuracy,
+ "altitude": self.altitude,
+ "speed": self.speed,
+ "direction": self.direction,
+ "latitude": self.latitude,
+ "longitude": self.longitude,
+ }
+ else:
+ return {
+ "type": "approximate_location",
+ "devtime": str(self.devtime),
+ "battery_percentage": self.battery_percentage,
+ "mcc": self.mcc,
+ "mnc": self.mnc,
+ "base_stations": self.base_stations,
+ "wifi_aps": self.wifi_aps,
+ }
+
class AL(_LOC_DATA):
RESPOND = Respond.INL
def exposed_protos() -> List[Tuple[str, bool]]:
return [
- (proto_name(UD), True),
- (proto_name(UD2), False),
+ (proto_name(cls), False)
+ for cls in CLASSES.values()
+ if hasattr(cls, "rectified")
]
from sqlite3 import connect
import sys
from .zx303proto import *
+ from .zx303proto import WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING
db = connect(sys.argv[1])
c = db.cursor()
from datetime import datetime, timezone
import sys
from .zx303proto import *
+ from .zx303proto import WIFI_POSITIONING, WIFI_OFFLINE_POSITIONING
db = connect(sys.argv[1])
c = db.cursor()
from . import common
from .zx303proto import *
+from .zx303proto import STATUS, SETUP, POSITION_UPLOAD_INTERVAL
from .zmsg import Bcast, Resp, topic
log = getLogger("loctrkd/termconfig")
if pmod.proto_handled(zmsg.proto):
msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming)
print(msg)
+ if zmsg.is_incoming and hasattr(msg, "rectified"):
+ print(msg.rectified())
except KeyboardInterrupt:
pass
"proto_name",
"DecodeError",
"Respond",
- "GPS303Pkt",
- "UNKNOWN",
- "LOGIN",
- "SUPERVISION",
- "HEARTBEAT",
- "GPS_POSITIONING",
- "GPS_OFFLINE_POSITIONING",
- "STATUS",
- "HIBERNATION",
- "RESET",
- "WHITELIST_TOTAL",
- "WIFI_OFFLINE_POSITIONING",
- "TIME",
- "PROHIBIT_LBS",
- "GPS_LBS_SWITCH_TIMES",
- "REMOTE_MONITOR_PHONE",
- "SOS_PHONE",
- "DAD_PHONE",
- "MOM_PHONE",
- "STOP_UPLOAD",
- "GPS_OFF_PERIOD",
- "DND_PERIOD",
- "RESTART_SHUTDOWN",
- "DEVICE",
- "ALARM_CLOCK",
- "STOP_ALARM",
- "SETUP",
- "SYNCHRONOUS_WHITELIST",
- "RESTORE_PASSWORD",
- "WIFI_POSITIONING",
- "MANUAL_POSITIONING",
- "BATTERY_CHARGE",
- "CHARGER_CONNECTED",
- "CHARGER_DISCONNECTED",
- "VIBRATION_RECEIVED",
- "POSITION_UPLOAD_INTERVAL",
- "SOS_ALARM",
- "UNKNOWN_B3",
)
PROTO_PREFIX = "ZX:"
ttup = (tup[0] % 100,) + tup[1:6]
return pack("BBBBBB", *ttup)
+ def rectified(self) -> Dict[str, Any]: # JSON-able dict
+ return {
+ "type": "location",
+ "devtime": str(self.devtime),
+ "speed": self.speed,
+ "direction": self.heading,
+ "latitude": self.latitude,
+ "longitude": self.longitude,
+ }
+
class GPS_POSITIONING(_GPS_POSITIONING):
PROTO = 0x10
]
)
+ def rectified(self) -> Dict[str, Any]: # JSON-able dict
+ return {
+ "type": "approximate_location",
+ "devtime": str(self.devtime),
+ "mcc": self.mcc,
+ "mnc": self.mnc,
+ "base_stations": self.gsm_cells,
+ "wifi_aps": self.wifi_aps,
+ }
+
class WIFI_OFFLINE_POSITIONING(_WIFI_POSITIONING):
PROTO = 0x17
def exposed_protos() -> List[Tuple[str, bool]]:
return [
- (proto_name(GPS_POSITIONING), True),
- (proto_name(WIFI_POSITIONING), False),
- (proto_name(STATUS), True),
+ (proto_name(cls), cls.RESPOND is Respond.EXT)
+ for cls in CLASSES.values()
+ if hasattr(cls, "rectified")
]
import unittest
from .common import send_and_drain, TestWithServers
from loctrkd.zx303proto import *
+from loctrkd.zx303proto import (
+ STATUS,
+ WIFI_POSITIONING,
+ WIFI_OFFLINE_POSITIONING,
+ WIFI_POSITIONING,
+ LOGIN,
+ HIBERNATION,
+ SETUP,
+)
from loctrkd.ocid_dload import SCHEMA