diff --git a/low_level/comms.py b/low_level/comms.py index 9ef1461..92b93de 100644 --- a/low_level/comms.py +++ b/low_level/comms.py @@ -154,15 +154,15 @@ def send(self, data_to_send): except serial.serialutil.SerialTimeoutException as err: print(repr(err)) print("ERROR: Write Has Timed Out") - callback_exception_handler("ERROR: Write Has Timed Out") + # callback_exception_handler("ERROR: Write Has Timed Out") except serial.serialutil.PortNotOpenError as err: print(repr(err)) print("ERROR: Port " + config.COM_PORT + " Not Open") - callback_exception_handler("ERROR: Port" + config.COM_PORT + " Not Open") + # callback_exception_handler("ERROR: Port" + config.COM_PORT + " Not Open") except serial.serialutil.SerialException as err: print(repr(err)) print("ERROR: The handle is invalid") - callback_exception_handler("ERROR: The handle is invalid") + # callback_exception_handler("ERROR: The handle is invalid") class StateMachineState(Enum): @@ -284,7 +284,7 @@ def reading_data(self, rx_byte): except struct.error as err: print(repr(err)) print("ERROR: Data Length is not 4 bytes") - callback_exception_handler("ERROR: Data Length is not 4 bytes") + # callback_exception_handler("ERROR: Data Length is not 4 bytes") self.got_data_length = True # Read a byte into Data Buffer @@ -301,7 +301,7 @@ def reading_data(self, rx_byte): # Check the data type against all known data types if not any(x.value == data_type for x in DataType): invalid_frame = True - callback_exception_handler("ERROR: Frame Data Type Field does not match actual type.") + # callback_exception_handler("ERROR: Frame Data Type Field does not match actual type.") # Get the data type name to use with comparing against the right data length data_type_key = DataType(data_type).name @@ -309,7 +309,7 @@ def reading_data(self, rx_byte): # Check the actual data length against the expected length for the data type if self.data_length != DataTypeSize[data_type_key].value: invalid_frame = True - callback_exception_handler("ERROR: Frame Data Length Field does not match actual length.") + # callback_exception_handler("ERROR: Frame Data Length Field does not match actual length.") if invalid_frame is False: # Append data length and data fields onto frame buffer @@ -405,7 +405,7 @@ def comms_init(port, baud_rate): GPIO.add_event_detect(DIO0_GPIO, GPIO.RISING, callback=comms_handler.radio.rx_interrupt, bouncetime=100) - signal.signal(signal.SIGINT, signal_handler) + # signal.signal(signal.SIGINT, signal_handler) def comms_send(data): diff --git a/low_level/continuous.py b/low_level/continuous.py index 415a85e..87ec1bd 100644 --- a/low_level/continuous.py +++ b/low_level/continuous.py @@ -91,7 +91,7 @@ def adjust_continuous(calls_per_second): except ZeroDivisionError as err: print("\n", repr(err)) print("ERROR: Rate is 0, cannot run continuously") - callback_exception_handler("ERROR: Rate is 0, cannot run continuously") + # callback_exception_handler("ERROR: Rate is 0, cannot run continuously") def continuous_stop(): diff --git a/low_level/packet.py b/low_level/packet.py index 41d3590..94332ff 100644 --- a/low_level/packet.py +++ b/low_level/packet.py @@ -122,7 +122,7 @@ def packetize(data_to_packet, data_type, is_continuous, message_object_database, except ZeroDivisionError as err: print("\n", repr(err)) print("ERROR: Rate is 0, cannot run continuously") - callback_exception_handler("ERROR: Rate is 0, cannot run continuously") + # callback_exception_handler("ERROR: Rate is 0, cannot run continuously") def delimiter_scan_and_add(data_to_scan): diff --git a/telecommand.py b/telecommand.py index 0a72184..e103c9c 100644 --- a/telecommand.py +++ b/telecommand.py @@ -50,7 +50,7 @@ def timeout(self): telecommand_database[:] = [telecommand for telecommand in telecommand_database if not tc_search_for_id_match(telecommand, self.ID)] # Increment the timeout counter - callback_telecommand_timeout() + # callback_telecommand_timeout() def telecommand_register_callback(tc_update_function_ptr, tc_timeout_function_ptr, exception_handler_function_ptr): @@ -74,7 +74,7 @@ def tc_request_send(telecommand_number, telecommand_data, telecommand_data_type, except ValueError as err: print(str(repr(err))) print("ERROR: Telecommand Request Channel is invalid") - callback_exception_handler("Telecommand Request Channel is invalid") + # callback_exception_handler("Telecommand Request Channel is invalid") try: if telecommand_data_type == "String": @@ -118,7 +118,7 @@ def tc_request_send(telecommand_number, telecommand_data, telecommand_data_type, except UnboundLocalError as err: print(repr(err)) print("ERROR: Could not format message") - callback_exception_handler("ERROR: Could not format message, " + type_error) + # callback_exception_handler("ERROR: Could not format message, " + type_error) def tc_search_for_id_match(telecommand, id_to_match, action=None): @@ -157,7 +157,7 @@ def tc_response(telecommand_packet): telecommand_response_status = TelecommandResponseState.INVALID_COMMAND_ARGUMENT.name # Pass the status back up to the GUI to display - callback_telecommand_response_update(str(telecommand_number), telecommand_response_status) + # callback_telecommand_response_update(str(telecommand_number), telecommand_response_status) def tc_time_send(telecommand_number, unix_time_seconds, millisec_through_sec): try: @@ -178,5 +178,5 @@ def tc_time_send(telecommand_number, unix_time_seconds, millisec_through_sec): except UnboundLocalError as err: print(repr(err)) print("ERROR: Could not format message") - callback_exception_handler("ERROR: Could not format message, " + type_error) + # callback_exception_handler("ERROR: Could not format message, " + type_error) diff --git a/telemetry.py b/telemetry.py index 3b922ab..bfdf5bb 100644 --- a/telemetry.py +++ b/telemetry.py @@ -49,7 +49,7 @@ def timeout(self): telemetry_database[:] = [telemetry for telemetry in telemetry_database if not tlm_search_for_id_match(telemetry, self.ID)] # Increment the timeout counter - callback_telemetry_timeout() + # callback_telemetry_timeout() def telemetry_register_callback(tlm_update_function_ptr, tlm_rejection_update_function_ptr, tlm_timeout_function_ptr, @@ -80,11 +80,11 @@ def tlm_request_send(tlm_channel, is_continuous): except UnboundLocalError as err: print("ERROR: ", err) print("INFO: Could not format message") - callback_exception_handler("ERROR: Could not format message") + # callback_exception_handler("ERROR: Could not format message") except ValueError as err: print("ERROR: ", err) print("INFO: Telemetry Request Channel is invalid") - callback_exception_handler("ERROR: Telemetry Request Channel is invalid") + # callback_exception_handler("ERROR: Telemetry Request Channel is invalid") def tlm_search_for_id_match(telemetry, id_to_match, action=None): @@ -112,7 +112,7 @@ def tlm_response(telemetry_packet): not tlm_search_for_id_match(telemetry, tlm_channel, "STOP_TIMEOUT")] # Pass the data back up to the GUI to display - callback_telemetry_response_update(str(tlm_channel), str(tlm_data)) + # callback_telemetry_response_update(str(tlm_channel), str(tlm_data)) def tlm_rejection_response(telemetry_packet): @@ -134,4 +134,4 @@ def tlm_rejection_response(telemetry_packet): tlm_rejection_message = "INVALID_DATA_LENGTH" # Pass the data back up to the GUI to display - callback_telemetry_rejection_response_update(str(tlm_channel), tlm_rejection_message) + # callback_telemetry_rejection_response_update(str(tlm_channel), tlm_rejection_message) diff --git a/web_server/main.py b/web_server/main.py new file mode 100755 index 0000000..280b7da --- /dev/null +++ b/web_server/main.py @@ -0,0 +1,52 @@ +import flask +from flask import request, jsonify + +app = flask.Flask(__name__) +app.config["DEBUG"] = True + +@app.route('/api/v1/ping', methods=['GET']) +def api_all(): + return jsonify({ + 'pong': 'success', + }) + + +@app.route('/api/v1/telecommand/send/request', methods=['POST']) +def send_telecommand_request(): + # TODO: need to add data validation here. + # TODO: How does middleware flask work? Need to add Auth JWT M2M token validation. + body = request.json + telecommand_number = body['telecommand_number'] + telecommand_data = body['telecommand_data'] + telecommand_data_type = body['telecommand_data_type'] + is_continuous = body['is_continuous'] + + print('============mercury py==============') + print('TC: {}'.format(telecommand_number)) + print('Data: {}'.format(telecommand_data)) + print('DataType: {}'.format(telecommand_data_type)) + print('Is continuous: {}'.format(is_continuous)) + print('==========================') + # TODO: Talk to Jamie about connecting this to the right functions. + + return 'OK' + +@app.route('/api/v1/telemetry/send/request', methods=['POST']) +def send_telemetry_request(): + body = request.json + tlm_channel = body['tlm_channel'] + is_continuous = body['is_continuous'] + + print('============mercury py==============') + print('Channel: {}'.format(tlm_channel)) + print('Is continuous: {}'.format(is_continuous)) + print('==========================') + # TODO: Talk to Jamie about connecting this to the right functions. + + return 'OK' + +@app.route('/api/v1/transmit/test', methods=['POST']) +def transmit_test(): + return 'OK' + +app.run() \ No newline at end of file