|
| 1 | +# Agent Guidelines for nodejs-poolcontroller-dashpanel |
| 2 | + |
| 3 | +This document provides guidance for AI agents working on this codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is the **dashboard/web UI** for nodejs-poolController, providing: |
| 8 | +- Message Manager for protocol analysis and debugging |
| 9 | +- Entity Flow Analyzer for entity-centric packet analysis |
| 10 | +- Real-time pool equipment monitoring interface |
| 11 | + |
| 12 | +## Key Documentation |
| 13 | + |
| 14 | +### Protocol & Entity Flow Analysis |
| 15 | + |
| 16 | +When working with **Message Manager**, **Entity Flow**, **packet parsing**, or **protocol analysis**: |
| 17 | + |
| 18 | +**ALWAYS READ FIRST**: |
| 19 | +- `.plan/ENTITY_FLOW_ANALYZER.md` - Complete guide to entity types, byte offsets, and extraction logic |
| 20 | + |
| 21 | +This document contains: |
| 22 | +- Packet → Entity mapping tables with exact byte offsets |
| 23 | +- Circuit/Feature/Body state extraction logic |
| 24 | +- Flow Timeline (flame graph) span types |
| 25 | +- Step-by-step guide for adding new entity types |
| 26 | +- Common bugs and fixes (e.g., Action 2 circuit offset is 2, not 3) |
| 27 | + |
| 28 | +### Message Documentation |
| 29 | + |
| 30 | +When working with **packet structures** or **protocol messages**: |
| 31 | +- `server/messages/docs/messageDoc.json` - Detailed packet documentation |
| 32 | +- `server/messages/docs/entityFlow.json` - Entity type definitions and matchers |
| 33 | +- `server/messages/docs/constants.json` - Device address names and constants |
| 34 | + |
| 35 | +### Key Source Files |
| 36 | + |
| 37 | +| Area | Files | |
| 38 | +|------|-------| |
| 39 | +| Entity Flow Widget | `scripts/messages/entityFlow/entityFlow.widget.js` | |
| 40 | +| Entity Extraction | `scripts/messages/entityFlow/intellicenterMappings.js` | |
| 41 | +| Entity Flow Styles | `scripts/messages/entityFlow/entityFlow.css` | |
| 42 | +| Message List Widget | `scripts/messages/messageList/messageList.widget.js` | |
| 43 | +| Main Page | `pages/messageManager.html` | |
| 44 | + |
| 45 | +## Critical Implementation Notes |
| 46 | + |
| 47 | +### IntelliCenter Circuit Offsets |
| 48 | + |
| 49 | +**Action 2 (Status Broadcast)** payload layout: |
| 50 | +``` |
| 51 | +[0] = hours |
| 52 | +[1] = minutes |
| 53 | +[2] = circuits 1-8 ← Spa = bit 0, Pool = bit 5 |
| 54 | +[3] = circuits 9-16 |
| 55 | +[4] = circuits 17-24 |
| 56 | +[5] = circuits 25-32 |
| 57 | +[6] = circuits 33-40 |
| 58 | +[7] = circuit groups (lower) + features 129-132 (upper nibble) |
| 59 | +... |
| 60 | +``` |
| 61 | + |
| 62 | +**Action 30/15 and 168/15** have circuits starting at byte 3 (different from Action 2). |
| 63 | + |
| 64 | +### Body State Extraction |
| 65 | + |
| 66 | +Body ON/OFF state is derived from circuit state: |
| 67 | +- **Spa** = Circuit 1 (bodyId=2 maps to circuitId=1) |
| 68 | +- **Pool** = Circuit 6 (bodyId=1 maps to circuitId=6) |
| 69 | + |
| 70 | +### State Display: Command vs Actual |
| 71 | + |
| 72 | +- `→ON` / `→OFF` = **Command** (request, WL→OCP or outbound) |
| 73 | +- `ON` / `OFF` = **Actual** state (Action 2 broadcast, OCP→Broadcast) |
| 74 | + |
| 75 | +### Action 184 Body Control (v3.004+) |
| 76 | + |
| 77 | +Payload layout: `[channelId, seq, format, reserved, targetHi, targetLo, data0, data1, data2, data3]` |
| 78 | + |
| 79 | +| Target ID | Name | Byte 6 Meaning | |
| 80 | +|-----------|------|----------------| |
| 81 | +| `168,237` | Body Toggle | 0=OFF, 1=ON | |
| 82 | +| `212,182` | Body Context | Pre-toggle context | |
| 83 | +| `114,145` | Body Select | 0=Pool, 1=Spa | |
| 84 | + |
| 85 | +### Flow Timeline Spans |
| 86 | + |
| 87 | +The flame graph detects these span types: |
| 88 | +- **Config sweep** - Extended 222→30 sessions |
| 89 | +- **Config item** - Individual 222→30 pairs |
| 90 | +- **Set circuit** - 168/184 → ACK → state readback |
| 91 | +- **Body ctrl** - Action 184 with body target IDs (168,237 / 212,182 / 114,145 / 94,131 / 108,225) |
| 92 | + |
| 93 | +## Related Projects |
| 94 | + |
| 95 | +- `nodejs-poolController` - The main pool controller server (protocol handling, equipment control) |
| 96 | +- Protocol documentation: `/Users/rgoldin/Programming/nodejs-poolController/.plan/` directory |
| 97 | + |
| 98 | +## Testing Changes |
| 99 | + |
| 100 | +After modifying entity extraction or flow timeline logic: |
| 101 | +1. Load a replay ZIP with packet logs |
| 102 | +2. Select the relevant entity type |
| 103 | +3. Verify state extraction matches expected values |
| 104 | +4. Check that byte offsets shown in "Relevant Bytes" column are correct |
| 105 | +5. Test Flow Timeline spans appear for the expected packet sequences |
| 106 | + |
0 commit comments