|
|
@@ -30,7 +30,12 @@
|
|
|
|
|
|
#define DEBUG_MSG 1
|
|
|
|
|
|
+/* Forward declarations. */
|
|
|
+
|
|
|
typedef struct ProtoViewApp ProtoViewApp;
|
|
|
+typedef struct ProtoViewMsgInfo ProtoViewMsgInfo;
|
|
|
+
|
|
|
+/* ============================== enumerations ============================== */
|
|
|
|
|
|
/* Subghz system state */
|
|
|
typedef enum {
|
|
|
@@ -55,6 +60,8 @@ typedef enum {
|
|
|
ViewGoPrev,
|
|
|
} ProtoViewCurrentView;
|
|
|
|
|
|
+/* ================================== RX/TX ================================= */
|
|
|
+
|
|
|
typedef struct {
|
|
|
const char *name; // Name to show to the user.
|
|
|
const char *id; // Identifier in the Flipper API/file.
|
|
|
@@ -88,34 +95,8 @@ struct ProtoViewTxRx {
|
|
|
|
|
|
typedef struct ProtoViewTxRx ProtoViewTxRx;
|
|
|
|
|
|
-/* This stucture is filled by the decoder for specific protocols with the
|
|
|
- * informations about the message. ProtoView will display such information
|
|
|
- * in the message info view. */
|
|
|
-#define PROTOVIEW_MSG_STR_LEN 32
|
|
|
-typedef struct ProtoViewMsgInfo {
|
|
|
- char name[PROTOVIEW_MSG_STR_LEN]; /* Protocol name and version. */
|
|
|
- char raw[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific raw representation.*/
|
|
|
- /* The following is what the decoder wants to show to user. Each decoder
|
|
|
- * can use the number of fileds it needs. */
|
|
|
- char info1[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 1. */
|
|
|
- char info2[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 2. */
|
|
|
- char info3[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 3. */
|
|
|
- char info4[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 4. */
|
|
|
- /* Low level information of the detected signal: the following are filled
|
|
|
- * by the protocol decoding function: */
|
|
|
- uint32_t start_off; /* Pulses start offset in the bitmap. */
|
|
|
- uint32_t pulses_count; /* Number of pulses of the full message. */
|
|
|
- /* The following are passed already filled to the decoder. */
|
|
|
- uint32_t short_pulse_dur; /* Microseconds duration of the short pulse. */
|
|
|
- /* The following are filled by ProtoView core after the decoder returned
|
|
|
- * success. */
|
|
|
- uint8_t *bits; /* Bitmap with the signal. */
|
|
|
- uint32_t bits_bytes; /* Number of full bytes in the bitmap, that
|
|
|
- is 'pulses_count/8' rounded to the next
|
|
|
- integer. */
|
|
|
-} ProtoViewMsgInfo;
|
|
|
+/* ============================== Main app state ============================ */
|
|
|
|
|
|
-/* Our main application context. */
|
|
|
#define ALERT_MAX_LEN 32
|
|
|
struct ProtoViewApp {
|
|
|
/* GUI */
|
|
|
@@ -174,6 +155,68 @@ struct ProtoViewApp {
|
|
|
ProtoViewModulations table. */
|
|
|
};
|
|
|
|
|
|
+/* =========================== Protocols decoders =========================== */
|
|
|
+
|
|
|
+/* This stucture is filled by the decoder for specific protocols with the
|
|
|
+ * informations about the message. ProtoView will display such information
|
|
|
+ * in the message info view. */
|
|
|
+#define PROTOVIEW_MSG_STR_LEN 32
|
|
|
+typedef struct ProtoViewMsgInfo {
|
|
|
+ char name[PROTOVIEW_MSG_STR_LEN]; /* Protocol name and version. */
|
|
|
+ char raw[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific raw representation.*/
|
|
|
+ /* The following is what the decoder wants to show to user. Each decoder
|
|
|
+ * can use the number of fileds it needs. */
|
|
|
+ char info1[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 1. */
|
|
|
+ char info2[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 2. */
|
|
|
+ char info3[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 3. */
|
|
|
+ char info4[PROTOVIEW_MSG_STR_LEN]; /* Protocol specific info line 4. */
|
|
|
+ /* Low level information of the detected signal: the following are filled
|
|
|
+ * by the protocol decoding function: */
|
|
|
+ uint32_t start_off; /* Pulses start offset in the bitmap. */
|
|
|
+ uint32_t pulses_count; /* Number of pulses of the full message. */
|
|
|
+ /* The following are passed already filled to the decoder. */
|
|
|
+ uint32_t short_pulse_dur; /* Microseconds duration of the short pulse. */
|
|
|
+ /* The following are filled by ProtoView core after the decoder returned
|
|
|
+ * success. */
|
|
|
+ uint8_t *bits; /* Bitmap with the signal. */
|
|
|
+ uint32_t bits_bytes; /* Number of full bytes in the bitmap, that
|
|
|
+ is 'pulses_count/8' rounded to the next
|
|
|
+ integer. */
|
|
|
+} ProtoViewMsgInfo;
|
|
|
+
|
|
|
+/* This structures describe a set of protocol fields. It is used by decoders
|
|
|
+ * supporting message building to receive and return information about the
|
|
|
+ * protocol. */
|
|
|
+typedef enum {
|
|
|
+ FieldTypeStr,
|
|
|
+ FieldTypeSignedInt,
|
|
|
+ FieldTypeUnsignedInt,
|
|
|
+ FieldTypeBytes,
|
|
|
+ FieldTypeFloat,
|
|
|
+} ProtoViewFieldType;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ ProtoViewFieldType type;
|
|
|
+ uint32_t len; // Depends on type:
|
|
|
+ // Bits for integers.
|
|
|
+ // Number of characters for strings.
|
|
|
+ // Number of nibbles for bytes (1 for each 4 bits).
|
|
|
+ // Not used for floats.
|
|
|
+ char *name; // Field name.
|
|
|
+ union {
|
|
|
+ char *str; // String type.
|
|
|
+ int64_t value; // Signed integer type.
|
|
|
+ uint64_t uvalue; // Unsigned integer type.
|
|
|
+ uint8_t *bytes; // Raw bytes type.
|
|
|
+ float fvalue; // Float type.
|
|
|
+ };
|
|
|
+} ProtoViewField;
|
|
|
+
|
|
|
+typedef struct {
|
|
|
+ ProtoViewField **fields;
|
|
|
+ uint32_t numfields;
|
|
|
+} ProtoViewFieldSet;
|
|
|
+
|
|
|
typedef struct ProtoViewDecoder {
|
|
|
const char *name; /* Protocol name. */
|
|
|
/* The decode function takes a buffer that is actually a bitmap, with
|
|
|
@@ -184,6 +227,8 @@ typedef struct ProtoViewDecoder {
|
|
|
* functions that perform bit extraction with bound checking, such as
|
|
|
* bitmap_get() and so forth. */
|
|
|
bool (*decode)(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoViewMsgInfo *info);
|
|
|
+ void (*get_fields)(ProtoViewMsgInfo *info, ProtoViewFieldSet *fields);
|
|
|
+ void (*build_message)(RawSamplesBuffer *samples, ProtoViewFieldSet *fields);
|
|
|
} ProtoViewDecoder;
|
|
|
|
|
|
extern RawSamplesBuffer *RawSamples, *DetectedSamples;
|
|
|
@@ -242,5 +287,14 @@ void ui_dismiss_alert(ProtoViewApp *app);
|
|
|
void ui_draw_alert_if_needed(Canvas *canvas, ProtoViewApp *app);
|
|
|
void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);
|
|
|
|
|
|
+/* fields.c */
|
|
|
+void fieldset_free_set(ProtoViewFieldSet *fs);
|
|
|
+ProtoViewFieldSet *fieldset_new(void);
|
|
|
+void fieldset_add_int(ProtoViewFieldSet *fs, const char *name, int64_t val, uint8_t bits);
|
|
|
+void fieldset_add_uint(ProtoViewFieldSet *fs, const char *name, uint64_t uval, uint8_t bits);
|
|
|
+void fieldset_add_str(ProtoViewFieldSet *fs, const char *name, const char *s);
|
|
|
+void fieldset_add_bytes(ProtoViewFieldSet *fs, const char *name, const uint8_t *bytes, uint32_t count);
|
|
|
+void fieldset_add_float(ProtoViewFieldSet *fs, const char *name, float val);
|
|
|
+
|
|
|
/* crc.c */
|
|
|
uint8_t crc8(const uint8_t *data, size_t len, uint8_t init, uint8_t poly);
|