// Autogenerated C header file for Common registers and commands
#ifndef _JACDAC_SPEC_SYSTEM_H
#define _JACDAC_SPEC_SYSTEM_H 1

#define JD_SERVICE_CLASS_SYSTEM  0x1ffffff1
#define JD_ANNOUNCE_INTERVAL 500

// enum ReadingThreshold (uint8_t)
#define JD_READING_THRESHOLD_NEUTRAL 0x1
#define JD_READING_THRESHOLD_INACTIVE 0x2
#define JD_READING_THRESHOLD_ACTIVE 0x3

// enum StatusCodes (uint16_t)
#define JD_STATUS_CODES_READY 0x0
#define JD_STATUS_CODES_INITIALIZING 0x1
#define JD_STATUS_CODES_CALIBRATING 0x2
#define JD_STATUS_CODES_SLEEPING 0x3
#define JD_STATUS_CODES_WAITING_FOR_INPUT 0x4
#define JD_STATUS_CODES_CALIBRATION_NEEDED 0x64

/**
 * No args. Enumeration data for control service; service-specific advertisement data otherwise.
 * Control broadcasts it automatically every `announce_interval`ms, but other service have to be queried to provide it.
 */
#define JD_CMD_ANNOUNCE 0x0

/**
 * Report: No args
 */

/**
 * No args. Registers number `N` is fetched by issuing command `0x1000 | N`.
 * The report format is the same as the format of the register.
 */
#define JD_CMD_GET_REGISTER 0x1000

/**
 * Report: No args
 */

/**
 * No args. Registers number `N` is set by issuing command `0x2000 | N`, with the format
 * the same as the format of the register.
 */
#define JD_CMD_SET_REGISTER 0x2000

/**
 * No args. Request to calibrate a sensor. The report indicates the calibration is done.
 */
#define JD_CMD_CALIBRATE 0x2

/**
 * Report: No args
 */

/**
 * This report may be emitted by a server in response to a command (action or register operation)
 * that it does not understand.
 * The `service_command` and `packet_crc` fields are copied from the command packet that was unhandled.
 * Note that it's possible to get an ACK, followed by such an error report.
 */
#define JD_CMD_COMMAND_NOT_IMPLEMENTED 0x3
typedef struct jd_system_command_not_implemented_report {
    uint16_t service_command;
    uint16_t packet_crc;
} jd_system_command_not_implemented_report_t;


/**
 * Read-write uint32_t. This is either binary on/off (0 or non-zero), or can be gradual (eg. brightness of an RGB LED strip).
 */
#define JD_REG_INTENSITY 0x1

/**
 * Read-write int32_t. The primary value of actuator (eg. servo pulse length, or motor duty cycle).
 */
#define JD_REG_VALUE 0x2

/**
 * Constant int32_t. The lowest value that can be reported for the value register.
 */
#define JD_REG_MIN_VALUE 0x110

/**
 * Constant int32_t. The highest value that can be reported for the value register.
 */
#define JD_REG_MAX_VALUE 0x111

/**
 * Read-write mA uint16_t. Limit the power drawn by the service, in mA.
 */
#define JD_REG_MAX_POWER 0x7

/**
 * Read-write # uint8_t. Asks device to stream a given number of samples
 * (clients will typically write `255` to this register every second or so, while streaming is required).
 */
#define JD_REG_STREAMING_SAMPLES 0x3

/**
 * Read-write ms uint32_t. Period between packets of data when streaming in milliseconds.
 */
#define JD_REG_STREAMING_INTERVAL 0x4

/**
 * Read-only int32_t. Read-only value of the sensor, also reported in streaming.
 */
#define JD_REG_READING 0x101

/**
 * Read-write uint32_t. For sensors that support it, sets the range (sometimes also described `min`/`max_reading`).
 * Typically only a small set of values is supported.
 * Setting it to `X` will select the smallest possible range that is at least `X`,
 * or if it doesn't exist, the largest supported range.
 */
#define JD_REG_READING_RANGE 0x8

/**
 * Constant. Lists the values supported as `reading_range`.
 */
#define JD_REG_SUPPORTED_RANGES 0x10a
typedef struct jd_system_supported_ranges {
    uint32_t range[0];
} jd_system_supported_ranges_t;


/**
 * Constant int32_t. The lowest value that can be reported by the sensor.
 */
#define JD_REG_MIN_READING 0x104

/**
 * Constant int32_t. The highest value that can be reported by the sensor.
 */
#define JD_REG_MAX_READING 0x105

/**
 * Read-only uint32_t. The real value of whatever is measured is between `reading - reading_error` and `reading + reading_error`. It should be computed from the internal state of the sensor. This register is often, but not always `const`. If the register value is modified,
 * send a report in the same frame of the `reading` report.
 */
#define JD_REG_READING_ERROR 0x106

/**
 * Constant uint32_t. Smallest, yet distinguishable change in reading.
 */
#define JD_REG_READING_RESOLUTION 0x108

/**
 * Read-write int32_t. Threshold when reading data gets inactive and triggers a `inactive`.
 */
#define JD_REG_INACTIVE_THRESHOLD 0x5

/**
 * Read-write int32_t. Thresholds when reading data gets active and triggers a `active` event.
 */
#define JD_REG_ACTIVE_THRESHOLD 0x6

/**
 * Constant ms uint32_t. Preferred default streaming interval for sensor in milliseconds.
 */
#define JD_REG_STREAMING_PREFERRED_INTERVAL 0x102

/**
 * Constant uint32_t. The hardware variant of the service.
 * For services which support this, there's an enum defining the meaning.
 */
#define JD_REG_VARIANT 0x107

/**
 * Read-write string (bytes). An optional register in the format of a URL query string where the client can provide hints how
 * the device twin should be rendered. If the register is not implemented, the client library can simulate the register client side.
 */
#define JD_REG_CLIENT_VARIANT 0x9

/**
 * Reports the current state or error status of the device. `code` is a standardized value from
 * the Jacdac status/error codes. `vendor_code` is any vendor specific error code describing the device
 * state. This report is typically not queried, when a device has an error, it will typically
 * add this report in frame along with the announce packet.
 */
#define JD_REG_STATUS_CODE 0x103
typedef struct jd_system_status_code {
    uint16_t code;  // StatusCodes
    uint16_t vendor_code;
} jd_system_status_code_t;


/**
 * Constant string (bytes). A friendly name that describes the role of this service instance in the device.
 */
#define JD_REG_INSTANCE_NAME 0x109

/**
 * Notifies that the service has been activated (eg. button pressed, network connected, etc.)
 */
#define JD_EV_ACTIVE 0x1

/**
 * Notifies that the service has been dis-activated.
 */
#define JD_EV_INACTIVE 0x2

/**
 * Notifies that the some state of the service changed.
 */
#define JD_EV_CHANGE 0x3

/**
 * Notifies that the status code of the service changed.
 */
#define JD_EV_STATUS_CODE_CHANGED 0x4
typedef struct jd_system_status_code_changed {
    uint16_t code;  // StatusCodes
    uint16_t vendor_code;
} jd_system_status_code_changed_t;


/**
 * Notifies that the threshold is back between `low` and `high`.
 */
#define JD_EV_NEUTRAL 0x7

#endif
