parameters.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. float wifi_nan_rate;
  19. float wifi_beacon_rate;
  20. float wifi_power;
  21. float bt4_rate;
  22. float bt4_power;
  23. float bt5_rate;
  24. float bt5_power;
  25. uint8_t done_init;
  26. uint8_t webserver_enable;
  27. uint8_t mavlink_sysid;
  28. char wifi_ssid[21] = "";
  29. char wifi_password[21] = "ArduRemoteID";
  30. uint8_t wifi_channel = 6;
  31. struct {
  32. char b64_key[64];
  33. } public_keys[MAX_PUBLIC_KEYS];
  34. enum class ParamType {
  35. NONE=0,
  36. UINT8=1,
  37. UINT32=2,
  38. FLOAT=3,
  39. CHAR20=4,
  40. CHAR64=5,
  41. };
  42. struct Param {
  43. char name[PARAM_NAME_MAX_LEN+1];
  44. ParamType ptype;
  45. const void *ptr;
  46. float default_value;
  47. float min_value;
  48. float max_value;
  49. uint16_t flags;
  50. uint8_t min_len;
  51. void set_float(float v) const;
  52. void set_uint8(uint8_t v) const;
  53. void set_uint32(uint32_t v) const;
  54. void set_char20(const char *v) const;
  55. void set_char64(const char *v) const;
  56. uint8_t get_uint8() const;
  57. uint32_t get_uint32() const;
  58. float get_float() const;
  59. const char *get_char20() const;
  60. const char *get_char64() const;
  61. bool get_as_float(float &v) const;
  62. void set_as_float(float v) const;
  63. };
  64. static const struct Param params[];
  65. static const Param *find(const char *name);
  66. static const Param *find_by_index(uint16_t idx);
  67. static const Param *find_by_index_float(uint16_t idx);
  68. void init(void);
  69. bool have_basic_id_info(void) const;
  70. bool set_by_name_uint8(const char *name, uint8_t v);
  71. bool set_by_name_char64(const char *name, const char *s);
  72. bool set_by_name_string(const char *name, const char *s);
  73. /*
  74. return a public key
  75. */
  76. bool get_public_key(uint8_t i, uint8_t key[32]) const;
  77. bool set_public_key(uint8_t i, const uint8_t key[32]);
  78. bool remove_public_key(uint8_t i);
  79. bool no_public_keys(void) const;
  80. static uint16_t param_count_float(void);
  81. static int16_t param_index_float(const Param *p);
  82. private:
  83. void load_defaults(void);
  84. };
  85. extern Parameters g;