levylabpitt / Krohn-Hite-7008

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

API methods #9

Open ciozi137 opened 4 days ago

ciozi137 commented 4 days ago

What methods should be supported? Follow conventions laid out in https://github.com/levylabpitt/Instrument-Framework/issues/91

channelProperties common schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/channelProperties",
  "definitions": {
    "channelProperties": {
      "type": "object",
      "properties": {
        "channel": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8
        },
        "gain": {
          "type": "integer",
          "enum": [1, 10, 100, 1000]
        },
        "input": {
          "type": "string",
          "enum": ["OFF", "SE+", "SE-", "DIFF"]
        },
        "shunt": {
          "type": "string",
          "enum": ["OPEN", "50", "500", "5000", "50000", "10000000"]
        },
        "couple": {
          "type": "string",
          "enum": ["AC", "DC"]
        },
        "filter": {
          "type": "string",
          "enum": ["OFF", "ON"]
        }
      },
      "required": ["channel", "gain", "input", "shunt", "couple", "filter"]
    }
  }
}

setChannel

request schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "jsonrpc": {
      "type": "string",
      "enum": ["2.0"]
    },
    "method": {
      "type": "string",
      "enum": ["setChannel"]
    },
    "params": {
      "$ref": "#/definitions/channelProperties"
    },
    "id": {
      "type": "string"
    }
  },
  "required": ["jsonrpc", "method", "params", "id"]
}

request example:

{
  "jsonrpc": "2.0",
  "method": "setChannel",
  "params": {
    "channel": 1,
    "gain": 1,
    "input": "OFF",
    "shunt": "OPEN",
    "couple": "AC",
    "filter": "OFF"
  },
  "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}

getChannel

request schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "jsonrpc": {
      "type": "string",
      "enum": ["2.0"]
    },
    "method": {
      "type": "string",
      "enum": ["getChannel"]
    },
    "params": {
      "type": "object",
      "properties": {
        "channel": {
          "$ref": "#/definitions/channelProperties/properties/channel"
        }
      },
      "required": ["channel"]
    },
    "id": {
      "type": "string"
    }
  },
  "required": ["jsonrpc", "method", "params", "id"]
}

request example:

{
    "jsonrpc": "2.0",
    "result": {
        "channel": 1,
        "gain": 1,
        "input": "OFF",
        "shunt": "50000",
        "couple": "DC",
        "filter": "OFF"
    },
    "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}

response schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "jsonrpc": {
      "type": "string",
      "enum": ["2.0"]
    },
    "result": {
      "$ref": "#/definitions/channelProperties"
    },
    "id": {
      "type": "string"
    }
  },
  "required": ["jsonrpc", "result", "id"]
}

response example:

{
    "jsonrpc": "2.0",
    "result": 
        {
            "channel": 1,
            "gain": 1,
            "input": "OFF",
            "shunt": "50000",
            "couple": "DC",
            "filter": "OFF"
        },
    "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}

setAllChannels

request schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "jsonrpc": {
      "type": "string",
      "enum": ["2.0"]
    },
    "method": {
      "type": "string",
      "enum": ["setAllChannels"]
    },
    "params": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/channelProperties"
      },
      "minItems": 1,
      "maxItems": 8
    },
    "id": {
      "type": "string"
    }
  },
  "required": ["jsonrpc", "method", "params", "id"]
}

request example

{
  "jsonrpc": "2.0",
  "method": "setAllChannels",
  "params": [
    {
      "channel": 1,
      "gain": 10,
      "input": "SE+",
      "shunt": "5000",
      "couple": "AC",
      "filter": "ON"
    },
    {
      "channel": 2,
      "gain": 100,
      "input": "OFF",
      "shunt": "OPEN",
      "couple": "DC",
      "filter": "OFF"
    }
  ],
  "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}

getAllChannels

request schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "jsonrpc": {
            "type": "string",
            "enum": ["2.0"]
        },
        "method": {
            "type": "string",
            "enum": ["getAllChannels"]
        },
        "id": {
            "type": "string"
        }
    },
    "required": ["jsonrpc","method","id"]
}

request example

{
  "jsonrpc": "2.0",
  "method": "getAllChannels",
  "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}

response schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "jsonrpc": {
            "type": "string",
            "enum": ["2.0"]
        }
    },
    "result": {
        "type": "array",
        "items": {
            "$ref": "#/definitions/channelProperties"
        },
        "minItems": 1,
        "maxItems": 8
    },
    "id": {
        "type": "string"
    },
    "required": ["jsonrpc","result","id"]
}

response example:

