From 4bb7e51d52130d66cf578f775e7dd8ab0d31b068 Mon Sep 17 00:00:00 2001
From: Dan Jones <danjon@noc.ac.uk>
Date: Thu, 5 Sep 2024 10:40:51 +0100
Subject: [PATCH] refactor: update action schema to use geojson

---
 examples/mas-dt/mission_plan.json |  36 +++++++++
 formats/mission_plan.py           | 117 +++++++++++++++++++-----------
 project/soar/swagger.json         | 116 ++++++++++++++++++-----------
 3 files changed, 183 insertions(+), 86 deletions(-)
 create mode 100644 examples/mas-dt/mission_plan.json

diff --git a/examples/mas-dt/mission_plan.json b/examples/mas-dt/mission_plan.json
new file mode 100644
index 0000000..10b7342
--- /dev/null
+++ b/examples/mas-dt/mission_plan.json
@@ -0,0 +1,36 @@
+{
+  "header": {  
+    "message_ID": "b427003c-0000-11aa-a1eb-bvcdfghjgfdd",
+    "timestamp": "2022-11-16T00:00:00Z",
+    "version": 2,
+    "source": "autonomy_engine",
+    "destination": "soar.noc.autosub.alr-52.to_platform.mission_plan",
+    "delivery_type": "publish",
+    "encoded": false
+  },
+  "payload":{
+    "message_type": "mission_plan",
+    "platform_ID": "alr-52",
+    "autonomy_engine_plan_ID": "a427003c-0000-11aa-a1eb-bvcdfghjgfcc",
+    "plan": [
+      {
+        "action": "move",
+        "start": {
+          "type": "Point",
+          "coordinates": [
+            -3.0071,
+            50.3707
+          ]
+        },
+        "target": {
+          "type": "Point",
+          "coordinates": [
+            -3.2371,
+            52.3707,
+            0.0
+          ]
+        }
+      }
+    ]
+  }
+}
\ No newline at end of file
diff --git a/formats/mission_plan.py b/formats/mission_plan.py
index f62e823..0f58208 100644
--- a/formats/mission_plan.py
+++ b/formats/mission_plan.py
@@ -25,42 +25,6 @@ action_schema = {
             ],
             "example": "move",
         },
-        "start_point_latitude": {
-            "type": "number",
-            "format": "float",
-            "description": "Start point, y-coordinate",
-            "example": 50.37072283932642,
-        },
-        "start_point_longitude": {
-            "type": "number",
-            "format": "float",
-            "description": "Start point, x-coordinate",
-            "example": -4.187143188645706,
-        },
-        "target_waypoint_latitude": {
-            "type": "number",
-            "format": "float",
-            "description": "Target waypoint, y-coordinate",
-            "example": 50.37072283932642,
-        },
-        "target_waypoint_longitude": {
-            "type": "number",
-            "format": "float",
-            "description": "Target waypoint, x-coordinate",
-            "example": -4.187143188645706,
-        },
-        "altitude": {
-            "type": "number",
-            "format": "float",
-            "description": "Altitude of next action",
-            "example": 15.0,
-        },
-        "depth": {
-            "type": "number",
-            "format": "float",
-            "description": "Depth of next action",
-            "example": 15.0,
-        },
         "activate_payload": {
             "type": "boolean",
             "description": "To activate/deactivate sensor for Autosub "
@@ -74,9 +38,66 @@ action_schema = {
             "example": 1800.0,
         },
     },
-    "required": [
-        "target_waypoint_latitude",
-        "target_waypoint_longitude",
+    "oneOf": [
+        {
+            "type": "object",
+            "properties": {
+                "start": {
+                    "$ref": "https://geojson.org/schema/Point.json",
+                },
+                "target": {
+                    "$ref": "https://geojson.org/schema/Point.json",
+                },
+            },
+            "required": [
+                "target",
+            ],
+        },
+        {
+            "type": "object",
+            "properties": {
+                "start_point_latitude": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Start point, y-coordinate",
+                    "example": 50.37072283932642,
+                },
+                "start_point_longitude": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Start point, x-coordinate",
+                    "example": -4.187143188645706,
+                },
+                "target_waypoint_latitude": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Target waypoint, y-coordinate",
+                    "example": 50.37072283932642,
+                },
+                "target_waypoint_longitude": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Target waypoint, x-coordinate",
+                    "example": -4.187143188645706,
+                },
+                "altitude": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Altitude of next action",
+                    "example": 15.0,
+                },
+                "depth": {
+                    "type": "number",
+                    "format": "float",
+                    "description": "Depth of next action",
+                    "example": 15.0,
+                },
+            },
+            "required": [
+                "target_waypoint_latitude",
+                "target_waypoint_longitude",
+            ],
+        },
     ],
 }
 
