serial_console.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. #include "serial_console.h"
  2. #include "radio.h"
  3. #include "rf_diag.h"
  4. #include "rf_link.h"
  5. #include "haptics.h"
  6. #include "bonds.h"
  7. #include "config.h"
  8. #include "puck_hid.h" // g_cmdCapture (feature-command capture toggle)
  9. #include "fault_diag.h"
  10. #include <Adafruit_TinyUSB.h>
  11. #include <Arduino.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14. // CDC commands: l=listen, s=stop, cN=channel, p<hex>=prefix, a<8hex>=base addr, b=bonds, etc.
  15. // Command order matters: else-if chain, FIRST matching letter wins. 'C' and 'H' appear twice; the second
  16. // occurrence is unreachable.
  17. void serialConsolePoll()
  18. {
  19. static char line[24];
  20. static uint8_t li = 0;
  21. while (Serial.available()) {
  22. char c = Serial.read();
  23. if (c == '\n' || c == '\r') {
  24. line[li] = 0;
  25. // FULL factory wipe -- requires the exact word "ERASE-ALL" so it can't be fat-fingered. Reformats the
  26. // internal FS (cfg.bin + bonds.bin gone), reboots into clean defaults; controller must be re-paired.
  27. if (!strcmp(line, "ERASE-ALL")) {
  28. Serial.println(
  29. "# ERASING ALL persistent storage (config + bonds)...");
  30. factoryErase();
  31. Serial.println(
  32. "# done -- rebooting into clean defaults; re-pair the controller");
  33. delay(40);
  34. faultDiagArmIntentionalReset();
  35. NVIC_SystemReset();
  36. } else if (!strcmp(line, "AMP")) {
  37. // A/B: land Steam's amp/haptic 0x87 config (0x18/0x2E/0x34/0x35) so haptics play as ticks
  38. g_landAmp = !g_landAmp;
  39. Serial.printf(
  40. "# land amp/haptic 0x87 config %s\n",
  41. g_landAmp ? "ON" : "off");
  42. } else if (!strcmp(line, "S81")) {
  43. // A/B: drop Steam's relayed 0x81 CLEAR_DIGITAL_MAPPINGS (the connect amp-clicker)
  44. g_drop81 = !g_drop81;
  45. Serial.printf(
  46. "# drop relayed 0x81 (Steam mode) %s\n",
  47. g_drop81 ? "ON" : "off");
  48. } else if (!strcmp(line, "FC")) {
  49. // feature-command capture: log Steam's USB SET/GET commands to serial + suppress I45
  50. g_cmdCapture = !g_cmdCapture;
  51. Serial.printf(
  52. "# feature-cmd capture %s (I45 %s)\n",
  53. g_cmdCapture ? "ON" : "off",
  54. g_cmdCapture ? "suppressed" : "on");
  55. } else if (!strcmp(line, "L87")) {
  56. // EXPERIMENT: land all relayed 0x87 config verbatim (real-puck relay) vs the discard-whitelist.
  57. // Exact-match string (single letters are all taken; 'l' alone = rfListenStart).
  58. g_landAll87 = !g_landAll87;
  59. saveCfg();
  60. Serial.printf(
  61. "# land-all-0x87 (verbatim 0x87 relay) %s\n",
  62. g_landAll87 ? "ON" : "off");
  63. } else if (!strcmp(line, "FR")) {
  64. // re-dump the flight recorder trail captured before the last watchdog hang (also printed
  65. // automatically at boot, but CDC may not be attached yet then -- this reprints on demand).
  66. faultDiagDumpFlight();
  67. } else if (!strcmp(line, "VIT")) {
  68. // toggle the live per-second CDC vitals line (loop rate / usbd stack / heap / relay trend)
  69. g_vitals = !g_vitals;
  70. Serial.printf("# live vitals line %s\n",
  71. g_vitals ? "ON" : "off");
  72. } else if (line[0] == 'l')
  73. rfListenStart();
  74. else if (line[0] == 'B') {
  75. g_rfBeacon = !g_rfBeacon;
  76. g_rfListen = false;
  77. Serial.printf("# beacon %s ch%u\n",
  78. g_rfBeacon ? "ON" : "off",
  79. g_rfCh);
  80. } else if (line[0] == 'L') {
  81. g_plen = strtol(line + 1, 0, 16);
  82. Serial.printf("# plen=%02X\n", g_plen);
  83. } else if (line[0] == '1') {
  84. g_s1incl = !g_s1incl;
  85. Serial.printf("# s1incl=%u\n", g_s1incl);
  86. } else if (line[0] == 'R') {
  87. g_rfCh = atoi(line + 1);
  88. g_rfRaw = true;
  89. g_rfListen = false;
  90. g_rfBeacon = false;
  91. rfRawStart(g_rfCh);
  92. Serial.printf("# raw cap ch%u\n", g_rfCh);
  93. } else if (line[0] == 'Z') {
  94. g_rfRaw = true;
  95. g_rfSweep = true;
  96. g_rfListen = false;
  97. g_rfBeacon = false;
  98. g_rfCh = 2;
  99. rfRawStart(g_rfCh);
  100. Serial.println("# raw SWEEP");
  101. } else if (line[0] == 'H') {
  102. g_rfHost = !g_rfHost;
  103. g_rfBeacon = false;
  104. g_rfListen = false;
  105. g_rfRaw = false;
  106. g_rfSweep = false;
  107. g_rfCh = 2;
  108. Serial.printf(
  109. "# HOSTFRAME beacon %s base %02X%02X%02X%02X (slot0 uuids %02X%02X%02X%02X/%02X%02X%02X%02X)\n",
  110. g_rfHost ? "ON" : "off", g_rfBase[0],
  111. g_rfBase[1], g_rfBase[2], g_rfBase[3],
  112. g_slot[0].rec[0], g_slot[0].rec[1],
  113. g_slot[0].rec[2], g_slot[0].rec[3],
  114. g_slot[0].rec[4], g_slot[0].rec[5],
  115. g_slot[0].rec[6], g_slot[0].rec[7]);
  116. } else if (line[0] == 'C') {
  117. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  118. g_rfHost = false;
  119. rfRespondStart();
  120. } else if (line[0] == 's') {
  121. g_rfListen = false;
  122. g_rfBeacon = false;
  123. g_rfRaw = false;
  124. g_rfSweep = false;
  125. g_rfHost = false;
  126. g_rfRespond = false;
  127. NRF_RADIO->TASKS_DISABLE = 1;
  128. Serial.println("# RF off");
  129. } else if (line[0] == 'u') {
  130. // id9=0 hold (MODE_STEAM only) A/B toggle (persisted; see haptics.h LIZKEEP_MS)
  131. g_lizKeep = !g_lizKeep;
  132. saveCfg();
  133. Serial.printf(
  134. "# id9=0 hold (Steam mode, /%ums) %s\n",
  135. (unsigned)LIZKEEP_MS,
  136. g_lizKeep ? "ON" : "off");
  137. }
  138. // switch USB mode: 0=steam 1=xbox 2=hori 3=lizard 4=swpro 5=ps5 6=hidgyro 7=ps5-game/clean 8=ds4-game/clean 9=ps3(dualshock3)
  139. else if (line[0] == 'x') {
  140. uint8_t m = strtoul(line + 1, 0, 10);
  141. if (modeValid(m)) {
  142. if (USBDevice.suspended()) {
  143. Serial.println(
  144. "# mode change blocked: host suspended");
  145. } else {
  146. Serial.printf(
  147. "# switch mode %u (reboot)\n",
  148. m);
  149. delay(20);
  150. saveMode(m);
  151. delay(40);
  152. faultDiagArmIntentionalReset();
  153. NVIC_SystemReset();
  154. }
  155. }
  156. } else if (line[0] == 'c') {
  157. g_rfCh = atoi(line + 1);
  158. Serial.printf("# ch=%u\n", g_rfCh);
  159. if (g_rfListen)
  160. rfListenStart();
  161. } else if (line[0] == 'p') {
  162. g_rfPrefix = strtol(line + 1, 0, 16);
  163. Serial.printf("# prefix=%02X\n", g_rfPrefix);
  164. if (g_rfListen)
  165. rfListenStart();
  166. } else if (line[0] == 'i') {
  167. g_crcinit = strtoul(line + 1, 0, 16);
  168. Serial.printf("# crcinit=%06lX\n",
  169. (unsigned long)g_crcinit);
  170. } else if (line[0] == 'w') {
  171. g_whiteiv = atoi(line + 1);
  172. Serial.printf("# whiteiv=%u\n", g_whiteiv);
  173. } else if (line[0] == '0') {
  174. g_pcnf0 = strtoul(line + 1, 0, 16);
  175. Serial.printf("# pcnf0=%08lX\n",
  176. (unsigned long)g_pcnf0);
  177. } else if (line[0] == '2') {
  178. g_pcnf1 = strtoul(line + 1, 0, 16);
  179. Serial.printf("# pcnf1=%08lX\n",
  180. (unsigned long)g_pcnf1);
  181. } else if (line[0] == 'M') {
  182. g_mode = strtoul(line + 1, 0, 16);
  183. Serial.printf(
  184. "# mode=%u (3=Ble1M,4=Ble2M,0/2=Nrf)\n",
  185. g_mode);
  186. } else if (line[0] == 'I') {
  187. g_crcinit = strtoul(line + 1, 0, 16);
  188. Serial.printf("# crcinit=%08lX\n",
  189. (unsigned long)g_crcinit);
  190. } else if (line[0] == 'P') {
  191. g_crcpoly = strtoul(line + 1, 0, 16);
  192. Serial.printf("# crcpoly=%lX\n",
  193. (unsigned long)g_crcpoly);
  194. } else if (line[0] == 'N') {
  195. g_crccnf = strtoul(line + 1, 0, 16);
  196. Serial.printf("# crccnf=%X\n", g_crccnf);
  197. } else if (line[0] == 'Y') {
  198. g_rfCap = true;
  199. g_rfCapOne = true;
  200. g_rfReplay = g_rfHost = g_rfAuto = false;
  201. g_rfCh = 2;
  202. rfCapStart(2);
  203. Serial.println(
  204. "# capture ONE frame for replay...");
  205. } else if (line[0] == 'y') {
  206. g_rfReplay = !g_rfReplay;
  207. g_rfCap = g_rfHost = g_rfAuto = false;
  208. Serial.printf("# REPLAY %s (%uB)\n",
  209. g_rfReplay ? "ON" : "off",
  210. g_replayLen);
  211. } else if (line[0] == 'T') {
  212. g_statlen = strtoul(line + 1, 0, 16);
  213. g_pcnf1 = 0;
  214. Serial.printf("# statlen=%02X\n", g_statlen);
  215. } else if (line[0] == 'k') {
  216. g_connOn = !g_connOn;
  217. if (g_connOn) {
  218. g_connSt = 0;
  219. g_connStep = 0;
  220. g_connPoll = 0;
  221. g_connF1 = 0;
  222. }
  223. Serial.printf(
  224. "# CONN mode %s: %s%s poll on ch%u (param=%02X). F1 seen=%lu\n",
  225. g_connOn ? "ON" : "off",
  226. g_e7announce ? "E7-awake[00 00] -> " :
  227. "",
  228. g_pollGet ? "E3+GET-report-0x45" :
  229. "bare E3",
  230. g_rfCh, g_getParam,
  231. (unsigned long)g_connF1);
  232. } else if (line[0] == 'q') {
  233. g_getParam = g_getParam ? 0x00 : 0x2D;
  234. Serial.printf("# GET-0x45 param=%02X\n",
  235. g_getParam);
  236. } else if (line[0] == 'v') {
  237. g_connVerbose = !g_connVerbose;
  238. Serial.printf(
  239. "# conn verbose %s (F1 seen=%lu)\n",
  240. g_connVerbose ? "ON" : "off",
  241. (unsigned long)g_connF1);
  242. } else if (line[0] == 'C') {
  243. g_sessCh = strtoul(line + 1, 0, 10);
  244. Serial.printf(
  245. "# session channel=%u (re-pair/reconnect to apply)\n",
  246. g_sessCh);
  247. } else if (line[0] == 'E') {
  248. g_mDiv = strtoul(line + 1, 0, 10);
  249. if (g_mDiv < 4)
  250. g_mDiv = 4;
  251. saveCfg();
  252. Serial.printf(
  253. "# xbox-mouse sensitivity divisor=%d (lower=faster)\n",
  254. g_mDiv);
  255. } else if (line[0] == 'F') {
  256. g_mFric = strtoul(line + 1, 0, 10);
  257. if (g_mFric > 99)
  258. g_mFric = 99;
  259. saveCfg();
  260. Serial.printf(
  261. "# xbox-mouse friction=%d%% (higher=more glide/momentum)\n",
  262. g_mFric);
  263. } else if (line[0] == 'W') {
  264. // A/B swap edits the ACTIVE emulated type (Xbox/Switch/DS4/DS5); puck modes have none.
  265. if (g_etype < ET_COUNT) {
  266. g_type[g_etype].abSwap =
  267. !g_type[g_etype].abSwap;
  268. applyActiveType();
  269. saveCfg();
  270. Serial.printf(
  271. "# A/B + X/Y swap %s (Nintendo layout) [type %u]\n",
  272. g_abSwap ? "ON" : "off",
  273. g_etype);
  274. } else
  275. Serial.println(
  276. "# A/B swap N/A in this mode (Steam/Lizard are not emulated types)");
  277. } else if (line[0] == 'K') {
  278. int i = line[1] - '0';
  279. uint8_t code = strtoul(line + 2, 0, 10);
  280. // back paddles edit the ACTIVE emulated type. code 18 = Capture/Screenshot (Switch only).
  281. if (i >= 0 && i < 4 && g_etype < ET_COUNT) {
  282. g_type[g_etype].back[i] = code;
  283. applyActiveType();
  284. saveCfg();
  285. Serial.printf(
  286. "# back[%d] (%s) -> code %u [type %u] [0=none 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n",
  287. i,
  288. (const char *[]){ "L4", "R4",
  289. "L5",
  290. "R5" }[i],
  291. code, g_etype);
  292. } else if (g_etype >= ET_COUNT)
  293. Serial.println(
  294. "# back map N/A in this mode (Steam/Lizard are not emulated types)");
  295. else
  296. Serial.println(
  297. "# usage: K<0-3> <code> (0=L4 1=R4 2=L5 3=R5)");
  298. } else if (line[0] == 'Q') {
  299. uint8_t code = strtoul(line + 1, 0, 10);
  300. if (g_etype < ET_COUNT) {
  301. g_type[g_etype].qamMap = code;
  302. applyActiveType();
  303. saveCfg();
  304. Serial.printf(
  305. "# QAM -> code %u [type %u] [0=default 1=A 2=B 3=X 4=Y 5=LB 6=RB 7=L3 8=R3 9=Back 10=QAM 11=Guide 12=Dup 13=Ddown 14=Dleft 15=Dright 16=TouchClick 17=Mute 18=Capture(Switch) 19=LT/L2/ZL 20=RT/R2/ZR]\n",
  306. code, g_etype);
  307. } else
  308. Serial.println(
  309. "# QAM map N/A in this mode (Steam/Lizard are not emulated types)");
  310. } else if (line[0] == 'J') {
  311. char *sp = 0;
  312. uint8_t id = strtoul(line + 1, &sp, 0);
  313. // inject SET-SETTINGS to controller: report 0x87 [id][val u16 LE]
  314. uint16_t val = sp ? strtoul(sp, 0, 0) : 0;
  315. uint8_t pl[3] = { id, (uint8_t)(val & 0xFF),
  316. (uint8_t)(val >> 8) };
  317. // console-injected writes go to all connected controllers (no specific slot in scope)
  318. relayEnqueue(0x87, pl, 3, 0xFF);
  319. Serial.printf(
  320. "# queued SET-SETTINGS id=0x%02X val=%u (relay 0x87) — watch new=/s\n",
  321. id, val);
  322. } else if (line[0] == 'G') {
  323. g_sniff = !g_sniff;
  324. g_sniffPh = 0;
  325. g_rfHost = g_connOn = g_rfCap = g_rfAuto =
  326. g_rfReplay = false;
  327. if (g_sniff)
  328. rfSniffStart();
  329. Serial.printf(
  330. "# SESSION SNIFF %s (phase0: catch host frame on ibex/ch2; phase1 PARK ch=%s)\n",
  331. g_sniff ? "ON" : "off",
  332. g_sniffPark ? "override" : "primary");
  333. } else if (line[0] == 'g') {
  334. g_sniffPark = strtoul(line + 1, 0, 10);
  335. if (g_sniffPh == 1)
  336. rfSniffStart();
  337. Serial.printf(
  338. "# sniff park channel=%u (0=learned primary)\n",
  339. g_sniffPark);
  340. } else if (line[0] == 'V') {
  341. g_e7b = strtoul(line + 1, 0, 10);
  342. Serial.printf(
  343. "# E7 protocol-version B-byte=%u (0=awake/slow, 1=try v1-fast; watch new=/s; revert if input stops)\n",
  344. g_e7b);
  345. } else if (line[0] == 'O') {
  346. g_relayOp = strtoul(line + 1, 0, 16);
  347. Serial.printf("# relay opcode=%02X\n",
  348. g_relayOp);
  349. } else if (line[0] == 'o') {
  350. g_relaySub = strtoul(line + 1, 0, 16);
  351. Serial.printf("# relay sub-type=%02X\n",
  352. g_relaySub);
  353. } else if (line[0] == 'h') {
  354. uint8_t nc = strtoul(line + 1, 0, 10);
  355. Serial.printf(
  356. "# HOP %u->%u (advertise on current ch, then poll new). Watch F1=/s\n",
  357. g_sessCh, nc);
  358. rfHopTo(nc);
  359. } else if (line[0] == 'z') {
  360. g_qos = !g_qos;
  361. g_hopIdx = 0;
  362. g_qosBad = 0;
  363. g_qosCheckMs = millis();
  364. Serial.printf(
  365. "# QoS adaptive channel hopping %s (candidates 18,46,76,22,68)\n",
  366. g_qos ? "ON" : "off");
  367. } else if (line[0] == 'U') {
  368. // Per-slot debug dump: which controllers are connected, their RSSI, haptic-block
  369. // state, and session address. Quick at-a-glance view for multi-controller testing.
  370. Serial.printf("# session ch%u, curSlot=%d\n",
  371. g_sessCh, g_curSlot);
  372. for (int s = 0; s < NSLOT; s++) {
  373. bool live = g_slot[s].used &&
  374. g_connReplyMs[s] != 0;
  375. unsigned long age =
  376. live ? (unsigned long)(millis() -
  377. g_connReplyMs
  378. [s]) :
  379. 0;
  380. int rssi =
  381. g_linkRssi[s] ?
  382. (int)g_linkRssi[s] -
  383. RSSI_DBM_OFFSET :
  384. 0;
  385. unsigned long now_ms = millis();
  386. unsigned long blk =
  387. (g_hapticBlockUntil[s] &&
  388. (int32_t)(g_hapticBlockUntil[s] -
  389. now_ms) > 0) ?
  390. (g_hapticBlockUntil[s] -
  391. now_ms) :
  392. 0;
  393. Serial.printf(
  394. "# slot %d: %s addr %02X%02X%02X%02X/%02X rssi=%ddBm conn=%lums ago batt=%u%% haptic-block=%lums uuid %02X%02X%02X%02X %02X%02X%02X%02X\n",
  395. s,
  396. g_slot[s].used ?
  397. (live ? "LIVE" :
  398. "BONDED") :
  399. "empty",
  400. g_sessBase[s][0],
  401. g_sessBase[s][1],
  402. g_sessBase[s][2],
  403. g_sessBase[s][3],
  404. g_sessPrefix[s], rssi, age,
  405. g_battery[s], blk,
  406. g_slot[s].rec[0],
  407. g_slot[s].rec[1],
  408. g_slot[s].rec[2],
  409. g_slot[s].rec[3],
  410. g_slot[s].rec[4],
  411. g_slot[s].rec[5],
  412. g_slot[s].rec[6],
  413. g_slot[s].rec[7]);
  414. }
  415. } else if (line[0] == 'r') {
  416. // poll RX-window is FIXED (not configurable) -- report only.
  417. Serial.printf(
  418. "# poll RX-window=%lu us (FIXED; poll rate caps ~%lu/s)\n",
  419. (unsigned long)g_rxWin,
  420. (unsigned long)(1000000 / g_rxWin));
  421. } else if (line[0] == 'e') {
  422. g_e3mode = strtoul(line + 1, 0, 10);
  423. Serial.printf(
  424. "# E3 poll PID mode=%u (0=fixed07, 1=cyclePID+noack1, 2=cyclePID+noack0) - watch new=/s\n",
  425. g_e3mode);
  426. } else if (line[0] == 'd') {
  427. g_pollGet = !g_pollGet;
  428. Serial.printf(
  429. "# poll = %s (real puck sends BARE E3) - watch F1=/s new=/s\n",
  430. g_pollGet ?
  431. "E3 + GET-report-0x45 TLV (legacy)" :
  432. "bare E3");
  433. } else if (line[0] == 'n') {
  434. g_e7announce = !g_e7announce;
  435. Serial.printf(
  436. "# E7 awake-announce %s (real puck never sends E7) - watch F1=/s\n",
  437. g_e7announce ? "ON (legacy)" : "off");
  438. } else if (line[0] == 'm') {
  439. g_e1keepalive = !g_e1keepalive;
  440. Serial.printf(
  441. "# session-channel E1 keepalive %s (real puck sends none; needed for shared addr) - watch F1=/s\n",
  442. g_e1keepalive ? "ON" : "off");
  443. } else if (line[0] == 't') {
  444. // inject n test haptics (output 0x82 [01 01 F7]) over the relay
  445. uint8_t n = line[1] ? strtoul(line + 1, 0, 10) :
  446. 40;
  447. g_testHaptic = n;
  448. Serial.printf(
  449. "# test-haptic burst x%u queued (relay 0x82 01 01 F7 via op=%02X sub=%02X)\n",
  450. n, g_relayOp, g_relaySub);
  451. }
  452. // dump the captured OUTPUT-report history (oldest->newest)
  453. else if (line[0] == 'H') {
  454. hapticDumpLog();
  455. } else if (line[0] == 'j') {
  456. g_connType = strtoul(line + 1, 0, 16);
  457. Serial.printf("# connType=%02X\n", g_connType);
  458. } else if (line[0] == 'Q') {
  459. g_connLen = strtoul(line + 1, 0, 16);
  460. Serial.printf("# connLen=%02X\n", g_connLen);
  461. } else if (line[0] == 'A') {
  462. g_balen = strtoul(line + 1, 0, 16);
  463. g_pcnf1 = 0;
  464. Serial.printf("# balen=%u\n", g_balen);
  465. } else if (line[0] == 'a') {
  466. uint32_t v = strtoul(line + 1, 0, 16);
  467. g_rfBase[0] = v >> 24;
  468. g_rfBase[1] = v >> 16;
  469. g_rfBase[2] = v >> 8;
  470. g_rfBase[3] = v;
  471. Serial.printf("# base=%08lX\n",
  472. (unsigned long)v);
  473. if (g_rfListen)
  474. rfListenStart();
  475. } else if (line[0] == 'b') {
  476. for (int i = 0; i < NSLOT; i++)
  477. if (g_slot[i].used) {
  478. Serial.printf("slot%d ", i);
  479. for (int j = 0; j < 24; j++)
  480. Serial.printf(
  481. "%02X",
  482. g_slot[i].rec[j]);
  483. Serial.println();
  484. }
  485. } else if (line[0] == 'D') {
  486. armDebugCdcNextBoot();
  487. Serial.println(
  488. "# debug-CDC armed: reset to KEEP the serial console one more boot (auto-reverts after; the wake mouse is dropped that boot)");
  489. } else if (line[0] == 'X') {
  490. g_rfCap = !g_rfCap;
  491. g_rfHost = g_rfAuto = g_rfBeacon = g_rfListen =
  492. g_rfRaw = g_rfSweep = g_rfRespond =
  493. false;
  494. g_rfCh = 2;
  495. g_capV = 0;
  496. if (g_rfCap)
  497. rfCapStart(g_rfCh);
  498. Serial.printf(
  499. "# CAPTURE(listen) %s ch%u on \"ibex\", cycling 1M/2M x BALEN3/4 (use cN to set ch)\n",
  500. g_rfCap ? "ON" : "off", g_rfCh);
  501. } else if (line[0] == 'S') {
  502. g_rfAuto = !g_rfAuto;
  503. g_rfHost = g_rfAuto;
  504. g_rfBeacon = g_rfListen = g_rfRaw = g_rfSweep =
  505. false;
  506. g_rfCh = 2;
  507. g_cfgIdx = 0;
  508. if (g_rfAuto)
  509. applyCfg(0);
  510. Serial.printf("# AUTOSWEEP %s\n",
  511. g_rfAuto ? "ON" : "off");
  512. }
  513. li = 0;
  514. } else if (li < sizeof line - 1)
  515. line[li++] = c;
  516. }
  517. }