소스 검색

Reorganise KISS protocol to close gaps.

ViezeVingertjes 6 달 전
부모
커밋
02ddc05c30
3개의 변경된 파일116개의 추가작업 그리고 52개의 파일을 삭제
  1. 52 27
      docs/kiss_modem_protocol.md
  2. 31 0
      examples/kiss_modem/KissModem.cpp
  3. 33 25
      examples/kiss_modem/KissModem.h

+ 52 - 27
docs/kiss_modem_protocol.md

@@ -96,17 +96,20 @@ MeshCore-specific functionality uses the standard KISS SetHardware command. The
 | Hash | `0x08` | Data to hash |
 | SetRadio | `0x09` | Freq (4) + BW (4) + SF (1) + CR (1) |
 | SetTxPower | `0x0A` | Power dBm (1) |
-| GetRadio | `0x0C` | - |
-| GetTxPower | `0x0D` | - |
-| GetVersion | `0x0F` | - |
-| GetCurrentRssi | `0x10` | - |
-| IsChannelBusy | `0x11` | - |
-| GetAirtime | `0x12` | Packet length (1) |
-| GetNoiseFloor | `0x13` | - |
-| GetStats | `0x14` | - |
-| GetBattery | `0x15` | - |
-| Ping | `0x16` | - |
-| GetSensors | `0x17` | Permissions (1) |
+| GetRadio | `0x0B` | - |
+| GetTxPower | `0x0C` | - |
+| GetCurrentRssi | `0x0D` | - |
+| IsChannelBusy | `0x0E` | - |
+| GetAirtime | `0x0F` | Packet length (1) |
+| GetNoiseFloor | `0x10` | - |
+| GetVersion | `0x11` | - |
+| GetStats | `0x12` | - |
+| GetBattery | `0x13` | - |
+| GetMCUTemp | `0x14` | - |
+| GetSensors | `0x15` | Permissions (1) |
+| GetDeviceName | `0x16` | - |
+| Ping | `0x17` | - |
+| Reboot | `0x18` | - |
 
 ### Response Sub-commands (TNC to Host)
 
@@ -121,20 +124,22 @@ MeshCore-specific functionality uses the standard KISS SetHardware command. The
 | SharedSecret | `0x27` | Shared secret (32) |
 | Hash | `0x28` | SHA-256 hash (32) |
 | OK | `0x29` | - |
-| Radio | `0x2A` | Freq (4) + BW (4) + SF (1) + CR (1) |
-| TxPower | `0x2B` | Power dBm (1) |
-| Version | `0x2D` | Version (1) + Reserved (1) |
-| Error | `0x2E` | Error code (1) |
-| TxDone | `0x2F` | Result (1): 0x00=failed, 0x01=success |
-| CurrentRssi | `0x30` | RSSI dBm (1, signed) |
-| ChannelBusy | `0x31` | Result (1): 0x00=clear, 0x01=busy |
-| Airtime | `0x32` | Milliseconds (4) |
-| NoiseFloor | `0x33` | dBm (2, signed) |
-| Stats | `0x34` | RX (4) + TX (4) + Errors (4) |
-| Battery | `0x35` | Millivolts (2) |
-| Pong | `0x36` | - |
-| Sensors | `0x37` | CayenneLPP payload |
-| RxMeta | `0x38` | SNR (1) + RSSI (1) |
+| Error | `0x2A` | Error code (1) |
+| Radio | `0x2B` | Freq (4) + BW (4) + SF (1) + CR (1) |
+| TxPower | `0x2C` | Power dBm (1) |
+| CurrentRssi | `0x2D` | RSSI dBm (1, signed) |
+| ChannelBusy | `0x2E` | Result (1): 0x00=clear, 0x01=busy |
+| Airtime | `0x2F` | Milliseconds (4) |
+| NoiseFloor | `0x30` | dBm (2, signed) |
+| Version | `0x31` | Version (1) + Reserved (1) |
+| Stats | `0x32` | RX (4) + TX (4) + Errors (4) |
+| Battery | `0x33` | Millivolts (2) |
+| MCUTemp | `0x34` | Temperature (2, signed) |
+| Sensors | `0x35` | CayenneLPP payload |
+| DeviceName | `0x36` | Name (variable, UTF-8) |
+| Pong | `0x37` | - |
+| TxDone | `0x38` | Result (1): 0x00=failed, 0x01=success |
+| RxMeta | `0x39` | SNR (1) + RSSI (1) |
 
 ### Error Codes
 
