Esempio n. 1
0
class QDataStreamWrite(unittest.TestCase):
    '''Test case for QDatastream write* functions'''

    def setUp(self):
        self.ba = QByteArray()
        self.read = QDataStream(self.ba, QIODevice.ReadOnly)
        self.write = QDataStream(self.ba, QIODevice.WriteOnly)

    def testWriteUInt8(self):
        '''QDataStream.writeUInt8 (accepting str of size 1)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeUInt8, 'aaaaa')

    def testWriteInt8(self):
        '''QDataStream.writeInt8 (accepting str of size 1)'''
        x = 65
        self.write.writeInt8(chr(x))
        y = self.read.readInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeInt8, 'aaaaa')

    def testWriteUInt8Int(self):
        '''QDataStream.writeUInt8 (accepting integer)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

    def testWriteInt8Int(self):
        '''QDataStream.writeInt8 (accepting integer)'''
        x = 65
        self.write.writeInt8(x)
        y = self.read.readInt8()
        self.assertEqual(x, y)

    def testWriteUInt16(self):
        '''QDataStream.writeUInt16'''
        x = 0x4423
        self.write.writeUInt16(x)
        y = int(self.read.readUInt16())
        self.assertEqual(x, y)

    def testWriteUInt32(self):
        '''QDataStream.writeUInt32'''
        x = 0xdeadbeef
        self.write.writeUInt32(x)
        y = int(self.read.readUInt32())
        self.assertEqual(x, y)
Esempio n. 2
0
class QDataStreamWrite(unittest.TestCase):
    '''Test case for QDatastream write* functions'''

    def setUp(self):
        self.ba = QByteArray()
        self.read = QDataStream(self.ba, QIODevice.ReadOnly)
        self.write = QDataStream(self.ba, QIODevice.WriteOnly)

    def testWriteUInt8(self):
        '''QDataStream.writeUInt8 (accepting str of size 1)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeUInt8, 'aaaaa')

    def testWriteInt8(self):
        '''QDataStream.writeInt8 (accepting str of size 1)'''
        x = 65
        self.write.writeInt8(chr(x))
        y = self.read.readInt8()
        self.assertEqual(x, y)

        self.assertRaises(TypeError, self.write.writeInt8, 'aaaaa')

    def testWriteUInt8Int(self):
        '''QDataStream.writeUInt8 (accepting integer)'''
        x = 0xFF
        self.write.writeUInt8(x)
        y = self.read.readUInt8()
        self.assertEqual(x, y)

    def testWriteInt8Int(self):
        '''QDataStream.writeInt8 (accepting integer)'''
        x = 65
        self.write.writeInt8(x)
        y = self.read.readInt8()
        self.assertEqual(x, y)

    def testWriteUInt16(self):
        '''QDataStream.writeUInt16'''
        x = 0x4423
        self.write.writeUInt16(x)
        y = int(self.read.readUInt16())
        self.assertEqual(x, y)

    def testWriteUInt32(self):
        '''QDataStream.writeUInt32'''
        x = 0xdeadbeef
        self.write.writeUInt32(x)
        y = int(self.read.readUInt32())
        self.assertEqual(x, y)
Esempio n. 3
0
    def send(self):
        datagram = QByteArray()
        stream = QDataStream(datagram, QIODevice.WriteOnly)

        stream.writeUInt8(self.emergency_led)
        self.socket.writeDatagram(datagram, self.target, self.port)
Esempio n. 4
0
    def send_data_old_main_board(self):

        datagram = QByteArray()
        stream = QDataStream(datagram, QIODevice.WriteOnly)
        # print(self.angularspeed.joint1)
        low_byte1, high_byte1 = two_byte_int_to_byte(self.angularspeed.joint1)
        low_byte2, high_byte2 = two_byte_int_to_byte(self.angularspeed.joint2)
        low_byte3, high_byte3 = two_byte_int_to_byte(self.angularspeed.joint3)
        low_byte4, high_byte4 = two_byte_int_to_byte(
            self.angularspeed.prismatic)
        low_byte5, high_byte5 = two_byte_int_to_byte(self.angularspeed.joint4)
        low_byte6, high_byte6 = two_byte_int_to_byte(self.angularspeed.joint5)
        low_byte7, high_byte7 = two_byte_int_to_byte(
            self.angularspeed.sensor_box)

        stream.writeInt8(self.direction.joint1)
        stream.writeInt8(self.direction.joint2)
        stream.writeInt8(self.direction.joint3)
        stream.writeInt8(self.direction.prismatic)
        stream.writeInt8(self.direction.joint4)
        stream.writeInt8(self.direction.joint5)

        stream.writeInt8(self.direction.sensor_box)

        stream.writeUInt8(low_byte1)
        stream.writeUInt8(high_byte1)

        stream.writeUInt8(low_byte2)
        stream.writeUInt8(high_byte2)

        stream.writeUInt8(low_byte3)
        stream.writeUInt8(high_byte3)

        stream.writeUInt8(low_byte4)
        stream.writeUInt8(high_byte4)

        stream.writeUInt8(low_byte5)
        stream.writeUInt8(high_byte5)

        stream.writeUInt8(low_byte6)
        stream.writeUInt8(high_byte6)

        stream.writeUInt8(low_byte7)
        stream.writeUInt8(high_byte7)

        stream.writeUInt8(self.reset_motor.reset_main_board_motor)
        stream.writeUInt8(self.home_position.home_position)
        stream.writeUInt8(self.emergency_stop.emergency_stop)
        self.socket_old_main_board.writeDatagram(
            datagram, self.main_board_ip, self.mainboard_port)
Esempio n. 5
0
    def send_main_board_manipulator_data(self):
        datagram = QByteArray()
        stream = QDataStream(datagram, QIODevice.WriteOnly)
        low_byte1, high_byte1 = two_byte_int_to_byte(self.angularspeed.joint1)
        low_byte2, high_byte2 = two_byte_int_to_byte(self.angularspeed.joint2)
        low_byte3, high_byte3 = two_byte_int_to_byte(self.angularspeed.joint3)
        stream.writeUInt8(self.direction.joint1)
        stream.writeUInt8(self.direction.joint2)
        stream.writeUInt8(self.direction.joint3)
        stream.writeUInt8(self.direction.prismatic)

        stream.writeUInt8(low_byte1)
        stream.writeUInt8(high_byte1)

        stream.writeUInt8(low_byte2)
        stream.writeUInt8(high_byte2)

        stream.writeUInt8(low_byte3)
        stream.writeUInt8(high_byte3)
        stream.writeUInt8(self.reset_motor.reset_main_board_motor)
        stream.writeUInt8(self.home_position.home_position)
        stream.writeUInt8(self.emergency_stop.emergency_stop)
        self.socket_main_board.writeDatagram(
            datagram, self.main_board_ip, self.mainboard_port)
Esempio n. 6
0
    def send_sensor_board_manipulator_data(self):
        datagram = QByteArray()
        stream = QDataStream(datagram, QIODevice.WriteOnly)
        low_byte4, high_byte4 = two_byte_int_to_byte(self.angularspeed.joint4)

        stream.writeUInt8(self.direction.joint4)
        stream.writeUInt8(self.direction.joint5)
        stream.writeUInt8(self.direction.gripper)
        stream.writeUInt8(self.direction.sensor_box)
        stream.writeUInt8(low_byte4)
        stream.writeUInt8(high_byte4)
        stream.writeUInt8(self.reset_motor.reset_sensor_board_motor)
        stream.writeUInt8(self.set_led.set_led)
        self.socket_sensor_board.writeDatagram(
            datagram, self.sensor_board_ip, 3032)