Ejemplo n.º 1
0
 def __init__(self, d):
     self.user_start = (d['user_start'], d['args'])
     self.init_str = buildinit(d)
     # Synchroniser idle until started.
     self.rtc_synchroniser = RTCsynchroniser(self, d['rtc_resync'], d['local_time_offset'])
     self.keepalive = d['keepalive']
     self._running = False
     self.verbose = d['verbose']
     # Watchdog timeout for ESP8266 (ms).
     wdog = d['timeout'] * 1000
     # SynCom string mode
     self.channel = SynCom(False, d['sckin'], d['sckout'], d['srx'], d['stx'],
                           d['reset'], wdog, True, self.verbose)
     loop = asyncio.get_event_loop()
     loop.create_task(heartbeat())
     # Start the SynCom instance. This will run self.start(). If an error
     # occurs self.quit() is called which cancels all NamedTask instances
     # and returns to Syncom's start() method. This waits on Cancellable.cancel_all()
     # before forcing a failure on the ESP8266 and re-running self.start()
     # to perform a clean restart.
     loop.create_task(self.channel.start(self.start, Killer()))
     self.subs = {} # Callbacks indexed by topic
     self.pubs = []
     self._pub_free = True  # No publication in progress
     self.s_han = default_status_handler
     self.wifi_han = (lambda *_ : None, ())
     self._wifi_up = False
     # Only specify network on first run
     self.first_run = True
Ejemplo n.º 2
0
 def __init__(self, d):
     self.user_start = (d['user_start'], d['args'])
     self.init_str = buildinit(d)
     # Synchroniser idle until started.
     self.rtc_synchroniser = RTCsynchroniser(self, d['rtc_resync'],
                                             d['local_time_offset'])
     self.keepalive = d['keepalive']
     self._running = False
     self.verbose = d['verbose']
     # Watchdog timeout for ESP8266 (ms).
     wdog = d['timeout'] * 1000
     # SynCom string mode
     self.channel = SynCom(False, d['sckin'], d['sckout'], d['srx'],
                           d['stx'], d['reset'], wdog, True, self.verbose)
     loop = asyncio.get_event_loop()
     loop.create_task(heartbeat())
     self.exit_gate = ExitGate()
     loop.create_task(self.channel.start(self.start, self.exit_gate))
     self.subs = {}  # Callbacks indexed by topic
     self.pubs = []
     self._pub_free = True  # No publication in progress
     self.s_han = default_status_handler
     self.wifi_han = (lambda *_: None, ())
     self._wifi_up = False
     # Only specify network on first run
     self.first_run = True
Ejemplo n.º 3
0
def test():
    freq(160000000)
    mtx = Pin(14, Pin.OUT)  # Define pins
    mckout = Pin(15, Pin.OUT, value=0)  # clocks must be initialised to zero.
    mrx = Pin(13, Pin.IN)
    mckin = Pin(12, Pin.IN)

    objsched = Sched(heartbeat=1)
    channel = SynCom(objsched, True, mckin, mckout, mrx, mtx)
    channel.start()
    objsched.add_thread(passive_thread(channel))
    try:
        objsched.run()
    finally:
        mckout(0)
Ejemplo n.º 4
0
def test():
    stx = Pin(Pin.board.Y5, Pin.OUT_PP)  # Define pins
    sckout = Pin(Pin.board.Y6, Pin.OUT_PP)
    sckout.value(0)  # Don't assert clock until data is set
    srx = Pin(Pin.board.Y7, Pin.IN)
    sckin = Pin(Pin.board.Y8, Pin.IN)
    reset = Pin(Pin.board.Y4, Pin.OPEN_DRAIN)

    objsched = Sched(heartbeat=1)
    channel = SynCom(objsched, False, sckin, sckout, srx, stx)
    channel.start(reset, 0)
    objsched.add_thread(initiator_thread(channel))
    try:
        objsched.run()
    finally:
        sckout.value(0)
Ejemplo n.º 5
0
def test():
    freq(160000000)
    dout = Pin(14, Pin.OUT, value=0)  # Define pins
    ckout = Pin(15, Pin.OUT, value=0)  # clocks must be initialised to zero.
    din = Pin(13, Pin.IN)
    ckin = Pin(12, Pin.IN)

    channel = SynCom(True, ckin, ckout, din, dout)
    loop = asyncio.get_event_loop()
    loop.create_task(heartbeat())
    loop.create_task(channel.start(passive_task))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        ckout(0)
Ejemplo n.º 6
0
def test():
    dout = Pin(Pin.board.Y5, Pin.OUT_PP, value=0)  # Define pins
    ckout = Pin(Pin.board.Y6, Pin.OUT_PP,
                value=0)  # Don't assert clock until data is set
    din = Pin(Pin.board.Y7, Pin.IN)
    ckin = Pin(Pin.board.Y8, Pin.IN)
    reset = Pin(Pin.board.Y4, Pin.OPEN_DRAIN)
    sig_reset = Signal(reset, invert=True)

    channel = SynCom(False, ckin, ckout, din, dout, sig_reset, 10000)

    loop = asyncio.get_event_loop()
    loop.create_task(heartbeat())
    loop.create_task(channel.start(initiator_task))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        ckout.value(0)
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     d = defaults  # d is the config dict: initially populate with default values
     for arg in args:
         d.update(arg)  # Hardware and network configs
     d.update(kwargs)
     # d is now populated.
     self.user_start = d['user_start']
     shan = d['status_handler']
     self.s_han = (default_status_handler, ()) if shan is None else shan  # coro
     self.crash_han = d['crash_handler']
     self.wifi_han = d['wifi_handler']
     self.init_str = buildinit(d)
     self.keepalive = d['keepalive']
     self._evtrun = asyncio.Event()
     self.verbose = d['verbose']
     # Watchdog timeout for ESP8266 (ms).
     wdog = d['timeout'] * 1000
     # SynCom string mode
     self.channel = SynCom(False, d['sckin'], d['sckout'], d['srx'], d['stx'],
                           d['reset'], wdog, True, self.verbose)
     if 'led' in d:
         asyncio.create_task(heartbeat(d['led']))
     # Start the SynCom instance. This will run self.start(). If an error
     # occurs self.quit() is called which returns to Syncom's start() method.
     # This waits on ._die before forcing a failure on the ESP8266 and re-running
     # self.start() to perform a clean restart.
     asyncio.create_task(self.channel.start(self.start, self._die))
     self.subs = {}  # (callback, qos, args) indexed by topic
     self.publock = asyncio.Lock()
     self.puback = asyncio.Event()
     self.evttim = asyncio.Event()
     self.evtwifi = asyncio.Event()
     # Only specify network on first run
     self.first_run = True
     self._time = 0  # NTP time. Invalid.
     # ESP8266 returns seconds from 2000 because I believed the docs.
     # Maintainers change the epoch on a whim.
     # Calculate ofsets in CPython using datetime.date:
     # (date(2000, 1, 1) - date(1970, 1, 1)).days * 24*60*60
     epoch = {2000 : 0, 1970 : 946684800}  # Offset to add.
     self._epoch_fix = epoch[gmtime(0)[0]]  # Find offset on current platform