iCub-main
parser_cfg_calibration.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 07/21/2014
23 **/
24 
25 // --------------------------------------------------------------------------------------------------------------------
26 // - external dependencies
27 // --------------------------------------------------------------------------------------------------------------------
28 
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <ctime>
32 #include <time.h>
33 #include <string>
34 
35 // ACE stuff
36 #include <ace/ACE.h>
37 #include "ace/SOCK_Dgram.h"
38 #include "ace/Addr.h"
39 
40 
41 //embody stuff
42 #include "EoCommon.h"
43 #include "EoMotionControl.h"
44 #include "eODeb_eoProtoParser.h"
45 #include "eOtheEthLowLevelParser.h"
46 //pcap stuff
47 #include "pcap_wrapper_linux.h"
48 
49 
50 
51 
52 // --------------------------------------------------------------------------------------------------------------------
53 // - declaration of extern public interface
54 // --------------------------------------------------------------------------------------------------------------------
55 
56 
57 
58 
59 // --------------------------------------------------------------------------------------------------------------------
60 // - declaration of extern hidden interface
61 // --------------------------------------------------------------------------------------------------------------------
62 // empty-section
63 
64 
65 
66 
67 
68 
69 
70 // --------------------------------------------------------------------------------------------------------------------
71 // - #define with internal scope
72 // --------------------------------------------------------------------------------------------------------------------
73 // empty-section
74 
75 
76 
77 const std::string currentDateTime() {
78  time_t now = time(0);
79  struct tm tstruct;
80  char buf[80];
81  tstruct = *localtime(&now);
82  // Visit http://en.cppreference.com/w/cpp/chrono/c/strftime
83  // for more information about date/time format
84  strftime(buf, sizeof(buf), "%d-%m-%Y %X", &tstruct);
85 
86  return buf;
87 }
88 
89 // --------------------------------------------------------------------------------------------------------------------
90 // - definition (and initialisation) of extern variables, but better using _get(), _set()
91 // --------------------------------------------------------------------------------------------------------------------
92 static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum);
93 static void my_cbk_fullScaleFound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr);
94 static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr);
95 
96 
97 
98 const eODeb_eoProtoParser_cfg_t deb_eoParserCfg =
99 {
100  EO_INIT(.checks)
101  {
102  EO_INIT(.seqNum)
103  {
104  EO_INIT(.cbk_onErrSeqNum) NULL, //my_cbk_onErrorSeqNum,
105  },
106 
107  EO_INIT(.nv)
108  {
109  EO_INIT(.NVs2searchArray)
110  {
111  EO_INIT(.head)
112  {
113  EO_INIT(.capacity) eODeb_eoProtoParser_maxNV2find,
114  EO_INIT(.itemsize) sizeof(eODeb_eoProtoParser_nv_identify_t),
115  EO_INIT(.size) 12,
116  },
117  EO_INIT(.data)
118  {
119  0x100000F, // calibration message
120  0x100010F,
121  0x100020F,
122  0x100030F,
123  0x100040F,
124  0x100050F,
125  0x100060F,
126  0x100070F,
127  0x100080F,
128  0x100090F,
129  0x1000A0F,
130  0x1000B0F
131  }
132 
133  },
134  EO_INIT(.cbk_onNVfound) my_cbk_fullScaleFound
135  },
136 
137  EO_INIT(.invalidRopFrame)
138  {
139  EO_INIT(.cbk) my_cbk_onInvalidRopFrame
140 
141  }
142  }
143 };
144 
145 
146 const eODeb_eoProtoParser_cfg_t *deb_eoParserCfg_ptr = &deb_eoParserCfg;
147 
148 // --------------------------------------------------------------------------------------------------------------------
149 // - typedef with internal scope
150 // --------------------------------------------------------------------------------------------------------------------
151 // empty-section
152 
153 
154 // --------------------------------------------------------------------------------------------------------------------
155 // - declaration of static functions
156 // --------------------------------------------------------------------------------------------------------------------
157 
158 
159 
160 
161 // --------------------------------------------------------------------------------------------------------------------
162 // - definition (and initialisation) of static variables
163 // --------------------------------------------------------------------------------------------------------------------
164 
165 
166 // --------------------------------------------------------------------------------------------------------------------
167 // - definition of extern public functions
168 // --------------------------------------------------------------------------------------------------------------------
169 
170 
171 
172 // --------------------------------------------------------------------------------------------------------------------
173 // - definition of extern hidden functions
174 // --------------------------------------------------------------------------------------------------------------------
175 
176 
177 
178 // --------------------------------------------------------------------------------------------------------------------
179 // - definition of static functions
180 // --------------------------------------------------------------------------------------------------------------------
181 
182 static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum)
183 {
184 
185  printf("ERR in SEQNUM from 0x%x; rec=%d expected=%d\n", pktInfo_ptr->src_addr, rec_seqNum, expected_seqNum );
186 return;
187 }
188 
189 
190 static void my_cbk_fullScaleFound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)
191 {
192  eOas_strain_config_t *straincfg_ptr = (eOas_strain_config_t *)ropAddInfo_ptr->desc.data;
193 
194 // time_t t = time(0); // get time now
195 // struct tm * now = localtime( & t );
196 // printf(" %d - %d - %d - ", (now->tm_year + 1900), (now->tm_mon + 1), now->tm_mday);
197  printf("date %s \n\t", currentDateTime().c_str());
198 
199  printf("Calibration MSG found: from 0x%x to 0x%x protoId=0x%x (%d) ropcode=0x%x plussig=%d sig=%d seqnum=%ld\n",
200  pktInfo_ptr->src_addr,
201  pktInfo_ptr->dst_addr,
202  ropAddInfo_ptr->desc.id32,
203  ropAddInfo_ptr->desc.id32,
204  ropAddInfo_ptr->desc.ropcode,
205  ropAddInfo_ptr->desc.control.plussign,
206  ropAddInfo_ptr->desc.signature,
207  ropAddInfo_ptr->seqnum);
208 
209  return;
210 }
211 
212 
213 static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr)
214 {
215  printf("Invalid ropframe rec from 0x%x\n", pktInfo_ptr->src_addr);
216  return;
217 }
218 
219 
220 
221 // --------------------------------------------------------------------------------------------------------------------
222 // - end-of-file (leave a blank line after)
223 // --------------------------------------------------------------------------------------------------------------------
224 
225 
226 
227 
const eODeb_eoProtoParser_cfg_t deb_eoParserCfg
const eODeb_eoProtoParser_cfg_t * deb_eoParserCfg_ptr
static void my_cbk_onErrorSeqNum(eOethLowLevParser_packetInfo_t *pktInfo_ptr, uint32_t rec_seqNum, uint32_t expected_seqNum)
degrees time
Definition: sine.m:5
const std::string currentDateTime()
static void my_cbk_onInvalidRopFrame(eOethLowLevParser_packetInfo_t *pktInfo_ptr)
static void my_cbk_fullScaleFound(eOethLowLevParser_packetInfo_t *pktInfo_ptr, eODeb_eoProtoParser_ropAdditionalInfo_t *ropAddInfo_ptr)