forked from vfp2/MeterFeeder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.h
111 lines (96 loc) · 3.04 KB
/
driver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* MeterFeeder Library
*
* by fp2.dev
*/
#pragma once
#include <cstring>
#include <iostream>
#include <stdarg.h>
#include <string>
#include <vector>
#include <math.h>
#include "ftd2xx/ftd2xx.h"
#include "constants.h"
#include "generator.h"
using namespace std;
namespace MeterFeeder {
/**
* Driver for MeterFeeder Library.
*
* Provides functionality to initialize connected USB MED MMI generators and get entropy from them.
*/
class Driver {
public:
/**
* Initialize all the connected generators.
*
* @param errorReason: Contains error reason string there was an error.
*
* @return true on successful initialization, false on failure
*/
bool Initialize(string* errorReason);
/**
* Shutdown and de-initialize all the generators.
*/
void Shutdown();
/**
* Stop streaming on the specified generator.
*
* @param Handle of the generator.
* @param Serial number identifying the device.
* @param Error reason upon failure to retrieve data.
*/
void Clear(FT_HANDLE handle, string* errorReason);
/**
* Get the number of connected and successfully initialized generators.
*
* @return The number of initialized devices
*/
int GetNumberGenerators();
/**
* Get the list of connected and successfully initialized generators.
*
* @return The list of Generators.
*/
vector<Generator>* GetListGenerators();
/**
* Find generator specified by FT_HANDLE.
*
* @param FT_HANDLE determined when the device was opened.
*
* @return The Generator object if found, else null.
*/
Generator* FindGeneratorByHandle(FT_HANDLE handle);
/**
* Find generator specified by serial number.
*
* @param Serial number identifying the device.
*
* @return The Generator object if found, else null.
*/
Generator* FindGeneratorBySerial(string serialNumber);
/**
* Get a byte of randomness.
*
* @param Handle of the generator.
* @param Pointer where to store the byte.
* @param Error reason upon failure to retrieve data.
*/
void GetByte(FT_HANDLE handle, unsigned char *entropyByte, string* errorReason) {
GetBytes(handle, 1, entropyByte, errorReason);
}
/**
* Get bytes of randomness.
*
* @param Handle of the generator.
* @param Length in bytes to read.
* @param Pointer where to store the bytes.
* @param Error reason upon failure to retrieve data.
*/
void GetBytes(FT_HANDLE handle, int length, unsigned char *entropyBytes, string* errorReason);
private:
vector<Generator> _generators;
void makeErrorStr(string* errorReason, const char* format, ...);
};
}