Ejemplo n.º 1
0
    def runTest(self):
        # Test time request
        request = Request(CommandPipe.Type.TIME)
        self.assertEqual(request.get(), array.array('B', [0x01, 0x00, 0x00, CommandPipe._sequence, 0x03, 0x00, 0x00, 0x00]))

        # Test time parse
        response_data = array.array('B', [0x03, 0x00, 0x00, 0x0f, 0x78, 0xb5, 0xca, 0x25,
                                          0xc8, 0xa0, 0xf4, 0x29, 0x01, 0x00, 0x00, 0x00])
        response = parse(response_data)
        self.assertIsInstance(response, Time)
        self.assertEqual(response.get_command(), 0x03)
        self.assertEqual(response.get_sequence(), 0x0f)
        current_time = (datetime.datetime(2010, 2, 2, 10, 42, 0) - datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_current_time(), current_time)
        system_time = (datetime.datetime(2012, 4, 20, 23, 10, 0) - datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_system_time(), system_time)
        self.assertEqual(response.get_time_format(), 1)

        # Test time create
        current_time = (datetime.datetime(2015, 1, 4, 21, 23, 30) - datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        system_time = (datetime.datetime(2012, 4, 20, 23, 10, 0) - datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()

        time = Time(int(current_time), int(system_time), Time.Format.COUNTER)
        self.assertEqual(time.get(), array.array('B', [0x03, 0x00, 0x00, CommandPipe._sequence, 0x52, 0x63, 0x0c, 0x2f,
                                                       0xc8, 0xa0, 0xf4, 0x29, 0x02, 0x00, 0x00, 0x00]))

        # Test time request response
        response_data = array.array('B', [0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
                                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
        response = parse(response_data)
        self.assertIsInstance(response, TimeResponse)
Ejemplo n.º 2
0
    def runTest(self):
        # Test time request
        request = Request(CommandPipe.Type.TIME)
        self.assertEqual(
            request.get(),
            array.array(
                "B",
                b"\x01\x00\x00" +
                CommandPipe._sequence.to_bytes(1, byteorder="big") +
                b"\x03\x00\x00\x00",
            ),
        )

        # Test time parse
        response_data = array.array(
            "B",
            b"\x03\x00\x00\x0F\x78\xB5\xCA\x25\xC8\xA0\xF4\x29\x01\x00\x00\x00"
        )
        response = parse(response_data)
        self.assertIsInstance(response, Time)
        self.assertEqual(response.get_command(), 0x03)
        self.assertEqual(response.get_sequence(), 0x0F)
        current_time = (
            datetime.datetime(2010, 2, 2, 10, 42, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_current_time(), current_time)
        system_time = (
            datetime.datetime(2012, 4, 20, 23, 10, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_system_time(), system_time)
        self.assertEqual(response.get_time_format(), 1)

        # Test time create
        current_time = (
            datetime.datetime(2015, 1, 4, 21, 23, 30) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        system_time = (
            datetime.datetime(2012, 4, 20, 23, 10, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()

        time = Time(int(current_time), int(system_time), Time.Format.COUNTER)
        self.assertEqual(
            time.get(),
            array.array(
                "B",
                b"\x03\x00\x00" +
                CommandPipe._sequence.to_bytes(1, byteorder="big") +
                b"\x52\x63\x0c\x2f\xc8\xa0\xf4\x29\x02\x00\x00\x00",
            ),
        )

        # Test time request response
        response_data = array.array(
            "B",
            b"\x02\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
        )
        response = parse(response_data)
        self.assertIsInstance(response, TimeResponse)
Ejemplo n.º 3
0
    def set_time(self, time=datetime.datetime.utcnow()):
        """
        :param time: datetime in UTC, or None to set to current time
        """
        utc_tai_diff_seconds = 35
        offset = time - datetime.datetime(1989, 12, 31, 0, 0, 0)
        t = Time(int(offset.total_seconds()) + utc_tai_diff_seconds, 0xFFFFFFFF, 0)
        self._send_commandpipe(t.get())

        result = self._get_commandpipe()

        if result.get_response() != TimeResponse.Response.OK:
            raise AntFSTimeException("Failed to set time", result.get_response())
Ejemplo n.º 4
0
    def set_time(self, time=datetime.datetime.utcnow()):
        """
        :param time: datetime in UTC, or None to set to current time
        """
        utc_tai_diff_seconds = 35
        offset = time - datetime.datetime(1989, 12, 31, 0, 0, 0)
        t = Time(int(offset.total_seconds()) + utc_tai_diff_seconds, 0xffffffff, 0)
        self._send_commandpipe(t.get())

        result = self._get_commandpipe()

        if result.get_response() != TimeResponse.Response.OK:
            raise AntFSTimeException("Failed to set time", result.get_response())
Ejemplo n.º 5
0
    def runTest(self):
        # Test time request
        request = Request(CommandPipe.Type.TIME)
        self.assertEqual(
            request.get(),
            array.array('B', [
                0x01, 0x00, 0x00, CommandPipe._sequence, 0x03, 0x00, 0x00, 0x00
            ]))

        # Test time parse
        response_data = array.array('B', [
            0x03, 0x00, 0x00, 0x0f, 0x78, 0xb5, 0xca, 0x25, 0xc8, 0xa0, 0xf4,
            0x29, 0x01, 0x00, 0x00, 0x00
        ])
        response = parse(response_data)
        self.assertIsInstance(response, Time)
        self.assertEqual(response.get_command(), 0x03)
        self.assertEqual(response.get_sequence(), 0x0f)
        current_time = (
            datetime.datetime(2010, 2, 2, 10, 42, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_current_time(), current_time)
        system_time = (
            datetime.datetime(2012, 4, 20, 23, 10, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        self.assertEqual(response.get_system_time(), system_time)
        self.assertEqual(response.get_time_format(), 1)

        # Test time create
        current_time = (
            datetime.datetime(2015, 1, 4, 21, 23, 30) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()
        system_time = (
            datetime.datetime(2012, 4, 20, 23, 10, 0) -
            datetime.datetime(1989, 12, 31, 0, 0, 0)).total_seconds()

        time = Time(int(current_time), int(system_time), Time.Format.COUNTER)
        self.assertEqual(
            time.get(),
            array.array('B', [
                0x03, 0x00, 0x00, CommandPipe._sequence, 0x52, 0x63, 0x0c,
                0x2f, 0xc8, 0xa0, 0xf4, 0x29, 0x02, 0x00, 0x00, 0x00
            ]))

        # Test time request response
        response_data = array.array('B', [
            0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00
        ])
        response = parse(response_data)
        self.assertIsInstance(response, TimeResponse)
Ejemplo n.º 6
0
 def on_transport(self, beacon):
     x = datetime.datetime.now() - datetime.datetime(1989, 12, 31, 0, 0, 0)
     t = Time(int(x.total_seconds()), 0xffffffff, 0)
 
     self._send_commandpipe(t.get())
     result = self._get_commandpipe()
 
     print "Time, response:", result.get_request_id(), result.get_response()
 
     print "Listener: Transport"
     directory = self.download_directory()
     print "Directory version:      ", directory.get_version()
     print "Directory time format:  ", directory.get_time_format()
     print "Directory system time:  ", directory.get_current_system_time()
     print "Directory last modified:", directory.get_last_modified()
     directory.print_list()
Ejemplo n.º 7
0
    def on_transport(self, beacon):
        x = datetime.datetime.now() - datetime.datetime(1989, 12, 31, 0, 0, 0)
        t = Time(int(x.total_seconds()), 0xffffffff, 0)

        self._send_commandpipe(t.get())
        result = self._get_commandpipe()

        print("Time, response:", result.get_request_id(),
              result.get_response())

        print("Listener: Transport")
        directory = self.download_directory()
        print("Directory version:      ", directory.get_version())
        print("Directory time format:  ", directory.get_time_format())
        print("Directory system time:  ", directory.get_current_system_time())
        print("Directory last modified:", directory.get_last_modified())
        directory.print_list()