parameters.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include <stdint.h>
  3. #include "board_config.h"
  4. #define MAX_PUBLIC_KEYS 5
  5. #define PUBLIC_KEY_LEN 32
  6. #define PARAM_NAME_MAX_LEN 16
  7. #define PARAM_FLAG_NONE 0
  8. #define PARAM_FLAG_PASSWORD (1U<<0)
  9. #define PARAM_FLAG_HIDDEN (1U<<1)
  10. class Parameters {
  11. public:
  12. #if defined(PIN_CAN_TERM)
  13. uint8_t can_term = !CAN_TERM_EN;
  14. #endif
  15. int8_t lock_level;
  16. uint8_t can_node;
  17. uint8_t bcast_powerup;
  18. uint32_t baudrate = 57600;
  19. uint8_t ua_type;
  20. uint8_t id_type;
  21. char uas_id[21] = "ABCD123456789";
  22. uint8_t ua_type_2;
  23. uint8_t id_type_2;
  24. char uas_id_2[21] = "ABCD123456789";
  25. float wifi_nan_rate;
  26. float wifi_beacon_rate;
  27. float wifi_power;
  28. float bt4_rate;
  29. float bt4_power;
  30. float bt5_rate;
  31. float bt5_power;
  32. uint8_t done_init;
  33. uint8_t webserver_enable;
  34. uint8_t mavlink_sysid;
  35. char wifi_ssid[21] = "";
  36. char wifi_password[21] = "ArduRemoteID";
  37. uint8_t wifi_channel = 6;
  38. uint8_t to_factory_defaults = 0;
  39. uint8_t options;
  40. struct {
  41. char b64_key[64];
  42. } public_keys[MAX_PUBLIC_KEYS];
  43. enum class ParamType {
  44. NONE=0,
  45. UINT8=1,
  46. UINT32=2,
  47. FLOAT=3,
  48. CHAR20=4,
  49. CHAR64=5,
  50. INT8=6,
  51. };
  52. struct Param {
  53. char name[PARAM_NAME_MAX_LEN+1];
  54. ParamType ptype;
  55. const void *ptr;
  56. float default_value;
  57. float min_value;
  58. float max_value;
  59. uint16_t flags;
  60. uint8_t min_len;
  61. void set_float(float v) const;
  62. void set_uint8(uint8_t v) const;
  63. void set_int8(int8_t v) const;
  64. void set_uint32(uint32_t v) const;
  65. void set_char20(const char *v) const;
  66. void set_char64(const char *v) const;
  67. uint8_t get_uint8() const;
  68. int8_t get_int8() const;
  69. uint32_t get_uint32() const;
  70. float get_float() const;
  71. const char *get_char20() const;
  72. const char *get_char64() const;
  73. bool get_as_float(float &v) const;
  74. void set_as_float(float v) const;
  75. };
  76. static const struct Param params[];
  77. static const Param *find(const char *name);
  78. static const Param *find_by_index(uint16_t idx);
  79. static const Param *find_by_index_float(uint16_t idx);
  80. void init(void);
  81. bool have_basic_id_info(void) const;
  82. bool have_basic_id_2_info(void) const;
  83. bool set_by_name_uint8(const char *name, uint8_t v);
  84. bool set_by_name_int8(const char *name, int8_t v);
  85. bool set_by_name_char64(const char *name, const char *s);
  86. bool set_by_name_string(const char *name, const char *s);
  87. /*
  88. return a public key
  89. */
  90. bool get_public_key(uint8_t i, uint8_t key[32]) const;
  91. bool set_public_key(uint8_t i, const uint8_t key[32]);
  92. bool remove_public_key(uint8_t i);
  93. bool no_public_keys(void) const;
  94. static uint16_t param_count_float(void);
  95. static int16_t param_index_float(const Param *p);
  96. private:
  97. void load_defaults(void);
  98. };
  99. // bits for OPTIONS parameter
  100. #define OPTIONS_FORCE_ARM_OK (1U<<0)
  101. #define OPTIONS_DONT_SAVE_BASIC_ID_TO_PARAMETERS (1U<<1)
  102. #define OPTIONS_PRINT_RID_MAVLINK (1U<<2)
  103. extern Parameters g;