20
20
#include " config.h"
21
21
#include < EEPROM.h>
22
22
#include " wifi.h"
23
+ extern " C" {
24
+ #include " user_interface.h"
25
+ }
23
26
24
27
// read a string
25
28
// a string is multibyte + \0, this is won't work if 1 char is multibyte like chinese char
26
29
bool CONFIG::read_string (int pos, char byte_buffer[], int size_max)
27
30
{
28
31
// check if parameters are acceptable
29
32
if (size_max==0 || pos+size_max+1 > EEPROM_SIZE || byte_buffer== NULL )return false ;
33
+ EEPROM.begin (EEPROM_SIZE);
30
34
byte b=0 ;
31
35
int i=0 ;
32
36
// read first byte
@@ -42,6 +46,7 @@ bool CONFIG::read_string(int pos, char byte_buffer[], int size_max)
42
46
}
43
47
// if it is a string be sure there is an 0 at the end
44
48
if (b!=0 )byte_buffer[i-1 ]=0x00 ;
49
+ EEPROM.end ();
45
50
return true ;
46
51
}
47
52
@@ -52,6 +57,7 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
52
57
byte b=0 ;
53
58
int i=0 ;
54
59
sbuffer=" " ;
60
+ EEPROM.begin (EEPROM_SIZE);
55
61
// read first byte
56
62
b = EEPROM.read (pos + i);
57
63
sbuffer+=char (b);
@@ -63,6 +69,7 @@ bool CONFIG::read_string(int pos, String & sbuffer, int size_max)
63
69
sbuffer+=char (b);
64
70
i++;
65
71
}
72
+ EEPROM.end ();
66
73
return true ;
67
74
}
68
75
@@ -72,12 +79,14 @@ bool CONFIG::read_buffer(int pos, byte byte_buffer[], int size_buffer)
72
79
// check if parameters are acceptable
73
80
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL )return false ;
74
81
int i=0 ;
82
+ EEPROM.begin (EEPROM_SIZE);
75
83
// read until max size is reached
76
84
while (i<size_buffer )
77
85
{
78
86
byte_buffer[i]=EEPROM.read (pos+i);
79
87
i++;
80
88
}
89
+ EEPROM.end ();
81
90
return true ;
82
91
}
83
92
@@ -86,7 +95,9 @@ bool CONFIG::read_byte(int pos, byte * value)
86
95
{
87
96
// check if parameters are acceptable
88
97
if (pos+1 > EEPROM_SIZE)return false ;
98
+ EEPROM.begin (EEPROM_SIZE);
89
99
value[0 ] = EEPROM.read (pos);
100
+ EEPROM.end ();
90
101
return true ;
91
102
}
92
103
@@ -104,13 +115,15 @@ bool CONFIG::write_string(int pos, const char * byte_buffer)
104
115
// check if parameters are acceptable
105
116
if (size_buffer==0 || pos+size_buffer+1 > EEPROM_SIZE || byte_buffer== NULL )return false ;
106
117
// copy the value(s)
118
+ EEPROM.begin (EEPROM_SIZE);
107
119
for (int i = 0 ; i < size_buffer; i++) {
108
120
EEPROM.write (pos + i, byte_buffer[i]);
109
121
}
110
122
111
123
// 0 terminal
112
124
EEPROM.write (pos + size_buffer, 0x00 );
113
125
EEPROM.commit ();
126
+ EEPROM.end ();
114
127
return true ;
115
128
}
116
129
@@ -119,11 +132,13 @@ bool CONFIG::write_buffer(int pos, const byte * byte_buffer, int size_buffer)
119
132
{
120
133
// check if parameters are acceptable
121
134
if (size_buffer==0 || pos+size_buffer > EEPROM_SIZE || byte_buffer== NULL )return false ;
135
+ EEPROM.begin (EEPROM_SIZE);
122
136
// copy the value(s)
123
137
for (int i = 0 ; i < size_buffer; i++) {
124
138
EEPROM.write (pos + i, byte_buffer[i]);
125
139
}
126
140
EEPROM.commit ();
141
+ EEPROM.end ();
127
142
return true ;
128
143
}
129
144
@@ -132,8 +147,10 @@ bool CONFIG::write_byte(int pos, const byte value)
132
147
{
133
148
// check if parameters are acceptable
134
149
if (pos+1 > EEPROM_SIZE)return false ;
150
+ EEPROM.begin (EEPROM_SIZE);
135
151
EEPROM.write (pos, value);
136
152
EEPROM.commit ();
153
+ EEPROM.end ();
137
154
return true ;
138
155
}
139
156
@@ -168,24 +185,157 @@ void CONFIG::print_config()
168
185
char sbuf[MAX_PASSWORD_LENGTH+1 ];
169
186
byte bbuf=0 ;
170
187
int ibuf=0 ;
171
- if (CONFIG::read_byte (EP_WIFI_MODE, &bbuf ))Serial.println (byte (bbuf));
172
- if (CONFIG::read_string (EP_SSID, sbuf , MAX_SSID_LENGTH))Serial.println (sbuf);
188
+ if (CONFIG::read_byte (EP_WIFI_MODE, &bbuf ))
189
+ {
190
+ if (byte (bbuf)==CLIENT_MODE) Serial.println (" Mode: Station" );
191
+ else if (byte (bbuf)==AP_MODE) Serial.println (" Mode: Access Point" );
192
+ else Serial.println (" Mode: ???" );
193
+ }
194
+ else Serial.println (" Error reading mode" );
195
+ if (CONFIG::read_string (EP_SSID, sbuf , MAX_SSID_LENGTH))
196
+ {
197
+ Serial.print (" SSID: " );
198
+ Serial.println (sbuf);
199
+ }
200
+ else Serial.println (" Error reading SSID" );
173
201
// if (CONFIG::read_string(EP_PASSWORD, sbuf , MAX_PASSWORD_LENGTH))Serial.println(sbuf);
174
- if (CONFIG::read_byte (EP_IP_MODE, &bbuf ))Serial.println (byte (bbuf));
175
- if (CONFIG::read_buffer (EP_IP_VALUE,(byte *)sbuf , IP_LENGTH))Serial.println (wifi_config.ip2str ((byte *)sbuf));
176
- if (CONFIG::read_buffer (EP_MASK_VALUE, (byte *)sbuf , IP_LENGTH))Serial.println (wifi_config.ip2str ((byte *)sbuf));
177
- if (CONFIG::read_buffer (EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGTH))Serial.println (wifi_config.ip2str ((byte *)sbuf));
178
- if (CONFIG::read_buffer (EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
179
- if (CONFIG::read_byte (EP_PHY_MODE, &bbuf ))Serial.println (byte (bbuf));
180
- if (CONFIG::read_byte (EP_SLEEP_MODE, &bbuf ))Serial.println (byte (bbuf));
181
- if (CONFIG::read_byte (EP_CHANNEL, &bbuf ))Serial.println (byte (bbuf));
182
- if (CONFIG::read_byte (EP_AUTH_TYPE, &bbuf ))Serial.println (byte (bbuf));
183
- if (CONFIG::read_byte (EP_SSID_VISIBLE, &bbuf ))Serial.println (byte (bbuf));
184
- if (CONFIG::read_buffer (EP_WEB_PORT, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
185
- if (CONFIG::read_buffer (EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
186
- if (CONFIG::read_byte (EP_REFRESH_PAGE_TIME, &bbuf ))Serial.println (byte (bbuf));
187
- if (CONFIG::read_string (EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH))Serial.println (sbuf);
188
- if (CONFIG::read_buffer (EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
189
- if (CONFIG::read_buffer (EP_Z_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
190
- if (CONFIG::read_buffer (EP_E_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))Serial.println (ibuf);
202
+
203
+ if (CONFIG::read_byte (EP_IP_MODE, &bbuf ))
204
+ {
205
+ if (byte (bbuf)==STATIC_IP_MODE) Serial.println (" IP Mode: Static" );
206
+ else if (byte (bbuf)==DHCP_MODE) Serial.println (" IP Mode: DHCP" );
207
+ else Serial.println (" IP mode: ???" );
208
+ }
209
+ else Serial.println (" Error reading IP mode" );
210
+ if (CONFIG::read_buffer (EP_IP_VALUE,(byte *)sbuf , IP_LENGTH))
211
+ {
212
+ Serial.print (" IP: " );
213
+ Serial.println (wifi_config.ip2str ((byte *)sbuf));
214
+ }
215
+ else Serial.println (" Error reading IP" );
216
+ if (CONFIG::read_buffer (EP_MASK_VALUE, (byte *)sbuf , IP_LENGTH))
217
+ {
218
+ Serial.print (" Subnet: " );
219
+ Serial.println (wifi_config.ip2str ((byte *)sbuf));
220
+ }
221
+ else Serial.println (" Error reading subnet" );
222
+ if (CONFIG::read_buffer (EP_GATEWAY_VALUE, (byte *)sbuf , IP_LENGTH))
223
+ {
224
+ Serial.print (" Gateway : " );
225
+ Serial.println (wifi_config.ip2str ((byte *)sbuf));
226
+ }
227
+ else Serial.println (" Error reading gateway" );
228
+ if (CONFIG::read_buffer (EP_BAUD_RATE, (byte *)&ibuf , INTEGER_LENGTH))
229
+ {
230
+ Serial.print (" Baud rate : " );
231
+ Serial.println (ibuf);
232
+ }
233
+ else Serial.println (" Error reading baud rate" );
234
+ if (CONFIG::read_byte (EP_PHY_MODE, &bbuf ))
235
+ {
236
+ Serial.print (" Phy mode : " );
237
+ if (byte (bbuf)==PHY_MODE_11B)Serial.println (" 11b" );
238
+ else if (byte (bbuf)==PHY_MODE_11G)Serial.println (" 11g" );
239
+ else if (byte (bbuf)==PHY_MODE_11N)Serial.println (" 11n" );
240
+ else Serial.println (" ???" );
241
+ }
242
+ else Serial.println (" Error reading phy mode" );
243
+ if (CONFIG::read_byte (EP_SLEEP_MODE, &bbuf ))
244
+ {
245
+ Serial.print (" Sleep mode : " );
246
+ if (byte (bbuf)==NONE_SLEEP_T)Serial.println (" None" );
247
+ else if (byte (bbuf)==LIGHT_SLEEP_T)Serial.println (" Light" );
248
+ else if (byte (bbuf)==MODEM_SLEEP_T)Serial.println (" Modem" );
249
+ else Serial.println (" ???" );
250
+ }
251
+ else Serial.println (" Error reading sleep mode" );
252
+ if (CONFIG::read_byte (EP_CHANNEL, &bbuf ))
253
+ {
254
+ Serial.print (" Channel : " );
255
+ Serial.println (byte (bbuf));
256
+ }
257
+ else Serial.println (" Error reading channel" );
258
+
259
+ if (CONFIG::read_byte (EP_AUTH_TYPE, &bbuf ))
260
+ {
261
+ Serial.print (" Authentification : " );
262
+ if (byte (bbuf)==AUTH_OPEN)Serial.println (" None" );
263
+ else if (byte (bbuf)==AUTH_WEP)Serial.println (" WEP" );
264
+ else if (byte (bbuf)==AUTH_WPA_PSK)Serial.println (" WPA" );
265
+ else if (byte (bbuf)==AUTH_WPA2_PSK)Serial.println (" WPA2" );
266
+ else if (byte (bbuf)==AUTH_WPA_WPA2_PSK)Serial.println (" WPA/WPA2" );
267
+ else if (byte (bbuf)==AUTH_MAX)Serial.println (" Max" );
268
+ else Serial.println (" ???" );
269
+ }
270
+ else Serial.println (" Error reading authentification" );
271
+ if (CONFIG::read_byte (EP_SSID_VISIBLE, &bbuf ))
272
+ {
273
+ Serial.print (" SSID visibility: " );
274
+ if (bbuf==0 )Serial.println (" Hidden" );
275
+ else if (bbuf==1 )Serial.println (" Visible" );
276
+ else Serial.println (bbuf);
277
+ }
278
+ else Serial.println (" Error reading SSID visibility" );
279
+ if (CONFIG::read_buffer (EP_WEB_PORT, (byte *)&ibuf , INTEGER_LENGTH))
280
+ {
281
+ Serial.print (" Web port: " );
282
+ Serial.println (ibuf);
283
+ }
284
+ else Serial.println (" Error reading web port" );
285
+ if (CONFIG::read_buffer (EP_DATA_PORT, (byte *)&ibuf , INTEGER_LENGTH))
286
+ {
287
+ Serial.print (" Data port: " );
288
+ Serial.println (ibuf);
289
+ }
290
+ else Serial.println (" Error reading data port" );
291
+ if (CONFIG::read_byte (EP_REFRESH_PAGE_TIME, &bbuf ))
292
+ {
293
+ Serial.print (" Web page refresh time: " );
294
+ Serial.println (byte (bbuf));
295
+ }
296
+ else Serial.println (" Error reading refesh page" );
297
+ if (CONFIG::read_string (EP_HOSTNAME, sbuf , MAX_HOSTNAME_LENGTH))
298
+ {
299
+ Serial.print (" Hostname : " );
300
+ Serial.println (sbuf);
301
+ }
302
+ else Serial.println (" Error reading hostname" );
303
+
304
+ if (CONFIG::read_buffer (EP_XY_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))
305
+ {
306
+ Serial.print (" XY feed rate: " );
307
+ Serial.println (ibuf);
308
+ }
309
+ else Serial.println (" Error reading XY feed rate" );
310
+ if (CONFIG::read_buffer (EP_Z_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))
311
+ {
312
+ Serial.print (" Z feed rate: " );
313
+ Serial.println (ibuf);
314
+ }
315
+ else Serial.println (" Error reading Z feed rate" );
316
+ if (CONFIG::read_buffer (EP_E_FEEDRATE, (byte *)&ibuf , INTEGER_LENGTH))
317
+ {
318
+ Serial.print (" E feed rate: " );
319
+ Serial.println (ibuf);
320
+ }
321
+ else Serial.println (" Error reading E feed rate" );
322
+
323
+ Serial.print (" Captive portal : " );
324
+ #ifdef CAPTIVE_PORTAL_FEATURE
325
+ Serial.println (" Enabled" );
326
+ #else
327
+ Serial.println (" Disabled" );
328
+ #endif
329
+ Serial.print (" SSDP : " );
330
+ #ifdef SSDP_FEATURE
331
+ Serial.println (" Enabled" );
332
+ #else
333
+ Serial.println (" Disabled" );
334
+ #endif
335
+ Serial.print (" mDNS : " );
336
+ #ifdef MDNS
337
+ Serial.println (" Enabled" );
338
+ #else
339
+ Serial.println (" Disabled" );
340
+ #endif
191
341
}
0 commit comments