Exemplo n.º 1
0
Arquivo: OnAir.py Projeto: maxf/home
    def receive(self, radio_config=None): # -> (radio_measurements, address or None, payload or None)
        #   radio_params is an overlay on top of radio rx defaults (e.g. poll rate, timeout, min payload, max payload)
        #   radio_measurements might include rssi reading, short payload report, etc
        #TODO: merge radio_params with self.tx_defaults
        #TODO: configure radio modulation based on merged params

        #TODO: poll radio at rate until timeout or received
        #TODO: start timeout timer
        payload = None
        radio.receiver(ook=True)
        while True: # timer not expired
            if radio.is_receive_waiting():
                #TODO: radio config should set receive preamble 4 bytes to prevent false triggers
                payload = radio.receive(size=12) #TODO: payload, radio_measurements = radio.receive()
                p = TwoBit.decode(payload)
                #TODO: if failure, report it, but keep trying
                #if  check passes...
                break
            #TODO: inter-try delay
        #TODO: return radio to state it was before receiver (e.g. standby) - radio needs a pop() on this too?

        if payload == None: # nothing received in timeout
            return (None, None, None) # (radio_measurements, address, payload) #TODO: might be measurements, average min max?

        #TODO: extract addresses (house_address, device_index)
        radio_measurements = None #TODO: return this from radio.receive()
        h = 0xC8C8C #TODO: Get house address from TwoBit.decode()[:10]
        d = 0xEE    #TODO: Get device command from TwoBit.decode()[11:12]
        address = (h, d)
        return (radio_measurements, address, payload)
Exemplo n.º 2
0
Arquivo: OnAir.py Projeto: maxf/home
    def send(self, payload, radio_config=None):
        #   payload is just a list of bytes, or a byte buffer
        #   radio_config is an overlay on top of radio tx defaults

        house_address = payload["house_address"]
        device_index  = payload["device_index"]
        state         = payload["on"]
        bytes = TwoBit.encode_switch_message(state, device_index, house_address)
        radio.modulation(ook=True)

        # Set radio defaults, if no override
        outer_times = self.tx_defaults.outer_times
        outer_delay = self.tx_defaults.outer_delay
        inner_times = self.tx_defaults.inner_times

        # Merge any wanted radio params, if provided
        if radio_config != None:
            try:
                outer_times = radio_config.outer_times
            except AttributeError: pass
            try:
                outer_delay = radio_config.outer_delay
            except AttributeError: pass
            try:
                inner_times = radio_config.inner_times
            except AttributeError: pass

        ##print("inner times %s" % inner_times)
        radio.transmit(bytes, outer_times=outer_times, inner_times=inner_times, outer_delay=outer_delay)
Exemplo n.º 3
0
    def _send2(self, payload, radio_config=None):
        """Actually send a payload"""
        #   payload is just a list of bytes, or a byte buffer
        #   radio_config is an overlay on top of radio tx defaults

        house_address = payload["house_address"]
        device_index = payload["device_index"]
        state = payload["on"]
        bytes = TwoBit.encode_switch_message(state, device_index,
                                             house_address)
        radio.modulation(ook=True)

        # Set radio defaults, if no override
        outer_times = self.tx_defaults.outer_times
        outer_delay = self.tx_defaults.outer_delay
        inner_times = self.tx_defaults.inner_times

        # Merge any wanted radio params, if provided
        if radio_config != None:
            try:
                outer_times = radio_config.outer_times
            except AttributeError:
                pass
            try:
                outer_delay = radio_config.outer_delay
            except AttributeError:
                pass
            try:
                inner_times = radio_config.inner_times
            except AttributeError:
                pass

        ##print("inner times %s" % inner_times)
        radio.transmit(bytes,
                       outer_times=outer_times,
                       inner_times=inner_times,
                       outer_delay=outer_delay)
Exemplo n.º 4
0
    def receive(self,
                radio_config=None
                ):  # -> (radio_measurements, address or None, payload or None)
        #   radio_params is an overlay on top of radio rx defaults (e.g. poll rate, timeout, min payload, max payload)
        #   radio_measurements might include rssi reading, short payload report, etc
        #TODO: merge radio_params with self.tx_defaults
        #TODO: configure radio modulation based on merged params

        #TODO: poll radio at rate until timeout or received
        #TODO: start timeout timer
        payload = None
        radio.receiver(ook=True)
        while True:  # timer not expired
            if radio.is_receive_waiting():
                #TODO: radio config should set receive preamble 4 bytes to prevent false triggers
                payload = radio.receive(
                    size=12
                )  #TODO: payload, radio_measurements = radio.receive()
                p = TwoBit.decode(payload)
                #TODO: if failure, report it, but keep trying
                #if  check passes...
                break
            #TODO: inter-try delay
        #TODO: return radio to state it was before receiver (e.g. standby) - radio needs a pop() on this too?

        if payload == None:  # nothing received in timeout
            return (
                None, None, None
            )  # (radio_measurements, address, payload) #TODO: might be measurements, average min max?

        #TODO: extract addresses (house_address, device_index)
        radio_measurements = None  #TODO: return this from radio.receive()
        h = 0xC8C8C  #TODO: Get house address from TwoBit.decode()[:10]
        d = 0xEE  #TODO: Get device command from TwoBit.decode()[11:12]
        address = (h, d)
        return (radio_measurements, address, payload)
Exemplo n.º 5
0
class TestTwoBit(unittest.TestCase):
    ALL_ON = TwoBit.encode_switch_message(True)
    ALL_OFF = TwoBit.encode_switch_message(False)
    ONE_ON = TwoBit.encode_switch_message(True, device_address=1)
    ONE_OFF = TwoBit.encode_switch_message(False, device_address=1)
    TWO_ON = TwoBit.encode_switch_message(True, device_address=2)
    TWO_OFF = TwoBit.encode_switch_message(False, device_address=2)
    THREE_ON = TwoBit.encode_switch_message(True, device_address=3)
    THREE_OFF = TwoBit.encode_switch_message(False, device_address=3)
    FOUR_ON = TwoBit.encode_switch_message(True, device_address=4)
    FOUR_OFF = TwoBit.encode_switch_message(False, device_address=4)
    MYHOUSE_ALL_ON = TwoBit.encode_switch_message(True, house_address=0x12345)

    tests = [
        ALL_ON, ALL_OFF, ONE_ON, ONE_OFF, TWO_ON, TWO_OFF, THREE_ON, THREE_OFF,
        FOUR_ON, FOUR_OFF, MYHOUSE_ALL_ON
    ]

    def test_all(self):
        for t in self.tests:
            print('')
            print(ashex(t))