Ejemplo n.º 1
0
def test_int_to_bytes():
    assert int_to_bytes(0xFFFF) == [0xFF, 0xFF]
    assert int_to_bytes(0x1234) == [0x12, 0x34]
    # test that the value cannot exceed two bytes
    with pytest.raises(ValueError):
        int_to_bytes(0x123456)
    assert int_to_bytes(0x0001) == [0x00, 0x01]
Ejemplo n.º 2
0
    def getBytes(self) -> tuple:
        rtrnList = super().getBytes()
        # Flags and Length Framing Layer:--------------------
        rtrnList.extend(make_flagsandlength(self.length - 38))
        # Vector Framing Layer:------------------------------
        rtrnList.extend(VECTOR_E131_EXTENDED_DISCOVERY)
        # source Name Framing Layer:-------------------------
        # make a 64 byte long sourceName
        tmpSourceName = [0] * 64
        for i in range(0, min(len(tmpSourceName), len(self.sourceName))):
            tmpSourceName[i] = ord(self.sourceName[i])
        rtrnList.extend(tmpSourceName)
        # reserved fields:-----------------------------------
        rtrnList.extend([0] * 4)
        # Universe Discovery Layer:-------------------------------------
        # Flags and Length:----------------------------------
        rtrnList.extend(make_flagsandlength(self.length - 112))
        # Vector UDL:----------------------------------------
        rtrnList.extend(VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST)
        # page:----------------------------------------------
        rtrnList.append(self._page & 0xFF)
        # last page:-----------------------------------------
        rtrnList.append(self._lastPage & 0xFF)
        # universes:-----------------------------------------
        for universe in self._universes:  # universe is a 16-bit number!
            rtrnList.extend(int_to_bytes(universe))

        return tuple(rtrnList)
Ejemplo n.º 3
0
    def getBytes(self) -> list:
        rtrnList = super().getBytes()
        # Flags and Length Framing Layer:--------------------
        rtrnList.extend(make_flagsandlength(self.length - 38))
        # Vector Framing Layer:------------------------------
        rtrnList.extend(VECTOR_E131_EXTENDED_DISCOVERY)
        # source Name Framing Layer:-------------------------
        # sourceName:---------------------------
        # UTF-8 encode the string
        tmpSourceName = str(self._sourceName).encode('UTF-8')
        rtrnList.extend(tmpSourceName)
        # pad to 64 bytes
        rtrnList.extend([0] * (64 - len(tmpSourceName)))
        # reserved fields:-----------------------------------
        rtrnList.extend([0] * 4)
        # Universe Discovery Layer:-------------------------------------
        # Flags and Length:----------------------------------
        rtrnList.extend(make_flagsandlength(self.length - 112))
        # Vector UDL:----------------------------------------
        rtrnList.extend(VECTOR_UNIVERSE_DISCOVERY_UNIVERSE_LIST)
        # page:----------------------------------------------
        rtrnList.append(self._page & 0xFF)
        # last page:-----------------------------------------
        rtrnList.append(self._lastPage & 0xFF)
        # universes:-----------------------------------------
        for universe in self._universes:  # universe is a 16-bit number!
            rtrnList.extend(int_to_bytes(universe))

        return rtrnList
Ejemplo n.º 4
0
 def getBytes(self) -> tuple:
     rtrnList = super().getBytes()
     rtrnList.extend(make_flagsandlength(self.length - 38))
     rtrnList.extend(VECTOR_E131_EXTENDED_SYNCHRONIZATION)
     rtrnList.append(self._sequence)
     rtrnList.extend(int_to_bytes(self._syncAddr))
     rtrnList.extend((0, 0))  # the empty reserved slots
     return rtrnList
