parameters.h 2.3 KB

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