An access controller for man doors at our facility. It receives Wiegand signals from a keypad/card reader and activates a relay to open the door. Access codes are stored in EEPROM. The active code list is updated from TFTP on a local server.

Dependencies:   24LCxx_I2C CardReader USBHOST

Committer:
acesrobertm
Date:
Mon Sep 25 19:02:40 2017 +0000
Revision:
0:a56239ae90c2
in process of moving networking code to non-blocking format

Who changed what in which revision?

UserRevisionLine numberNew contents of line
acesrobertm 0:a56239ae90c2 1
acesrobertm 0:a56239ae90c2 2 #ifndef CODE_MEMORY_H_
acesrobertm 0:a56239ae90c2 3 #define CODE_MEMORY_H_
acesrobertm 0:a56239ae90c2 4
acesrobertm 0:a56239ae90c2 5 #include <algorithm>
acesrobertm 0:a56239ae90c2 6 #include "24LCxx_I2C/24LCxx_I2C.h"
acesrobertm 0:a56239ae90c2 7
acesrobertm 0:a56239ae90c2 8 #define EEPROM_LENGTH 1024
acesrobertm 0:a56239ae90c2 9 #define CODE_TABLE_SIZE 200 // bytes (codes * 2)
acesrobertm 0:a56239ae90c2 10 #define SPECIAL_CODE_TABLE_SIZE 20 // bytes (codes * 2)
acesrobertm 0:a56239ae90c2 11
acesrobertm 0:a56239ae90c2 12 #define EVENT_LOG_POINTER_SIZE 2 // bytes
acesrobertm 0:a56239ae90c2 13 #define EVENT_LOG_TIME_BASE_SIZE 4 // bytes
acesrobertm 0:a56239ae90c2 14 #define EVENT_SIZE 7 // bytes per event |1:event type|2:event value|4:ms timestamp|
acesrobertm 0:a56239ae90c2 15
acesrobertm 0:a56239ae90c2 16 // Event Types
acesrobertm 0:a56239ae90c2 17 #define EVENT_CARD_ACCESS_DENIED 1
acesrobertm 0:a56239ae90c2 18 #define EVENT_CARD_ACCESS_GRANTED 2
acesrobertm 0:a56239ae90c2 19 #define EVENT_KEYPAD_ACCESS_DENIED 3
acesrobertm 0:a56239ae90c2 20 #define EVENT_KEYPAD_ACCESS_GRANTED 4
acesrobertm 0:a56239ae90c2 21 #define EVENT_SPECIAL_CODE 5
acesrobertm 0:a56239ae90c2 22 #define EVENT_SPECIAL_CHANGE 6
acesrobertm 0:a56239ae90c2 23 #define EVENT_GATE_STATE_CHANGED 7 // 0 = Open, 1 = Closed
acesrobertm 0:a56239ae90c2 24 #define EVENT_ALARM_ACTIVE 8 // (Bit Array) 1:Power On, 2:East Tamper, 4:West Tamper, 8:Comms Loss
acesrobertm 0:a56239ae90c2 25 #define EVENT_ALARM_RESET 9
acesrobertm 0:a56239ae90c2 26
acesrobertm 0:a56239ae90c2 27 class CodeMemory
acesrobertm 0:a56239ae90c2 28 {
acesrobertm 0:a56239ae90c2 29 private:
acesrobertm 0:a56239ae90c2 30 C24LCXX_I2C* _eeprom;
acesrobertm 0:a56239ae90c2 31
acesrobertm 0:a56239ae90c2 32 int LogPointerAddress();
acesrobertm 0:a56239ae90c2 33 int FirstEventLogAddress();
acesrobertm 0:a56239ae90c2 34 int EventLogEndAddress();
acesrobertm 0:a56239ae90c2 35 void PrintEvent(unsigned short eventAddress);
acesrobertm 0:a56239ae90c2 36 int GetLatestEventAddress();
acesrobertm 0:a56239ae90c2 37 int GetNextEventAddress();
acesrobertm 0:a56239ae90c2 38 int GetNextEventAddress(unsigned short startAddress);
acesrobertm 0:a56239ae90c2 39 int GetPreviousEventAddress(unsigned short startAddress);
acesrobertm 0:a56239ae90c2 40
acesrobertm 0:a56239ae90c2 41 public:
acesrobertm 0:a56239ae90c2 42 CodeMemory(){_eeprom = new C24LCXX_I2C(D14, D15, 0, NC, 1000000);}
acesrobertm 0:a56239ae90c2 43 ~CodeMemory(){delete _eeprom;}
acesrobertm 0:a56239ae90c2 44 void EEPROMClear();
acesrobertm 0:a56239ae90c2 45 unsigned short ReadAccessCode(unsigned short address);
acesrobertm 0:a56239ae90c2 46 void WriteAccessCode(unsigned short address, unsigned short value);
acesrobertm 0:a56239ae90c2 47 unsigned int ReadEEPROMULong(unsigned short address);
acesrobertm 0:a56239ae90c2 48 void WriteEEPROMULong(unsigned short address, unsigned int value);
acesrobertm 0:a56239ae90c2 49 int FindAccessCode(unsigned short code);
acesrobertm 0:a56239ae90c2 50 int FindAccessCode(unsigned short code, unsigned short startAddress, unsigned short stopAddress);
acesrobertm 0:a56239ae90c2 51 int ActivateAccessCode(unsigned short value);
acesrobertm 0:a56239ae90c2 52 int DeactivateAccessCode(unsigned short value);
acesrobertm 0:a56239ae90c2 53 void PrintAllAccessCodes();
acesrobertm 0:a56239ae90c2 54 void SyncAccessCodes(unsigned short* codeList, unsigned short codeCount);
acesrobertm 0:a56239ae90c2 55 bool IsSpecialCode(unsigned short specialCodeIndex, unsigned short code, unsigned short defaultCode);
acesrobertm 0:a56239ae90c2 56 bool SetSpecialCode(unsigned short specialCodeIndex, unsigned short code);
acesrobertm 0:a56239ae90c2 57
acesrobertm 0:a56239ae90c2 58 void WriteEvent(unsigned char eventType, unsigned short eventValue);
acesrobertm 0:a56239ae90c2 59 void PrintEventLog();
acesrobertm 0:a56239ae90c2 60 void PrintRecentEvents();
acesrobertm 0:a56239ae90c2 61 void PrintRecentEvents(unsigned short numEvents);
acesrobertm 0:a56239ae90c2 62 };
acesrobertm 0:a56239ae90c2 63
acesrobertm 0:a56239ae90c2 64 #endif