parameters.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include <stdint.h>
  3. #define MAX_PUBLIC_KEYS 5
  4. #define PUBLIC_KEY_LEN 32
  5. #define PARAM_NAME_MAX_LEN 16
  6. #define PARAM_FLAG_NONE 0
  7. #define PARAM_FLAG_PASSWORD (1U<<0)
  8. #define PARAM_FLAG_HIDDEN (1U<<1)
  9. class Parameters {
  10. public:
  11. int8_t lock_level;
  12. uint8_t can_node;
  13. uint8_t bcast_powerup;
  14. uint32_t baudrate = 57600;
  15. uint8_t ua_type;
  16. uint8_t id_type;
  17. char uas_id[21] = "ABCD123456789";
  18. uint8_t ua_type_2;
  19. uint8_t id_type_2;
  20. char uas_id_2[21] = "ABCD123456789";
  21. float wifi_nan_rate;
  22. float wifi_beacon_rate;
  23. float wifi_power;
  24. float bt4_rate;
  25. float bt4_power;
  26. float bt5_rate;
  27. float bt5_power;
  28. uint8_t done_init;
  29. uint8_t webserver_enable;
  30. uint8_t mavlink_sysid;
  31. char wifi_ssid[21] = "";
  32. char wifi_password[21] = "ArduRemoteID";
  33. uint8_t wifi_channel = 6;
  34. uint8_t to_factory_defaults = 0;
  35. uint8_t options;
  36. struct {
  37. char b64_key[64];
  38. } public_keys[MAX_PUBLIC_KEYS];
  39. enum class ParamType {
  40. NONE=0,
  41. UINT8=1,
  42. UINT32=2,
  43. FLOAT=3,
  44. CHAR20=4,
  45. CHAR64=5,
  46. INT8=6,
  47. };
  48. struct Param {
  49. char name[PARAM_NAME_MAX_LEN+1];
  50. ParamType ptype;
  51. const void *ptr;
  52. float default_value;
  53. float min_value;
  54. float max_value;
  55. uint16_t flags;
  56. uint8_t min_len;
  57. void set_float(float v) const;
  58. void set_uint8(uint8_t v) const;
  59. void set_int8(int8_t v) const;
  60. void set_uint32(uint32_t v) const;
  61. void set_char20(const char *v) const;
  62. void set_char64(const char *v) const;
  63. uint8_t get_uint8() const;
  64. int8_t get_int8() const;
  65. uint32_t get_uint32() const;
  66. float get_float() const;
  67. const char *get_char20() const;
  68. const char *get_char64() const;
  69. bool get_as_float(float &v) const;
  70. void set_as_float(float v) const;
  71. };
  72. static const struct Param params[];
  73. static const Param *find(const char *name);
  74. static const Param *find_by_index(uint16_t idx);
  75. static const Param *find_by_index_float(uint16_t idx);
  76. void init(void);
  77. bool have_basic_id_info(void) const;
  78. bool have_basic_id_2_info(void) const;
  79. bool set_by_name_uint8(const char *name, uint8_t v);
  80. bool set_by_name_int8(const char *name, int8_t v);
  81. bool set_by_name_char64(const char *name, const char *s);
  82. bool set_by_name_string(const char *name, const char *s);
  83. /*
  84. return a public key
  85. */
  86. bool get_public_key(uint8_t i, uint8_t key[32]) const;
  87. bool set_public_key(uint8_t i, const uint8_t key[32]);
  88. bool remove_public_key(uint8_t i);
  89. bool no_public_keys(void) const;
  90. static uint16_t param_count_float(void);
  91. static int16_t param_index_float(const Param *p);
  92. private:
  93. void load_defaults(void);
  94. };
  95. // bits for OPTIONS parameter
  96. #define OPTIONS_FORCE_ARM_OK 1U<<0
  97. #define OPTIONS_DONT_SAVE_BASIC_ID_TO_PARAMETERS 1U<<1
  98. extern Parameters g;