Esempio n. 1
0
    def __str__(self):
        """
		Build a human readable packet
		:return: str
		"""
        flash_color = 0
        flash_color_str = ""
        if self.color_red:
            flash_color += 1
            flash_color_str += "01 Red | "
        if self.color_green:
            flash_color += 2
            flash_color_str += "02 Green | "
        if self.color_blue:
            flash_color += 4
            flash_color_str += "04 Blue | "
        out = "LED Data package\n"
        out += "Part\t\t\t\t\tLength\tData\n"
        out += "DataLengthSegment\t\t2\t\t07 (7*2=14B) Always 07 for LEDData\n"
        out += "FlashColor\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
            flash_color, little_endian=False,
            number_of_hex_digits=2), flash_color_str)
        out += "ServiceCode\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
            self.service_code, little_endian=False,
            number_of_hex_digits=4), self.service_code)
        out += "Hardcoded\t\t\t\t4\t\t00ED Hardcoded value\n"
        out += "FlashTimes\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
            self.flash_times, little_endian=False,
            number_of_hex_digits=4), self.flash_times)
        return out
Esempio n. 2
0
    def __repr__(self):
        """
		Build and return a LED data package
		:return: str representing LED flash data
		"""
        flash_color = 0
        if self.color_red:
            flash_color += 1
        if self.color_green:
            flash_color += 2
        if self.color_blue:
            flash_color += 4
        # Start with packet, then add length of packet
        out = ""
        out += int_to_hexstring(flash_color,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.service_code,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += "00ED"  # Hardcoded value? it always seems fixed
        out += int_to_hexstring(self.flash_times,
                                little_endian=False,
                                number_of_hex_digits=4)
        length = int_to_hexstring(int(len(out) / 2),
                                  little_endian=False,
                                  number_of_hex_digits=2)
        out = length + out
        return out
Esempio n. 3
0
    def __repr__(self):
        """
		Build and return a text entity package
		:return: str representing entity
		"""
        # Start with packet, then add length of packet
        out = ""
        out += int_to_hexstring(self.vertical,
                                little_endian=True,
                                number_of_hex_digits=3)
        out += int_to_hexstring(self.horizontal,
                                little_endian=False,
                                number_of_hex_digits=3)
        out += int_to_hexstring(self.draw_style,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.font_style,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += utf8_to_utf16hexstring(self.text)
        length = int_to_hexstring(int(len(out) / 2),
                                  little_endian=False,
                                  number_of_hex_digits=2)
        out = length + out
        return out
Esempio n. 4
0
 def test_int_to_hexstring_little(self):
     self.assertEqual(
         "0100",
         int_to_hexstring(number=1,
                          little_endian=True,
                          number_of_hex_digits=4))
     self.assertEqual(
         "010",
         int_to_hexstring(number=1,
                          little_endian=True,
                          number_of_hex_digits=3))
     self.assertEqual(
         "FF0",
         int_to_hexstring(number=255,
                          little_endian=True,
                          number_of_hex_digits=3))
     self.assertEqual(
         "001",
         int_to_hexstring(number=256,
                          little_endian=True,
                          number_of_hex_digits=3))
     self.assertEqual(
         "FF1",
         int_to_hexstring(number=511,
                          little_endian=True,
                          number_of_hex_digits=3))
     self.assertEqual(
         "002",
         int_to_hexstring(number=512,
                          little_endian=True,
                          number_of_hex_digits=3))
     self.assertEqual(
         "314E",
         int_to_hexstring(number=20017,
                          little_endian=True,
                          number_of_hex_digits=4))
     self.assertEqual(
         "04000000",
         int_to_hexstring(number=4,
                          little_endian=True,
                          number_of_hex_digits=8))
     self.assertEqual(
         "0D0C",
         int_to_hexstring(number=0x0c0d,
                          little_endian=True,
                          number_of_hex_digits=4))
     self.assertEqual(
         "0D0C0B0A",
         int_to_hexstring(number=0x0a0b0c0d,
                          little_endian=True,
                          number_of_hex_digits=8))
Esempio n. 5
0
 def test_int_to_hexstring_big(self):
     self.assertEqual(
         "0001",
         int_to_hexstring(number=1,
                          little_endian=False,
                          number_of_hex_digits=4))
     self.assertEqual(
         "001",
         int_to_hexstring(number=1,
                          little_endian=False,
                          number_of_hex_digits=3))
     self.assertEqual(
         "0FF",
         int_to_hexstring(number=255,
                          little_endian=False,
                          number_of_hex_digits=3))
     self.assertEqual(
         "100",
         int_to_hexstring(number=256,
                          little_endian=False,
                          number_of_hex_digits=3))
     self.assertEqual(
         "1FF",
         int_to_hexstring(number=511,
                          little_endian=False,
                          number_of_hex_digits=3))
     self.assertEqual(
         "200",
         int_to_hexstring(number=512,
                          little_endian=False,
                          number_of_hex_digits=3))
     self.assertEqual(
         "4E31",
         int_to_hexstring(number=20017,
                          little_endian=False,
                          number_of_hex_digits=4))
     self.assertEqual(
         "00000004",
         int_to_hexstring(number=4,
                          little_endian=False,
                          number_of_hex_digits=8))
     self.assertEqual(
         "0C0D",
         int_to_hexstring(number=0x0c0d,
                          little_endian=False,
                          number_of_hex_digits=4))
     self.assertEqual(
         "0A0B0C0D",
         int_to_hexstring(number=0x0a0b0c0d,
                          little_endian=False,
                          number_of_hex_digits=8))
Esempio n. 6
0
    def __repr__(self):
        """
		Build and return a rectangle entity package
		:return: str representing entity
		"""
        # Start with packet, then add length of packet
        out = ""
        out += int_to_hexstring(self.vertical,
                                little_endian=True,
                                number_of_hex_digits=3)
        out += int_to_hexstring(self.horizontal,
                                little_endian=False,
                                number_of_hex_digits=3)
        out += int_to_hexstring(self.font_style,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.draw_style,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.height,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += int_to_hexstring(self.width,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += int_to_hexstring(self.border,
                                little_endian=False,
                                number_of_hex_digits=4)
        length = int_to_hexstring(int(len(out) / 2),
                                  little_endian=False,
                                  number_of_hex_digits=2)
        out = length + out
        return out
Esempio n. 7
0
    def __str__(self):
        """
		Build a human readable packet
		:return: str
		"""
        repr = self.__repr__()
        out = "Entity Image package\n"
        out += "Part\t\t\t\t\tLength\tData\n"
        out += "ImageType\t\t\t\t2\t\tFC(ImageCompress)\n"
        out += "X\t\t\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
            self.x, little_endian=False, number_of_hex_digits=4), self.x)
        out += "Y\t\t\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
            self.y, little_endian=False, number_of_hex_digits=4), self.y)
        out += "Height\t\t\t\t\t4\t\t%s (%d-1=%d)\n" % (int_to_hexstring(
            self.height - 1, little_endian=False,
            number_of_hex_digits=4), self.height, self.height - 1)
        out += "Width\t\t\t\t\t4\t\t%s (%d-1=%d)\n" % (int_to_hexstring(
            self.width - 1, little_endian=False,
            number_of_hex_digits=4), self.width, self.width - 1)
        out += "Size\t\t\t\t\t8\t\t%s (%d/2=%d)\n" % (
            int_to_hexstring(
                int(len(self.image_black_compressed) / 2),
                little_endian=False,
                number_of_hex_digits=8), len(self.image_black_compressed),
            int(len(self.image_black_compressed) / 2))
        out += "ImageData\t\t\t\t\t\t%s\n" % self.image_black_compressed
        if self.colored_image:
            out += "Image color part follows.\n"
            out += "ImageType\t\t\t\t2\t\tFC(ImageCompress)\n"
            out += "Filler\t\t\t\t\t1\t\t8 (Hardcoded for color part)\n"
            out += "X\t\t\t\t\t\t3\t\t%s (%d)\n" % (int_to_hexstring(
                self.x, little_endian=False, number_of_hex_digits=3), self.x)
            out += "Y\t\t\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
                self.y, little_endian=False, number_of_hex_digits=4), self.y)
            out += "Filler\t\t\t\t\t1\t\t8 (Hardcoded for color part)\n"
            out += "Height\t\t\t\t\t3\t\t%s (%d-1=%d)\n" % (int_to_hexstring(
                self.height - 1, little_endian=False,
                number_of_hex_digits=3), self.height, self.height - 1)
            out += "Width\t\t\t\t\t4\t\t%s (%d-1=%d)\n" % (int_to_hexstring(
                self.width - 1, little_endian=False,
                number_of_hex_digits=4), self.width, self.width - 1)
            out += "Size\t\t\t\t\t8\t\t%s (%d/2=%d)\n" % (
                int_to_hexstring(
                    int(len(self.image_color_compressed) / 2),
                    little_endian=False,
                    number_of_hex_digits=8), len(self.image_color_compressed),
                int(len(self.image_color_compressed) / 2))
            out += "ImageData\t\t\t\t\t\t%s\n" % self.image_color_compressed
        return out
Esempio n. 8
0
    def __repr__(self):
        """
		Build and return a text entity package
		:return: str representing entity
		"""
        out = "FC"  # Start header for compressed image
        out += int_to_hexstring(self.x,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += int_to_hexstring(self.y,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += int_to_hexstring(self.height - 1,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += int_to_hexstring(self.width - 1,
                                little_endian=False,
                                number_of_hex_digits=4)
        self.image_black_raw, self.image_color_raw = image_to_black_and_colored_pixel_strings(
            self.image)
        self.image_black_compressed = compress_pixel_array(
            self.image_black_raw)
        out += int_to_hexstring(int(len(self.image_black_compressed) / 2),
                                little_endian=False,
                                number_of_hex_digits=8)
        out += self.image_black_compressed
        if self.colored_image:
            out += "FC"
            out += "8"
            out += int_to_hexstring(self.x,
                                    little_endian=False,
                                    number_of_hex_digits=3)
            out += int_to_hexstring(self.y,
                                    little_endian=False,
                                    number_of_hex_digits=4)
            out += "8"
            out += int_to_hexstring(self.height - 1,
                                    little_endian=False,
                                    number_of_hex_digits=3)
            out += int_to_hexstring(self.width - 1,
                                    little_endian=False,
                                    number_of_hex_digits=4)
            self.image_color_compressed = compress_pixel_array(
                self.image_color_raw)
            out += int_to_hexstring(int(len(self.image_color_compressed) / 2),
                                    little_endian=False,
                                    number_of_hex_digits=8)
            out += self.image_color_compressed
        return out
Esempio n. 9
0
    def __str__(self):
        """
		Build a human readable packet
		:return: str
		"""
        out = "Entity Text package\n"
        out += "Part\t\t\t\t\tLength\tData\n"
        length = len(self.__repr__()) - 2
        out += "DataLengthSegment\t\t2\t\t%s (%d*2=%d bytes)\n" % (
            int_to_hexstring(int(length / 2),
                             little_endian=False,
                             number_of_hex_digits=2), int(length / 2), length)
        out += "Vertical\t\t\t\t3\t\t%s (%d)\n" % (int_to_hexstring(
            self.vertical, little_endian=True,
            number_of_hex_digits=3), self.vertical)
        out += "Horizontal\t\t\t\t3\t\t%s (%d)\n" % (int_to_hexstring(
            self.horizontal, little_endian=False,
            number_of_hex_digits=3), self.horizontal)
        if self.draw_style in DrawStyles:
            out += "DrawStyle\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.draw_style, little_endian=False,
                number_of_hex_digits=2), DrawStyles[self.draw_style])
        else:
            out += "DrawStyle\t\t\t\t2\t\t%s (Unknown)\n" % int_to_hexstring(
                self.draw_style, little_endian=False, number_of_hex_digits=2)
        if self.font_style in FontStyles:
            out += "FontStyle\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.font_style, little_endian=False,
                number_of_hex_digits=2), FontStyles[self.font_style])
        else:
            out += "FontStyle\t\t\t\t2\t\t%s (Unknown)\n" % int_to_hexstring(
                self.font_style, little_endian=False, number_of_hex_digits=2)
        out += "Text\t\t\t\t\t\t\t%s (%s)" % (utf8_to_utf16hexstring(
            self.text), self.text)
        return out
