Skip to content

Commit

Permalink
Moved CLI 'blink' implementation to core/cli.c
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Sep 27, 2023
1 parent 642870c commit 41578db
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
6 changes: 3 additions & 3 deletions pico/controller/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "acl.h"
#include "common.h"
#include "led.h"
#include "logd.h"
#include "relays.h"
#include "sdcard.h"
Expand Down Expand Up @@ -71,11 +70,11 @@ void execw(char *cmd, txrx f, void *context) {

if (N > 0) {
if (strncasecmp(cmd, "reboot", 6) == 0) {
reboot(f, context);
cli_reboot(f, context);
} else if (strncasecmp(cmd, "time ", 5) == 0) {
cli_set_time(&cmd[5], f, context);
} else if (strncasecmp(cmd, "blink", 5) == 0) {
led_blink(5);
cli_blink(f, context);
} else if (strncasecmp(cmd, "query", 5) == 0) {
query(f, context);
} else if (strncasecmp(cmd, "unlock", 6) == 0) {
Expand Down Expand Up @@ -262,6 +261,7 @@ void help(txrx f, void *context) {
f(context, "LIST ACL List cards in ACL");
f(context, "READ ACL Read ACL from SD card");
f(context, "WRITE ACL Write ACL to SD card");
f(context, "PASSCODES Sets the override passcodes");
f(context, "QUERY Display last card read/write");
f(context, "");
f(context, "MOUNT Mount SD card");
Expand Down
2 changes: 1 addition & 1 deletion pico/core/include/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ extern bool acl_grant(uint32_t, uint32_t);
extern bool acl_revoke(uint32_t, uint32_t);
extern bool acl_allowed(uint32_t, uint32_t);

extern bool acl_set_passcodes(uint32_t,uint32_t ,uint32_t ,uint32_t);
extern bool acl_set_passcodes(uint32_t, uint32_t, uint32_t, uint32_t);
extern bool acl_passcode(const char *);
3 changes: 2 additions & 1 deletion pico/core/include/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
typedef void (*txrx)(void *, const char *);

// CLI functions
void reboot();
void cli_reboot(txrx, void *);
void cli_set_time(char *, txrx, void *);
void cli_blink(txrx, void *);
void keypad(char *, txrx, void *);
void set_passcodes(char *, txrx, void *);
4 changes: 2 additions & 2 deletions pico/core/src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ bool acl_allowed(uint32_t facility_code, uint32_t card) {
/* Sets the override passcodes.
*
*/
bool acl_set_passcodes(uint32_t passcode1,uint32_t passcode2,uint32_t passcode3,uint32_t passcode4) {
bool acl_set_passcodes(uint32_t passcode1, uint32_t passcode2, uint32_t passcode3, uint32_t passcode4) {
PASSCODES[0] = passcode1 > 0 && passcode1 < 1000000 ? passcode1 : 0;
PASSCODES[1] = passcode2 > 0 && passcode2 < 1000000 ? passcode2 : 0;
PASSCODES[2] = passcode3 > 0 && passcode3 < 1000000 ? passcode3 : 0;
PASSCODES[3] = passcode4 > 0 && passcode4 < 1000000 ? passcode4 : 0;

return true;
return true;
}

/* Checks a keycode against the ACL passcode. Falls back to the compiled in master
Expand Down
27 changes: 17 additions & 10 deletions pico/core/src/cli.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <TPIC6B595.h>
#include <acl.h>
#include <buzzer.h>
#include <cli.h>
#include <led.h>
#include <logd.h>
#include <sys.h>
#include <TPIC6B595.h>
#include <wiegand.h>
#include <write.h>

/* Goes into a tight loop until the watchdog resets the processor.
*
*/
void reboot(txrx f, void *context) {
void cli_reboot(txrx f, void *context) {
while (true) {
buzzer_beep(1);

Expand All @@ -41,28 +42,34 @@ void cli_set_time(char *cmd, txrx f, void *context) {
f(context, ">> SET TIME OK");
}

/* Blinks the blue LED.
*
*/
void cli_blink(txrx f, void *context) {
led_blink(5);
}

/* Sets the override passcodes.
*
*/
void set_passcodes(char *cmd, txrx f, void *context) {
uint32_t passcodes[] = {0,0,0,0};
uint32_t passcodes[] = {0, 0, 0, 0};
int ix = 0;
char *token = strtok(cmd," ,");
char *token = strtok(cmd, " ,");

while (token != NULL && ix < 4) {
printf(">>>>>>> %s\n",token);
char *end = NULL;
unsigned long v = strtoul(token, &end, 10);

if (v > 0 && v < 1000000) {
passcodes[ix] = v;
passcodes[ix] = v;
}

token = strtok (NULL, " ,");
token = strtok(NULL, " ,");
ix++;
}

if (acl_set_passcodes(passcodes[0],passcodes[1],passcodes[2],passcodes[3])) {
if (acl_set_passcodes(passcodes[0], passcodes[1], passcodes[2], passcodes[3])) {
f(context, "ACL SET PASSCODES OK");
} else {
f(context, "ACL SET PASSCODES ERROR");
Expand Down
8 changes: 5 additions & 3 deletions pico/emulator/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ void execw(char *cmd, txrx f, void *context) {
int N = strlen(cmd);

if (N > 0) {
if (strncasecmp(cmd, "time ", 5) == 0) {
if (strncasecmp(cmd, "reboot", 6) == 0) {
cli_reboot(f, context);
} else if (strncasecmp(cmd, "time ", 5) == 0) {
cli_set_time(&cmd[5], f, context);
} else if (strncasecmp(cmd, "blink", 5) == 0) {
cli_blink(f, context);
} else if (strncasecmp(cmd, "query", 5) == 0) {
query(f, context);
} else if (strncasecmp(cmd, "open", 4) == 0) {
Expand All @@ -62,8 +66,6 @@ void execw(char *cmd, txrx f, void *context) {
on_press_button(f, context);
} else if (strncasecmp(cmd, "release", 7) == 0) {
on_release_button(f, context);
} else if (strncasecmp(cmd, "reboot", 6) == 0) {
reboot(f, context);
} else if (strncasecmp(cmd, "card ", 5) == 0) {
swipe(&cmd[5], f, context);
} else if (strncasecmp(cmd, "code ", 5) == 0) {
Expand Down
5 changes: 2 additions & 3 deletions pico/reference/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "acl.h"
#include "buzzer.h"
#include "common.h"
#include "led.h"
#include "logd.h"
#include "relays.h"
#include "sdcard.h"
Expand Down Expand Up @@ -73,11 +72,11 @@ void execw(char *cmd, txrx f, void *context) {

if (N > 0) {
if (strncasecmp(cmd, "reboot", 6) == 0) {
reboot(f, context);
cli_reboot(f, context);
} else if (strncasecmp(cmd, "time ", 5) == 0) {
cli_set_time(&cmd[5], f, context);
} else if (strncasecmp(cmd, "blink", 5) == 0) {
led_blink(5);
cli_blink(f, context);
} else if (strncasecmp(cmd, "unlock", 6) == 0) {
on_door_unlock(f, context);
} else if (strncasecmp(cmd, "query", 5) == 0) {
Expand Down

0 comments on commit 41578db

Please sign in to comment.