bigger try except and more logging
This commit is contained in:
@@ -102,7 +102,7 @@ class ApiListener(Node):
|
|||||||
{'type': ResponseMessage.IMAGE, 'image': image_data}))
|
{'type': ResponseMessage.IMAGE, 'image': image_data}))
|
||||||
|
|
||||||
def send_available_commands(self):
|
def send_available_commands(self):
|
||||||
self.get_logger().info('Sending available commands')
|
print('Sending available commands')
|
||||||
result = {}
|
result = {}
|
||||||
for command in RequestCommand:
|
for command in RequestCommand:
|
||||||
result[command.name] = command.value
|
result[command.name] = command.value
|
||||||
@@ -112,34 +112,36 @@ class ApiListener(Node):
|
|||||||
{'type': ResponseMessage.ALL_REQUESTS_RESPONSES.name, 'data': result}))
|
{'type': ResponseMessage.ALL_REQUESTS_RESPONSES.name, 'data': result}))
|
||||||
|
|
||||||
def consume_message(self, message):
|
def consume_message(self, message):
|
||||||
self.get_logger().info(f'Consuming message: {message}')
|
print(f'Consuming message: {message}')
|
||||||
try:
|
try:
|
||||||
message_json = json.loads(message)
|
message_json = json.loads(message)
|
||||||
|
if not message_json['command']:
|
||||||
|
self.get_logger().error('Received message without command')
|
||||||
|
self.send_available_commands()
|
||||||
|
else:
|
||||||
|
self.get_logger().info(
|
||||||
|
f'Received command: {message_json["command"]}')
|
||||||
|
if message_json['command'] == RequestCommand.TAKEOFF:
|
||||||
|
self.get_logger().info('Takeoff command received')
|
||||||
|
elif message_json['command'] == RequestCommand.LAND:
|
||||||
|
self.get_logger().info('Land command received')
|
||||||
|
elif message_json['command'] == RequestCommand.MOVE_POSITION:
|
||||||
|
self.get_logger().info('Move position command received')
|
||||||
|
elif message_json['command'] == RequestCommand.MOVE_DIRECTION:
|
||||||
|
self.get_logger().info('Move direction command received')
|
||||||
|
elif message_json['command'] == RequestCommand.TAKE_PICTURE:
|
||||||
|
self.process_image_request(message_json)
|
||||||
|
elif message_json['command'] == RequestCommand.GET:
|
||||||
|
self.get_logger().info('Get command received')
|
||||||
|
self.send_available_commands()
|
||||||
|
else:
|
||||||
|
self.get_logger().error('Received unknown command')
|
||||||
|
self.send_available_commands()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.get_logger().error('Received unknown command')
|
self.get_logger().error('Received unknown command')
|
||||||
self.send_available_commands()
|
self.send_available_commands()
|
||||||
if not message_json['command']:
|
except Exception:
|
||||||
self.get_logger().error('Received message without command')
|
self.get_logger().error('Something went wrong!')
|
||||||
self.send_available_commands()
|
|
||||||
else:
|
|
||||||
self.get_logger().info(
|
|
||||||
f'Received command: {message_json["command"]}')
|
|
||||||
if message_json['command'] == RequestCommand.TAKEOFF:
|
|
||||||
self.get_logger().info('Takeoff command received')
|
|
||||||
elif message_json['command'] == RequestCommand.LAND:
|
|
||||||
self.get_logger().info('Land command received')
|
|
||||||
elif message_json['command'] == RequestCommand.MOVE_POSITION:
|
|
||||||
self.get_logger().info('Move position command received')
|
|
||||||
elif message_json['command'] == RequestCommand.MOVE_DIRECTION:
|
|
||||||
self.get_logger().info('Move direction command received')
|
|
||||||
elif message_json['command'] == RequestCommand.TAKE_PICTURE:
|
|
||||||
self.process_image_request(message_json)
|
|
||||||
elif message_json['command'] == RequestCommand.GET:
|
|
||||||
self.get_logger().info('Get command received')
|
|
||||||
self.send_available_commands()
|
|
||||||
else:
|
|
||||||
self.get_logger().error('Received unknown command')
|
|
||||||
self.send_available_commands()
|
|
||||||
|
|
||||||
async def api_handler(self, websocket):
|
async def api_handler(self, websocket):
|
||||||
self.get_logger().info('New connection')
|
self.get_logger().info('New connection')
|
||||||
|
|||||||
Reference in New Issue
Block a user