From 242b186fc4f09853214faf9dc5bf0d65ce2637fc Mon Sep 17 00:00:00 2001
From: Trishna Saeharaseelan <trishna.saeharaseelan@noc.ac.uk>
Date: Wed, 16 Nov 2022 16:22:04 +0000
Subject: [PATCH] feat: initial commit with sample data

---
 README.md                                     |  78 ++++++-
 __init__.py                                   |   8 +
 autonomy_configuration.py                     |   0
 examples/autonomy_engine/configuration.jsonc  |  71 +++++++
 examples/autonomy_engine/mission_plan.json    |   0
 ...sample_autosub.alr-3.v1.mission_script.sbd | Bin 0 -> 94 bytes
 .../autosub_c2/sample_decoded_ah1_status.json | 199 ++++++++++++++++++
 .../sample_decoded_ecosub_status.txt          |  23 ++
 examples/gui/emergency_stop.json              |   0
 vehicle_status_schema.py                      |  84 ++++++++
 10 files changed, 461 insertions(+), 2 deletions(-)
 create mode 100644 __init__.py
 create mode 100644 autonomy_configuration.py
 create mode 100644 examples/autonomy_engine/configuration.jsonc
 create mode 100644 examples/autonomy_engine/mission_plan.json
 create mode 100644 examples/autosub_c2/sample_autosub.alr-3.v1.mission_script.sbd
 create mode 100644 examples/autosub_c2/sample_decoded_ah1_status.json
 create mode 100644 examples/ecosub_c2/sample_decoded_ecosub_status.txt
 create mode 100644 examples/gui/emergency_stop.json
 create mode 100644 vehicle_status_schema.py

diff --git a/README.md b/README.md
index e608362..ca15683 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,77 @@
-# backbone-message-format
+# Message Formats (DRAFT)
+Consists of all messages transferred into and out of the Communications Backbone. Message type schemas will be developed once reviewing each vehicle's data and statuses defined by each partner.
 
