# Light

This repository contains code and distribution tools for the Light
STS6 vending system.

The `deprecated` directory contains the previous STS4 version of the
code for reference, nothing in that directory is used by the current
version of the code.

## Production Installation

`make tarball`: build the distribution tarball for the service

1. Create the `Light` directory on the target machine, in `/home/pi`
2. `tar xzf` the tarball in that directory
3. `./bin/pi-install` runs apt-get (ssh and ntp)
4. `./bin/go-install` installs go 1.11 (unavailable in apt)
5. Edit `etc/light` to configure this instance of the service
6. `sudo make install`: install the systemd service

## Key Loading

1. run `. etc/light` to load configuration in your current shell
2. from email, download a copy of the KMC's public key in email format
3. run `./bin/light-keyreq pubkey.txt > request.txt` (file names are up to you)
4. email the request file to the KMC
5. the KMC will email back a key load file
6. run `./bin/light-load klf.txt` to load the response
7. run `./bin/light-keyprn > keys.csv` to print the loaded keys

## Juice API

Light makes an https request to its configured Juice host to get
commands to execute on the STS6 device. It runs the commands, and
posts responses to back to Juice. See the Prism API docs.

https://api.utiliflex.com/prism-api/#introduction

`src/api/api.go` contains type definitions for the api objects, it's
shared between Light and Juice.

## Device

For the TSM 250, The device `/tty/ACM0` is supported out of the box by
`Linux raspberrypi 4.14.71-v7+ #1145 SMP Fri Sep 21 15:38:35 BST 2018 armv7l GNU/Linux`

At connection time, light runs the `stty` executable to set the device
to `raw` mode (no echo, no line ending translation) which is necessary
for the device to work properly.

The TSM 500 provides a TCP interface on port 5100, and the `DEVICE`
environment variable should be set to the IP address and port for the
device, e.g. `192.168.1.50:5100`. The TSM 500 should not be directly
addressable by the internet, it is unsecured.

## Running tests

You may need to edit the top of the Makefile to set local
configuration (security module IP address, api key).

- `Make lint`: recursively run `golangci-lint` on the code
- `make test-unit`: run unit tests
- `make test-dev`: run integration tests against a running juice api
- `make test-spec`: run the STS 531-10-02 tests
