stop wrapping messages in DotMap, some users might not want that

This commit is contained in:
geeksville
2020-05-03 18:36:24 -07:00
parent 56bf66c926
commit 06a00e317b
3 changed files with 19 additions and 7 deletions

View File

@@ -184,8 +184,9 @@ class MeshInterface:
- meshtastic.receive.data(packet = MeshPacket dictionary)
"""
# FIXME, update node DB as needed
# We provide our objects as DotMaps - which work with . notation or as dictionaries
asObj = DotMap(google.protobuf.json_format.MessageToDict(meshPacket))
asDict = google.protobuf.json_format.MessageToDict(meshPacket)
# We could provide our objects as DotMaps - which work with . notation or as dictionaries
#asObj = DotMap(asDict)
topic = None
if meshPacket.payload.HasField("position"):
topic = "meshtastic.receive.position"
@@ -198,7 +199,7 @@ class MeshInterface:
# asObj.payload.data.text = asObj.payload.data.payload.decode(
# "utf-8")
pub.sendMessage(topic, packet=asObj, interface=self)
pub.sendMessage(topic, packet=asDict, interface=self)
class StreamInterface(MeshInterface):

View File

@@ -5,6 +5,7 @@ from pubsub import pub
import time
import sys
import threading
from dotmap import DotMap
"""The interfaces we are using for our tests"""
interfaces = None
@@ -17,12 +18,14 @@ testsRunning = False
testNumber = 0
def onReceive(packet):
def onReceive(packet, interface):
"""Callback invoked when a packet arrives"""
print(f"Received: {packet}")
if packet.payload.data.typ == "CLEAR_TEXT":
print(f"From {interface.devPath}: {packet}")
p = DotMap(packet)
if p.payload.data.typ == "CLEAR_TEXT":
# We only care a about clear text packets
receivedPackets.append(packet)
receivedPackets.append(p)
def onNode(node):

View File

@@ -1,4 +1,5 @@
from collections import defaultdict
import serial
import serial.tools.list_ports
@@ -14,3 +15,10 @@ def findPorts():
serial.tools.list_ports.comports())))
l.sort()
return l
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__