{
  "name": "DeviceScript Manager",
  "status": "experimental",
  "shortId": "devicescriptmanager",
  "camelName": "deviceScriptManager",
  "shortName": "deviceScriptManager",
  "extends": [
    "_base"
  ],
  "notes": {
    "short": "Allows for deployment and control over DeviceScript virtual machine.\n\nPrograms start automatically after device restart or uploading of new program.\nYou can stop programs until next reset by setting the `running` and `autostart` registers to `false`.",
    "events": "When program is running, `status_code == Ready`.\nWhen there is a valid program, but it is not running, `status_code == Sleeping`.\nWhen there is no valid program, `status_code == WaitingForInput`."
  },
  "classIdentifier": 288680491,
  "enums": {},
  "constants": {},
  "packets": [
    {
      "kind": "report",
      "name": "command_not_implemented",
      "identifier": 3,
      "description": "This report may be emitted by a server in response to a command (action or register operation)\nthat it does not understand.\nThe `service_command` and `packet_crc` fields are copied from the command packet that was unhandled.\nNote that it's possible to get an ACK, followed by such an error report.",
      "fields": [
        {
          "name": "service_command",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "packet_crc",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "identifierName": "command_not_implemented",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "const",
      "name": "instance_name",
      "identifier": 265,
      "description": "A friendly name that describes the role of this service instance in the device.\nIt often corresponds to what's printed on the device:\nfor example, `A` for button A, or `S0` for servo channel 0.\nWords like `left` should be avoided because of localization issues (unless they are printed on the device).",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "instance_name",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "ro",
      "name": "status_code",
      "identifier": 259,
      "description": "Reports the current state or error status of the device. ``code`` is a standardized value from \nthe Jacdac status/error codes. ``vendor_code`` is any vendor specific error code describing the device\nstate. This report is typically not queried, when a device has an error, it will typically\nadd this report in frame along with the announce packet. If a service implements this register,\nit should also support the ``status_code_changed`` event defined below.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "rw",
      "name": "client_variant",
      "identifier": 9,
      "description": "An optional register in the format of a URL query string where the client can provide hints how\nthe device twin should be rendered. If the register is not implemented, the client library can simulate the register client side.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "optional": true,
      "identifierName": "client_variant",
      "packFormat": "s",
      "derived": "_base"
    },
    {
      "kind": "event",
      "name": "status_code_changed",
      "identifier": 4,
      "description": "Notifies that the status code of the service changed.",
      "fields": [
        {
          "name": "code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "vendor_code",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "identifierName": "status_code_changed",
      "packFormat": "u16 u16",
      "derived": "_base"
    },
    {
      "kind": "command",
      "name": "deploy_bytecode",
      "identifier": 128,
      "description": "Open pipe for streaming in the bytecode of the program. The size of the bytecode has to be declared upfront.\nTo clear the program, use `bytecode_size == 0`.\nThe bytecode is streamed over regular pipe data packets.\nThe bytecode shall be fully written into flash upon closing the pipe.\nIf `autostart` is true, the program will start after being deployed.\nThe data payloads, including the last one, should have a size that is a multiple of 32 bytes.\nThus, the initial bytecode_size also needs to be a multiple of 32.",
      "fields": [
        {
          "name": "bytecode_size",
          "unit": "B",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "unique": true,
      "hasReport": true,
      "packFormat": "u32"
    },
    {
      "kind": "report",
      "name": "deploy_bytecode",
      "identifier": 128,
      "description": "Open pipe for streaming in the bytecode of the program. The size of the bytecode has to be declared upfront.\nTo clear the program, use `bytecode_size == 0`.\nThe bytecode is streamed over regular pipe data packets.\nThe bytecode shall be fully written into flash upon closing the pipe.\nIf `autostart` is true, the program will start after being deployed.\nThe data payloads, including the last one, should have a size that is a multiple of 32 bytes.\nThus, the initial bytecode_size also needs to be a multiple of 32.",
      "fields": [
        {
          "name": "bytecode_port",
          "type": "pipe_port",
          "storage": 2
        }
      ],
      "secondary": true,
      "pipeType": "deploy_bytecode",
      "packFormat": "u16"
    },
    {
      "kind": "command",
      "name": "read_bytecode",
      "identifier": 129,
      "description": "Get the current bytecode deployed on device.",
      "fields": [
        {
          "name": "bytecode",
          "type": "pipe",
          "storage": 12
        }
      ],
      "pipeType": "read_bytecode",
      "packFormat": "b[12]"
    },
    {
      "kind": "pipe_report",
      "name": "bytecode",
      "identifier": 0,
      "description": "Get the current bytecode deployed on device.",
      "fields": [
        {
          "name": "data",
          "type": "bytes",
          "storage": 0,
          "isSimpleType": true
        }
      ],
      "pipeType": "read_bytecode",
      "packFormat": "b"
    },
    {
      "kind": "rw",
      "name": "running",
      "identifier": 128,
      "description": "Indicates if the program is currently running.\nTo restart the program, stop it (write `0`), read back the register to make sure it's stopped,\nstart it, and read back.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "rw",
      "name": "autostart",
      "identifier": 129,
      "description": "Indicates wheather the program should be re-started upon `reboot()` or `panic()`.\nDefaults to `true`.",
      "fields": [
        {
          "name": "_",
          "type": "bool",
          "storage": 1
        }
      ],
      "packFormat": "u8"
    },
    {
      "kind": "ro",
      "name": "program_size",
      "identifier": 384,
      "description": "The size of current program.",
      "fields": [
        {
          "name": "_",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "ro",
      "name": "program_hash",
      "identifier": 385,
      "description": "Return FNV1A hash of the current bytecode.",
      "fields": [
        {
          "name": "_",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32"
    },
    {
      "kind": "ro",
      "name": "program_sha256",
      "identifier": 386,
      "description": "Return 32-byte long SHA-256 hash of the current bytecode.",
      "fields": [
        {
          "name": "_",
          "type": "bytes",
          "storage": 32,
          "isSimpleType": true,
          "maxBytes": 32
        }
      ],
      "packFormat": "b[32]"
    },
    {
      "kind": "const",
      "name": "runtime_version",
      "identifier": 387,
      "description": "Returns the runtime version number compatible with [Semver](https://semver.org/).\nWhen read as 32-bit little endian integer a version `7.15.500` would be `0x07_0F_01F4`.",
      "fields": [
        {
          "name": "patch",
          "type": "u16",
          "storage": 2,
          "isSimpleType": true
        },
        {
          "name": "minor",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        },
        {
          "name": "major",
          "type": "u8",
          "storage": 1,
          "isSimpleType": true
        }
      ],
      "optional": true,
      "packFormat": "u16 u8 u8"
    },
    {
      "kind": "ro",
      "name": "program_name",
      "identifier": 388,
      "description": "The name of currently running program. The compiler takes is from `package.json`.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "s"
    },
    {
      "kind": "ro",
      "name": "program_version",
      "identifier": 389,
      "description": "The version number of currently running program. The compiler takes is from `package.json`\nand `git`.",
      "fields": [
        {
          "name": "_",
          "type": "string",
          "storage": 0
        }
      ],
      "packFormat": "s"
    },
    {
      "kind": "event",
      "name": "program_panic",
      "identifier": 128,
      "description": "Emitted when the program calls `panic(panic_code)` or `reboot()` (`panic_code == 0` in that case).\nThe byte offset in byte code of the call is given in `program_counter`.\nThe program will restart immediately when `panic_code == 0` or in a few seconds otherwise.",
      "fields": [
        {
          "name": "panic_code",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        },
        {
          "name": "program_counter",
          "type": "u32",
          "storage": 4,
          "isSimpleType": true
        }
      ],
      "packFormat": "u32 u32"
    },
    {
      "kind": "event",
      "name": "program_change",
      "identifier": 3,
      "description": "Emitted after bytecode of the program has changed.",
      "fields": [],
      "identifierName": "change"
    }
  ],
  "tags": [
    "management",
    "devicescript"
  ],
  "restricted": true
}