iCub-main
Loading...
Searching...
No Matches
diagnostics_buttons.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3 * Author: Valentina Gaggero
4 * email: valentina.gaggero@iit.it
5 * website: www.robotcub.org
6 * Permission is granted to copy, distribute, and/or modify this program
7 * under the terms of the GNU General Public License, version 2 or any
8 * later version published by the Free Software Foundation.
9 *
10 * A copy of the license can be found at
11 * http://www.robotcub.org/icub/license/gpl.txt
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details
17*/
18
19/* @file template_buttons.c
20 @brief
21 @author valentina.gaggero@iit.it
22 @date 03/22/2013
23**/
24
25
26// --------------------------------------------------------------------------------------------------------------------
27// - external dependencies
28// --------------------------------------------------------------------------------------------------------------------
29
30
31
32// --------------------------------------------------------------------------------------------------------------------
33// - declaration of external variables
34// --------------------------------------------------------------------------------------------------------------------
35
36
37// --------------------------------------------------------------------------------------------------------------------
38// - declaration of extern public interface
39// --------------------------------------------------------------------------------------------------------------------
40#include "template_buttons.hpp"
41#include "OPCprotocolManager.h"
42#include "OPCprotocolManager_Cfg.h"
43#include "EoDiagnostics.h"
44
45// --------------------------------------------------------------------------------------------------------------------
46// - declaration of extern hidden interface
47// --------------------------------------------------------------------------------------------------------------------
48
49
50// --------------------------------------------------------------------------------------------------------------------
51// - #define with internal scope
52// --------------------------------------------------------------------------------------------------------------------
53
54
55
56// --------------------------------------------------------------------------------------------------------------------
57// - definition (and initialisation) of extern variables, but better using _get(), _set()
58// --------------------------------------------------------------------------------------------------------------------
59extern OPCprotocolManager *opcMan_ptr;
60extern ACE_SOCK_Dgram *ACE_socket;
61
62eOdgn_commands_t dgnCommands={0};
64
65// --------------------------------------------------------------------------------------------------------------------
66// - typedef with internal scope
67// --------------------------------------------------------------------------------------------------------------------
68
69
70
71// --------------------------------------------------------------------------------------------------------------------
72// - declaration of static functions
73// --------------------------------------------------------------------------------------------------------------------
74static uint32_t s_getAddressFromUser(void);
75static void enaDisaDiagnostic(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr);
76
77// --------------------------------------------------------------------------------------------------------------------
78// - definition (and initialization) of static variables
79// --------------------------------------------------------------------------------------------------------------------
80
81
82// --------------------------------------------------------------------------------------------------------------------
83// - definition of extern public functions
84// --------------------------------------------------------------------------------------------------------------------
85void commands(void)
86{
87 printf("\nq: quit\n");
88 printf("0: ena/disa diagnostics on a ems\n");
89 printf("1: ena/disa diagnostics on a group of ems (exteranl fault is NOT checked)\n");
90 printf("2: ena/disa diagnostics on a group of ems and exteranl fault is checked \n");
91 printf("3: advanced configuration....\n");
92 printf("4: ena/disa rx setpoint che for red ball demo.\n");
93 printf("5: ........\n");
94 printf("\n");
95}
96
97static uint32_t s_getAddressFromUser(void)
98{
99 char addrstr[20];
100 int ret;
101 uint32_t ip1,ip2,ip3,ip4, address=0;
102
103 printf("Insert destination host: x.x.x.x ");
104 ret = scanf("%s", &addrstr[0]);
105 ret = sscanf(addrstr,"%d.%d.%d.%d",&ip1,&ip2,&ip3,&ip4);
106 address = (ip1<<24)|(ip2<<16)|(ip3<<8)|ip4 ;
107
108 return(address);
109}
110
111
112int32_t callback_button_x(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr, int16_t id)
113{
114 printf("button %d\n", id);
115
116 uint32_t dest_addr = s_getAddressFromUser();
117 uint16_t size = 0;
118 opcprotman_res_t res;
119
120 addr->set(4444, dest_addr);
121
122 if(opcMan_ptr == NULL)
123 {
124 printf("opcMan_ptr is NULL\n");
125 return(0);
126 }
127
128 res = opcprotman_Form(opcMan_ptr, opcprotman_opc_ask, id, NULL /*setdata*/, (opcprotman_message_t*)payload_ptr, &size);
129 if(opcprotman_OK != res)
130 {
131
132 printf("erron in former\n");
133 return(0);
134 }
135 printf("in button %d : size=%d \n", id, size);
136
137 return(size);
138}
139
140// fill the callback with your code
141uint32_t callback_button_0(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
142{
143 uint32_t dest_addr;
144 uint16_t size = 0;
145 uint32_t cmdena=0;
146 uint32_t extFaultEna=0;
147 uint32_t canStatistics=0;
148 uint32_t ethCounters=0;
149 opcprotman_res_t res;
150 int ret;
151
152 if(opcMan_ptr == NULL)
153 {
154 printf("opcMan_ptr is NULL\n");
155 return(0);
156 }
157
158
159 printf("enable/disable diagnostics. Press 1 to enable 0 otherwise\n");
160 ret = scanf("%d", &cmdena);
161
162 printf("enable/disable Check external fault. Press 1 to enable 0 otherwise\n");
163 ret = scanf("%d", &extFaultEna);
164
165 printf("enable/disable can statistics. Press 1 to enable 0 otherwise\n");
166 ret = scanf("%d", &canStatistics);
167
168 printf("enable/disable Check eth counters. Press 0 to disable or 1 for crcError, 2 for num of rxUnicat, 4 for txtUnicast\n");
169 ret = scanf("%d", &ethCounters);
170
171 dest_addr = s_getAddressFromUser();
172 printf("address is 0x %x \n", dest_addr);
173
174 if(cmdena>1)
175 {
176 cmdena=1;
177 }
178
179 if(extFaultEna>1)
180 {
181 extFaultEna=1;
182 }
183
184 if(canStatistics>1)
185 {
186 canStatistics=1;
187 }
188 dgnCommands.enable = cmdena;
189 dgnCommands.signalExtFault = extFaultEna;
190 dgnCommands.signalEthCounters = ethCounters;
191 dgnCommands.signalCanStatistics = canStatistics;
192// addr->set(4444, (10<<24)|(255<<16)|(72<<8)|19 );
193 addr->set(4444, dest_addr);
194
195 res = opcprotman_Form(opcMan_ptr, opcprotman_opc_set, eodgn_nvidbdoor_cmds, &dgnCommands, (opcprotman_message_t*)payload_ptr, &size);
196 if(opcprotman_OK != res)
197 {
198
199 printf("erron in former\n");
200 return(0);
201 }
202
203 return(size);
204}
205
206
207
208
209uint32_t callback_button_1(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
210{
211 uint32_t cmdena=0;
212 int ret;
213
214 if(opcMan_ptr == NULL)
215 {
216 printf("opcMan_ptr is NULL\n");
217 return(0);
218 }
219
220 printf("enable/disable diagnostics for a set of board. Press 1 to enable 0 otherwise\n");
221 ret = scanf("%d", &cmdena);
222 dgnCommands.enable = cmdena;
223
224 dgnCommands.signalExtFault = 0;
225 dgnCommands.signalEthCounters = 0;
226 dgnCommands.signalCanStatistics = 0;
227
228 enaDisaDiagnostic(payload_ptr, payload_size, addr);
229
230 return(0); //no data to send in main loop
231
232}
233
234uint32_t callback_button_2(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
235{
236 uint32_t cmdena=0;
237 int ret;
238
239 if(opcMan_ptr == NULL)
240 {
241 printf("opcMan_ptr is NULL\n");
242 return(0);
243 }
244
245 printf("enable/disable diagnostics for a set of board. Press 1 to enable 0 otherwise\n");
246 ret = scanf("%d", &cmdena);
247 dgnCommands.enable = cmdena;
248
249 dgnCommands.signalExtFault = 1;
250 dgnCommands.signalEthCounters = 0;
251 dgnCommands.signalCanStatistics = 0;
252
253 enaDisaDiagnostic(payload_ptr, payload_size, addr);
254 return(0); //no data to send in main loop
255}
256
257
258uint32_t callback_button_3(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
259{
260 uint32_t cmdena=0;
261 uint32_t extFaultEna=0;
262 uint32_t canStatistics=0;
263 uint32_t ethCounters=0;
264 int ret;
265
266 if(opcMan_ptr == NULL)
267 {
268 printf("opcMan_ptr is NULL\n");
269 return(0);
270 }
271
272 printf("enable/disable diagnostics for a set of board. Press 1 to enable 0 otherwise\n");
273 ret = scanf("%d", &cmdena);
274 dgnCommands.enable = cmdena;
275
276 if(cmdena)
277 {
278 printf("enable/disable Check external fault. Press 1 to enable 0 otherwise\n");
279 ret = scanf("%d", &extFaultEna);
280
281 printf("enable/disable can statistics. Press 1 to enable 0 otherwise\n");
282 ret = scanf("%d", &canStatistics);
283
284 printf("enable/disable Check eth counters. Press 0 to disable or 1 for crcError, 2 for num of rxUnicat, 4 for txtUnicast\n");
285 ret = scanf("%d", &ethCounters);
286
287 dgnCommands.signalExtFault = extFaultEna;
288 dgnCommands.signalEthCounters = ethCounters;
289 dgnCommands.signalCanStatistics = canStatistics;
290 }
291 else
292 {
293 dgnCommands.signalExtFault = 0;
294 dgnCommands.signalEthCounters = 0;
295 dgnCommands.signalCanStatistics = 0;
296 }
297
298 enaDisaDiagnostic(payload_ptr, payload_size, addr);
299
300
301 return(0);
302}
303
304uint32_t callback_button_4(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
305{
306 uint16_t size = 0;
307 uint32_t cmdena=0;
308 uint32_t min, max, j;
309 opcprotman_res_t res;
310 uint32_t address=0;
311 int ret;
312
313
314 printf("enable/disable diagnostics about rx setpoint (red ball demo). Press 1 to enable 0 otherwise\n");
315 ret = scanf("%d", &cmdena_rxsetPointCheck);
316
317}
318
319uint32_t callback_button_5(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
320{
321 return(0);
322}
323
324uint32_t callback_button_6(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
325{
326 return(0);
327}
328
329uint32_t callback_button_7(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
330{
331 return(0);
332}
333
334uint32_t callback_button_8(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
335{
336 return(0);
337}
338
339uint32_t callback_button_9(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
340{
341 return(0);
342}
343
344
345uint32_t callback_button_10(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
346{
347 return(0);
348}
349
350
351
352static void enaDisaDiagnostic(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
353{
354
355 uint16_t size = 0;
356 uint32_t min, max, j;
357 opcprotman_res_t res;
358 uint32_t address=0;
359 int ret;
360
361 printf("insert renge of board[1,11]: min max\n");
362 ret = scanf("%d %d", &min, &max);
363 if(min>max)
364 {
365 printf("error: min > max!\n");
366 return;
367 }
368
369 if((min == 0) && (max ==0))
370 {
371 //use debug board on desk
372 address = (10<<24)|(0<<16)|(1<<8)|99 ;
373 addr->set(4444, address);
374 res = opcprotman_Form(opcMan_ptr, opcprotman_opc_set, eodgn_nvidbdoor_cmds, &dgnCommands, (opcprotman_message_t*)payload_ptr, &size);
375 if(opcprotman_OK != res)
376 {
377
378 printf("erron in former\n");
379 return;
380 }
381 ssize_t sentBytes = ACE_socket->send(payload_ptr, size, *addr, 0/*flags*/);
382 ACE_TCHAR address[64];
383 addr->addr_to_string(address, 64);
384 printf("payload of size %d is sent to %s!! (sentbytes=%ld)\n", size, address, sentBytes);
385 }
386
387
388 if(min<1)
389 {
390 min = 1;
391 }
392 if(max>11)
393 {
394 max = 11;
395 }
396
397 for(j=min; j<=max; j++)
398 {
399 address = (10<<24)|(0<<16)|(1<<8)|j ;
400 addr->set(4444, address);
401 res = opcprotman_Form(opcMan_ptr, opcprotman_opc_set, eodgn_nvidbdoor_cmds, &dgnCommands, (opcprotman_message_t*)payload_ptr, &size);
402 if(opcprotman_OK != res)
403 {
404
405 printf("erron in former\n");
406 return;
407 }
408 ssize_t sentBytes = ACE_socket->send(payload_ptr, size, *addr, 0/*flags*/);
409 ACE_TCHAR address[64];
410 addr->addr_to_string(address, 64);
411 printf("payload of size %d is sent to %s!! (sentbytes=%ld)\n", size, address, sentBytes);
412 }
413
414}
uint32_t callback_button_3(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_8(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
int32_t callback_button_x(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr, int16_t id)
OPCprotocolManager * opcMan_ptr
Definition main.cpp:88
uint32_t callback_button_7(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_0(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
ACE_SOCK_Dgram * ACE_socket
Definition main.cpp:121
uint32_t callback_button_1(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_4(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
eOdgn_commands_t dgnCommands
uint32_t callback_button_5(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
void commands(void)
uint32_t callback_button_2(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_10(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
static uint32_t s_getAddressFromUser(void)
uint32_t callback_button_6(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
static void enaDisaDiagnostic(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t callback_button_9(uint8_t *payload_ptr, uint32_t payload_size, ACE_INET_Addr *addr)
uint32_t cmdena_rxsetPointCheck