Skip to content

Instantly share code, notes, and snippets.

@tkurki
Last active November 16, 2021 20:42
Show Gist options
  • Save tkurki/73ebbfaec2ad1474d623d5f39c4c87b5 to your computer and use it in GitHub Desktop.
Save tkurki/73ebbfaec2ad1474d623d5f39c4c87b5 to your computer and use it in GitHub Desktop.
Signal K value handling examples

Number valued PathValue

Delta

{
  "updates": [
    {
      "values": [
        {
          "path": "navigation.speedOverGround",
          "value": 2.5
        }
      ]
    }
  ]
}

Full

{
  "vessels": {
    "self": {
      "navigation": {
        "speedOverGround": {
          "value": 2.5,
          "$source": "input-test",
          "timestamp": "2021-11-16T20:15:39.190Z"
        }
      }
    }
  }
}

Full resulting from same path from multiple sources. value holds the "best" value per the server's policy (current implementation just puts the latest value there) and values the values from all sources.

{
  "vessels": {
    "self": {
      "navigation": {
        "speedOverGround": {
          "value": 2.4,
          "$source": "source2",
          "timestamp": "2021-11-16T20:22:17.632Z",
          "values": {
            "input-test": {
              "value": 2.5,
              "timestamp": "2021-11-16T20:15:39.190Z"
            },
            "source2": {
              "value": 2.4,
              "timestamp": "2021-11-16T20:22:17.632Z"
            }
          }
        }
      }
    }
  }
}

Object valued PathValue

Delta

{
  "updates": [
    {
      "values": [
        {
          "path": "navigation.position",
          "value": {
            "latitude": 51.4934,
            "longitude": 0.0098
          }
        }
      ]
    }
  ]
}

Full

{
  "vessels": {
    "self": {
      "navigation": {
        "position": {
          "value": {
            "latitude": 51.4934,
            "longitude": 0.0098
          },
          "$source": "input-test",
          "timestamp": "2021-11-16T20:33:33.812Z"
        }
      }
    }
  }
}

Special case: Object valued Pathvalue with empty path

If the path is empty the value is simply merged into the full model, with no timestamps, source data or value/values structure.

Some paths in the specification schema are defined like this, mainly because they are static in nature and source of the data is not really meaningful for them.

Delta

{
  "updates": [
    {
      "values": [
        {
          "path": "",
          "value": {
            "communication": {
              "callsignVhf": "TheShip"
            }
          }
        }
      ]
    }
  ]
}

Full

{
  "vessels": {
    "self": {
      "communication": {
        "callsignVhf": "TheShip"
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment