<s> import struct <EOL> import response <EOL> class Request ( object ) : <EOL> SOP1 = <NUM_LIT> <EOL> SOP2 = <NUM_LIT> <EOL> did = <NUM_LIT> <EOL> cid = <NUM_LIT> <EOL> fmt = None <EOL> def __init__ ( self , seq = <NUM_LIT> , * data ) : <EOL> self . seq = seq <EOL> self . data = data <EOL> if not self . fmt : <EOL> self . fmt = '<STR_LIT>' % len ( self . data ) <EOL> def __str__ ( self ) : <EOL> return self . bytes <EOL> def checksum ( self ) : <EOL> body = self . packet_header ( ) + self . packet_body ( ) <EOL> body = struct . unpack ( '<STR_LIT>' % len ( body ) , body ) <EOL> return struct . pack ( '<STR_LIT:B>' , ~ ( sum ( body [ <NUM_LIT:2> : ] ) % <NUM_LIT> ) & <NUM_LIT> ) <EOL> @ property <EOL> def bytes ( self ) : <EOL> return self . packet_header ( ) + self . packet_body ( ) + self . checksum ( ) <EOL> def packet_header ( self ) : <EOL> return struct . pack ( '<STR_LIT>' , * self . header ( ) ) <EOL> def packet_body ( self ) : <EOL> if not self . data : <EOL> return '<STR_LIT>' <EOL> return struct . pack ( self . fmt , * self . data ) <EOL> @ property <EOL> def dlen ( self ) : <EOL> return struct . calcsize ( self . fmt ) + <NUM_LIT:1> <EOL> def header ( self ) : <EOL> return [ self . SOP1 , self . SOP2 , self . did , self . cid , self . seq , self . dlen ] <EOL> def response ( self , header , body ) : <EOL> name = self . __class__ . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> klass = getattr ( response , name , response . Response ) <EOL> return klass ( header , body ) <EOL> class Core ( Request ) : <EOL> did = <NUM_LIT> <EOL> class Ping ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class GetVersion ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetDeviceName ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class GetBluetoothInfo ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class GetAutoReconnect ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetAutoReconnect ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class GetPowerState ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetPowerNotification ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class Sleep ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class GetVoltageTripPoints ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetVoltageTripPoints ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetInactivityTimeout ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class JumpToBootloader ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class PerformLevel1Diagnostics ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class PerformLevel2Diagnostics ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class ClearCounters ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class SetTimeValue ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class PollPacketTimes ( Core ) : <EOL> cid = <NUM_LIT> <EOL> class Sphero ( Request ) : <EOL> did = <NUM_LIT> <EOL> class SetHeading ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> fmt = '<STR_LIT>' <EOL> class SetStabilization ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetRotationRate ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetApplicationConfigurationBlock ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetApplicationConfigurationBlock ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class ReenableDemoMode ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetChassisId ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetChassisId ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SelfLevel ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetVDL ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetDataStreaming ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class ConfigureCollisionDetection ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class Locator ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetAccelerometer ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class ReadLocator ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetRGB ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetBackLEDOutput ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetRGB ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class Roll ( Sphero ) : <EOL> fmt = '<STR_LIT>' <EOL> cid = <NUM_LIT> <EOL> class SetBoostWithTime ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetRawMotorValues ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetMotionTimeout ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetOptionFlags ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetOptionFlags ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetConfigurationBlock ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetDeviceMode ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class RunMacro ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SaveTemporaryMacro ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class ReinitMacro ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class AbortMacro ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class GetMacroStatus ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class SetMacroParameter ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class AppendMacroChunk ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class EraseOrbbasicStorage ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class AppendOrbbasicFragment ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class RunOrbbasicProgram ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class AbortOrbbasicProgram ( Sphero ) : <EOL> cid = <NUM_LIT> <EOL> class AnswerInput ( Sphero ) : <EOL> cid = <NUM_LIT> </s>
