iCub-main
Loading...
Searching...
No Matches
parser_cfg_template.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 main.cpp
20 @brief
21 @author valentina.gaggero@iit.it
22 @date 03/19/2013
23**/
24
25// --------------------------------------------------------------------------------------------------------------------
26// - external dependencies
27// --------------------------------------------------------------------------------------------------------------------
28
29#include <unistd.h>
30#include <stdio.h>
31
32
33// ACE stuff
34#include <ace/ACE.h>
35#include "ace/SOCK_Dgram.h"
36#include "ace/Addr.h"
37
38
39//embody stuff
40#include "EoCommon.h"
41#include "EoMotionControl.h"
42#include "eODeb_eoProtoParser.h"
43#include "eOtheEthLowLevelParser.h"
44//pcap stuff
45#include "pcap_wrapper_linux.h"
46
47
48
49
50// --------------------------------------------------------------------------------------------------------------------
51// - declaration of extern public interface
52// --------------------------------------------------------------------------------------------------------------------
53
54
55
56
57// --------------------------------------------------------------------------------------------------------------------
58// - declaration of extern hidden interface
59// --------------------------------------------------------------------------------------------------------------------
60// empty-section
61
62
63
64
65
66
67
68// --------------------------------------------------------------------------------------------------------------------
69// - #define with internal scope
70// --------------------------------------------------------------------------------------------------------------------
71// empty-section
72
73
74
75
76
77// --------------------------------------------------------------------------------------------------------------------
78// - definition (and initialisation) of extern variables, but better using _get(), _set()
79// --------------------------------------------------------------------------------------------------------------------
80static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum);
81static void my_cbk_onNVfound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr);
82static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr);
83
84
85
86const eODeb_eoProtoParser_cfg_t deb_eoParserCfg =
87{
88 EO_INIT(.checks)
89 {
90 EO_INIT(.seqNum)
91 {
92 EO_INIT(.cbk_onErrSeqNum) my_cbk_onErrorSeqNum,
93 },
94
95 EO_INIT(.nv)
96 {
97 EO_INIT(.NVs2searchArray)
98 {
99 EO_INIT(.head)
100 {
101 EO_INIT(.capacity) eODeb_eoProtoParser_maxNV2find,
102 EO_INIT(.itemsize) sizeof(eODeb_eoProtoParser_nvidEp_couple_t),
103 EO_INIT(.size) 1,
104 },
105 EO_INIT(.data)
106 {
107 {0x18, 0xbc1a}, //ep EB8 mc , nvid setpoint for joint 0
108 }
109
110 },
111 EO_INIT(.cbk_onNVfound) my_cbk_onNVfound
112 },
113
114 EO_INIT(.invalidRopFrame)
115 {
116 EO_INIT(.cbk) my_cbk_onInvalidRopFrame
117
118 }
119 }
120};
121
122
123const eODeb_eoProtoParser_cfg_t *deb_eoParserCfg_ptr = &deb_eoParserCfg;
124
125// --------------------------------------------------------------------------------------------------------------------
126// - typedef with internal scope
127// --------------------------------------------------------------------------------------------------------------------
128// empty-section
129
130
131// --------------------------------------------------------------------------------------------------------------------
132// - declaration of static functions
133// --------------------------------------------------------------------------------------------------------------------
134
135
136
137
138// --------------------------------------------------------------------------------------------------------------------
139// - definition (and initialisation) of static variables
140// --------------------------------------------------------------------------------------------------------------------
141
142
143// --------------------------------------------------------------------------------------------------------------------
144// - definition of extern public functions
145// --------------------------------------------------------------------------------------------------------------------
146
147
148
149// --------------------------------------------------------------------------------------------------------------------
150// - definition of extern hidden functions
151// --------------------------------------------------------------------------------------------------------------------
152
153
154
155// --------------------------------------------------------------------------------------------------------------------
156// - definition of static functions
157// --------------------------------------------------------------------------------------------------------------------
158
159static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum)
160{
161
162 printf("ERR in SEQNUM; rec=%d expected=%d\n",rec_seqNum, expected_seqNum );
163return;
164}
165
166static void my_cbk_onNVfound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)
167{
168
169 printf("NV found!!: ep=%x id=%x\n", ropAddInfo_ptr->desc.ep, ropAddInfo_ptr->desc.id);
170 return;
171}
172
173static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr)
174{
175 printf("Invalid ropframe\n");
176 return;
177
178}
179static void my_cbk_onNVsetpointFound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)
180{
181 eOmc_setpoint_t * setpoint_ptr = (eOmc_setpoint_t *)ropAddInfo_ptr->desc.data;
182 uint8_t board = 0, j;
183 float enc_factor, zero, enc_factor_6=182.044 , enc_factor_8=182.044, zero_6=180, zero_8=-180;
184
185 //printf("NV found!!: ep=%x id=%x\n", ropAddInfo_ptr->desc.ep, ropAddInfo_ptr->desc.id);
186
187 if(ropAddInfo_ptr->desc.ep == 0x18)
188 {
189 board = 8;
190 enc_factor = enc_factor_8;
191 zero = zero_8;
192 }
193 else if(ropAddInfo_ptr->desc.ep == 0x16)
194 {
195 board = 6;
196 enc_factor = enc_factor_6;
197 zero = zero_6;
198 }
199 else
200 {
201 printf("\n\n ERROR: un expected ep!!! %d \n ", ropAddInfo_ptr->desc.ep);
202 return;
203 }
204
205 if(setpoint_ptr->type != eomc_setpoint_position)
206 {
207 printf("ERR: no setpoint position. typse= %d", setpoint_ptr->type);
208 return;
209 }
210
211 switch(ropAddInfo_ptr->desc.id)
212 {
213 case 0xbc1a:
214 {
215 j = 0;
216 }break;
217
218 case 0xbc3a:
219 {
220 j = 1;
221 }break;
222
223 case 0xbc5a:
224 {
225 j = 2;
226 }break;
227
228 case 0xbc7a:
229 {
230 j = 3;
231 }break;
232 default:
233 {
234 printf("ERROR: receiv unexpected nvid %x", ropAddInfo_ptr->desc.id);
235 return;
236 }
237 }
238 float vel, pos;
239
240 pos = (setpoint_ptr->to.position.value/enc_factor)-zero;
241 vel = setpoint_ptr->to.position.withvelocity/fabs(enc_factor);
242
243 printf("board %d j %d pos %f (%d) vel %f (%d) enc_factor=%f zero=%f\n", board, j, pos, setpoint_ptr->to.position.value, vel, setpoint_ptr->to.position.withvelocity,enc_factor,zero);
244
245 return;
246}
247
248
249// --------------------------------------------------------------------------------------------------------------------
250// - end-of-file (leave a blank line after)
251// --------------------------------------------------------------------------------------------------------------------
252
253
254
255
@ data
uint8_t board
static void my_cbk_onNVsetpointFound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)
static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum)
static void my_cbk_onNVfound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)
const eODeb_eoProtoParser_cfg_t deb_eoParserCfg
static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr)
const eODeb_eoProtoParser_cfg_t * deb_eoParserCfg_ptr