# TermTCP

A terminal TCP client for BPQ32 packet radio nodes, written in C with an ncurses TUI. Connects via BPQTermTCP protocol, displays split output/monitor panes, supports real-time RF frame monitoring with port filtering, multiple simultaneous sessions, and built-in forms for ICS-213 and packet check-in.

## Features

- ncurses TUI with split output and monitor panes
- BPQTermTCP protocol (compatible with QtTermTCP)
- Up to 4 simultaneous sessions with live background receive
- RF monitor with per-port and frame-type filtering
- Auto-populates port names from the BPQ server on connect
- Scrollable output and monitor windows with history
- Input history (Up/Down arrows)
- Session logging to timestamped files
- Function key bar (F1/F3–F10) at bottom of screen
- ICS-213 General Message form with F2 background send
- PKTNET Packet Check-In form
- Multiple host configuration with quick connect
- Unicode box-drawing borders on all menus

## Dependencies

- GCC
- ncurses with wide character support (`libncursesw6`)

### Install dependencies on Debian/Ubuntu

```bash
sudo apt install gcc libncurses-dev
```

## Build

```bash
make
```

The binary is `./termtcp`.

### Other make targets

```
make clean      # Remove build artifacts
make debug      # Build with debug symbols
make install    # Install to /usr/local/bin/
```

### Manual compile

```bash
gcc -Wall -Wextra -O2 -std=gnu99 -D_XOPEN_SOURCE_EXTENDED \
    -o termtcp termtcp.c -lm -lncursesw
```

## Configuration

Config is stored in `~/.BPQTermTCP.ini` and created automatically on first run. Edit it to add BPQ nodes:

```ini
[Host1]
Host=10.0.2.7
Port=17023
Username=kb8pmy
Password=yourpassword
Name=Home Node

[Host2]
Host=10.121.15.68
Port=17023
Username=kb8pmy
Password=yourpassword
Name=Water Tower
```

Port names, monitor settings, and port mask are saved here automatically when you change them in-program.

## Usage

```bash
./termtcp
```

Press **Ctrl+A** to open the menu, then select an option.

### Key bindings

| Key | Action |
|-----|--------|
| Ctrl+A | Open menu |
| Ctrl+A C | Connect to a host |
| Ctrl+A D | Disconnect current session |
| Ctrl+A N | Open a new session |
| Ctrl+A X | Close current session |
| Ctrl+A 1–4 | Switch to session 1, 2, 3, or 4 |
| Ctrl+A O | Config / host editor |
| Ctrl+A M | Monitor options |
| Ctrl+A L | Toggle session log |
| Ctrl+A F | Forms submenu (ICS-213, PKTNET check-in) |
| Ctrl+A H | Help |
| Ctrl+A Q | Quit |
| F1 | Connect |
| F3 | Monitor options |
| F4 | Config / host editor |
| F5 | Toggle log |
| F6 | Forms submenu |
| F7 | New session |
| F8 | Previous session |
| F9 | Next session |
| F10 | Quit |
| Up / Down | Input history |
| PgUp / PgDn | Scroll output window |
| Home / End | Scroll monitor window |
| Enter | Send line to server |

### Multiple sessions

Open up to 4 connections simultaneously. All sessions receive data in the background — switch between them with F8/F9 or Ctrl+A 1–4. The status bar shows `[current/total]` session count. Close the current session with Ctrl+A X (if it is the last open session, the program exits).

### Forms (Ctrl+A F)

- **ICS-213 General Message** — fills in all numbered fields, sends via F2 in the background using silence-based prompt detection
- **PKTNET Packet Check-In** — pre-formatted check-in template

### Monitor options (Ctrl+A M)

- Toggle TX, supervisor, nodes, and UI-only frame filtering
- Toggle monitor pane visibility
- Select which RF ports to monitor (Tab to switch to port list)

Port names are auto-populated from the BPQ server when you connect and saved to config.

## BPQ Protocol Notes

- Uses BPQTermTCP protocol (same wire format as QtTermTCP)
- Sends trace options on connect to enable RF monitoring
- Port list requested automatically via P8=1 on connect
- Monitor frames delimited by `0xFF 0x1B` / `0xFE` byte markers
- Port info delivered as `0xFF 0xFF` packet on connect
- NODES broadcasts filtered client-side via `>NODES` in AX.25 header

## Version

Current: **0.0.60**