@@ -151,9 +156,9 @@ MeshCore-specific functionality uses the standard KISS SetHardware command. The
 
 The TNC sends these SetHardware frames without a preceding request:
 
-**TxDone (0x2F)**: Sent after a packet has been transmitted. Contains a single byte: 0x01 for success, 0x00 for failure.
+**TxDone (0x38)**: Sent after a packet has been transmitted. Contains a single byte: 0x01 for success, 0x00 for failure.
 
-**RxMeta (0x38)**: Sent immediately after each standard data frame (type 0x00) with metadata for the received packet. Contains SNR (1 byte, signed, value x4 for 0.25 dB precision) followed by RSSI (1 byte, signed, dBm). Standard KISS clients ignore this frame.
+**RxMeta (0x39)**: Sent immediately after each standard data frame (type 0x00) with metadata for the received packet. Contains SNR (1 byte, signed, value x4 for 0.25 dB precision) followed by RSSI (1 byte, signed, dBm). Standard KISS clients ignore this frame.
 
 ## Data Formats
 
@@ -218,6 +223,26 @@ All values little-endian.
 |-------|------|-------------|
 | Millivolts | 2 bytes | uint16_t, battery voltage in mV |
 
+### MCU Temperature (MCUTemp response)
+
+All values little-endian.
+
+| Field | Size | Description |
+|-------|------|-------------|
+| Temperature | 2 bytes | int16_t, tenths of °C (e.g., 253 = 25.3°C) |
+
+Returns `NoCallback` error if the board does not support temperature readings.
+
+### Device Name (DeviceName response)
+
+| Field | Size | Description |
+|-------|------|-------------|
+| Name | variable | UTF-8 string, no null terminator |
+
+### Reboot
+
+Sends an `OK` response, flushes serial, then reboots the device. The host should expect the connection to drop.
+
 ### Sensor Permissions (GetSensors)
 
 | Bit | Value | Description |

+ 31 - 0
examples/kiss_modem/KissModem.cpp

@@ -225,6 +225,15 @@ void KissModem::handleHardwareCommand(uint8_t sub_cmd, const uint8_t* data, uint
     case HW_CMD_GET_SENSORS:
       handleGetSensors(data, len);
       break;
+    case HW_CMD_GET_MCU_TEMP:
+      handleGetMCUTemp();
+      break;
+    case HW_CMD_REBOOT:
+      handleReboot();
+      break;
+    case HW_CMD_GET_DEVICE_NAME:
+      handleGetDeviceName();
+      break;
     default:
       writeHardwareError(HW_ERR_UNKNOWN_CMD);
       break;
@@ -536,3 +545,25 @@ void KissModem::handleGetSensors(const uint8_t* data, uint16_t len) {
     writeHardwareFrame(HW_RESP_SENSORS, nullptr, 0);
   }
 }
+
+void KissModem::handleGetMCUTemp() {
+  float temp = _board.getMCUTemperature();
+  if (isnan(temp)) {
+    writeHardwareError(HW_ERR_NO_CALLBACK);
+    return;
+  }
+  int16_t temp_tenths = (int16_t)(temp * 10.0f);
+  writeHardwareFrame(HW_RESP_MCU_TEMP, (uint8_t*)&temp_tenths, 2);
+}
+
+void KissModem::handleReboot() {
+  writeHardwareFrame(HW_RESP_OK, nullptr, 0);
+  _serial.flush();
+  delay(50);
+  _board.reboot();
+}
+
+void KissModem::handleGetDeviceName() {
+  const char* name = _board.getManufacturerName();
+  writeHardwareFrame(HW_RESP_DEVICE_NAME, (const uint8_t*)name, strlen(name));
+}

+ 33 - 25
examples/kiss_modem/KissModem.h

