antirez 3 lat temu
rodzic
commit
1fe8a7f5f8
6 zmienionych plików z 75 dodań i 9 usunięć
  1. 6 1
      TODO
  2. 1 0
      app.h
  3. 1 1
      application.fam
  4. 60 0
      protocols/citroen_tpms.c
  5. 3 1
      signal.c
  6. 4 6
      view_info.c

+ 6 - 1
TODO

@@ -1,7 +1,12 @@
 Core improvements
 Core improvements
 =================
 =================
 
 
-- More protocols, especially TPMS.
+- Decoders should declare the short pulse duration range, so that
+  only matching decoders will be called. This may also be useful for
+  modulations. If a signal is only OOK, does not make much sense to
+  call it for samples obtained in FSK.
+- More protocols, especially TPMS and other stuff not supported right now
+  by the Flipper.
 - CC1101 synchronous mode with protocol hopping?
 - CC1101 synchronous mode with protocol hopping?
 - Protocols decoded can register actions, for instance to generate
 - Protocols decoded can register actions, for instance to generate
   sub files with modified signal and so forth.
   sub files with modified signal and so forth.

+ 1 - 0
app.h

@@ -96,6 +96,7 @@ typedef struct ProtoViewMsgInfo {
     char info1[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 1. */
     char info1[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 1. */
     char info2[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 2. */
     char info2[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 2. */
     char info3[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 3. */
     char info3[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 3. */
+    char info4[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 4. */
     uint64_t len;       /* Bits consumed from the stream. */
     uint64_t len;       /* Bits consumed from the stream. */
 } ProtoViewMsgInfo;
 } ProtoViewMsgInfo;
 
 

+ 1 - 1
application.fam

@@ -1,6 +1,6 @@
 App(
 App(
     appid="protoview",
     appid="protoview",
-    name="Protocols visualizer",
+    name="ProtoView",
     apptype=FlipperAppType.EXTERNAL,
     apptype=FlipperAppType.EXTERNAL,
     entry_point="protoview_app_entry",
     entry_point="protoview_app_entry",
     cdefines=["APP_PROTOVIEW"],
     cdefines=["APP_PROTOVIEW"],

+ 60 - 0
protocols/citroen_tpms.c

@@ -0,0 +1,60 @@
+/* Citroen TPMS. Usually 443.92 Mhz FSK.
+ *
+ * Preamble of ~14 high/low 52 us pulses
+ * Sync of high 100us pulse then 50us low
+ * Then Manchester bits, 10 bytes total.
+ * Simple XOR checksum. */
+
+#include "../app.h"
+
+static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info) {
+
+    /* We consider a preamble of 17 symbols. They are more, but the decoding
+     * is more likely to happen if we don't pretend to receive from the
+     * very start of the message. */
+    uint32_t sync_len = 17;
+    const char *sync_pattern = "10101010101010110";
+    if (numbits-sync_len < 8*10) return false; /* Expect 10 bytes. */
+
+    uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
+    if (off == BITMAP_SEEK_NOT_FOUND) return false;
+    FURI_LOG_E(TAG, "Renault TPMS preamble+sync found");
+
+    off += sync_len; /* Skip preamble + sync. */
+
+    uint8_t raw[10];
+    uint32_t decoded =
+        convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
+            "01","10"); /* Manchester. */
+    FURI_LOG_E(TAG, "Citroen TPMS decoded bits: %lu", decoded);
+
+    if (decoded < 8*10) return false; /* Require the full 10 bytes. */
+
+    /* Check the CRC. It's a simple XOR of bytes 1-9, the first byte
+     * is not included. The meaning of the first byte is unknown and
+     * we don't display it. */
+    uint8_t crc = 0;
+    for (int j = 1; j < 10; j++) crc ^= raw[j];
+    if (crc != 0) return false; /* Require sane checksum. */
+
+    int repeat = raw[5] & 0xf;
+    float kpa = (float)raw[6]*1.364;
+    int temp = raw[7]-50;
+    int battery = raw[8]; /* This may be the battery. It's not clear. */
+
+    snprintf(info->name,sizeof(info->name),"%s","Citroen TPMS");
+    snprintf(info->raw,sizeof(info->raw),
+        "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
+        raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
+        raw[6],raw[7],raw[8],raw[9],raw[10]);
+    snprintf(info->info1,sizeof(info->info1),"Tire ID %02X%02X%02X%02X",
+        raw[1],raw[2],raw[3],raw[4]);
+    snprintf(info->info2,sizeof(info->info2),"Pressure %.2f kpa", (double)kpa);
+    snprintf(info->info3,sizeof(info->info3),"Temperature %d C", temp);
+    snprintf(info->info4,sizeof(info->info4),"Repeat %d, Bat %d", repeat, battery);
+    return true;
+}
+
+ProtoViewDecoder CitroenTPMSDecoder = {
+    "Citroen TPMS", decode
+};

+ 3 - 1
signal.c

@@ -385,6 +385,7 @@ extern ProtoViewDecoder B4B1Decoder;
 extern ProtoViewDecoder RenaultTPMSDecoder;
 extern ProtoViewDecoder RenaultTPMSDecoder;
 extern ProtoViewDecoder ToyotaTPMSDecoder;
 extern ProtoViewDecoder ToyotaTPMSDecoder;
 extern ProtoViewDecoder SchraderTPMSDecoder;
 extern ProtoViewDecoder SchraderTPMSDecoder;
+extern ProtoViewDecoder CitroenTPMSDecoder;
 
 
 ProtoViewDecoder *Decoders[] = {
 ProtoViewDecoder *Decoders[] = {
     &Oregon2Decoder,        /* Oregon sensors v2.1 protocol. */
     &Oregon2Decoder,        /* Oregon sensors v2.1 protocol. */
@@ -392,6 +393,7 @@ ProtoViewDecoder *Decoders[] = {
     &RenaultTPMSDecoder,    /* Renault TPMS. */
     &RenaultTPMSDecoder,    /* Renault TPMS. */
     &ToyotaTPMSDecoder,     /* Toyota TPMS. */
     &ToyotaTPMSDecoder,     /* Toyota TPMS. */
     &SchraderTPMSDecoder,   /* Schrader TPMS. */
     &SchraderTPMSDecoder,   /* Schrader TPMS. */
+    &CitroenTPMSDecoder,    /* Citroen TPMS. */
     NULL
     NULL
 };
 };
 
 
@@ -445,7 +447,7 @@ bool decode_signal(RawSamplesBuffer *s, uint64_t len, ProtoViewMsgInfo *info) {
     if (!decoded) {
     if (!decoded) {
         FURI_LOG_E(TAG, "No decoding possible");
         FURI_LOG_E(TAG, "No decoding possible");
     } else {
     } else {
-        FURI_LOG_E(TAG, "Decoded %s, raw=%s info=[%s,%s,%s]", info->name, info->raw, info->info1, info->info2, info->info3);
+        FURI_LOG_E(TAG, "Decoded %s, raw=%s info=[%s,%s,%s,%s]", info->name, info->raw, info->info1, info->info2, info->info3, info->info4);
     }
     }
     free(bitmap);
     free(bitmap);
     return decoded;
     return decoded;

+ 4 - 6
view_info.c

@@ -25,12 +25,10 @@ void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
         canvas_draw_str(canvas, 0, y, buf);
         canvas_draw_str(canvas, 0, y, buf);
         y += lineheight;
         y += lineheight;
     }
     }
-    canvas_draw_str(canvas, 0, y, app->signal_info.info1);
-    y += lineheight;
-    canvas_draw_str(canvas, 0, y, app->signal_info.info2);
-    y += lineheight;
-    canvas_draw_str(canvas, 0, y, app->signal_info.info3);
-    y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info1); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info2); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info3); y += lineheight;
+    canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
 }
 }
 
 
 /* Handle input for the settings view. */
 /* Handle input for the settings view. */