parameters.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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] = "RID_123456";
  27. char wifi_password[21] = "penguin1234";
  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. };
  59. static const struct Param params[];
  60. static const Param *find(const char *name);
  61. static const Param *find_by_index(uint16_t idx);
  62. void init(void);
  63. bool have_basic_id_info(void) const;
  64. bool set_by_name_uint8(const char *name, uint8_t v);
  65. bool set_by_name_char64(const char *name, const char *s);
  66. private:
  67. void load_defaults(void);
  68. };
  69. extern Parameters g;