`paddlemgr`
===

This is a program to manage "paddles", the name for bus trips and bus routes.

This program is in charge of taking "advance bus stop" requests as well as monitoring
GPS messages and system time to advance the route appropriately.

Building
---

```
$ ./buildit_native.sh
```

Program Overview
---

The `paddlemgr` program manages "paddles", including bus stops and advances due to driver
input or from GPS updates.

On driver login, the driver will select a paddle which will send a message to the `paddlemgr` through
the IPC to load a paddle.
On successful paddle load, the `paddlemgr` will store the paddle in memory for use.

The GPS updates come in through the IPC hub and is processed to determine if a stop rollover should occur.
If the stop time, as recorded in the `paddle` file, is within some time window (currently set to 10mins)
and the current position is within a distance window of the stop (currently set to 60m), the stop is advanced.

The drive can manually advance stops by pressing the 'NXT' or 'PRV' buttons from the driver UI which
will send messages through the IPC to the `paddlemgr` to advance the stop.
Regardless of whether a driver signal for 'NXT', 'PRV' or an automatic stop rollover has occured,
the internal state of `paddlemgr` is updated to reflect the new stop and a message sent through the IPC
to signal what the current stop is.

Inter Process Communication (IPC)
---

| IPC Mailbox | Function |
|---|---|
| `MAILBOX_GPS_STATUS` | `handle_gps_update` |
| `MAILBOX_STATUS_REQUEST` | `handle_status_req` |
| `MAILBOX_SET_PADDLE` | `handle_set_paddle_req` |
| `MAILBOX_NEXT_STOP` | `handle_next_req` |
| `MAILBOX_PREV_STOP` | `handle_prev_req` |

| IPC Messages | Description |
|---|---|
| `MAILBOX_PADDLE_ACK` | Sent on receipt of paddle and successful paddle load (through `load_paddle`) |
| `MAILBOX_STOP_STATUS` | Sent on receipt of a "status request" messages or on stop change (through `send_status_update`) |

Quick Reference
---

| Value | Description |
|---|---|
| `CONFIG_FILE_PATH` | Default location of where to look for config files (paddles etc.). Default to `/home/bus/config`. |
| `ROLLOVER_TIME_WINDOW` | Window to consider stop if it's within +/- the time window. Default to `600` seconds (10min). |
| `ROLLOVER_DISTANCE` | Distance window to consider a stop rollover if it's within +/- the range. Default to `60.0f` (in DMM format). |

See the [Paddle Format](...) documentation for the format of the paddle file.


