@jcoreio/iron-pi-device-client
Version:
Client library for reading and writing Iron Pi input and output states
99 lines (81 loc) • 2.5 kB
Flow
// @flow
export const METHOD_GET_NETWORK_STATE = 'getNetworkState'
export const METHOD_GET_NETWORK_SETTINGS = 'getNetworkSettings'
export const METHOD_SET_NETWORK_SETTINGS = 'setNetworkSettings'
export const METHOD_IS_SSH_ENABLED = 'isSSHEnabled'
export const METHOD_SET_SSH_ENABLED = 'setSSHEnabled'
export const METHOD_SET_SYSTEM_PASSWORD = 'setSystemPassword'
export type DeviceModel = {
name: string, // e.g. 'iron-pi-cm8' or 'iron-pi-io16'
version: string,
numDigitalInputs: number,
numDigitalOutputs: number,
numAnalogInputs: number,
hasConnectButton: boolean,
}
export type DetectedDevice = {
address: number,
ioOffset: number, // Offset of the first I/O point on this device, e.g. 0 for the first device, 8 for the second device if the first device has 8 channels
model: DeviceModel,
}
export type HardwareInfo = {
devices: ?Array<DetectedDevice>,
serialNumber: string,
accessCode: string,
}
export type DeviceInputState = {
address: number,
ioOffset: number, // Offset of the first I/O point on this device, e.g. 0 for the first device, 8 for the second device if the first device has 8 channels
digitalInputs: Array<boolean>,
digitalInputEventCounts: Array<number>,
digitalOutputs: Array<boolean>,
analogInputs: Array<number>,
connectButtonPressed?: boolean,
connectButtonEventCount?: number,
}
export type DeviceInputStates = {
inputStates: Array<DeviceInputState>,
hasError: boolean,
}
export type MethodValue = Object | string | boolean | number
export type MessageFromDriver = {
hardwareInfo?: HardwareInfo,
deviceInputStates?: DeviceInputStates,
methodSerial?: number,
methodResult?: MethodValue,
methodError?: string,
}
export type DeviceOutputState = {
address: number,
levels: Array<boolean>,
}
export type SetOutputs = {
outputs: Array<DeviceOutputState>,
}
export type LEDCommand = {
address: number,
colors: string, // e.g. 'gg' or 'ggrr'
onTime?: number,
offTime?: number,
idleTime?: number,
}
export type SetLEDs = {
leds: Array<LEDCommand>,
}
export type MessageToDriver = {
setOutputs?: SetOutputs,
setLEDs?: SetLEDs,
methodName?: string,
methodSerial?: number,
methodArg?: MethodValue,
}
export type IPv4Address = string
export type DNSServers = string
export type NetworkSettings = {|
dhcpEnabled: boolean,
ipAddress?: ?IPv4Address,
netmask?: ?IPv4Address,
gateway?: ?IPv4Address,
dnsServers?: ?DNSServers,
|}
export const UNIX_SOCKET_PATH = '/tmp/socket-iron-pi'