@@ -42,27 +42,24 @@ def listen(self):
4242
4343 :raises ConnectionError: when it loses connection to the SDK
4444 '''
45- try :
46- while True :
47- header = bytearray (utils .HEADER_SIZE )
48- self .sock .recv_into (header )
45+ while True :
46+ header = bytearray (utils .HEADER_SIZE )
47+ self .sock .recv_into (header )
4948
50- # Unpacking the contents of the raw header struct into a list
51- buff = list (struct .unpack ('ccccIII' , header ))
52- # print(buff[:4])
53- if buff [:4 ] == [b'O' , b'R' , b'G' , b'B' ]:
54- device_id , packet_type , packet_size = buff [4 :]
55- # print(device_id, packet_type, packet_size)
56- if packet_type == utils .PacketType .NET_PACKET_ID_REQUEST_CONTROLLER_COUNT :
57- buff = struct .unpack ("I" , self .sock .recv (packet_size ))
58- self .callback (device_id , packet_type , buff [0 ])
59- elif packet_type == utils .PacketType .NET_PACKET_ID_REQUEST_CONTROLLER_DATA :
60- data = bytearray (packet_size )
61- self .sock .recv_into (data )
62- self .callback (device_id , packet_type , utils .ControllerData .unpack (data ))
63- sleep (.2 )
64- except BrokenPipeError :
65- raise ConnectionError ("Disconnected. Did you disable the SDK?" )
49+ # Unpacking the contents of the raw header struct into a list
50+ buff = list (struct .unpack ('ccccIII' , header ))
51+ # print(buff[:4])
52+ if buff [:4 ] == [b'O' , b'R' , b'G' , b'B' ]:
53+ device_id , packet_type , packet_size = buff [4 :]
54+ # print(device_id, packet_type, packet_size)
55+ if packet_type == utils .PacketType .NET_PACKET_ID_REQUEST_CONTROLLER_COUNT :
56+ buff = struct .unpack ("I" , self .sock .recv (packet_size ))
57+ self .callback (device_id , packet_type , buff [0 ])
58+ elif packet_type == utils .PacketType .NET_PACKET_ID_REQUEST_CONTROLLER_DATA :
59+ data = bytearray (packet_size )
60+ self .sock .recv_into (data )
61+ self .callback (device_id , packet_type , utils .ControllerData .unpack (data ))
62+ sleep (.2 )
6663
6764 def requestDeviceData (self , device : int ):
6865 '''
@@ -80,7 +77,4 @@ def send_header(self, device_id: int, packet_type: int, packet_size: int):
8077 :param packet_type: a utils.PacketType
8178 :param packet_size: the full size of the data to be send after the header
8279 '''
83- try :
84- self .sock .send (struct .pack ('ccccIII' , b'O' , b'R' , b'G' , b'B' , device_id , packet_type , packet_size ), socket .MSG_NOSIGNAL )
85- except BrokenPipeError :
86- raise ConnectionError ("Disconnected. Did you disable the SDK?" )
80+ self .sock .send (struct .pack ('ccccIII' , b'O' , b'R' , b'G' , b'B' , device_id , packet_type , packet_size ), socket .MSG_NOSIGNAL )
0 commit comments