Skip to content

Commit

Permalink
Fixed write ACL to SD card logic
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 4, 2023
1 parent 374b2f5 commit f41b687
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
11 changes: 3 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- (?) Make -Wimplicit-function-declaration an error

- [x] Weird card after ACL revoking a card in the middle of a list

- [ ] Emulate keypad (cf. https://github.com/uhppoted/uhppoted-wiegand/issues/4)
- [x] 4-bit burst mode write
- [x] 4-bit burst mode read
Expand All @@ -11,19 +13,12 @@
- [x] set passcodes
- [x] include passcodes in CRC
- [x] clear ACL
- [ ] Weird card after ACL revoking a card in the middle of a list
- (?) list-acl issue probably
```
> ACL 10058399
> ACL 2147483647
> ACL 10058444
```

- [ ] 8-bit burst mode write
- [ ] 8-bit burst mode read
- [ ] card + PIN writer
- [ ] card + PIN read


- [ ] PicoW+TCP/IP
- [ ] Figure out SD card detect interrupt conflict
- (?) Use GPIO poll
Expand Down
40 changes: 24 additions & 16 deletions pico/core/src/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ int sdcard_read_acl(CARD cards[], int *N) {
while (f_gets(buffer, sizeof(buffer), &file) && ix < *N) {
buffer[strcspn(buffer, "\n")] = 0;

printf(">> READ %s\n", buffer);

char *p = strtok(buffer, " ");

if (p && ((card_number = strtol(p, NULL, 10)) != 0)) {
Expand Down Expand Up @@ -236,25 +238,31 @@ int sdcard_write_acl(CARD cards[], int N) {
return fr;
}

for (int i = 0; i < N; i++) {
int count = 0;
for (int i = 0; i < 32 && count < N; i++) {
CARD card = cards[i];
char record[64];

snprintf(record,
sizeof(record),
"%-8u %04d-%02d-%02d %04d-%02d-%02d %c %s",
card.card_number,
card.start.year,
card.start.month,
card.start.day,
card.end.year,
card.end.month,
card.end.day,
card.allowed ? 'Y' : 'N',
card.name);
if ((fr = f_printf(&file, "%s\n", record)) < 0) {
f_close(&file);
return fr;
if (card.card_number != 0 && card.card_number != 0xffffffff) {
snprintf(record,
sizeof(record),
"%-8u %04d-%02d-%02d %04d-%02d-%02d %c %s",
card.card_number,
card.start.year,
card.start.month,
card.start.day,
card.end.year,
card.end.month,
card.end.day,
card.allowed ? 'Y' : 'N',
card.name);

if ((fr = f_printf(&file, "%s\n", record)) < 0) {
f_close(&file);
return fr;
}

count++;
}
}

Expand Down

0 comments on commit f41b687

Please sign in to comment.