forked from psi46/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_dtb.cpp
158 lines (135 loc) · 2.6 KB
/
pixel_dtb.cpp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// psi46_tb.cpp
#include "pixel_dtb.h"
#include <stdio.h>
#ifndef _WIN32
#include <unistd.h>
#include <iostream>
#endif
bool CTestboard::RpcLink(bool verbose)
{
bool error = false;
for (unsigned short i = 2; i < rpc_cmdListSize; i++)
{
try
{
rpc_GetCallId(i);
}
catch (CRpcError &e)
{
e.SetFunction(0);
if (verbose)
{
if (!error) printf("\nMissing DTB functions:\n");
std::string fname(rpc_cmdName[i]);
std::string fname_pretty;
rpc_TranslateCallName(fname, fname_pretty);
printf("%s\n", fname_pretty.c_str());
}
error = true;
}
}
return !error;
}
bool CTestboard::EnumNext(string &name)
{
char s[64];
if (!usb.EnumNext(s)) return false;
name = s;
return true;
}
bool CTestboard::Enum(unsigned int pos, string &name)
{
char s[64];
if (!usb.Enum(s, pos)) return false;
name = s;
return true;
}
bool CTestboard::FindDTB(string &usbId)
{
string name;
vector<string> devList;
unsigned int nDev;
unsigned int nr;
try
{
if (!EnumFirst(nDev)) throw int(1);
for (nr=0; nr<nDev; nr++)
{
if (!EnumNext(name)) continue;
if (name.size() < 4) continue;
if (name.compare(0, 4, "DTB_") == 0) devList.push_back(name);
}
}
catch (int e)
{
switch (e)
{
case 1: printf("Cannot access the USB driver\n"); return false;
default: return false;
}
}
if (devList.size() == 0)
{
printf("No DTB connected.\n");
return false;
}
if (devList.size() == 1)
{
usbId = devList[0];
return true;
}
// If more than 1 connected device list them
printf("\nConnected DTBs:\n");
for (nr=0; nr<devList.size(); nr++)
{
printf("%2u: %s", nr, devList[nr].c_str());
if (Open(devList[nr], false))
{
try
{
unsigned int bid = GetBoardId();
printf(" BID=%2u\n", bid);
}
catch (...)
{
printf(" Not identifiable\n");
}
Close();
}
else printf(" - in use\n");
}
printf("Please choose DTB (0-%u): ", (nDev-1));
char choice[8];
fgets(choice, 8, stdin);
sscanf (choice, "%d", &nr);
if (nr >= devList.size())
{
nr = 0;
printf("No DTB opened\n");
return false;
}
usbId = devList[nr];
return true;
}
bool CTestboard::Open(string &usbId, bool init)
{
rpc_Clear();
if (!usb.Open(&(usbId[0]))) return false;
if (init) Init();
return true;
}
void CTestboard::Close()
{
// if (usb.Connected()) Daq_Close();
usb.Close();
rpc_Clear();
}
void CTestboard::mDelay(uint16_t ms)
{
Flush();
#ifdef _WIN32
Sleep(ms); // Windows
#else
usleep(ms*1000); // Linux
#endif
}