Jelajahi Sumber

Initial proto generation

Scott Bezek 4 tahun lalu
induk
melakukan
fb4ab7d2a1

+ 30 - 0
firmware/src/proto_gen/smartknob.pb.c

@@ -0,0 +1,30 @@
+/* Automatically generated nanopb constant definitions */
+/* Generated by nanopb-0.4.7-dev */
+
+#include "smartknob.pb.h"
+#if PB_PROTO_HEADER_VERSION != 40
+#error Regenerate this file with the current version of nanopb generator.
+#endif
+
+PB_BIND(PB_FromSmartKnob, PB_FromSmartKnob, 2)
+
+
+PB_BIND(PB_Ack, PB_Ack, AUTO)
+
+
+PB_BIND(PB_Log, PB_Log, 2)
+
+
+PB_BIND(PB_SmartKnobState, PB_SmartKnobState, AUTO)
+
+
+PB_BIND(PB_ToSmartknob, PB_ToSmartknob, AUTO)
+
+
+PB_BIND(PB_SmartKnobConfig, PB_SmartKnobConfig, AUTO)
+
+
+PB_BIND(PB_RequestState, PB_RequestState, AUTO)
+
+
+

+ 159 - 0
firmware/src/proto_gen/smartknob.pb.h

@@ -0,0 +1,159 @@
+/* Automatically generated nanopb header */
+/* Generated by nanopb-0.4.7-dev */
+
+#ifndef PB_PB_SMARTKNOB_PB_H_INCLUDED
+#define PB_PB_SMARTKNOB_PB_H_INCLUDED
+#include <pb.h>
+
+#if PB_PROTO_HEADER_VERSION != 40
+#error Regenerate this file with the current version of nanopb generator.
+#endif
+
+/* Struct definitions */
+typedef struct _PB_RequestState {
+    char dummy_field;
+} PB_RequestState;
+
+typedef struct _PB_SmartKnobConfig {
+    char dummy_field;
+} PB_SmartKnobConfig;
+
+typedef struct _PB_SmartKnobState {
+    char dummy_field;
+} PB_SmartKnobState;
+
+typedef struct _PB_Ack {
+    uint32_t nonce;
+} PB_Ack;
+
+typedef struct _PB_Log {
+    char msg[256];
+} PB_Log;
+
+/* Message TO the Smartknob from the USB host */
+typedef struct _PB_ToSmartknob {
+    uint32_t nonce;
+    pb_size_t which_payload;
+    union {
+        PB_RequestState request_state;
+        PB_SmartKnobConfig smartknob_config;
+    } payload;
+} PB_ToSmartknob;
+
+/* Message FROM the SmartKnob to USB host */
+typedef struct _PB_FromSmartKnob {
+    pb_size_t which_payload;
+    union {
+        PB_Ack ack;
+        PB_Log log;
+        PB_SmartKnobState smartknob_state;
+    } payload;
+} PB_FromSmartKnob;
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Initializer values for message structs */
+#define PB_FromSmartKnob_init_default            {0, {PB_Ack_init_default}}
+#define PB_Ack_init_default                      {0}
+#define PB_Log_init_default                      {""}
+#define PB_SmartKnobState_init_default           {0}
+#define PB_ToSmartknob_init_default              {0, 0, {PB_RequestState_init_default}}
+#define PB_SmartKnobConfig_init_default          {0}
+#define PB_RequestState_init_default             {0}
+#define PB_FromSmartKnob_init_zero               {0, {PB_Ack_init_zero}}
+#define PB_Ack_init_zero                         {0}
+#define PB_Log_init_zero                         {""}
+#define PB_SmartKnobState_init_zero              {0}
+#define PB_ToSmartknob_init_zero                 {0, 0, {PB_RequestState_init_zero}}
+#define PB_SmartKnobConfig_init_zero             {0}
+#define PB_RequestState_init_zero                {0}
+
+/* Field tags (for use in manual encoding/decoding) */
+#define PB_Ack_nonce_tag                         1
+#define PB_Log_msg_tag                           1
+#define PB_ToSmartknob_nonce_tag                 1
+#define PB_ToSmartknob_request_state_tag         2
+#define PB_ToSmartknob_smartknob_config_tag      3
+#define PB_FromSmartKnob_ack_tag                 1
+#define PB_FromSmartKnob_log_tag                 2
+#define PB_FromSmartKnob_smartknob_state_tag     3
+
+/* Struct field encoding specification for nanopb */
+#define PB_FromSmartKnob_FIELDLIST(X, a) \
+X(a, STATIC,   ONEOF,    MESSAGE,  (payload,ack,payload.ack),   1) \
+X(a, STATIC,   ONEOF,    MESSAGE,  (payload,log,payload.log),   2) \
+X(a, STATIC,   ONEOF,    MESSAGE,  (payload,smartknob_state,payload.smartknob_state),   3)
+#define PB_FromSmartKnob_CALLBACK NULL
+#define PB_FromSmartKnob_DEFAULT NULL
+#define PB_FromSmartKnob_payload_ack_MSGTYPE PB_Ack
+#define PB_FromSmartKnob_payload_log_MSGTYPE PB_Log
+#define PB_FromSmartKnob_payload_smartknob_state_MSGTYPE PB_SmartKnobState
+
+#define PB_Ack_FIELDLIST(X, a) \
+X(a, STATIC,   SINGULAR, UINT32,   nonce,             1)
+#define PB_Ack_CALLBACK NULL
+#define PB_Ack_DEFAULT NULL
+
+#define PB_Log_FIELDLIST(X, a) \
+X(a, STATIC,   SINGULAR, STRING,   msg,               1)
+#define PB_Log_CALLBACK NULL
+#define PB_Log_DEFAULT NULL
+
+#define PB_SmartKnobState_FIELDLIST(X, a) \
+
+#define PB_SmartKnobState_CALLBACK NULL
+#define PB_SmartKnobState_DEFAULT NULL
+
+#define PB_ToSmartknob_FIELDLIST(X, a) \
+X(a, STATIC,   SINGULAR, UINT32,   nonce,             1) \
+X(a, STATIC,   ONEOF,    MESSAGE,  (payload,request_state,payload.request_state),   2) \
+X(a, STATIC,   ONEOF,    MESSAGE,  (payload,smartknob_config,payload.smartknob_config),   3)
+#define PB_ToSmartknob_CALLBACK NULL
+#define PB_ToSmartknob_DEFAULT NULL
+#define PB_ToSmartknob_payload_request_state_MSGTYPE PB_RequestState
+#define PB_ToSmartknob_payload_smartknob_config_MSGTYPE PB_SmartKnobConfig
+
+#define PB_SmartKnobConfig_FIELDLIST(X, a) \
+
+#define PB_SmartKnobConfig_CALLBACK NULL
+#define PB_SmartKnobConfig_DEFAULT NULL
+
+#define PB_RequestState_FIELDLIST(X, a) \
+
+#define PB_RequestState_CALLBACK NULL
+#define PB_RequestState_DEFAULT NULL
+
+extern const pb_msgdesc_t PB_FromSmartKnob_msg;
+extern const pb_msgdesc_t PB_Ack_msg;
+extern const pb_msgdesc_t PB_Log_msg;
+extern const pb_msgdesc_t PB_SmartKnobState_msg;
+extern const pb_msgdesc_t PB_ToSmartknob_msg;
+extern const pb_msgdesc_t PB_SmartKnobConfig_msg;
+extern const pb_msgdesc_t PB_RequestState_msg;
+
+/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
+#define PB_FromSmartKnob_fields &PB_FromSmartKnob_msg
+#define PB_Ack_fields &PB_Ack_msg
+#define PB_Log_fields &PB_Log_msg
+#define PB_SmartKnobState_fields &PB_SmartKnobState_msg
+#define PB_ToSmartknob_fields &PB_ToSmartknob_msg
+#define PB_SmartKnobConfig_fields &PB_SmartKnobConfig_msg
+#define PB_RequestState_fields &PB_RequestState_msg
+
+/* Maximum encoded size of messages (where known) */
+#define PB_Ack_size                              6
+#define PB_FromSmartKnob_size                    261
+#define PB_Log_size                              258
+#define PB_RequestState_size                     0
+#define PB_SmartKnobConfig_size                  0
+#define PB_SmartKnobState_size                   0
+#define PB_ToSmartknob_size                      8
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif

+ 34 - 0
proto/generate_protobuf.py

@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+from pathlib import Path
+
+import os
+import shutil
+import subprocess
+import sys
+
+def run():
+    SCRIPT_PATH = Path(__file__).absolute().parent
+    REPO_ROOT = SCRIPT_PATH.parent
+
+    proto_path = REPO_ROOT / 'proto'
+
+    nanopb_path = REPO_ROOT / 'thirdparty' / 'nanopb'
+
+    # Make sure nanopb submodule is available
+    if not os.path.isdir(nanopb_path):
+        print(f'Nanopb checkout not found! Make sure you have inited/updated the submodule located at {nanopb_path}', file=sys.stderr)
+        exit(1)
+
+    nanopb_generator_path = nanopb_path / 'generator' / 'nanopb_generator.py'
+    c_generated_output_path = REPO_ROOT / 'firmware' / 'src' / 'proto_gen'
+
+    proto_files = [f for f in os.listdir(proto_path) if f.endswith('.proto')]
+    assert len(proto_files) > 0, 'No proto files found!'
+
+    # Generate C files via nanopb
+    subprocess.check_call(['python3', nanopb_generator_path, '-D', c_generated_output_path] + proto_files, cwd=proto_path)
+
+
+if __name__ == '__main__':
+    run()

+ 45 - 0
proto/smartknob.proto

@@ -0,0 +1,45 @@
+syntax = "proto3";
+
+import "nanopb.proto";
+
+package PB;
+
+/*
+ * Message FROM the SmartKnob to USB host
+ */
+message FromSmartKnob {
+    oneof payload {
+        Ack ack = 1;
+        Log log = 2;
+        SmartKnobState smartknob_state = 3;
+    }
+}
+
+message Ack {
+    uint32 nonce = 1;
+}
+
+message Log {
+    string msg = 1 [(nanopb).max_length = 255];
+}
+
+message SmartKnobState {
+}
+
+/*
+ * Message TO the Smartknob from the USB host
+ */
+message ToSmartknob {
+    uint32 nonce = 1;
+
+    oneof payload {
+        RequestState request_state = 2;
+        SmartKnobConfig smartknob_config = 3;
+    }
+}
+
+message SmartKnobConfig {
+}
+
+message RequestState {}
+