Esempio n. 10
0
    def __str__(self):
        """
		Build a human readable packet
		:return: str
		"""
        out = "Entity Rectangle package\n"
        out += "Part\t\t\t\t\tLength\tData\n"
        length = len(self.__repr__()) - 2
        out += "DataLengthSegment\t\t2\t\t%s (%d*2=%d bytes)\n" % (
            int_to_hexstring(int(length / 2),
                             little_endian=False,
                             number_of_hex_digits=2), int(length / 2), length)
        out += "Vertical\t\t\t\t3\t\t%s (%d)\n" % (int_to_hexstring(
            self.vertical, little_endian=True,
            number_of_hex_digits=3), self.vertical)
        out += "Horizontal\t\t\t\t3\t\t%s (%d)\n" % (int_to_hexstring(
            self.horizontal, little_endian=False,
            number_of_hex_digits=3), self.horizontal)
        if self.font_style in FontStyles:
            out += "FontStyle\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.font_style, little_endian=False,
                number_of_hex_digits=2), FontStyles[self.font_style])
        else:
            out += "FontStyle\t\t\t\t2\t\t%s (Unknown)\n" % int_to_hexstring(
                self.font_style, little_endian=False, number_of_hex_digits=2)
        if self.draw_style in DrawStyles:
            out += "DrawStyle\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.draw_style, little_endian=False,
                number_of_hex_digits=2), DrawStyles[self.draw_style])
        else:
            out += "DrawStyle\t\t\t\t2\t\t%s (Unknown)\n" % int_to_hexstring(
                self.draw_style, little_endian=False, number_of_hex_digits=2)
        out += "Height\t\t\t\t\t4\t\t%s (%d px?)\n" % (int_to_hexstring(
            self.height, little_endian=False,
            number_of_hex_digits=4), self.height)
        out += "Width\t\t\t\t\t4\t\t%s (%d px?)\n" % (int_to_hexstring(
            self.width, little_endian=False,
            number_of_hex_digits=4), self.width)
        out += "Border?\t\t\t\t\t4\t\t%s (%d px?)\n" % (int_to_hexstring(
            self.border, little_endian=False,
            number_of_hex_digits=4), self.border)
        return out
