Skip to content

Commit

Permalink
(interim commit) skeleton implementation of card+keycode
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 10, 2023
1 parent a3e3e71 commit bcba783
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion pico/emulator/common/src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef void (*handler)(uint32_t, uint32_t, txrx, void *);
void help(txrx, void *);
void query(txrx, void *);
void swipe(char *cmd, txrx, void *);
void swipex(char *cmd, txrx, void *);

void on_press_button(txrx, void *);
void on_release_button(txrx, void *);
Expand Down Expand Up @@ -64,6 +65,8 @@ void execw(char *cmd, txrx f, void *context) {
on_release_button(f, context);
} else if (strncasecmp(cmd, "card ", 5) == 0) {
swipe(&cmd[5], f, context);
} else if (strncasecmp(cmd, "card+ ", 6) == 0) {
swipex(&cmd[6], f, context);
} else if (strncasecmp(cmd, "code ", 5) == 0) {
keypad(&cmd[1], f, context);
} else if (strncasecmp(cmd, "query", 5) == 0) {
Expand Down Expand Up @@ -91,8 +94,9 @@ void query(txrx f, void *context) {
void help(txrx f, void *context) {
f(context, "-----");
f(context, "Commands:");
f(context, "TIME YYYY-MM-DD HH:mm:ss Set date/time");
f(context, "TIME yyyy-mm-dd hh:mm:ss Set date/time");
f(context, "CARD nnnnnn Write card to Wiegand-26 interface");
f(context, "CARD+ nnnnnn dddddd Write card+keycode to Wiegand-26 interface");
f(context, "CODE dddddd Enter keypad digits");
f(context, "QUERY Display last card read/write");
f(context, "OPEN Opens door contact relay");
Expand Down Expand Up @@ -143,6 +147,45 @@ void swipe(char *cmd, txrx f, void *context) {
logd_log("CARD WRITE OK");
}

/* Card swipe + keycode emulation.
* Extract the facility code, card number keycode and invokes the handler function.
*
*/
void swipex(char *cmd, txrx f, void *context) {
// uint32_t facility_code = FACILITY_CODE;
// uint32_t card = 0;
// int N = strlen(cmd);
// int rc;

// if (N < 5) {
// if ((rc = sscanf(cmd, "%0u", &card)) < 1) {
// return;
// }
// } else {
// if ((rc = sscanf(&cmd[N - 5], "%05u", &card)) < 1) {
// return;
// }

// if (N == 6 && ((rc = sscanf(cmd, "%01u", &facility_code)) < 1)) {
// return;
// } else if (N == 7 && ((rc = sscanf(cmd, "%02u", &facility_code)) < 1)) {
// return;
// } else if (N == 8 && ((rc = sscanf(cmd, "%03u", &facility_code)) < 1)) {
// return;
// } else if (N > 8) {
// return;
// }
// }

if ((mode == WRITER) || (mode == EMULATOR)) {
write_card(100, 58401);
keypad("7531#", f, context);
}

f(context, "CARD+ WRITE OK");
logd_log("CARD+ WRITE OK");
}

/* Pushbutton emulation command handler.
* Opens/closes the pushbutton emulation relay (in reader mode only).
*
Expand Down

0 comments on commit bcba783

Please sign in to comment.