@@ -2076,6 +2076,7 @@ int socket_getpeername(const uint8_t command[], uint8_t response[])
2076
2076
#include " Preferences.h"
2077
2077
2078
2078
Preferences preferences;
2079
+ const char PREF_TAG[] = " preferences" ;
2079
2080
2080
2081
int pref_begin (const uint8_t command[], uint8_t response[])
2081
2082
{
@@ -2100,7 +2101,9 @@ int pref_begin(const uint8_t command[], uint8_t response[])
2100
2101
const uint8_t * command_ptr = &command[3 ];
2101
2102
2102
2103
if (nargs < 1 && nargs > 3 ) {
2103
- // TODO error
2104
+ ESP_LOGE (PREF_TAG, " Prefrences begin wrong number of arguments" );
2105
+ response[4 ] = 255 ;
2106
+ goto error;
2104
2107
}
2105
2108
2106
2109
memset (store_name, 0x00 , sizeof (store_name));
@@ -2125,12 +2128,12 @@ int pref_begin(const uint8_t command[], uint8_t response[])
2125
2128
partition_label_ptr = command_ptr;
2126
2129
}
2127
2130
2131
+ response[4 ] = preferences.begin (store_name, readonly, (char *)partition_label_ptr) ? 0 : 1 ;
2132
+
2133
+ error:
2128
2134
response[2 ] = 1 ; // number of parameters
2129
2135
response[3 ] = 1 ; // length of first parameter
2130
- // result of Preferences begin operation
2131
- response[4 ] = preferences.begin (store_name, readonly, (char *)partition_label_ptr) ? 1 : 0 ;
2132
- // response has to start ad position 2, and has to take into account
2133
- // 0xee that is put after the function being called
2136
+
2134
2137
return 6 ;
2135
2138
}
2136
2139
@@ -2151,7 +2154,7 @@ int pref_clear(const uint8_t command[], uint8_t response[])
2151
2154
2152
2155
response[2 ] = 1 ; // number of parameters
2153
2156
response[3 ] = 1 ; // length of first parameter
2154
- response[4 ] = preferences.clear () ? 1 : 0 ; // result of Preferences clear operation
2157
+ response[4 ] = preferences.clear () ? 0 : 1 ; // result of Preferences clear operation
2155
2158
2156
2159
// response has to start ad position 2, and has to take into account
2157
2160
// 0xee that is put after the function being called
@@ -2174,16 +2177,19 @@ int pref_remove(const uint8_t command[], uint8_t response[])
2174
2177
const uint8_t * command_ptr = &command[3 ];
2175
2178
2176
2179
if (nargs != 1 ) {
2177
- // TODO error
2180
+ ESP_LOGE (PREF_TAG, " Prefrences remove wrong number of arguments" );
2181
+ response[4 ] = 255 ;
2182
+ goto error;
2178
2183
}
2179
2184
2180
2185
memset (key, 0x00 , sizeof (key));
2181
2186
memcpy (key, command_ptr+1 , *command_ptr);
2182
2187
key[*command_ptr] = ' \0 ' ;
2183
2188
2189
+ response[4 ] = preferences.remove (key) ? 0 : 1 ; // result of Preferences end operation
2190
+ error:
2184
2191
response[2 ] = 1 ; // number of parameters
2185
2192
response[3 ] = 1 ; // length of first parameter
2186
- response[4 ] = preferences.remove (key) ? 1 : 0 ; // result of Preferences end operation
2187
2193
2188
2194
// response has to start ad position 2, and has to take into account
2189
2195
// 0xee that is put after the function being called
@@ -2209,7 +2215,11 @@ int pref_len(const uint8_t command[], uint8_t response[])
2209
2215
uint32_t len = 0 ;
2210
2216
2211
2217
if (nargs != 1 ) {
2212
- // TODO error
2218
+ ESP_LOGE (PREF_TAG, " Prefrences length wrong number of arguments" );
2219
+ response[2 ] = 1 ;
2220
+ response[3 ] = 1 ;
2221
+ response[4 ] = 255 ;
2222
+ return 6 ;
2213
2223
}
2214
2224
2215
2225
memset (key, 0x00 , sizeof (key));
@@ -2222,10 +2232,10 @@ int pref_len(const uint8_t command[], uint8_t response[])
2222
2232
response[3 ] = 4 ; // length of first parameter
2223
2233
2224
2234
// write the result in big endian into the response buffer
2225
- response[7 ] = (len >> 24 ) & 0xff ;
2226
- response[6 ] = (len >> 16 ) & 0xff ;
2227
- response[5 ] = (len >> 8 ) & 0xff ;
2228
2235
response[4 ] = (len >> 0 ) & 0xff ;
2236
+ response[5 ] = (len >> 8 ) & 0xff ;
2237
+ response[6 ] = (len >> 16 ) & 0xff ;
2238
+ response[7 ] = (len >> 24 ) & 0xff ;
2229
2239
2230
2240
return 9 ;
2231
2241
}
@@ -2244,10 +2254,10 @@ int pref_stat(const uint8_t command[], uint8_t response[])
2244
2254
response[3 ] = 4 ; // length of first parameter
2245
2255
2246
2256
// write the result in big endian into the response buffer
2247
- response[7 ] = (res >> 24 ) & 0xff ;
2248
- response[6 ] = (res >> 16 ) & 0xff ;
2249
- response[5 ] = (res >> 8 ) & 0xff ;
2250
2257
response[4 ] = (res >> 0 ) & 0xff ;
2258
+ response[5 ] = (res >> 8 ) & 0xff ;
2259
+ response[6 ] = (res >> 16 ) & 0xff ;
2260
+ response[7 ] = (res >> 24 ) & 0xff ;
2251
2261
2252
2262
return 9 ;
2253
2263
}
@@ -2278,8 +2288,12 @@ int pref_put(const uint8_t command[], uint8_t response[])
2278
2288
// restricting the return as 32 bit integer as it is enough
2279
2289
size_t res = 0 ;
2280
2290
2281
- if (nargs != 2 && nargs != 3 ) {
2282
- // TODO error
2291
+ if (nargs != 3 ) {
2292
+ ESP_LOGE (PREF_TAG, " Prefrences put wrong number of arguments" );
2293
+ response[2 ] = 1 ;
2294
+ response[3 ] = 1 ;
2295
+ response[4 ] = 255 ;
2296
+ return 6 ;
2283
2297
}
2284
2298
2285
2299
memset (key, 0x00 , sizeof (key));
@@ -2289,10 +2303,6 @@ int pref_put(const uint8_t command[], uint8_t response[])
2289
2303
// next argument
2290
2304
command_ptr += *command_ptr + 1 ;
2291
2305
2292
- if (*command_ptr >= PT_INVALID) {
2293
- // TODO error
2294
- }
2295
-
2296
2306
command_ptr++; // The first byte contains the length of the parameter, which is 1
2297
2307
PreferenceType type = (PreferenceType)*command_ptr;
2298
2308
command_ptr++;
@@ -2341,17 +2351,20 @@ int pref_put(const uint8_t command[], uint8_t response[])
2341
2351
break ;
2342
2352
case PT_INVALID:
2343
2353
default :
2344
- // TODO error
2345
- break ;
2354
+ ESP_LOGE (PREF_TAG, " Prefrences put invalid type" );
2355
+ response[2 ] = 1 ;
2356
+ response[3 ] = 1 ;
2357
+ response[4 ] = 254 ;
2358
+ return 6 ;
2346
2359
}
2347
2360
2348
2361
response[2 ] = 1 ; // response nargs
2349
2362
response[3 ] = 4 ; // length of first parameter
2350
2363
2351
- response[7 ] = (res >> 24 ) & 0xff ;
2352
- response[6 ] = (res >> 16 ) & 0xff ;
2353
- response[5 ] = (res >> 8 ) & 0xff ;
2354
2364
response[4 ] = (res >> 0 ) & 0xff ;
2365
+ response[5 ] = (res >> 8 ) & 0xff ;
2366
+ response[6 ] = (res >> 16 ) & 0xff ;
2367
+ response[7 ] = (res >> 24 ) & 0xff ;
2355
2368
2356
2369
return 9 ;
2357
2370
}
@@ -2379,7 +2392,10 @@ int pref_get(const uint8_t command[], uint8_t response[])
2379
2392
uint32_t res=0 ;
2380
2393
2381
2394
if (nargs != 2 ) {
2382
- // TODO error
2395
+ ESP_LOGE (PREF_TAG, " Prefrences put wrong number of arguments" );
2396
+ response[2 ] = 1 ;
2397
+ response[3 ] = 0 ;
2398
+ return 5 ;
2383
2399
}
2384
2400
2385
2401
memset (key, 0x00 , sizeof (key));
@@ -2392,9 +2408,6 @@ int pref_get(const uint8_t command[], uint8_t response[])
2392
2408
command_ptr++; // The first byte contains the length of the parameter, which is 1
2393
2409
PreferenceType type = static_cast <PreferenceType>(*command_ptr);
2394
2410
2395
- if (type >= PT_INVALID) {
2396
- // TODO error
2397
- }
2398
2411
command_ptr++;
2399
2412
2400
2413
switch (type) {
@@ -2438,8 +2451,10 @@ int pref_get(const uint8_t command[], uint8_t response[])
2438
2451
goto array_return;
2439
2452
case PT_INVALID:
2440
2453
default :
2441
- // TODO error
2442
- break ;
2454
+ ESP_LOGE (PREF_TAG, " Prefrences put invalid type" );
2455
+ response[2 ] = 1 ;
2456
+ response[3 ] = 0 ;
2457
+ return 5 ;
2443
2458
}
2444
2459
2445
2460
// fill the response buffer
0 commit comments