Popufare Notes
===

This is a scratch space to write down some notes about the system.

See `PopuFare-Documentation.md` for a more thorough explanation.

* **Location**:
* **Description**:
* **Mailboxes**:
* **Server Connections**:

There is a central server that maintains a database of passes, vehicle positions
and administrator logins.
Each deployed bus unit has a collection of processes that maintain a local copy
of the database and communicate back to the central server to both push updates and receive
updates.

The bus units (BU) have a local communication pub/sub system.
The BUs also have various processes connected to the central servers maintenance processes
via an SSH tunnel through various ports.

### BU Mailboxes

| | | | | |
|---|---|---|---|---|
| `MAILBOX_BILLING_LOG` | `MAILBOX_BILL_STATUS` | `MAILBOX_BROADCAST`   | `MAILBOX_DRIVER_NOTIFY`       | `MAILBOX_DRIVER_STATUS` |
| `MAILBOX_ERROR`       | `MAILBOX_EXIT`        | `MAILBOX_FLUSH_PASSES`        | `MAILBOX_GPS_STATUS`  | `MAILBOX_HELLO` |
| `MAILBOX_HUP` | `MAILBOX_NAME_MAX`    | `MAILBOX_NEXT_STOP`   | `MAILBOX_PADDLE_ACK`  | `MAILBOX_PASS_STATUS` |
| `MAILBOX_PING`        | `MAILBOX_PIU_MESSAGE` | `MAILBOX_PONG`        | `MAILBOX_PREV_STOP`   | `MAILBOX_RULE_CALL` |
| `MAILBOX_SET_PADDLE`  | `MAILBOX_STATUS_REQUEST`      | `MAILBOX_STOP_STATUS` | `MAILBOX_SUBSCRIBE`   | `MAILBOX_TOKEN_MAG` |
| `MAILBOX_TOKEN_RFID`  | `MAILBOX_UNSUBSCRIBE` | `MAILBOX_UPDATE_PASSES`       | `MAILBOX_VAULT_DROP`  | `MAILBOX_WIRETAP` |

The 'system' mailboxes are:

* `MAILBOX_GPS_STATUS`
* `MAILBOX_STOP_STATUS`
* `MAILBOX_DRIVER_STATUS`
* `MAILBOX_PASS_STATUS`
* `MAILBOX_BILL_STATUS`
* `MAILBOX_EXIT`
* `MAILBOX_HUP`
* `MAILBOX_PING`

### BU Peripheral Management

The linux board communicates through the serial channels to microcontrollers that control the various peripherals.

There are four (4) serial communication lines:

* `CONSOLE_PORT` - for direct console output
* `DRIVER_UI_PORT` - communication to the microcontroller managing the `touchscreen`, `GPS`, `vault`, `clock`
* `PASSENGER_UI_PORT` - communication to the microcontroller manaing the PIU `LCD`, `RFID`, `magstripe`
* `MODEM_PORT` - ppp connection to the GPRS modem for connectivity

The only BU processes that are in 'direct' communication with the peripherals are the `diu_minder` and the `piu_minder`, both
managing the appropriate peripherals listed above.

Once an event is detected (for example, a magstripe read), the appropriate process can send a message to the mailboxes
that need it for processing.

`ipc_server`
---

* **Location**: `commhub/`
* **Description**: A pub/sub message intermediary that takes care of message subscriptions and dispatch

`piu_minder`
---

* **Location**: `PIU/`
* **Description**: Communicates with the Passenger Interface Unit (PIU) to display messages, beep and get messages from the PIU such as magstripe swipes or RFID reads

`diu_minder`
---

* **Location**: `DIU/`
* **Description**: Screen updates, paddle stop advancement, driver login

`avls`
---

* **Location**: `avls/`
* **Description**: GPS messages
* **Mailboxes**: `MAILBOX_STATUS_REQUEST` 
* **Server Connections**: `avls_server` (port `2857`)

`paddlemgr`
---

* **Location**: `avls/`
* **Description**: Paddle maintenance while driving


`billdb`
---

* **Location**: `billdb/`
* **Description**: Communicates with the server to update pass information

`passdb`
---

* **Location**: `passdb/`
* **Description**: Updates local pass database with local pass updates as well as pass updates received from server

`passdb` loads the scheme rules file (`rules.scm`), the RFID patterns file (`xx`)


scripts
---

There are also a variety of scripts that run to keep track of all the services that are running on the BU.

### `update_loop.sh`

* **Location**: `client_scripts/`
* **Description**: starts `client_supervisor`, downloads 'firmware' updates and configuration

### `ppp-dialer.sh`

* **Location**: `ppp-dialer/etc/ppp/`
* **Description**: setup GPRS modem, create SSH tunnel back to central server



Notes
---

Testing:

(from [SO](https://stackoverflow.com/questions/52187/virtual-serial-port-for-linux))

```
socat -d -d pty,raw,echo=0,link=/tmp/ttyTEST0 pty,raw,echo=0,link=/tmp/ttyTEST1
```