Esempio n. 11
0
    def __str__(self):
        """
		Build a human readable packet
		:return: str
		"""
        out = "Answer package\n"
        out += "Part\t\t\t\t\tLength\tData\n"
        out += "Start\t\t\t\t\t1\t\t@\n"
        out += "Length\t\t\t\t\t4\t\t0012 (18 bytes)\n"
        out += "ServiceCode\t\t\t\t4\t\t%s (%d)\n" % (int_to_hexstring(
            self.service_code, little_endian=False,
            number_of_hex_digits=4), self.service_code)
        out += "Display Tag ID\t\t\t6\t\t%s\n" % self.display_tag_id
        out += "RSSI\t\t\t\t\t2\t\t%s (%d-254=%d)\n" % (int_to_hexstring(
            self.rssi + 254, little_endian=False,
            number_of_hex_digits=2), self.rssi + 254, self.rssi)
        if self.tag_status in AnswerTagStatus:
            out += "TagStatus\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.tag_status, little_endian=False,
                number_of_hex_digits=2), AnswerTagStatus[self.tag_status])
        else:
            out += "TagStatus\t\t\t\t2\t\t%s (%s)\n" % (int_to_hexstring(
                self.tag_status, little_endian=False,
                number_of_hex_digits=2), "Unknown")
        out += "Volt\t\t\t\t\t2\t\t%s (%d=%.1fV)\n" % (int_to_hexstring(
            int(self.volt * 10), little_endian=False,
            number_of_hex_digits=2), int(self.volt * 10), self.volt)
        out += "Temperature\t\t\t\t2\t\t%s (%d degree Celsius)\n" % (
            int_to_hexstring(self.temperature,
                             little_endian=False,
                             number_of_hex_digits=2), self.temperature)
        return out
Esempio n. 12
0
    def __repr__(self):
        """
		Build and return a answer package
		:return: str representing answer package
		"""
        # Start with packet, add start and length after
        out = ""
        out += int_to_hexstring(self.service_code,
                                little_endian=False,
                                number_of_hex_digits=4)
        out += self.display_tag_id
        out += int_to_hexstring(self.rssi + 254,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.tag_status,
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(int(self.volt * 10),
                                little_endian=False,
                                number_of_hex_digits=2)
        out += int_to_hexstring(self.temperature,
                                little_endian=False,
                                number_of_hex_digits=2)
        length = int_to_hexstring(len(out),
                                  little_endian=False,
                                  number_of_hex_digits=4)
        out = '@' + length + out
        return out