{
  "jsonrpc": "2.0",
  "result": [
    {
      "channel": 1,
      "gain": 10,
      "input": "SE+",
      "shunt": "5000",
      "couple": "AC",
      "filter": "ON"
    },
    {
      "channel": 2,
      "gain": 100,
      "input": "OFF",
      "shunt": "OPEN",
      "couple": "DC",
      "filter": "OFF"
    }
  ],
  "id": "ac3caf5f75f9d4ed9b1bf5cd8a3812d2"
}
ciozi137 commented 4 days ago

Remove support for "all" in channel#: it is not supported by the hardware e,g, AL;S/cr; I don't see the point in having it to set all channels the same...just call setChannel N times

ciozi137 commented 3 days ago

refactor and move to issue description

ciozi137 commented 3 days ago

Database schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "items": {
        "$ref": "#/definitions/channelProperties"
    },
    "minItems": 1,
    "maxItems": 8
}

database example

[
  {
    "channel": 1,
    "gain": 10,
    "input": "SE+",
    "shunt": "500",
    "couple": "AC",
    "filter": "ON"
  },
  {
    "channel": 2,
    "gain": 100,
    "input": "DIFF",
    "shunt": "10000000",
    "couple": "DC",
    "filter": "OFF"
  },
  {
    "channel": 3,
    "gain": 1,
    "input": "OFF",
    "shunt": "OPEN",
    "couple": "AC",
    "filter": "ON"
  }
]
ciozi137 commented 3 days ago

@pgwijesinghe given the "database schema" defined here, how do I reference the "channelProperties" defined here

pgwijesinghe commented 3 days ago

@ciozi137

  1. I don't quite understand why there is a self reference (#/definitions/channelProperties) inside channelProperties
  2. If we have channelProperties as a separate JSON (say channelPropertiesSch.json), I guess we could ref it inside the database schema with channelPropertiesSch.json#/definitions/channelProperties

i.e. (Database schema)

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "array",
    "items": {
        "$ref": "channelPropertiesSch.json#/definitions/channelProperties"
    },
    "minItems": 1,
    "maxItems": 8
}
ciozi137 commented 3 days ago

@pgwijesinghe here is what I observe:

regarding the "database schema" I'm wondering if there is a way to reference channelProperties if they are both in the same file?

something like:

{
{"channelPropertiesSch"},
{"schema that references channelPropertiesSch"}
}
ciozi137 commented 3 days ago

OK I think I see the gist of what I need. something like:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
        "channelPropertiesSch": {}
    },
    "setChannelSch": {
        "$ref": "#/channelPropertiesSch"
    },
    "getChannelSch": {
        "$ref": "#/channelPropertiesSch"
    }
}
pgwijesinghe commented 3 days ago

@ciozi137 I see. In that case, we can do something like this, right? (tested it here)

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/databaseSch", //schema selection
  "definitions": {
    "channelPropertiesSch": {
      "type": "object",
      "properties": {
        "channel": {
          "type": "integer",
          "minimum": 1,
          "maximum": 8
        },
        "gain": {
          "type": "integer",
          "enum": [1, 10, 100, 1000]
        },
        "input": {
          "type": "string",
          "enum": ["OFF", "SE+", "SE-", "DIFF"]
        },
        "shunt": {
          "type": "string",
          "enum": ["OPEN", "50", "500", "5000", "50000", "10000000"]
        },
        "couple": {
          "type": "string",
          "enum": ["AC", "DC"]
        },
        "filter": {
          "type": "string",
          "enum": ["OFF", "ON"]
        }
      },
      "required": ["channel", "gain", "input", "shunt", "couple", "filter"]
    }
  },

  "setChannelSch": {
    "$ref": "#/definitions/channelPropertiesSch"
  },

  "getChannelSch": {
    "$ref": "#/definitions/channelPropertiesSch"
  },

  "databaseSch": {
    "type": "array",
    "items": {
      "$ref": "#/definitions/channelPropertiesSch"
    },
    "minItems": 1,
    "maxItems": 8
  }
}
ciozi137 commented 3 days ago

Ah yes very nice! I see what you did here "$ref": "#/database", //schema selection. Now I think I'm getting the hang of the "entry point" for the schema. Here is the complete schema: https://github.com/levylabpitt/Krohn-Hite-7008/blob/Instrument.KH7008/jsonrpcSch.json

and test: https://www.jsonschemavalidator.net/s/n0khgPaz

ciozi137 commented 3 days ago

todo: redefine databaseSch as a $defs item e.g. channelArray or allProperties or allChannels and reuse

ciozi137 commented 3 days ago

https://github.com/levylabpitt/Krohn-Hite-7008/commit/aa0323cb27e9487081e89da6246a625a7d34a852