fixing up the dongle demo and code

master
Ondřej Hruška 7 years ago
parent 30727b7640
commit c47e196312
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 17
      examples/test_dongle.py
  2. 28
      gex/transport.py

@ -11,13 +11,18 @@ with gex.DongleAdapter(gex.TrxRawUSB(remote=True), 0x10) as transport:
# connect GEX client library to the remote slave # connect GEX client library to the remote slave
client = gex.Client(transport) client = gex.Client(transport)
do = gex.DOut(client, "led")
adc = gex.ADC(client, "adc")
while True: while True:
do.toggle(confirm=True) client.query_raw(type=gex.MSG_PING)
print(adc.read_smooth()) print("ok")
time.sleep(0.2) time.sleep(0.1)
# do = gex.DOut(client, "led")
# adc = gex.ADC(client, "adc")
#
# while True:
# do.toggle(confirm=True)
# print(adc.read_smooth())
# time.sleep(0.2)
# adc = gex.ADC(client, "adc") # adc = gex.ADC(client, "adc")
# for j in range(10): # for j in range(10):

@ -84,8 +84,6 @@ class DongleAdapter(BaseGexTransport):
def write(self, buffer): def write(self, buffer):
# multipart sending # multipart sending
pb = gex.PayloadBuilder() pb = gex.PayloadBuilder()
# pb.u8(0x47)
# pb.u8(0xB8)
pb.u8(ord('m')) pb.u8(ord('m'))
pb.u8(self._slaveAddr) pb.u8(self._slaveAddr)
pb.u16(len(buffer)) pb.u16(len(buffer))
@ -101,6 +99,9 @@ class DongleAdapter(BaseGexTransport):
spaceused = len(pb.buf) spaceused = len(pb.buf)
fits = min(64-spaceused, len(buffer)) fits = min(64-spaceused, len(buffer))
pb.blob(buffer[start:fits]) pb.blob(buffer[start:fits])
# TODO rewrite this to send_raw
if (spaceused + fits) < 64: if (spaceused + fits) < 64:
pb.zeros(64 - (spaceused + fits)) pb.zeros(64 - (spaceused + fits))
start += fits start += fits
@ -126,28 +127,25 @@ class DongleAdapter(BaseGexTransport):
def poll(self, timeout, testfunc=None): def poll(self, timeout, testfunc=None):
self._transport.poll(timeout, testfunc) self._transport.poll(timeout, testfunc)
def gw_reset(self): def gw_write_raw(self, pb:gex.PayloadBuilder):
pb = gex.PayloadBuilder()
# pb.u8(0x47)
# pb.u8(0xB8)
pb.u8(ord('r'))
spaceused = len(pb.buf) spaceused = len(pb.buf)
pb.zeros(64 - spaceused) pb.zeros(64 - spaceused)
self._transport.write(pb.close()) self._transport.write(pb.close())
def gw_reset(self):
pb = gex.PayloadBuilder()
pb.u8(ord('r'))
self.gw_write_raw(pb)
def gw_add_nodes(self, nodes): def gw_add_nodes(self, nodes):
pb = gex.PayloadBuilder() pb = gex.PayloadBuilder()
# pb.u8(0x47)
# pb.u8(0xB8)
pb.u8(ord('n')) pb.u8(ord('n'))
pb.u8(len(nodes)) pb.u8(len(nodes))
for n in nodes: for n in nodes:
pb.u8(n) pb.u8(n)
spaceused = len(pb.buf) self.gw_write_raw(pb)
pb.zeros(64 - spaceused)
self._transport.write(pb.close())
def gw_get_net_id(self): def gw_get_net_id(self):
if self._address is not None: if self._address is not None:
@ -155,12 +153,8 @@ class DongleAdapter(BaseGexTransport):
return self._address return self._address
pb = gex.PayloadBuilder() pb = gex.PayloadBuilder()
# pb.u8(0x47)
# pb.u8(0xB8)
pb.u8(ord('i')) pb.u8(ord('i'))
spaceused = len(pb.buf) self.gw_write_raw(pb)
pb.zeros(64 - spaceused)
self._transport.write(pb.close())
self.poll(0.5, lambda: self._address is not None) self.poll(0.5, lambda: self._address is not None)
return self._address return self._address

Loading…
Cancel
Save