parameters.h 3.0 KB

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