Ejemplo n.º 5
0
    def getBytes(self) -> tuple:
        rtrnList = super().getBytes()
        # Flags and Length Framing Layer:-------
        rtrnList.extend(make_flagsandlength(self.length - 38))
        # Vector Framing Layer:-----------------
        rtrnList.extend(self._vector1)
        # sourceName:---------------------------
        # make a 64 byte long sourceName
        tmpSourceName = [0] * 64
        for i in range(0, min(len(tmpSourceName), len(self.sourceName))):
            tmpSourceName[i] = ord(self.sourceName[i])
        rtrnList.extend(tmpSourceName)
        # priority------------------------------
        rtrnList.append(self._priority)
        # syncAddress---------------------------
        rtrnList.extend(int_to_bytes(self._syncAddr))
        # sequence------------------------------
        rtrnList.append(self._sequence)
        # Options Flags:------------------------
        tmpOptionsFlags = 0
        # stream terminated:
        tmpOptionsFlags += int(self.option_StreamTerminated) << 6
        # preview data:
        tmpOptionsFlags += int(self.option_PreviewData) << 7
        # force synchronization
        tmpOptionsFlags += int(self.option_ForceSync) << 5
        rtrnList.append(tmpOptionsFlags)
        # universe:-----------------------------
        rtrnList.extend(int_to_bytes(self._universe))
        # DMP Layer:---------------------------------------------------
        # Flags and Length DMP Layer:-----------
        rtrnList.extend(make_flagsandlength(self.length - 115))
        # Vector DMP Layer:---------------------
        rtrnList.append(self._vector2)
        # Some static values (Address & Data Type, First Property addr, ...)
        rtrnList.extend([0xa1, 0x00, 0x00, 0x00, 0x01])
        # Length of the data:-------------------
        lengthDmxData = len(self._dmxData) + 1
        rtrnList.extend(int_to_bytes(lengthDmxData))
        # DMX data:-----------------------------
        rtrnList.append(0x00)  # DMX Start Code
        rtrnList.extend(self._dmxData)

        return tuple(rtrnList)
Ejemplo n.º 6
0
 def getBytes(self) -> tuple:
     rtrnList = super().getBytes()
     # Flags and Length Framing Layer:-------
     rtrnList.extend(make_flagsandlength(self.length - 38))
     # Vector Framing Layer:-----------------
     rtrnList.extend(VECTOR_E131_DATA_PACKET)
     # sourceName:---------------------------
     # UTF-8 encode the string
     tmpSourceName = str(self._sourceName).encode('UTF-8')
     rtrnList.extend(tmpSourceName)
     # pad to 64 bytes
     rtrnList.extend([0] * (64 - len(tmpSourceName)))
     # priority------------------------------
     rtrnList.append(self._priority)
     # syncAddress---------------------------
     rtrnList.extend(int_to_bytes(self._syncAddr))
     # sequence------------------------------
     rtrnList.append(self._sequence)
     # Options Flags:------------------------
     tmpOptionsFlags = 0
     # stream terminated:
     tmpOptionsFlags += int(self.option_StreamTerminated) << 6
     # preview data:
     tmpOptionsFlags += int(self.option_PreviewData) << 7
     # force synchronization
     tmpOptionsFlags += int(self.option_ForceSync) << 5
     rtrnList.append(tmpOptionsFlags)
     # universe:-----------------------------
     rtrnList.extend(int_to_bytes(self._universe))
     # DMP Layer:---------------------------------------------------
     # Flags and Length DMP Layer:-----------
     rtrnList.extend(make_flagsandlength(self.length - 115))
     # Vector DMP Layer:---------------------
     rtrnList.append(VECTOR_DMP_SET_PROPERTY)
     # Some static values (Address & Data Type, First Property addr, ...)
     rtrnList.extend([0xa1, 0x00, 0x00, 0x00, 0x01])
     # Length of the data:-------------------
     lengthDmxData = len(self._dmxData) + 1
     rtrnList.extend(int_to_bytes(lengthDmxData))
     # DMX data:-----------------------------
     rtrnList.append(self._dmxStartCode)  # DMX Start Code
     rtrnList.extend(self._dmxData)
     return tuple(rtrnList)
Ejemplo n.º 7
0
def test_int_byte_transitions():
    # test the full 0-65534 range, though only using 0-63999 currently
    for input_i in range(65536):
        converted_i = byte_tuple_to_int(tuple(int_to_bytes(input_i)))
        assert input_i == converted_i