npm package: @samtec-ash/fireflyi2cserver
Description: Firefly I2C backend server
Author: Adam Page
Latest version: 2.0.8

# FireFlyI2CServer

## Overview

FireFly I2C Server is used to perform I2C read and write
operations to FireFly's EEPROM over IPC. The design attempts to be stateless and enable __redux__ oriented actions over IPC.

**Supported FireFly Variants:**  
* FireFly ECUOB04 (28 GHz)
* FireFly ECUO14B04 (14 GHz)
* FireFly ECUOT12
* FireFly ECUOR12

### Publishing to NPM registry

```bash
yarn run prepublish
```

### Installation

Local install:
```bash
yarn add @samtec-ash/fireflyi2cserver
```
Global install:
```bash
yarn global add @samtec-ash/fireflyi2cserver --prefix /usr/local
```

### Environmental Variables
* NODE_ENV: development, production
* ENV_TEST: true, false
* IPC_ADDRESS: IPC IP Address to use. Defaults to localhost.
* IPC_PORT: IPC IP Port to use. Defaults to 7777
* I2C_WRITE_DELAY: Delay between i2c writes.
* I2C_READ_DELAY: Delay between i2c reads.
* I2C_PAGE_DELAY: Delay between EEPROM pages changes.
* I2C_INT_PINS: FireFly interrupt pins
* I2C_PRS_PINS: FireFly present pins
* I2C_RST_PINS: FireFly reset pins
* I2C_SLT_PINS: FireFly select pins

### Run

```bash
./node_modules/.bin/fireflyi2cserver
```

### Actions:
#### DETECT_FIREFLYS
Input Payload:
```javascript
{
  actionUUID: string,
  action: 'DETECT_FIREFLYS',
  payload: null
}
```
Output Payload:
```javascript
{
  action: 'DETECT_FIREFLYS',
  success: boolean,
  error: string | null,
  payload: Array<FireFlyStatus>
}
```

#### READ_FIREFLY_STATUS
Input Payload:
```javascript
{
  action: 'READ_FIREFLY_STATUS',
  payload: {
    ids: ?Array<string>
  }
}
```
Output Payload:
```javascript
{
  action: 'READ_FIREFLY_STATUS',
  success: boolean,
  error: string | null,
  payload: Array<FireFlyStatus>
}
```

####  READ_FIREFLY_EEPROM
Input Payload:
```javascript
{
  action: 'READ_FIREFLY_EEPROM',
  payload: {
    id: string,
    fields: Array<string>
  }
}
```
Output Payload:
```javascript
{
  action: 'READ_FIREFLY_EEPROM',
  success: boolean,
  error: string | null,
  payload: {
    status: FireFlyStatus,
    fields: Array<FireFlyField>
  }
}
```

#### WRITE_FIREFLY_EEPROM
Input Payload:
```javascript
{
  action: 'WRITE_FIREFLY_EEPROM',
  payload: {
    id: string,
    fields: Array<FireFlyField>
  }
}
```
Output Payload:
```javascript
{
  action: 'WRITE_FIREFLY_EEPROM',
  success: boolean,
  error: string | null,
  payload: {
    status: FireFlyStatus
  }
}
```

### Types:
```javascript
type GPIOSetting = {
  +pin: number,
  +dir: "output" | "input",
  +value: "low" | "high"
}

type FireFlyStatus = {
  +id: string,  // Serial Number
  +name: string,
  +type: string,
  +i2cAddress: string,
  +gpioSettings: [GPIOSetting],
  +connected: bool,
  +error: string,  
};

type FireFlyField = {
  +name: string,
  +value: boolean|string|number|Array<boolean|string|number>
}

type FireFlyECUOB04 = {
  // General Indicator
  +serialNumber: string,
  +partNumber: string,
  +firmwareVersion: string,
  +eepromVersion: string,
  +vendorDate: string,
  +temperature: number,
  +voltage1v8: number,
  +voltage3v3: number,
  +temperatureHighAlarm: Array<boolean>,
  +temperatureLowAlarm: Array<boolean>,
  +temperatureHighWarn: Array<boolean>,
  +temperatureLowWarn: Array<boolean>,  
  +temperatureTimes: Array<number>,
  +voltage1v8HighAlarm: Array<boolean>,  
  +voltage1v8LowAlarm: Array<boolean>,  
  +voltage1v8HighWarn: Array<boolean>,  
  +voltage1v8LowWarn: Array<boolean>,  
  +voltage3v3HighAlarm: Array<boolean>,  
  +voltage3v3LowAlarm: Array<boolean>,  
  +voltage3v3HighWarn: Array<boolean>,  
  +voltage3v3LowWarn: Array<boolean>,  
  // RX Control
  +rxEnable: Array<boolean>,
  +rxPolarityInvert: Array<boolean>,
  +rxOutputVoltageSwing: Array<number>,
  +rxOutputPreEmphasis: Array<number>,
  +rxCDREnable: Array<boolean>,
  +rxCDRRate: Array<number>,
  // RX Indicator
  +rxRSSIStatus: Array<number>,
  +rxLOSStatus: Array<boolean>,
  +rxLOLStatus: Array<boolean>,
  // TX Control
  +txEnable: Array<boolean>,
  +txPolarityInvert: Array<boolean>,
  +txInputEqualization: Array<number>,
  +txCDREnable: Array<boolean>,
  +txCDRRate: Array<number>,
  +txSquelch: Array<boolean>,
  // TX Indicator
  +txRSSIStatus: Array<number>,
  +txLOSStatus: Array<boolean>,
  +txLOLStatus: Array<boolean>,
  +txFault: Array<boolean>
}

type FireFlyECUOT12 = {
  // General Indicator
  +serialNumber: string,
  +partNumber: string,
  +firmwareVersion: string,
  +eepromVersion: string,
  +vendorDate: string,
  +temperature: number,
  +voltage3v3: number,
  +temperatureHighAlarm: Array<boolean>,
  +temperatureLowAlarm: Array<boolean>,
  +temperatureTimes: Array<number>,
  +voltage3v3HighAlarm: Array<boolean>,  
  +voltage3v3LowAlarm: Array<boolean>,  
  // TX Control
  +txEnable: Array<boolean>,
  +txPolarityInvert: Array<boolean>,
  // TX Indicator
  +txFault: Array<boolean>
}

type FireFlyECUOR12 = {
  // General Indicator
  +serialNumber: string,
  +partNumber: string,
  +firmwareVersion: string,
  +eepromVersion: string,
  +vendorDate: string,
  +temperature: number,
  +voltage3v3: number,
  +temperatureHighAlarm: Array<boolean>,
  +temperatureLowAlarm: Array<boolean>,
  +temperatureTimes: Array<number>,
  +voltage3v3HighAlarm: Array<boolean>,  
  +voltage3v3LowAlarm: Array<boolean>,  
  // RX Control
  +rxEnable: Array<boolean>,
  +rxOutputEnable: Array<boolean>,
  +rxOutputVoltageSwing: Array<number>,
  +rxOutputPreEmphasis: Array<number>,
  // RX Indicator
  +rxLOSStatus: Array<boolean>,
}
```