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 /* TFTPClient.h */
acesrobertm 0:a56239ae90c2 2
acesrobertm 0:a56239ae90c2 3 /** \file
acesrobertm 0:a56239ae90c2 4 TFTP Client header file
acesrobertm 0:a56239ae90c2 5 */
acesrobertm 0:a56239ae90c2 6
acesrobertm 0:a56239ae90c2 7 #ifndef TFTPCLIENT_H_
acesrobertm 0:a56239ae90c2 8 #define TFTPCLIENT_H_
acesrobertm 0:a56239ae90c2 9
acesrobertm 0:a56239ae90c2 10 #include <cstdint>
acesrobertm 0:a56239ae90c2 11 #include "EthernetInterface.h"
acesrobertm 0:a56239ae90c2 12 #include "NetworkStack.h"
acesrobertm 0:a56239ae90c2 13 #include "UDPSocket.h"
acesrobertm 0:a56239ae90c2 14 #include <inet.h>
acesrobertm 0:a56239ae90c2 15
acesrobertm 0:a56239ae90c2 16 using std::uint8_t;
acesrobertm 0:a56239ae90c2 17 using std::uint16_t;
acesrobertm 0:a56239ae90c2 18 using std::uint32_t;
acesrobertm 0:a56239ae90c2 19
acesrobertm 0:a56239ae90c2 20 #define TFTP_DEFAULT_PORT 69
acesrobertm 0:a56239ae90c2 21 #define TFTP_DEFAULT_TIMEOUT 4000
acesrobertm 0:a56239ae90c2 22 #define TFTP_MAX_DATA_SIZE 512
acesrobertm 0:a56239ae90c2 23 #define TFTP_MAX_PACKET_SIZE TFTP_MAX_DATA_SIZE+4
acesrobertm 0:a56239ae90c2 24 #define MAX_TFTP_FILE_SIZE 30000 // bytes
acesrobertm 0:a56239ae90c2 25
acesrobertm 0:a56239ae90c2 26 enum TFTPOpcode
acesrobertm 0:a56239ae90c2 27 {
acesrobertm 0:a56239ae90c2 28 RRQ = 1, // Read request
acesrobertm 0:a56239ae90c2 29 WRQ, // Write request
acesrobertm 0:a56239ae90c2 30 DATA, // Data packet
acesrobertm 0:a56239ae90c2 31 ACK, // Acknowledgement
acesrobertm 0:a56239ae90c2 32 ERR // Error
acesrobertm 0:a56239ae90c2 33 };
acesrobertm 0:a56239ae90c2 34
acesrobertm 0:a56239ae90c2 35 enum TFTPError
acesrobertm 0:a56239ae90c2 36 {
acesrobertm 0:a56239ae90c2 37 NOT_DEFINED, // Not defined, see error message (if any).
acesrobertm 0:a56239ae90c2 38 FILE_NOT_FOUND, // File not found.
acesrobertm 0:a56239ae90c2 39 ACCESS_VIOLATION, // Access violation.
acesrobertm 0:a56239ae90c2 40 DISK_FULL, // Disk full or allocation exceeded.
acesrobertm 0:a56239ae90c2 41 ILLEGAL_OP, // Illegal TFTP operation.
acesrobertm 0:a56239ae90c2 42 UNKNOWN_TID, // Unknown transfer ID.
acesrobertm 0:a56239ae90c2 43 FILE_EXISTS, // File already exists.
acesrobertm 0:a56239ae90c2 44 NO_USER, // No such user.
acesrobertm 0:a56239ae90c2 45 };
acesrobertm 0:a56239ae90c2 46
acesrobertm 0:a56239ae90c2 47 class TFTPClient
acesrobertm 0:a56239ae90c2 48 {
acesrobertm 0:a56239ae90c2 49 public:
acesrobertm 0:a56239ae90c2 50 TFTPClient(EthernetInterface *stack) : m_eth(stack){
acesrobertm 0:a56239ae90c2 51 m_download_in_progress = false;
acesrobertm 0:a56239ae90c2 52 m_tftp_addr = NULL;
acesrobertm 0:a56239ae90c2 53 }
acesrobertm 0:a56239ae90c2 54
acesrobertm 0:a56239ae90c2 55 /**Get current time (blocking)
acesrobertm 0:a56239ae90c2 56 Retrieve file from TFTP server. Non-blocking
acesrobertm 0:a56239ae90c2 57 @param host TFTP server IPv4 address or hostname (will be resolved via DNS)
acesrobertm 0:a56239ae90c2 58 @param filename File to retrieve from the server.
acesrobertm 0:a56239ae90c2 59 */
acesrobertm 0:a56239ae90c2 60 bool readFile(char* data, const char* host, const char* filename, const uint16_t port = TFTP_DEFAULT_PORT, const uint32_t timeout = TFTP_DEFAULT_TIMEOUT);
acesrobertm 0:a56239ae90c2 61 int update();
acesrobertm 0:a56239ae90c2 62
acesrobertm 0:a56239ae90c2 63 private:
acesrobertm 0:a56239ae90c2 64 EthernetInterface *m_eth;
acesrobertm 0:a56239ae90c2 65 UDPSocket m_sock;
acesrobertm 0:a56239ae90c2 66 SocketAddress* m_tftp_addr;
acesrobertm 0:a56239ae90c2 67 char* m_data;
acesrobertm 0:a56239ae90c2 68 int m_bytes_sent;
acesrobertm 0:a56239ae90c2 69 int m_bytes_received;
acesrobertm 0:a56239ae90c2 70 int m_block_number;
acesrobertm 0:a56239ae90c2 71 bool m_download_in_progress;
acesrobertm 0:a56239ae90c2 72 int m_next_data_byte_index;
acesrobertm 0:a56239ae90c2 73 };
acesrobertm 0:a56239ae90c2 74
acesrobertm 0:a56239ae90c2 75 #endif /* TFTPCLIENT_H_ */
acesrobertm 0:a56239ae90c2 76