-Message format(s) for the Communications Backbone System
\ No newline at end of file
+## Types of Messages by Software Component
+### 1/ Autonomy Engine
+#### Transmit
+* mission plan _(sent per vehicle)_
+* TBD: 
+    * Will emergency commands be sent via the autonomy engine (from the GUI) or directly to the C2s?
+
+#### Receive
+* configuration file
+* emergency stop all
+* decoded ecosub status message
+* decoded reav status message
+* decoded autosub-hover status message
+* decoded ecosub survey data _(from squad 1 vehicles)_
+
+----------------------------------
+
+### 2/ Ecosub C2
+#### Transmit
+* compiled ecosub mission plan
+* decoded ecosub status message
+* configuration file
+* decoded ecosub survey data
+
+
+#### Receive
+* mission plan
+* encoded ecosub status message
+* encoded ecosub survey data
+
+----------------------------------
+
+### 3/ Autosub C2 
+#### Transmit
+* compiled autosub-hover mission plan
+* decoded autosub-hover status message
+* configuration file
+
+
+#### Receive
+* mission plan
+* encoded autosub-hover status message
+
+
+----------------------------------
+
+### 4/ Reav C2 
+#### Transmit
+* decoded reav-60 status message?
+
+
+#### Receive
+* mission plan
+* encoded reav-60 status message?
+
+----------------------------------
+
+### 5/ Hermes Box/Hydrosurv Smart Router? 
+#### Transmit
+* encoded ecosub status message
+* encoded (or is this already decoded?) reav status message
+* encoded autosub status message
+* encoded ecosub survey data
+* TBD: 
+    * are there acknowledgment messages from vehicles?
+    * how are we receiving beacon messages per vehicle?
+
+#### Receive
+* compiled ecosub mission plan
+* compiled reav mission plan
+* compiled autosub mission plan
+* compiled ecosub emergency command
+* compiled reav emergency command
+* compiled autosub emergency command
diff --git a/__init__.py b/__init__.py
new file mode 100644
index 0000000..2253a07
--- /dev/null
+++ b/__init__.py
@@ -0,0 +1,8 @@
+import os
+
+
+__all__ = [
+    os.path.splitext(os.path.basename(x))[0]
+    for x in os.listdir(os.path.dirname(__file__))
+    if x.endswith(".py") and x != "__init__.py"
+]
diff --git a/autonomy_configuration.py b/autonomy_configuration.py
new file mode 100644
index 0000000..e69de29
diff --git a/examples/autonomy_engine/configuration.jsonc b/examples/autonomy_engine/configuration.jsonc
new file mode 100644
index 0000000..169d865
--- /dev/null
+++ b/examples/autonomy_engine/configuration.jsonc
@@ -0,0 +1,71 @@
+//****************************************************************
+// File: config.json  (THIS FILE WILL BE IN JSON FORMAT, NOT JSONC)
+// Description: This file is configured by the respective
+// vehicle's C2 if a vehicle is no longer active or change
+// a configured value. 
+//
+// Notes: All comments in this document will be stripped out
+// during SOAR operations.
+// (TODO: RHU to identify values that can and cannot be
+// configured).
+//----------------------------------------------------------------
+// CHANGELOG
+// -------------------
+// 11-11-2022 Trishna S.  Added comments, header, and data types  
+//                        for each field.
+// 10-11-2022 Izzat K.    Converted contents to json schema.
+// 06-10-2022 Trishna S.  New initialisation file.
+//****************************************************************
+{
+    "mission_config": {
+        "execute_stage": {
+            "survey": true, // bool
+            "detail": false // bool
+        }
+    },
+    "survey_team": {
+        "no_of_vehicles": 3, // int
+        "vehicles": [
+            {
+                "id": 1, // int
+                "platform": "ecosub", // str
+                "vehicle_serial": "eco101", // str
+                "active": true // bool
+            },
+            {
+                "id": 2,
+                "platform": "ecosub", // str
+                "vehicle_serial": "eco-102",  // str
+                "active": true // bool
+            },
+            {
+                "id": 3, // int
+                "platform": "ecosub", // str
+                "vehicle_serial": "ecosub3", // str
+                "active": true // bool
+            }
+        ],
+        "min_altitude": 0.0, // float
+        "min_velocity": 0.0, // float
+        "max_velocity": 0.0 // float
+    },
+    "detail_team": {
+        "execute_stage": true, // bool
+        "no_of_vehicles": 1, // int
+        "vehicles": [
+            {
+                "id": 1, // int
+                "platform": "autosub-hover", // str
+                "vehicle_serial": "ah1", // str
+                "active": true // bool
+            }
+        ],
+        "min_altitude": 0.0, // float
+        "min_velocity": 0.0, // float
+        "max_velocity": 0.0 // float
+    },
+    "environment": {
+        "region_of_interest": 0.0, // float
+        "exclusion_zone": 0.0 // float
+    }
+}
\ No newline at end of file
diff --git a/examples/autonomy_engine/mission_plan.json b/examples/autonomy_engine/mission_plan.json
new file mode 100644
index 0000000..e69de29
diff --git a/examples/autosub_c2/sample_autosub.alr-3.v1.mission_script.sbd b/examples/autosub_c2/sample_autosub.alr-3.v1.mission_script.sbd
new file mode 100644
index 0000000000000000000000000000000000000000..8bb401d29c37cb88a6a069a2fe6d51ab536761e1
GIT binary patch
literal 94
zcmZQ%WS0N3;Jypnbw?&f200A|AUNoLRKuwG_Mcb5M>Q_V-28Kg^$x2fgCv872meQ)
lv;z<`GH`|-)o}QH<Il6iqZ%1gul=cIsAb>+LL^1^x&YG`9?<{*

literal 0
HcmV?d00001

diff --git a/examples/autosub_c2/sample_decoded_ah1_status.json b/examples/autosub_c2/sample_decoded_ah1_status.json
new file mode 100644
index 0000000..fe6c911
--- /dev/null
+++ b/examples/autosub_c2/sample_decoded_ah1_status.json
@@ -0,0 +1,199 @@
+{
+    "reason": "ready",
+    "gps_source": "internal",
+    "gps_lat": 60.16048651129611,
+    "gps_lon": -1.156730960091541,
+    "gps_fix_seconds_ago": 1665580800,
+    "alr_data": {
+      "format_version": "ocsv3",
+      "message_type": "H",
+      "message_source": 3,
+      "transmit_timestamp": 1665580753.564244,
+      "content_mask": 18410715202459939000,
+      "depth": -1.304158329963684,
+      "water_conductivity": 0,
+      "water_temperature": 0,
+      "max_depth": 0,
+      "altitude": 1000,
+      "min_altitude": 0,
+      "vehicle_heading": -58.08430862426758,
+      "water_speed": -0.000008320044798892923,
+      "time_since_last_gps": 1665580800,
+      "time_on_surface": 7814.99365234375,
+      "w_hours": 28.418603897094727,
+      "battery_current": 0.4806833267211914,
+      "battery_max_current": 65.45500183105469,
+      "battery_voltage": 25.113433837890625,
+      "battery_min_voltage": 23.034000396728516,
+      "leak_sensor_output": 9,
+      "ground_fault_sensor_out": 752,
+      "propeller_rpm": 0,
+      "rs485_fault_flags": {},
+      "rs232_fault_flags": {},
+      "helm_state": {
+        "8": "idle"
+      },
+      "max_abort_link_state": 358,
+      "health_events": {},
+      "helm_events": {
+        "14": "waiting"
+      },
+      "log_storage_space": 98649407488,
+      "sbd_parser_error": {},
+      "alr_warning": 0,
+      "compass_align_value": -1.8788431882858276,
+      "battery_energy_used": 0,
+      "dead_nodes": {},
+      "position": {
+        "latitude": 60.16048651129611,
+        "longitude": -1.156730960091541
+      },
+      "pth_1": {
+        "pressure_temp": 2.0399177074432373,
+        "pressure": 593,
+        "temp": 17.80158233642578,
+        "rel_humidity": 7
+      },
+      "pth_2": {
+        "pressure_temp": 1.9932914972305298,
+        "pressure": 574,
+        "temp": 14.916650772094727,
+        "rel_humidity": 16
+      },
+      "rs232_mute_counts": {
+        "port00": 0,
+        "port01": 0,
+        "port02": 0,
+        "port03": 0,
+        "port04": 0,
+        "port05": 0,
+        "port06": 0,
+        "port07": 0,
+        "port08": 0,
+        "port09": 0,
+        "port10": 0,
+        "port11": 0,
+        "port12": 0,
+        "port13": 0,
+        "port14": 0,
+        "port15": 0
+      },
+      "rs485_mute_counts": {
+        "port00": 0,
+        "port01": 0,
+        "port02": 0,
+        "port03": 0,
+        "port04": 0,
+        "port05": 0,
+        "port06": 0,
+        "port07": 0,
+        "port08": 0,
+        "port09": 0,
+        "port10": 0,
+        "port11": 0,
+        "port12": 0,
+        "port13": 0,
+        "port14": 0,
+        "port15": 0
+      },
+      "helm_state_bitmask": 8388608,
+      "helm_state_bitstring": "00000000100000000000000000000000",
+      "helm_events_bitmask": 562949953421312,
+      "helm_events_bitstring": "0000000000000010000000000000000000000000000000000000000000000000",
+      "health_events_bitmask": 0,
+      "health_events_bitstring": "0000000000000000000000000000000000000000000000000000000000000000",
+      "sbd_parser_error_bitmask": 128,
+      "sbd_parser_error_bitstring": "10000000",
+      "dead_nodes_bitmask": 0,
+      "dead_nodes_bitstring": "0000000000000000000000000000000000000000000000000000000000000000",
+      "rs232_fault_flags_bitmask": 0,
+      "rs232_fault_flags_bitstring": "0000000000000000",
+      "rs485_fault_flags_bitmask": 0,
+      "rs485_fault_flags_bitstring": "0000000000000000",
+      "rudder_status": {
+        "errors": [
+          "current_info_not_received"
+        ],
+        "error_bitmask": 16,
+        "error_bitstring": "00010000",
+        "angle": 0
+      },
+      "sternplane_status": {
+        "errors": [
+          "current_info_not_received"
+        ],
+        "error_bitmask": 16,
+        "error_bitstring": "00010000",
+        "angle": 0
+      },
+      "auv_roll": -0.8640746474266052,
+      "auv_pitch": 0.2900053858757019,
+      "biocam_status": {
+        "biocam_current_mode": 9,
+        "biocam_cam_0_image_count": 0,
+        "biocam_cam_1_image_count": 0,
+        "biocam_cpu_temperature": 273,
+        "biocam_cam_0_temperature": 273,
+        "biocam_cam_1_temperature": 273,
+        "biocam_available_disk_space": 0
+      },
+      "serial_states": {
+        "port01": {
+          "3": "on"
+        },
+        "port02": {
+          "3": "on"
+        },
+        "port03": {
+          "0": "off"
+        },
+        "port04": {
+          "0": "off"
+        },
+        "port05": {
+          "0": "off"
+        },
+        "port06": {
+          "0": "off"
+        },
+        "port07": {
+          "0": "off"
+        },
+        "port08": {
+          "0": "off"
+        },
+        "port09": {
+          "0": "off"
+        },
+        "port10": {
+          "3": "on"
+        },
+        "port11": {
+          "3": "on"
+        },
+        "port12": {
+          "0": "off"
+        },
+        "port13": {
+          "3": "on"
+        },
+        "port14": {
+          "0": "off"
+        },
+        "port15": {
+          "0": "off"
+        },
+        "port16": {
+          "0": "off"
+        }
+      },
+      "computed": {}
+    },
+    "serial_number": "alr-3",
+    "time": 1665580753.564244,
+    "version": "ocsv3",
+    "_kind": "comms",
+    "autosub_message_format": {
+      "git_commit_hash": "ba3e33a9e786772d9642390711cf48b0a08755ea"
+    }
+}
\ No newline at end of file
diff --git a/examples/ecosub_c2/sample_decoded_ecosub_status.txt b/examples/ecosub_c2/sample_decoded_ecosub_status.txt
new file mode 100644
index 0000000..bacf888
--- /dev/null
+++ b/examples/ecosub_c2/sample_decoded_ecosub_status.txt
@@ -0,0 +1,23 @@
+#C2#
+4338
+(4338,)
+11111111111111111000000000000000
+Health : 722
+Content_Mask : 4
+Battery Voltage : 82045
+Battery Amps : 0
+Battery Acc charge : 767
+Battery Max Amps : 548
+Battery Max Voltage : 18
+Inner pressure : 43
+Inner Temp : 4
+Inner Humidity : 0
+Max depth : 0
+Current Pitch : -80
+Max pitch : 0
+Current RPM : 0
+Surface Time : 1636015764
+last GPS Time : 0
+(b'A', 0, 60, 1636016049, 57.33663558959961, -4.444321632385254, 0, 4294934528, 722, 4, 82045, 0, 767, 548, 18, 43, 4, 0, 0, -80, 0, 0, 1636015764, 0)
+['Type', 'Version', 'Sub_Num', 'Time', 'Latitude', 'Longitude', 'Health', 'Content_Mask', 'Battery Voltage', 'Battery Amps', 'Battery Acc charge', 'Battery Max Amps', 'Battery Max Voltage', 'Inner pressure', 'Inner Temp', 'Inner Humidity', 'Max depth', 'Current Pitch', 'Max pitch', 'Current RPM', 'Surface Time', 'last GPS Time']
+(b'A', 0, 60, 1636016049, 57.33663558959961, -4.444321632385254, 0, 4294934528, 722, 4, 82045, 0, 767, 548, 18, 43, 4, 0, 0, -80, 0, 0, 1636015764, 0)
\ No newline at end of file
diff --git a/examples/gui/emergency_stop.json b/examples/gui/emergency_stop.json
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle_status_schema.py b/vehicle_status_schema.py
new file mode 100644
index 0000000..a44eb2d
--- /dev/null
+++ b/vehicle_status_schema.py
@@ -0,0 +1,84 @@
+"""
+    schemas: vehicle-specific decoded status message (DRAFT ONLY)
+"""
+from flask_restx import Api, fields
+from flask import Flask
+
+app = Flask(__name__)
+api = Api(app)
+
+vehicle_status_message_schema = api.model(
+    "VehicleStatusMessage",
+    {
+        "message_source": fields.String(
+            required=True,
+            description="Where is this message from",
+            example="autonomy_engine",
+        ),
+        "message_destination": fields.String(
+            required=True,
+            description="What is the destination of this message",
+            example="ah-1",
+        ),
+        "encoded": fields.Boolean(
+            required=True,
+            description="Is this message encoded (encoded=True, decoded=False)",
+            example=False,
+        ),
+        "serial_number": fields.String(
+            required=True,
+            description="vehicle serial number",
+            example="ah-1",
+        ),
+        "time": fields.String(
+            required=True,
+            description="Timestamp of message",
+            example="2022-11-16T00:00:00Z",
+        ),
+        "version": fields.Integer(
+            required=True,
+            description="", # we can track the version of the AE plan?
+            example="",
+        ),
+        "platform_ID": fields.Integer(
+            required=True,
+            description="Platform ID",
+            example=2,
+        ),
+        "platform_type": fields.String(
+            required=True,
+            description="The high level type of this vehicle",
+            example="alr",
+        ),
+        "platform_state": fields.String(
+            required=True,
+            description="",
+            example="SAFETY_STOP",
+        ),
+        "current_mission_state": fields.String(
+            required=True,
+            description="",
+            example="",
+        ),
+        "gps_source": fields.Float(
+            required=True,
+            description="",
+            example="",
+        ),
+        "gps_lat": fields.Float(
+            required=True,
+            description="",
+            example="",
+        ),
+        "gps_lon": fields.Float(
+            required=True,
+            description="",
+            example="",
+        ),
+        "gps_fix_seconds_ago": fields.String(
+            required=True,
+            description="",
+            example="",
+        ),
+    },
+)
-- 
GitLab