Skip to content

Commit

Permalink
Keypad emulation wrap up (cf. #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 26, 2023
1 parent f10b61e commit 2418782
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 48 deletions.
15 changes: 2 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [x] Weird card after ACL revoking a card in the middle of a list
- [x] Clear ACL

- [ ] Emulate keypad (cf. https://github.com/uhppoted/uhppoted-wiegand/issues/4)
- [x] Emulate keypad (cf. https://github.com/uhppoted/uhppoted-wiegand/issues/4)
- [x] 4-bit burst mode write
- [x] 4-bit burst mode read
- [x] controller passcodes
Expand All @@ -16,19 +16,8 @@
- [x] card + PIN read
- [x] CHANGELOG
- [x] Check mode == CONTROLLER/READER
- [x] unlock
- [x] door sensor emulation
- [x] pushbutton emulation
= [x] LEDs
- [x] Replace READER with CONTROLLER
- [x] Replace WRITER with EMULATOR
- [x] README
- [x] build constants
- [x] _operating modes_
- [x] keypad modes
- [x] passcodes
- [x] master passcode
- [ ] Restructure emulator CLI
- [x] Restructure emulator

- [ ] PicoW+TCP/IP
- [ ] Figure out SD card detect interrupt conflict
Expand Down
37 changes: 37 additions & 0 deletions pico/emulator/common/src/emulator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <stdlib.h>

#include <acl.h>
#include <common.h>
#include <led.h>
#include <logd.h>
#include <read.h>
#include <relays.h>
#include <wiegand.h>

const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;

void dispatch(uint32_t v) {
char s[64];

if ((v & MSG) == MSG_CARD) {
on_card_read(v & 0x0fffffff);

cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}

if ((v & MSG) == MSG_CODE) {
char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));

snprintf(s, sizeof(s), "CODE %s", b);
logd_log(s);
free(b);
}

if ((v & MSG) == MSG_KEYPAD_DIGIT) {
on_keypad_digit(v & 0x0fffffff);
}
}
1 change: 1 addition & 0 deletions pico/emulator/pico/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pico_sdk_init()
add_executable(wiegand-emulator
./src/emulator.c
${COMMON}/src/cli.c
${COMMON}/src/emulator.c
${CORE}/src/common.c
${CORE}/src/uart.c
${CORE}/src/sys.c
Expand Down
3 changes: 3 additions & 0 deletions pico/emulator/pico/base/include/emulator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include <stdint.h>
#include "wiegand.h"

extern void dispatch(uint32_t);
46 changes: 23 additions & 23 deletions pico/emulator/pico/base/src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <uart.h>
#include <write.h>

#include "../include/emulator.h"

#define VERSION "v0.8.5"

// GPIO
Expand All @@ -30,9 +32,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
const uint32_t MSG_DOOR = 0x90000000;
Expand Down Expand Up @@ -81,6 +80,7 @@ int main() {
while (true) {
uint32_t v;
queue_remove_blocking(&queue, &v);
dispatch(v);

if ((v & MSG) == MSG_SYSINIT) {
sysinit();
Expand All @@ -107,26 +107,26 @@ int main() {
free(b);
}

if ((v & MSG) == MSG_CARD) {
on_card_read(v & 0x0fffffff);

char s[64];
cardf(&last_card, s, sizeof(s), false);
logd_log(s);
}

if ((v & MSG) == MSG_CODE) {
char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));
char s[64];

snprintf(s, sizeof(s), "CODE %s", b);
logd_log(s);
free(b);
}

if ((v & MSG) == MSG_KEYPAD_DIGIT) {
on_keypad_digit(v & 0x0fffffff);
}
// if ((v & MSG) == MSG_CARD) {
// on_card_read(v & 0x0fffffff);
//
// char s[64];
// cardf(&last_card, s, sizeof(s), false);
// logd_log(s);
// }
//
// if ((v & MSG) == MSG_CODE) {
// char *b = (char *)(SRAM_BASE | (v & 0x0fffffff));
// char s[64];
//
// snprintf(s, sizeof(s), "CODE %s", b);
// logd_log(s);
// free(b);
// }
//
// if ((v & MSG) == MSG_KEYPAD_DIGIT) {
// on_keypad_digit(v & 0x0fffffff);
// }

if ((v & MSG) == MSG_LED) {
led_event(v & 0x0fffffff);
Expand Down
1 change: 1 addition & 0 deletions pico/emulator/pico/usb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pico_sdk_init()
add_executable(wiegand-emulator-usb
../src/emulator.c
${COMMON}/src/cli.c
${COMMON}/src/emulator.c
${CORE}/src/common.c
${CORE}/src/uart.c
${CORE}/src/sys.c
Expand Down
3 changes: 3 additions & 0 deletions pico/emulator/pico/usb/include/emulator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include "wiegand.h"
#include <stdint.h>

extern void dispatch(uint32_t);
6 changes: 3 additions & 3 deletions pico/emulator/pico/usb/src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <usb.h>
#include <write.h>

#include "../include/emulator.h"

#define VERSION "v0.8.5"

// GPIO
Expand All @@ -31,9 +33,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
const uint32_t MSG_DOOR = 0x90000000;
Expand Down Expand Up @@ -81,6 +80,7 @@ int main() {
while (true) {
uint32_t v;
queue_remove_blocking(&queue, &v);
dispatch(v);

if ((v & MSG) == MSG_SYSINIT) {
sysinit();
Expand Down
1 change: 1 addition & 0 deletions pico/emulator/picow/base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pico_sdk_init()
add_executable(wiegand-emulator-picow
./src/emulator.c
${COMMON}/src/cli.c
${COMMON}/src/emulator.c
${CORE}/src/common.c
${CORE}/src/uart.c
${CORE}/src/sys.c
Expand Down
3 changes: 3 additions & 0 deletions pico/emulator/picow/base/include/emulator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include "wiegand.h"
#include <stdint.h>

extern void dispatch(uint32_t);
6 changes: 3 additions & 3 deletions pico/emulator/picow/base/src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include <uart.h>
#include <write.h>

#include "../include/emulator.h"

#define VERSION "v0.8.5"

// GPIO
Expand All @@ -31,9 +33,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
const uint32_t MSG_DOOR = 0x90000000;
Expand Down Expand Up @@ -84,6 +83,7 @@ int main() {
while (true) {
uint32_t v;
queue_remove_blocking(&queue, &v);
dispatch(v);

if ((v & MSG) == MSG_SYSINIT) {
sysinit();
Expand Down
1 change: 1 addition & 0 deletions pico/emulator/picow/wifi+usb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pico_sdk_init()

add_executable(wiegand-emulator-wifi-usb
./src/emulator.c
${COMMON}/src/emulator.c
${COMMON}/src/cli.c
${CORE}/src/common.c
${CORE}/src/uart.c
Expand Down
3 changes: 3 additions & 0 deletions pico/emulator/picow/wifi+usb/include/emulator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include "wiegand.h"
#include <stdint.h>

extern void dispatch(uint32_t);
6 changes: 3 additions & 3 deletions pico/emulator/picow/wifi+usb/src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <usb.h>
#include <write.h>

#include "../include/emulator.h"

#define VERSION "v0.8.5"

// GPIO
Expand All @@ -33,9 +35,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
const uint32_t MSG_DOOR = 0x90000000;
Expand Down Expand Up @@ -88,6 +87,7 @@ int main() {
while (true) {
uint32_t v;
queue_remove_blocking(&queue, &v);
dispatch(v);

if ((v & MSG) == MSG_SYSINIT) {
sysinit();
Expand Down
1 change: 1 addition & 0 deletions pico/emulator/picow/wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pico_sdk_init()

add_executable(wiegand-emulator-wifi
./src/emulator.c
${COMMON}/src/emulator.c
${COMMON}/src/cli.c
${CORE}/src/common.c
${CORE}/src/uart.c
Expand Down
3 changes: 3 additions & 0 deletions pico/emulator/picow/wifi/include/emulator.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once

#include "wiegand.h"
#include <stdint.h>

extern void dispatch(uint32_t);
6 changes: 3 additions & 3 deletions pico/emulator/picow/wifi/src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <uart.h>
#include <write.h>

#include "../include/emulator.h"

#define VERSION "v0.8.5"

// GPIO
Expand All @@ -32,9 +34,6 @@ const uint32_t MSG_WATCHDOG = 0x00000000;
const uint32_t MSG_SYSCHECK = 0x10000000;
const uint32_t MSG_RX = 0x20000000;
const uint32_t MSG_TX = 0x30000000;
const uint32_t MSG_CARD = 0x40000000;
const uint32_t MSG_CODE = 0x50000000;
const uint32_t MSG_KEYPAD_DIGIT = 0x60000000;
const uint32_t MSG_LED = 0x70000000;
const uint32_t MSG_RELAY = 0x80000000;
const uint32_t MSG_DOOR = 0x90000000;
Expand Down Expand Up @@ -87,6 +86,7 @@ int main() {
while (true) {
uint32_t v;
queue_remove_blocking(&queue, &v);
dispatch(v);

if ((v & MSG) == MSG_SYSINIT) {
sysinit();
Expand Down

0 comments on commit 2418782

Please sign in to comment.