parameters.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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_HIDDEN (1U<<0)
  7. class Parameters {
  8. public:
  9. uint8_t lock_level;
  10. uint8_t can_node;
  11. uint8_t bcast_powerup;
  12. uint32_t baudrate = 57600;
  13. char uas_id[21] = "ABCD123456789";
  14. float wifi_nan_rate;
  15. float bt4_rate;
  16. float bt5_rate;
  17. uint8_t webserver_enable;
  18. char wifi_ssid[21] = "RID_123456";
  19. char wifi_password[21] = "penguin1234";
  20. struct {
  21. char b64_key[64];
  22. } public_keys[MAX_PUBLIC_KEYS];
  23. enum class ParamType {
  24. NONE=0,
  25. UINT8=1,
  26. UINT32=2,
  27. FLOAT=3,
  28. CHAR20=4,
  29. CHAR64=5,
  30. };
  31. struct Param {
  32. char name[PARAM_NAME_MAX_LEN+1];
  33. ParamType ptype;
  34. const void *ptr;
  35. float default_value;
  36. float min_value;
  37. float max_value;
  38. uint16_t flags;
  39. void set_float(float v) const;
  40. void set_uint8(uint8_t v) const;
  41. void set_uint32(uint32_t v) const;
  42. void set_char20(const char *v) const;
  43. void set_char64(const char *v) const;
  44. uint8_t get_uint8() const;
  45. uint32_t get_uint32() const;
  46. float get_float() const;
  47. const char *get_char20() const;
  48. const char *get_char64() const;
  49. };
  50. static const struct Param params[];
  51. static const Param *find(const char *name);
  52. static const Param *find_by_index(uint16_t idx);
  53. void init(void);
  54. private:
  55. void load_defaults(void);
  56. };
  57. extern Parameters g;