def command_incoming(self, link, cmd): """ Callback for incoming commands received from bluetooth link. Change in States will be received in this callback :param link Link: :class:`link` object :param bytearray cmd: data received :rtype: None """ log.info("Len: " + str(len(cmd))) #log.debug("\n App: Cmd :", cmd) b_string = codecs.encode(cmd, 'hex') log.info("Hex:* " + str(b_string) + " + Type: " + str(type(b_string))) hmkit_inst = hmkit.get_instance() hmkit_inst.autoapi_dump.message_dump(cmd) cmd_obj = CommandResolver.resolve(cmd) log.debug("cmd_obj: " + str(cmd_obj)) #log.debug(" isinstance of LockState: " + str(isinstance(cmd_obj, lockstate.LockState))) self.app.incoming_message(cmd_obj) return 1
def command_incoming(self, link, cmd): """ Callback for incoming commands received from bluetooth link. Change in States will be received in this callback :param link Link: :class:`link` object :param bytearray cmd: data received :rtype: None """ log.info("Len: " + str(len(cmd))) #log.debug("\n App: Cmd :", cmd) b_string = codecs.encode(cmd, 'hex') log.debug("*** Hex:* " + str(b_string) + " + Type: " + str(type(b_string))) #print("*** Hex:* " + str(b_string) + " + Type: " + str(type(b_string))) hmkit_inst = hmkit.get_instance() hmkit_inst.autoapi_dump.message_dump(cmd) cmd_obj = CommandResolver.resolve(cmd) log.debug("cmd_obj: " + str(cmd_obj)) #log.debug(" isinstance of LockState: " + str(isinstance(cmd_obj, lockstate.LockState))) if isinstance(cmd_obj, capabilities.Capabilities): #print("App: Capabilities received ") # Example: Capability Checks doorlock_capability = cmd_obj.get_capability( Identifiers.DOOR_LOCKS) is_sup = doorlock_capability.is_supported( msg_type.MsgType(Identifiers.DOOR_LOCKS, 0x00)) #print("App: get doorlocks() is_sup: " + str(is_sup)) diags_capability = cmd_obj.get_capability(Identifiers.DIAGNOSTICS) is_sup = diags_capability.is_supported( msg_type.MsgType(Identifiers.DIAGNOSTICS, 0x00)) #print("App: diags get() is_sup: " + str(is_sup)) vehsts_capability = cmd_obj.get_capability( Identifiers.VEHICLE_STATUS) if vehsts_capability is not None: is_sup = vehsts_capability.is_supported( msg_type.MsgType(Identifiers.VEHICLE_STATUS, 0x00)) #print("App: is_sup: " + str(is_sup)) #else: #print("Vehicle Status Capability not present") # Example: Permissions Check # Test Permission for VehicleStatus READ vehsts_permission_bitlocation = PermissionLocation.locationfor( Identifiers.VEHICLE_STATUS, PermissionType.READ) # get access_certificate, get permissions, serial mocked access_cert = hmkit_inst.get_certificate(None) permissions = access_cert.get_permissions() # check is_allowed from permissions. isallowed = permissions.is_allowed(vehsts_permission_bitlocation) #print("Permission check for Vehicle Status. isAllowed: ", isallowed) return 1
def command_incoming(self, link, cmd): """ Callback for incoming commands received from bluetooth link. Change in States will be received in this callback :param link Link: :class:`link` object :param bytearray cmd: data received :rtype: None """ log.info("Len: " + str(len(cmd))) log.info("\n App: Cmd :" + str(cmd)) hmkit_inst = hmkit.get_instance() hmkit_inst.autoapi_dump.message_dump(cmd) cmd_obj = CommandResolver.resolve(cmd) log.debug("cmd_obj: " + str(cmd_obj)) #log.debug(" isinstance of LockState: " + str(isinstance(cmd_obj, lockstate.LockState))) if isinstance(cmd_obj, Capabilities): print("App: Capabilities received ") return 1
constructed_bytes = get_ignition_state.GetIgnitionState( ).get_bytearray() hmkit.bluetooth.link.sendcommand(constructed_bytes) return if __name__ == "__main__": # Initialise with HMKit class with a Device Certificate and private key. # This can accept Base64 strings straight from the Developer Center hmkit = hmkit.HmKit(["PASTE DEVICE CERTIFICATE SNIPPET HERE"], logging.DEBUG) # Download Access Certificate with the token try: hmkit.get_instance().download_access_certificate( "PASTE ACCESS TOKEN HERE") except Exception as e: # Handle the error log.critical("Error in Access certicate download " + str(e.args[0])) print("Error in Access certicate download " + str(e.args[0])) hmkit.hmkit_exit() # local LinkListener object of sampleapp linkListener = Link_Listener() # local BroadcastListener object of sampleapp broadcastListener = Broadcast_Listener() # set link listener for BLE link device events hmkit.bluetooth.link.set_listener(linkListener)
print(" Parked_Vehicle, get_licenseplate() ") return self.license_plate # ----------------------------------------------------------------------- if __name__ == "__main__": # Initialise with HMKit class with a Device Certificate and private key. To start with # this can accept Base64 strings straight from the Developer Center hmkit = hmkit.HmKit(["<< COPY DEVICE CERTIFICATE HERE >>"], logging.INFO) # Download Access Certificate with the token try: hmkit.get_instance().download_access_certificate( b"<< COPY THE TOKEN HERE >>") except Exception as e: # Handle the error #log.critical("Error in Access certicate download " + str(e.args[0])) #hmkit.hmkit_exit() print("empty") parkingmachine = ParkingMachine(hmkit) # local LinkListener object of sampleapp linkListener = Link_Listener(parkingmachine) # local BroadcastListener object of sampleapp broadcastListener = Broadcast_Listener(parkingmachine) # set link listener for BLE link device events
# ----------------------------------------------------------------------- if __name__ == "__main__": # Initialise with HMKit class with a Device Certificate and private key. To start with # this can accept Base64 strings straight from the Developer Center hmkit = hmkit.HmKit([ "dGVzdEUTEM0a92kpgEW5Yvfq8VEQmf2f8IFEgAQ34X7TPZjG6P4IGPyqorpJD8rXyK3aLejImdLZHaHT6jrPPdxpm+JzEjIGlwux3TZknv64nAAbejubKmAO8ua0MRs7lrzJ0r8CqMAUSY3+abRmmzRhHp6bQE0Q2pWMb0kqvGCsAbq92YuNkbvNSsSzeKo0vya7wrb8RoYs", "bXVCzrYtwwehRNYhJ2+wWj3iJBS1BvPYL9P8MofMBDI=", "5jAC31ddtR4RKeF2O10fuSNkYtCtzTW9uUWu+K4PfVZ1ZEO5L6so+zFpvykVxYdfEOqhX2Eba3gdjrEDvX144Q==" ], logging.DEBUG) # Download Access Certificate with the token try: hmkit.get_instance().download_access_certificate( b"b063d69b-a069-4abc-ad02-d2ae99deffe4") except Exception as e: # Handle the error log.critical("Error in Access certicate download " + str(e.args[0])) print("Error in Access certicate download " + str(e.args[0])) hmkit.hmkit_exit() # local LinkListener object of sampleapp linkListener = Link_Listener() # local BroadcastListener object of sampleapp broadcastListener = Broadcast_Listener() # set link listener for BLE link device events hmkit.bluetooth.link.set_listener(linkListener)