parameters.h 2.7 KB

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