parameters.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. uint8_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. struct {
  35. char b64_key[64];
  36. } public_keys[MAX_PUBLIC_KEYS];
  37. enum class ParamType {
  38. NONE=0,
  39. UINT8=1,
  40. UINT32=2,
  41. FLOAT=3,
  42. CHAR20=4,
  43. CHAR64=5,
  44. };
  45. struct Param {
  46. char name[PARAM_NAME_MAX_LEN+1];
  47. ParamType ptype;
  48. const void *ptr;
  49. float default_value;
  50. float min_value;
  51. float max_value;
  52. uint16_t flags;
  53. uint8_t min_len;
  54. void set_float(float v) const;
  55. void set_uint8(uint8_t v) const;
  56. void set_uint32(uint32_t v) const;
  57. void set_char20(const char *v) const;
  58. void set_char64(const char *v) const;
  59. uint8_t get_uint8() const;
  60. uint32_t get_uint32() const;
  61. float get_float() const;
  62. const char *get_char20() const;
  63. const char *get_char64() const;
  64. bool get_as_float(float &v) const;
  65. void set_as_float(float v) const;
  66. };
  67. static const struct Param params[];
  68. static const Param *find(const char *name);
  69. static const Param *find_by_index(uint16_t idx);
  70. static const Param *find_by_index_float(uint16_t idx);
  71. void init(void);
  72. bool have_basic_id_info(void) const;
  73. bool have_basic_id_2_info(void) const;
  74. bool set_by_name_uint8(const char *name, uint8_t v);
  75. bool set_by_name_char64(const char *name, const char *s);
  76. bool set_by_name_string(const char *name, const char *s);
  77. /*
  78. return a public key
  79. */
  80. bool get_public_key(uint8_t i, uint8_t key[32]) const;
  81. bool set_public_key(uint8_t i, const uint8_t key[32]);
  82. bool remove_public_key(uint8_t i);
  83. bool no_public_keys(void) const;
  84. static uint16_t param_count_float(void);
  85. static int16_t param_index_float(const Param *p);
  86. private:
  87. void load_defaults(void);
  88. };
  89. extern Parameters g;