iCub-main
Loading...
Searching...
No Matches
diagnosticInfoFormatter.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Istituto Italiano di Tecnologia (IIT)
3 * All rights reserved.
4 *
5 * This software may be modified and distributed under the terms of the
6 * BSD-3-Clause license. See the accompanying LICENSE file for details.
7 */
8
11
12
13
14using namespace Diagnostic::LowLevel;
15using namespace Diagnostic;
16
17
18InfoFormatter::InfoFormatter(eth::TheEthManager* ethManager, eOmn_info_basic_t* infobasic, uint8_t * extra, const EOnv* nv, const eOropdescriptor_t* rd) :
19 m_ethManager(ethManager),m_infobasic(infobasic), m_extra(extra), m_nv(nv), m_rd(rd)
20{;}
21
22
24{
25 //==> firts of all fill all the common info to all messages and then parser the parameter depending on the specific message
26
27 AuxEmbeddedInfo dnginfo;
28
29 //1. fill all the common info to all messages
30 dnginfo.sourceBoardIpAddr = eo_nv_GetIP(m_nv);
31 dnginfo.baseInfo.sourceBoardName = m_ethManager->getName(eo_nv_GetIP(m_nv));
32 getTimeOfInfo(dnginfo.baseInfo.timeOfInfo);
33 getSourceOfMessage(dnginfo.baseInfo);
34 getSeverityOfError(dnginfo.baseInfo);
35
36 dnginfo.baseMessage = std::string(eoerror_code2string(m_infobasic->properties.code));
37
38 eOmn_info_extraformat_t extraf = static_cast<eOmn_info_extraformat_t>EOMN_INFO_PROPERTIES_FLAGS_get_extraformat(m_infobasic->properties.flags);
39 dnginfo.extraMessage.clear();
40
41 if(eomn_info_extraformat_verbal == extraf)
42 {
43 dnginfo.extraMessage.append((NULL == m_extra) ? ("no extra info despite we are in verbal mode") : ((const char *)m_extra));
44 }
45 else
46 {
47 dnginfo.extraMessage.append(".");
48 }
49
50
51 ipv4ToString(dnginfo.baseInfo);
52 dnginfo.param64 = m_infobasic->properties.par64;
53 dnginfo.param16 = m_infobasic->properties.par16;
54 dnginfo.errorCode = m_infobasic->properties.code;
55
56 EntityNameProvider entityNameProvider{dnginfo.sourceBoardIpAddr, m_ethManager};
57
58 //2. create the parser related to the error cod family
59 std::unique_ptr<DefaultParser> parser_ptr;
60
61 eOerror_category_t category = eoerror_code2category(m_infobasic->properties.code);
62 switch(category)
63 {
64 case eoerror_category_Config: parser_ptr = std::make_unique<ConfigParser>(dnginfo, entityNameProvider); break;
65
66 case eoerror_category_MotionControl: parser_ptr = std::make_unique<MotionControlParser>(dnginfo, entityNameProvider); break;
67
68 case eoerror_category_HardWare: parser_ptr = std::make_unique<HwErrorParser>(dnginfo, entityNameProvider); break;
69
70 case eoerror_category_System: parser_ptr = std::make_unique<SysParser>(dnginfo, entityNameProvider); break;
71
72 case eoerror_category_ETHmonitor: parser_ptr = std::make_unique<EthMonitorParser>(dnginfo, entityNameProvider); break;
73
74 case eoerror_category_Skin: parser_ptr = std::make_unique<SkinParser>(dnginfo, entityNameProvider); break;
75
76 case eoerror_category_InertialSensor: parser_ptr = std::make_unique<InertialSensorParser>(dnginfo, entityNameProvider); break;
77
78 case eoerror_category_AnalogSensor: parser_ptr = std::make_unique<AnalogSensorParser>(dnginfo, entityNameProvider); break;
79
80 default: parser_ptr = std::make_unique<DefaultParser>(dnginfo, entityNameProvider); break;
81 };
82
83 parser_ptr->parseInfo();
84
85 //3. return the parsered info
86 info = dnginfo.baseInfo;
87
88 return true;
89
90}
91
92void InfoFormatter::getSourceOfMessage(EmbeddedInfo &info)
93{
94 const char * const sourcenames[] =
95 {
96 "LOCAL",
97 "CAN1",
98 "CAN2",
99 "UNKNOWN"
100 };
101
102 eOmn_info_source_t source = static_cast<eOmn_info_source_t>EOMN_INFO_PROPERTIES_FLAGS_get_source(m_infobasic->properties.flags);
103
104 info.sourceCANBoardAddr = EOMN_INFO_PROPERTIES_FLAGS_get_address(m_infobasic->properties.flags);
105
106 info.sourceCANPortStr = std::string(((source > eomn_info_source_can2) ? (sourcenames[3]) : (sourcenames[source])));
107
108}
109
110
111
112void InfoFormatter::getTimeOfInfo(TimeOfInfo &timeOfInfo)
113{
114 timeOfInfo.sec = m_infobasic->timestamp / 1000000;
115 timeOfInfo.msec = (m_infobasic->timestamp % 1000000) / 1000;
116 timeOfInfo.usec = m_infobasic->timestamp % 1000;
117}
118
119
120void InfoFormatter::ipv4ToString(EmbeddedInfo &info)
121{
122 char ipinfo[20] = {0};
123 eo_common_ipv4addr_to_string(eo_nv_GetIP(m_nv), ipinfo, sizeof(ipinfo));
124 info.sourceBoardIpAddrStr.clear();
125 info.sourceBoardIpAddrStr.append(ipinfo);
126}
127
128void InfoFormatter::getSeverityOfError(EmbeddedInfo &info)
129{
130 eOmn_info_type_t type = static_cast<eOmn_info_type_t>EOMN_INFO_PROPERTIES_FLAGS_get_type(m_infobasic->properties.flags);
131 switch(type)
132 {
133 case eomn_info_type_info: {info.severity = SeverityOfError::info;return;}
134 case eomn_info_type_debug: {info.severity = SeverityOfError::debug;return;}
135 case eomn_info_type_warning: {info.severity = SeverityOfError::warning;return;}
136 case eomn_info_type_error: {info.severity = SeverityOfError::error;return;}
137 case eomn_info_type_fatal: {info.severity = SeverityOfError::fatal;return;}
138
139
140 };
141}
142
143/**************************************************************************************************************************/
144/****************************************** EntityNameProvider ***************************************************/
145/**************************************************************************************************************************/
146EntityNameProvider::EntityNameProvider(eOipv4addr_t boardAddr, eth::TheEthManager* ethManager):m_ethManager(ethManager)
147{
148 m_MC_ethRes = m_ethManager->getInterface(boardAddr, eth::iethresType_t::iethres_motioncontrol);
149}
150
151bool EntityNameProvider::getAxisName(uint32_t entityId, std::string &axisName)
152{
153 if(m_MC_ethRes == nullptr)
154 {
155 axisName = "N/A";
156 return false;
157 }
158
159 return (m_MC_ethRes->getEntityName(entityId, axisName));
160}
161
162bool EntityNameProvider::getEncoderTypeName(uint32_t jomoId, eOmc_position_t pos, std::string &encoderTypeName)
163{
164 if (m_MC_ethRes == nullptr)
165 {
166 encoderTypeName = "N/A";
167 return false;
168 }
169
170 return (m_MC_ethRes->getEncoderTypeName(jomoId, pos, encoderTypeName));
171}
Diagnostic::TimeOfInfo timeOfInfo
bool getEncoderTypeName(uint32_t jomoId, eOmc_position_t pos, std::string &encoderTypeName)
bool getAxisName(uint32_t entityId, std::string &axisName)
virtual bool getDiagnosticInfo(Diagnostic::EmbeddedInfo &info)
virtual bool getEncoderTypeName(uint32_t jomoId, eOmc_position_t pos, std::string &encoderTypeName)
virtual bool getEntityName(uint32_t entityId, std::string &entityName)
IethResource * getInterface(eOipv4addr_t ipv4, eOprotID32_t id32)
const string & getName(eOipv4addr_t ipv4)
@ iethres_motioncontrol