@@ -90,10 +111,20 @@ mission_plan_schema = {
             "enum": ["mission_plan"],
         },
         "autonomy_engine_plan_ID": {
-            "type": "integer",
-            "description": "Unique identifier for this plan"
-            + "generated by the Autonomy Engine",
-            "example": 3,
+            "oneOf": [
+                {
+                    "type": "string",
+                    "format": "uuid",
+                    "description": "Unique identifier for this plan"
+                    + "generated by the Autonomy Engine",
+                },
+                {
+                    "type": "integer",
+                    "description": "Unique identifier for this plan"
+                    + "generated by the Autonomy Engine",
+                    "example": 3,
+                },
+            ]
         },
         "platform_ID": {
             "type": "string",
diff --git a/project/soar/swagger.json b/project/soar/swagger.json
index 2296040..2ff1d4f 100644
--- a/project/soar/swagger.json
+++ b/project/soar/swagger.json
@@ -1449,9 +1449,18 @@
       "mission_plan": {
         "properties": {
           "autonomy_engine_plan_ID": {
-            "description": "Unique identifier for this plangenerated by the Autonomy Engine",
-            "example": 3,
-            "type": "integer"
+            "oneOf": [
+              {
+                "description": "Unique identifier for this plangenerated by the Autonomy Engine",
+                "format": "uuid",
+                "type": "string"
+              },
+              {
+                "description": "Unique identifier for this plangenerated by the Autonomy Engine",
+                "example": 3,
+                "type": "integer"
+              }
+            ]
           },
           "emergency": {
             "default": false,
@@ -1469,6 +1478,67 @@
           },
           "plan": {
             "items": {
+              "oneOf": [
+                {
+                  "properties": {
+                    "start": {
+                      "$ref": "#/components/schemas/geojson.org.schema.Point.json"
+                    },
+                    "target": {
+                      "$ref": "#/components/schemas/geojson.org.schema.Point.json"
+                    }
+                  },
+                  "required": [
+                    "target"
+                  ],
+                  "type": "object"
+                },
+                {
+                  "properties": {
+                    "altitude": {
+                      "description": "Altitude of next action",
+                      "example": 15.0,
+                      "format": "float",
+                      "type": "number"
+                    },
+                    "depth": {
+                      "description": "Depth of next action",
+                      "example": 15.0,
+                      "format": "float",
+                      "type": "number"
+                    },
+                    "start_point_latitude": {
+                      "description": "Start point, y-coordinate",
+                      "example": 50.37072283932642,
+                      "format": "float",
+                      "type": "number"
+                    },
+                    "start_point_longitude": {
+                      "description": "Start point, x-coordinate",
+                      "example": -4.187143188645706,
+                      "format": "float",
+                      "type": "number"
+                    },
+                    "target_waypoint_latitude": {
+                      "description": "Target waypoint, y-coordinate",
+                      "example": 50.37072283932642,
+                      "format": "float",
+                      "type": "number"
+                    },
+                    "target_waypoint_longitude": {
+                      "description": "Target waypoint, x-coordinate",
+                      "example": -4.187143188645706,
+                      "format": "float",
+                      "type": "number"
+                    }
+                  },
+                  "required": [
+                    "target_waypoint_latitude",
+                    "target_waypoint_longitude"
+                  ],
+                  "type": "object"
+                }
+              ],
               "properties": {
                 "action": {
                   "description": "Autonomy Engine's action from `move`, `payload`, `dive`, `send_hits`, `scanline`, `scanpoint`.",
@@ -1492,42 +1562,6 @@
                   "example": true,
                   "type": "boolean"
                 },
-                "altitude": {
-                  "description": "Altitude of next action",
-                  "example": 15.0,
-                  "format": "float",
-                  "type": "number"
-                },
-                "depth": {
-                  "description": "Depth of next action",
-                  "example": 15.0,
-                  "format": "float",
-                  "type": "number"
-                },
-                "start_point_latitude": {
-                  "description": "Start point, y-coordinate",
-                  "example": 50.37072283932642,
-                  "format": "float",
-                  "type": "number"
-                },
-                "start_point_longitude": {
-                  "description": "Start point, x-coordinate",
-                  "example": -4.187143188645706,
-                  "format": "float",
-                  "type": "number"
-                },
-                "target_waypoint_latitude": {
-                  "description": "Target waypoint, y-coordinate",
-                  "example": 50.37072283932642,
-                  "format": "float",
-                  "type": "number"
-                },
-                "target_waypoint_longitude": {
-                  "description": "Target waypoint, x-coordinate",
-                  "example": -4.187143188645706,
-                  "format": "float",
-                  "type": "number"
-                },
                 "timeout": {
                   "description": "Timeout set to perform action",
                   "example": 1800.0,
@@ -1535,10 +1569,6 @@
                   "type": "number"
                 }
               },
-              "required": [
-                "target_waypoint_latitude",
-                "target_waypoint_longitude"
-              ],
               "type": "object"
             },
             "type": "array"
-- 
GitLab