Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * DatakeyToken.h
- *
- * Created on: Mar 15, 2014
- * Author: swindle
- */
- #ifndef DATAKEYTOKEN_H_
- #define DATAKEYTOKEN_H_
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdio>
- #include <linux/i2c-dev.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- #include <cstring>
- #include <unistd.h>
- #include <stdint.h>
- #include <ctype.h>
- #include <iomanip>
- #include <iterator>
- #include <algorithm>
- #include <sstream>
- #include <fstream>
- //#define MAX_BUS 0x1FFF
- ///////////////////////////////////////////////////////////////////////////
- //
- // Preprocessor Defines :
- // The first 2 of these can be found by using i2ctools installed
- // in most linux distributions. Using "i2cdetect -l" will list
- // the buses available for use on the system. "i2cdetect -y -r 1"
- // ( where 1 is the bus where your device is located) will give you
- // the address of the device. Using the output from "i2cdetect -y -r 1"
- // we can see that we have a device in 0x50 below. This happens to be
- // the token and this should match the information provided on the data
- // sheet, but here we have conformation that the device is present.
- //
- // 0 1 2 3 4 5 6 7 8 9 a b c d e f
- // 00: -- -- -- -- -- -- -- -- -- -- -- -- --
- // 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // 50: 50 -- -- -- UU UU UU UU -- -- -- -- -- -- -- --
- // 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- // 70: -- -- -- -- -- -- -- --
- //
- // I2C_BUS the bus which the token is placed confirmed by i2cdetect.
- // TOKEN_BUS_ADDRESS memory address of token. This is on the data sheet
- // but can also be deduced via i2cdetect.
- //
- ////////////////////////////////////////////////////////////////////////////
- #define I2C_BUS 1
- #define TOKEN_BUS_ADDRESS 0x50
- ////////////////////////////////////////////////////////////////////////////
- //
- // The following defines are relevent only to the specific token type
- // the datakey token ISK. And can be found in the datakey specifications
- // sheet. Hex is easier to use for all values instead of mixing them up,
- // at least for me).
- //
- // TOKEN_I2C_BUFFER is the page size of the line (e.g. 32 characters for 0x20)
- // TOKEN_MIN_RANGE is the start address of where data can be placed. Factoid:
- // Some I2C devices can start at higer ranges.
- // TOKEN_MAX_RANGE is the max range of the token and the last available storage
- // byte.
- // TOKEN_MAX_PAGE is defined by dividing the TOKEN_MAX_RANGE / TOKEN_I2C_BUFFER
- // all loops based on this number must start begin at 0 for full
- // range.
- // TOKEN_PROGRESS is the percentage of 1 action over the TOKEN_MAX_RANGE
- //
- //
- //
- //////////////////////////////////////////////////////////////////////////////
- #define TOKEN_I2C_BUFFER 0x20
- #define TOKEN_MIN_RANGE 0x0000
- #define TOKEN_MAX_RANGE 0x1FFF
- #define TOKEN_MAX_PAGE ( TOKEN_MAX_RANGE / TOKEN_I2C_BUFFER )
- #define TOKEN_PROGRESS (float)( 1.0 / TOKEN_MAX_RANGE )
- using namespace std;
- class DatakeyToken {
- public:
- DatakeyToken();
- virtual ~DatakeyToken();
- ///////////////////////////////////////////////////////////////////////////////////
- //
- // The DatakeToken header is arranged to give user access to controllable members
- // but keep the workhorse members private. Example: the readTheToken member
- // can control 3 diffrent private members; tokenDisplayAll(), tokenDisplayLine(),
- // and tokenDisplayPrintable(). This allows for the minimum of public members.
- // Greater detail is in cpp file.
- //
- ///////////////////////////////////////////////////////////////////////////////////
- int readTheToken( char , unsigned int ); // displays data from token
- int formatTheToken( bool ); // formats the token with 0xff
- int writeToToken( char*, char, unsigned int ); // writes data to the token
- int eraseLine( unsigned int ); // erases a line of the token
- long long int checksumToken(); // creates a checksum of the token
- int tokenCopy( int, int ); // copies the token to another token
- int copyFileToToken( string ); // copies file to token ( inop )
- private:
- ///////////////////////////////////////////////////////////////////////////
- // defines of private class variables
- ///////////////////////////////////////////////////////////////////////////
- int file; // identifies the opened token
- vector<string> tokenVec; // vector that all token data is read into
- char dataBuffer[TOKEN_BUS_ADDRESS]; // size of each buffer ( 32 bytes )
- ////////////////////////////////////////////////////////////////////////////
- // defines private functions of class. Greater detail of each is in cpp file
- /////////////////////////////////////////////////////////////////////////////
- void tokenDisplayAll(); // displays all characters in token
- void tokenDisplayLine( unsigned int ); // displays single line of token
- void tokenDisplayPrintable(); // displays only printable characters
- int tokenFormat(); // formats the token
- int tokenOpen(); // opens the token for read/write
- int tokenRead(); // places token data in tokenVec vector
- void tokenClose(); // closes the token
- int tokenWrite( char*, char, unsigned int ); // writes to data to token
- };
- #endif /* DATAKEYTOKEN_H_ */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement