SingingCat 0
application
config.h
1#ifndef CONFIG_H
2#define CONFIG_H 1
3#include "espressif/esp8266.h"
4
5// NO POINTERS IN HERE!
6// the initialiser in config_init() will
7// override any initialisers in here
8typedef struct cnw_config {
9 int size;
10 uint32_t crc;
11 int crc_start[0]; // takes up 0 space,but indicates start of crc in struct
12 char apcredentials[ESP_AP_NAME_SIZE];
13 byte wifidetected; // if 1 do not touch esp8266
14 byte flags2; // see below all zero by default
15 byte unused1;
16 byte unused2;
17 byte flags1; // see below - all zero by default
18 byte flashmode;
19 byte quickstart;
20 byte pad1; // must be even aligned
21 long nodeid; // my nodeid
22 char cloudtoken[64]; // token identifying us to the server
23 char sensorserver[64]; // server to which to send sensor data to
24 char cloudserver[64]; // server to which to send sensor data to
25 long lognode; // nodeid to send logs to
26 uint64_t moduleid;
27 uint32_t userapp; // address of current userapp
28 uint32_t userflags; // flags for the userapp
29 /*
30 * uint8_t reserved_userflags2; // flags for the userapp
31 * uint8_t reserved_userflags3; // flags for the userapp
32 * uint8_t reserved_userflags4; // flags for the userapp
33 */
34 uint32_t clock_mul; // internal clock frequency multiplier
35 uint32_t clock_div; // internal clock frequency divisor
36 uint32_t tz; // timezone
37 uint32_t powermodeflags; // if powersave is enable this is the mode we use
38 uint16_t wifioff_duration; // (seconds) wifioff duration in seconds before it is being re-enabled
39 uint16_t radiooff_duration; // (seconds) radiooff duration before it is being re-enabled
40 uint16_t sleep_duration; // (seconds) how long to sleep
41 uint16_t nonsleep_duration; // (seconds) how long to wait before sleeping
42 // add new stuff directly above this line here
43 uint32_t guaranteed_to_be_zero0; // zero in case we add to the struct, this keeps the crc ok
44 uint32_t guaranteed_to_be_zero1; // zero in case we add to the struct, this keeps the crc ok
45 uint32_t guaranteed_to_be_zero2; // zero in case we add to the struct, this keeps the crc ok
46 uint32_t guaranteed_to_be_zero3; // zero in case we add to the struct, this keeps the crc ok
47 uint32_t guaranteed_to_be_zero4; // zero in case we add to the struct, this keeps the crc ok
48 uint32_t guaranteed_to_be_zero5; // zero in case we add to the struct, this keeps the crc ok
50
51// 0..7 : flags1
52// 8..15 : flags2
53#define CONFIG_FLAGS_LEDEXTERN 0
54#define CONFIG_FLAGS_RADIODISABLE 1
55#define CONFIG_FLAGS_TEMP212 2
56#define CONFIG_FLAGS_WIFI_DISABLE 3
57#define CONFIG_FLAGS_TEMP211 4
58#define CONFIG_FLAGS_TEMP207 5
59// if 1 - no sensors are running
60#define CONFIG_FLAGS_SENSORS_DISABLED 6
61// if true, invert the LED (e.g. active-low timers)
62#define CONFIG_FLAGS_INTERNAL_LED_INVERTED 7
63#define CONFIG_FLAGS_ROUTING_ENABLED 8
64#define CONFIG_FLAGS_POWER_SAVE 9
65#define CONFIG_FLAGS_UDP_ENABLED 10
66#define CONFIG_FLAGS_START_USERAPP_ON_BOOT 11
67#define CONFIG_FLAGS_WHITE_MOSFET0 12
68#define CONFIG_FLAGS_WHITE_MOSFET1 13
69#define CONFIG_FLAGS_ESP_COMSYNC 14
70#define CONFIG_FLAGS_CLOCKSYNC_DISABLED 15
71
72// the powerflags
73#define CONFIG_POWERFLAG_THROTTLE 0
74
75// returns 0 if ok
76int flash_config_init();
77int config_check_crc(struct cnw_config *c);
78uint32_t config_calc_crc(struct cnw_config *c);
79
80// save to flash
81// >0 if ok, <0 if error
82int config_commit();
83int config_get_quickstart();
84void config_set_quickstart(int b);
85
86
87int config_get_sensors_enabled();
88void config_set_sensors_enabled(int b);
89
90int config_get_owdisable();
91void config_set_owdisable(int b);
92
93void config_set_wifidisable(int b);
94int config_get_wifidisable();
95
96void config_set_wifidetected(int b);
97int config_get_wifidetected();
98
99void config_set_ti1101disable(int b);
100int config_get_ti1101disable();
101void config_set_ssid(const char *ssid);
102const char *config_get_ssid();
103void config_set_wireless_pw(const char *pw);
104const char *config_get_wireless_pw();
105// return a pointer to the volatile in-ram struct
106struct cnw_config *config_get_ram_struct();
107void config_set_flashmode(byte b);
108// return >0 if ok
109int config_is_valid();
110// return >0 if ok
111int config_is_ram_valid();
112const char *config_get_cloud_token();
113void config_set_cloud_token(const char *token);
114void config_erase();
115long config_get_log_node();
116void config_set_log_node(long nodeid);
117byte config_get_flag(int flag);
118void config_set_flag(int flag, byte value);
119uint32_t config_get_flags();
120void config_flag_line(const char *line);
121const char *config_get_sensor_server();
122void config_set_sensor_server(const char *name);
123const char *config_get_cloud_server();
124void config_set_cloud_server(const char *name);
125void config_set_moduleid(uint64_t modid);
126uint64_t config_get_moduleid();
127struct userapp_info *config_get_userapp();
128void config_set_userapp(uint32_t userapp_base);
129
130int get_user_config_flag(int flag);
131uint32_t get_user_config_flags();
132void set_user_config_flag(int flag, int value);
133void set_user_config_flags(uint32_t flags);
134uint32_t config_get_clock_mul();
135uint32_t config_get_clock_div();
136void config_set_clock_mul(uint32_t mul);
137void config_set_clock_div(uint32_t div);
138void config_set_timezone(uint32_t tz);
139uint32_t config_get_timezone();
140int config_get_powermode_flag(int b);
141void config_set_powermode_flags(uint32_t new_flags);
142uint32_t config_get_powermode_flags();
143void config_set_radiooff_duration(uint16_t dur);
144uint16_t config_get_radiooff_duration();
145uint16_t config_get_wifioff_duration();
146void config_set_wifioff_duration(uint16_t wifioff);
147#endif
this must be implemented by the userapp, stored in flash at the beginning of the file (offset 0)