@@ -37,17 +37,20 @@
 #define HW_CMD_HASH              0x08
 #define HW_CMD_SET_RADIO         0x09
 #define HW_CMD_SET_TX_POWER      0x0A
-#define HW_CMD_GET_RADIO         0x0C
-#define HW_CMD_GET_TX_POWER      0x0D
-#define HW_CMD_GET_VERSION       0x0F
-#define HW_CMD_GET_CURRENT_RSSI  0x10
-#define HW_CMD_IS_CHANNEL_BUSY   0x11
-#define HW_CMD_GET_AIRTIME       0x12
-#define HW_CMD_GET_NOISE_FLOOR   0x13
-#define HW_CMD_GET_STATS         0x14
-#define HW_CMD_GET_BATTERY       0x15
-#define HW_CMD_PING              0x16
-#define HW_CMD_GET_SENSORS       0x17
+#define HW_CMD_GET_RADIO         0x0B
+#define HW_CMD_GET_TX_POWER      0x0C
+#define HW_CMD_GET_CURRENT_RSSI  0x0D
+#define HW_CMD_IS_CHANNEL_BUSY   0x0E
+#define HW_CMD_GET_AIRTIME       0x0F
+#define HW_CMD_GET_NOISE_FLOOR   0x10
+#define HW_CMD_GET_VERSION       0x11
+#define HW_CMD_GET_STATS         0x12
+#define HW_CMD_GET_BATTERY       0x13
+#define HW_CMD_GET_MCU_TEMP      0x14
+#define HW_CMD_GET_SENSORS       0x15
+#define HW_CMD_GET_DEVICE_NAME   0x16
+#define HW_CMD_PING              0x17
+#define HW_CMD_REBOOT            0x18
 
 #define HW_RESP_IDENTITY         0x21
 #define HW_RESP_RANDOM           0x22
@@ -58,20 +61,22 @@
 #define HW_RESP_SHARED_SECRET    0x27
 #define HW_RESP_HASH             0x28
 #define HW_RESP_OK               0x29
-#define HW_RESP_RADIO            0x2A
-#define HW_RESP_TX_POWER         0x2B
-#define HW_RESP_VERSION          0x2D
-#define HW_RESP_ERROR            0x2E
-#define HW_RESP_TX_DONE          0x2F
-#define HW_RESP_CURRENT_RSSI     0x30
-#define HW_RESP_CHANNEL_BUSY     0x31
-#define HW_RESP_AIRTIME          0x32
-#define HW_RESP_NOISE_FLOOR      0x33
-#define HW_RESP_STATS            0x34
-#define HW_RESP_BATTERY          0x35
-#define HW_RESP_PONG             0x36
-#define HW_RESP_SENSORS          0x37
-#define HW_RESP_RX_META          0x38
+#define HW_RESP_ERROR            0x2A
+#define HW_RESP_RADIO            0x2B
+#define HW_RESP_TX_POWER         0x2C
+#define HW_RESP_CURRENT_RSSI     0x2D
+#define HW_RESP_CHANNEL_BUSY     0x2E
+#define HW_RESP_AIRTIME          0x2F
+#define HW_RESP_NOISE_FLOOR      0x30
+#define HW_RESP_VERSION          0x31
+#define HW_RESP_STATS            0x32
+#define HW_RESP_BATTERY          0x33
+#define HW_RESP_MCU_TEMP         0x34
+#define HW_RESP_SENSORS          0x35
+#define HW_RESP_DEVICE_NAME      0x36
+#define HW_RESP_PONG             0x37
+#define HW_RESP_TX_DONE          0x38
+#define HW_RESP_RX_META          0x39
 
 #define HW_ERR_INVALID_LENGTH    0x01
 #define HW_ERR_INVALID_PARAM     0x02
@@ -171,6 +176,9 @@ class KissModem {
   void handleGetBattery();
   void handlePing();
   void handleGetSensors(const uint8_t* data, uint16_t len);
+  void handleGetMCUTemp();
+  void handleReboot();
+  void handleGetDeviceName();
 
 public:
   KissModem(Stream& serial, mesh::LocalIdentity& identity, mesh::RNG& rng,