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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
//
// Copyright 2013 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include <uhd/transport/nirio/rpc/usrprio_rpc_client.hpp>
#include <uhd/utils/platform.hpp>
namespace uhd { namespace usrprio_rpc {
usrprio_rpc_client::usrprio_rpc_client(
std::string server,
std::string port
) : _rpc_client(server, port, uhd::get_process_id(), uhd::get_host_id()),
_timeout(boost::posix_time::milliseconds(DEFAULT_TIMEOUT_IN_MS))
{
_ctor_status = _rpc_client.status() ? NiRio_Status_RpcConnectionError : NiRio_Status_Success;
}
usrprio_rpc_client::~usrprio_rpc_client()
{
}
nirio_status usrprio_rpc_client::niusrprio_enumerate(NIUSRPRIO_ENUMERATE_ARGS)
/*
#define NIUSRPRIO_ENUMERATE_ARGS \
usrprio_device_info_vtr& device_info_vtr
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
uint32_t vtr_size = 0;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_ENUMERATE, in_args, out_args, _timeout));
if (nirio_status_not_fatal(status)) {
out_args >> status;
out_args >> vtr_size;
}
if (nirio_status_not_fatal(status) && vtr_size > 0) {
device_info_vtr.resize(vtr_size);
for (size_t i = 0; i < (size_t)vtr_size; i++) {
usrprio_device_info info;
out_args >> info;
device_info_vtr[i] = info;
}
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_open_session(NIUSRPRIO_OPEN_SESSION_ARGS)
/*
#define NIUSRPRIO_OPEN_SESSION_ARGS \
const std::string& resource, \
const std::string& path, \
const std::string& signature, \
const uint16_t& download_fpga
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
in_args << path;
in_args << signature;
in_args << download_fpga;
//Open needs a longer timeout because the FPGA download can take upto 6 secs and the NiFpga libload can take 4.
static const uint32_t OPEN_TIMEOUT = 15000;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_OPEN_SESSION, in_args, out_args, boost::posix_time::milliseconds(OPEN_TIMEOUT)));
if (nirio_status_not_fatal(status)) {
out_args >> status;
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_close_session(NIUSRPRIO_CLOSE_SESSION_ARGS)
/*
#define NIUSRPRIO_CLOSE_SESSION_ARGS \
const std::string& resource
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_CLOSE_SESSION, in_args, out_args, _timeout));
if (nirio_status_not_fatal(status)) {
out_args >> status;
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_reset_device(NIUSRPRIO_RESET_SESSION_ARGS)
/*
#define NIUSRPRIO_RESET_SESSION_ARGS \
const std::string& resource
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_RESET_SESSION, in_args, out_args, _timeout));
if (nirio_status_not_fatal(status)) {
out_args >> status;
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_get_interface_path(NIUSRPRIO_GET_INTERFACE_PATH_ARGS)
/*
#define NIUSRPRIO_GET_INTERFACE_PATH_ARGS \
const std::string& resource, \
std::string& interface_path
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_GET_INTERFACE_PATH, in_args, out_args, _timeout));
if (nirio_status_not_fatal(status)) {
out_args >> status;
out_args >> interface_path;
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_download_fpga_to_flash(NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH_ARGS)
/*
#define NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH_ARGS \
const uint32_t& interface_num, \
const std::string& bitstream_path
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
in_args << bitstream_path;
static const uint32_t DOWNLOAD_FPGA_TIMEOUT = 1200000;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_DOWNLOAD_FPGA_TO_FLASH, in_args, out_args,
boost::posix_time::milliseconds(DOWNLOAD_FPGA_TIMEOUT)));
if (nirio_status_not_fatal(status)) {
out_args >> status;
}
return status;
}
nirio_status usrprio_rpc_client::niusrprio_download_bitstream_to_fpga(NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA_ARGS)
/*
#define NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA_ARGS \
const std::string& resource
*/
{
usrprio_rpc::func_args_writer_t in_args;
usrprio_rpc::func_args_reader_t out_args;
nirio_status status = NiRio_Status_Success;
in_args << resource;
status = _boost_error_to_nirio_status(
_rpc_client.call(NIUSRPRIO_DOWNLOAD_BITSTREAM_TO_FPGA, in_args, out_args, _timeout));
if (nirio_status_not_fatal(status)) {
out_args >> status;
}
return status;
}
nirio_status usrprio_rpc_client::_boost_error_to_nirio_status(const boost::system::error_code& err) {
if (err) {
switch (err.value()) {
case boost::asio::error::connection_aborted:
case boost::asio::error::connection_refused:
case boost::asio::error::eof:
return NiRio_Status_RpcSessionError;
case boost::asio::error::timed_out:
case boost::asio::error::operation_aborted:
return NiRio_Status_RpcOperationError;
default:
return NiRio_Status_SoftwareFault;
}
} else {
return NiRio_Status_Success;
}
}
}}
|