Эх сурвалжийг харах

allow lock_level to set to -1

BlueMark Innovations BV 3 жил өмнө
parent
commit
fc60679018

+ 16 - 0
RemoteIDModule/DroneCAN.cpp

@@ -608,6 +608,12 @@ void DroneCAN::handle_param_getset(CanardInstance* ins, CanardRxTransfer* transf
                 }
                 vp->set_uint8(uint8_t(req.value.integer_value));
                 break;
+            case Parameters::ParamType::INT8:
+                if (req.value.union_tag != UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE) {
+                    return;
+                }
+                vp->set_int8(int8_t(req.value.integer_value));
+                break;
             case Parameters::ParamType::UINT32:
                 if (req.value.union_tag != UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE) {
                     return;
@@ -659,6 +665,16 @@ void DroneCAN::handle_param_getset(CanardInstance* ins, CanardRxTransfer* transf
             pkt.max_value.union_tag = UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE;
             pkt.max_value.integer_value = uint8_t(vp->max_value);
             break;
+        case Parameters::ParamType::INT8:
+            pkt.value.union_tag = UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE;
+            pkt.value.integer_value = vp->get_int8();
+            pkt.default_value.union_tag = UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE;
+            pkt.default_value.integer_value = int8_t(vp->default_value);
+            pkt.min_value.union_tag = UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE;
+            pkt.min_value.integer_value = int8_t(vp->min_value);
+            pkt.max_value.union_tag = UAVCAN_PROTOCOL_PARAM_NUMERICVALUE_INTEGER_VALUE;
+            pkt.max_value.integer_value = int8_t(vp->max_value);
+            break;
         case Parameters::ParamType::UINT32:
             pkt.value.union_tag = UAVCAN_PROTOCOL_PARAM_VALUE_INTEGER_VALUE;
             pkt.value.integer_value = vp->get_uint32();

+ 42 - 1
RemoteIDModule/parameters.cpp

@@ -10,7 +10,7 @@ Parameters g;
 static nvs_handle handle;
 
 const Parameters::Param Parameters::params[] = {
-    { "LOCK_LEVEL",        Parameters::ParamType::UINT8,  (const void*)&g.lock_level,       0, 0, 2 },
+    { "LOCK_LEVEL",        Parameters::ParamType::INT8,  (const void*)&g.lock_level,       0, -1, 2 },
     { "CAN_NODE",          Parameters::ParamType::UINT8,  (const void*)&g.can_node,         0, 0, 127 },
     { "UAS_TYPE",          Parameters::ParamType::UINT8,  (const void*)&g.ua_type,          0, 0, 15 },
     { "UAS_ID_TYPE",       Parameters::ParamType::UINT8,  (const void*)&g.id_type,          0, 0, 4 },
@@ -54,6 +54,7 @@ uint16_t Parameters::param_count_float(void)
         }
         switch (p.ptype) {
         case ParamType::UINT8:
+        case ParamType::INT8:
         case ParamType::UINT32:
         case ParamType::FLOAT:
             count++;
@@ -76,6 +77,7 @@ int16_t Parameters::param_index_float(const Parameters::Param *f)
         }
         switch (p.ptype) {
         case ParamType::UINT8:
+        case ParamType::INT8:
         case ParamType::UINT32:
         case ParamType::FLOAT:
             if (&p == f) {
@@ -124,6 +126,7 @@ const Parameters::Param *Parameters::find_by_index_float(uint16_t index)
         }
         switch (p.ptype) {
         case ParamType::UINT8:
+        case ParamType::INT8:
         case ParamType::UINT32:
         case ParamType::FLOAT:
             if (index == count) {
@@ -143,6 +146,13 @@ void Parameters::Param::set_uint8(uint8_t v) const
     nvs_set_u8(handle, name, *p);
 }
 
+void Parameters::Param::set_int8(int8_t v) const
+{
+    auto *p = (int8_t *)ptr;
+    *p = v;
+    nvs_set_i8(handle, name, *p);
+}
+
 void Parameters::Param::set_uint32(uint32_t v) const
 {
     auto *p = (uint32_t *)ptr;
@@ -188,6 +198,12 @@ uint8_t Parameters::Param::get_uint8() const
     return *p;
 }
 
+int8_t Parameters::Param::get_int8() const
+{
+    const auto *p = (const int8_t *)ptr;
+    return *p;
+}
+
 uint32_t Parameters::Param::get_uint32() const
 {
     const auto *p = (const uint32_t *)ptr;
@@ -221,6 +237,9 @@ bool Parameters::Param::get_as_float(float &v) const
         case ParamType::UINT8:
             v = float(get_uint8());
             break;
+        case ParamType::INT8:
+            v = float(get_int8());
+            break;
         case ParamType::UINT32:
             v = float(get_uint32());
             break;
@@ -242,6 +261,9 @@ void Parameters::Param::set_as_float(float v) const
         case ParamType::UINT8:
             set_uint8(uint8_t(v));
             break;
+        case ParamType::INT8:
+            set_int8(int8_t(v));
+            break;
         case ParamType::UINT32:
             set_uint32(uint32_t(v));
             break;
@@ -262,6 +284,9 @@ void Parameters::load_defaults(void)
         case ParamType::UINT8:
             *(uint8_t *)p.ptr = uint8_t(p.default_value);
             break;
+        case ParamType::INT8:
+            *(int8_t *)p.ptr = int8_t(p.default_value);
+            break;
         case ParamType::UINT32:
             *(uint32_t *)p.ptr = uint32_t(p.default_value);
             break;
@@ -286,6 +311,9 @@ void Parameters::init(void)
         case ParamType::UINT8:
             nvs_get_u8(handle, p.name, (uint8_t *)p.ptr);
             break;
+        case ParamType::INT8:
+            nvs_get_i8(handle, p.name, (int8_t *)p.ptr);
+            break;
         case ParamType::UINT32:
             nvs_get_u32(handle, p.name, (uint32_t *)p.ptr);
             break;
@@ -350,6 +378,16 @@ bool Parameters::set_by_name_uint8(const char *name, uint8_t v)
     return true;
 }
 
+bool Parameters::set_by_name_int8(const char *name, int8_t v)
+{
+    const auto *f = find(name);
+    if (!f) {
+        return false;
+    }
+    f->set_int8(v);
+    return true;
+}
+
 bool Parameters::set_by_name_char64(const char *name, const char *s)
 {
     const auto *f = find(name);
@@ -370,6 +408,9 @@ bool Parameters::set_by_name_string(const char *name, const char *s)
         case ParamType::UINT8:
             f->set_uint8(uint8_t(strtoul(s, nullptr, 0)));
             return true;
+        case ParamType::INT8:
+            f->set_int8(int8_t(strtoul(s, nullptr, 0)));
+            return true;
         case ParamType::UINT32:
             f->set_uint32(strtoul(s, nullptr, 0));
             return true;

+ 5 - 1
RemoteIDModule/parameters.h

@@ -12,7 +12,7 @@
 
 class Parameters {
 public:
-    uint8_t lock_level;
+    int8_t lock_level;
     uint8_t can_node;
     uint8_t bcast_powerup;
     uint32_t baudrate = 57600;
@@ -47,6 +47,7 @@ public:
         FLOAT=3,
         CHAR20=4,
         CHAR64=5,
+        INT8=6,
     };
 
     struct Param {
@@ -60,10 +61,12 @@ public:
         uint8_t min_len;
         void set_float(float v) const;
         void set_uint8(uint8_t v) const;
+        void set_int8(int8_t v) const;
         void set_uint32(uint32_t v) const;
         void set_char20(const char *v) const;
         void set_char64(const char *v) const;
         uint8_t get_uint8() const;
+        int8_t get_int8() const;
         uint32_t get_uint32() const;
         float get_float() const;
         const char *get_char20() const;
@@ -83,6 +86,7 @@ public:
     bool have_basic_id_2_info(void) const;
 
     bool set_by_name_uint8(const char *name, uint8_t v);
+    bool set_by_name_int8(const char *name, int8_t v);
     bool set_by_name_char64(const char *name, const char *s);
     bool set_by_name_string(const char *name, const char *s);