parameters.h 2.4 KB

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