Skip to content

Commit 195d29d

Browse files
committed
add some comments
helps us mere mortals can understand what's happening :) also quote username in debug output for clarity
1 parent 9c19fa2 commit 195d29d

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/rfid.esp

+34-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ void rfidRead()
253253
}
254254
}
255255

256+
257+
/*
258+
* Try and read a PIN code from Wiegand hardware
259+
*/
256260
void pinCodeRead()
257261
{
258262
if (config.readertype != READER_WIEGAND ||
@@ -320,6 +324,11 @@ int weekdayFromMonday(int weekdayFromSunday) {
320324
return ( weekdayFromSunday + 5 ) % 7;
321325
}
322326

327+
328+
/*
329+
* If we have successfully read an RFID card, check if access
330+
* should be granted
331+
*/
323332
void rfidProcess()
324333
{
325334
if (rfidState == waitingRfid ||
@@ -328,12 +337,14 @@ void rfidProcess()
328337
return;
329338
}
330339

340+
/* Each user has a file named after the RFID UID */
331341
File f = SPIFFS.open("/P/" + uid, "r");
332342

333343
/*
334344
* If the file was not found then this is an unknown user, so no more
335-
* processing to be done. However, we do a secondary check here to see
336-
* if an old esp-rfid v1 uid exists and if so use that.
345+
* processing to be done. However, for backwards compatibility we do a
346+
* secondary check here to see if an old esp-rfid v1 uid exists and if
347+
* so use that.
337348
*/
338349
if (!f)
339350
{
@@ -352,13 +363,19 @@ void rfidProcess()
352363
#endif
353364
}
354365

366+
/*
367+
* Read the user's settings
368+
*/
355369
size_t size = f.size();
356370
std::unique_ptr<char[]> buf(new char[size]);
357371
f.readBytes(buf.get(), size);
358372
f.close();
359373
DynamicJsonDocument json(512);
360374
auto error = deserializeJson(json, buf.get(), size);
361375

376+
/*
377+
* Corrupt user data file, so return invalid user
378+
*/
362379
if (error)
363380
{
364381
processingState = notValid;
@@ -380,24 +397,32 @@ void rfidProcess()
380397
return;
381398
}
382399

400+
/*
401+
* Get account type (for FIRST relay only) and username from user's data
402+
*/
383403
accountType = json["acctype"];
384404
username = json["user"].as<String>();
385405

386406
#ifdef DEBUG
387407
Serial.println(" = known PICC");
388-
Serial.print("[ INFO ] User Name: ");
408+
Serial.print("[ INFO ] User Name: '");
389409
if (username == "undefined")
390410
Serial.print(uid);
391411
else
392412
Serial.print(username);
413+
Serial.print("'");
393414
#endif
394415

395416
if (accountType == ACCESS_GRANTED)
396417
{
418+
/*
419+
* Normal user - relay but no admin access
420+
*/
397421
unsigned long validSinceL = json["validsince"];
398422
unsigned long validUntilL = json["validuntil"];
399423
unsigned long nowL = epoch;
400424
int hourTz = timeinfo.tm_hour;
425+
401426
if (validUntilL < nowL || validSinceL > nowL)
402427
{
403428
processingState = expired;
@@ -410,9 +435,15 @@ void rfidProcess()
410435
}
411436
} else if (accountType == ACCESS_ADMIN)
412437
{
438+
/*
439+
* Admin user - enable relay (with no time limits) and wifi
440+
*/
413441
doEnableWifi = true;
414442
processingState = validAdmin;
415443
} else {
444+
/*
445+
* User exists but does not have access
446+
*/
416447
processingState = notValid;
417448
}
418449

0 commit comments

Comments
 (0)