Beispiel #1
0
 def push_button(self, msec):
     log.info('ESP: PUSH BUTTON for {} msec'.format(msec))
     self.api.pinMode(self.button_pin, OUTPUT)
     self.api.digitalWrite(self.button_pin, LOW)
     self.api.delay(msec)
     self.api.digitalWrite(self.button_pin, HIGH)
     self.api.pinMode(self.button_pin, INPUT)
Beispiel #2
0
    def get_header(self):
        fields = [  # name, type
            ('version',   'B'),  # unsigned char
            ('service',   'B'),
            ('voltage',   'L'),
            ('resets',    'B'),
            ('model',     'B'),
            ('state0',    'B'),
            ('state1',    'B'),
            ('impulses0', 'L'),
            ('impulses1', 'L'),
            ('adc0',      'H'),  # unsigned short
            ('adc1',      'H'),
            ('crc',       'B'),
            ('reserved1', 'B')
        ]

        header_len = DataStruct.calcsize(fields)
        crc_shift = DataStruct.calcsize(fields, 'crc')

        log.info('ESP: get header')

        ret = self.api.i2c_ask(self.ADDR, 'B', header_len)

        header = DataStruct(fields, ret)

        if header.version < 13:
            if header.crc == waterius12_crc(ret, crc_shift):
                return header
        else:
            if header.crc == dallas_crc8(ret, crc_shift):
                return header

        raise Exception('некорректный CRC')
Beispiel #3
0
    def impulse(self, pins=[], **kwargs):

        width = kwargs.get('width', 300)
        pause = kwargs.get('pause', 800)

        for pin in pins:
            self.api.pinMode(pin, OUTPUT)
            self.api.digitalWrite(pin, HIGH)
            log.info('ESP: impulse on pin {}'.format(pin))

        self.api.delay(width)

        for pin in pins:
            self.api.digitalWrite(pin, LOW)

        for pin in pins:
            self.api.pinMode(pin, INPUT)

        self.api.delay(pause)
Beispiel #4
0
 def manual_turn_off(self):
     self.api.pinMode(self.power_pin, INPUT)
     if self.api.digitalRead(self.power_pin) == HIGH:
         log.info('--------------')
         log.info('ESP: manual turn off')
         self.push_button(4000)
     else:
         log.info('ESP: Already off')
Beispiel #5
0
 def wait_off(self):
     log.info('ESP: wait power pin LOW')
     assert self.api.wait_digital(self.power_pin, LOW, 2.0)
     self.api.delay(20)
Beispiel #6
0
 def send_sleep(self):
     log.info('ESP: send sleep')
     ret = self.api.i2c_ask(self.ADDR, 'Z', 1)
     return ret
Beispiel #7
0
 def get_mode(self):
     log.info('ESP: get mode')
     ret = self.api.i2c_ask(self.ADDR, 'M', 1)
     return ord(ret[0])
Beispiel #8
0
    if args.wakeup:
        w.wake_up()

    if args.mode:
        w.get_mode()

    if args.header:
        w.get_header()

    if args.sleep:
        w.send_sleep()
        w.wait_off()

    if args.impulse > 0:
        for i in range(0, args.impulse):
            log.info('Impulse {} of {}'.format(i, args.impulse))
            w.impulse()

    if args.imitation:
        log.info('Imitation of turn on Wi-Fi')
        w.wake_up()
        w.start_i2c()
        w.get_mode()

        t = time.time()
        while time.time() - t < 10.0:
            w.get_header()
            time.sleep(0.2)

        w.send_sleep()
        w.wait_off()
Beispiel #9
0
    def test_counter_while_transmitting(self):
        """
        Включаем, запоминаем текущие показания
        Делаем 10 импульсов
        Выключаем
        Включаем, смотрим, увеличились ли на 10
        :return:
        """
        try:
            self.w.wake_up()

            self.w.start_i2c()

            header = self.w.get_header()

            log.info('ESP: impules0={}'.format(header.impulses0))
            log.info('ESP: impules1={}'.format(header.impulses1))

            log.info('ESP -- impulses --- ')

            impulses = 5
            for i in range(0, impulses):
                self.w.impulse()

            self.w.send_sleep()

            # Ждем когда снимет питание
            self.w.wait_off()

            self.api.delay(2000)

            self.w.wake_up()

            self.api.i2c_begin(self.w.sda, self.w.sdl)

            assert self.w.get_mode() == self.w.TRANSMIT_MODE

            header2 = self.w.get_header()

            self.w.send_sleep()
            self.w.wait_off()

            log.info('ESP: header 2')
            log.info('ESP: impules0={}'.format(header2.impulses0))
            log.info('ESP: impules1={}'.format(header2.impulses1))

            assert header2.impulses0 == header.impulses0 + impulses
            if not LOG_ON:
                assert header2.impulses1 == header.impulses1 + impulses

        finally:
            self.w.manual_turn_off()
Beispiel #10
0
    def test_counter(self):
        try:
            self.w.wake_up()

            self.w.start_i2c()

            assert self.w.get_mode() == self.w.TRANSMIT_MODE

            header = self.w.get_header()

            self.w.send_sleep()

            log.info('ESP: impules0={}'.format(header.impulses0))
            log.info('ESP: impules1={}'.format(header.impulses1))

            # Ждем когда снимет питание
            self.w.wait_off()

            log.info('ESP -- impulses --- ')

            self.w.impulse()

            self.w.wake_up()

            self.api.i2c_begin(self.w.sda, self.w.sdl)

            assert self.w.get_mode() == self.w.TRANSMIT_MODE

            header2 = self.w.get_header()

            self.w.send_sleep()
            self.w.wait_off()

            log.info('ESP: header 2')
            log.info('ESP: impules0={}'.format(header2.impulses0))
            log.info('ESP: impules1={}'.format(header2.impulses1))

            assert header2.impulses0 == header.impulses0 + 1
            #assert header2.impulses1 == header.impulses1 + 1

        finally:
            self.w.manual_turn_off()