26 #include <yarp/os/Time.h>
33 using yarp::os::PeriodicThread;
35 #define SKINMANAGER_TH_DIAGREAD_DEBUG 1
40 SkinDiagnosticsReadThread::SkinDiagnosticsReadThread(
const int aPeriod,
const yarp::os::ResourceFinder &aRf)
41 : PeriodicThread((double)aPeriod/1000.0) {
45 dbgTag =
"SkinDiagnosticsReadThread: ";
60 using yarp::os::Value;
62 cout << dbgTag <<
"Initialising. \n";
65 string moduleName = rf.check(
"name", Value(
"skiManager"),
"module name (string)").asString();
66 string portNameRoot =
"/" + moduleName;
69 portSkinDiagnosticsErrorsIn.open((portNameRoot +
"/diagnostics/skin/errors:i").c_str());
70 portSkinManagerErrorsOut.open((portNameRoot +
"/diagnostics/skin/errors:o").c_str());
72 cout << dbgTag <<
"Initialised correctly. \n";
85 using std::stringstream;
87 using yarp::sig::Vector;
88 using yarp::os::Bottle;
92 Vector *
data = portSkinDiagnosticsErrorsIn.read(
false);
94 #if SKINMANAGER_TH_DIAGREAD_DEBUG
96 cout << dbgTag <<
"Skin diagnostics data: ";
97 for (
size_t i = 0; i <
data->size(); ++i) {
98 cout << (*data)[i] <<
" ";
104 Bottle &
out = portSkinManagerErrorsOut.prepare();
108 deque<bool> errorTaxels;
109 int errorCode = (int) (*
data)[3];
110 if (!(errorCode & SkinErrorCode::StatusOK)) {
113 if (errorCode & 0xFFF0) {
114 errorTaxels.resize(12,
false);
115 int errorMask = SkinErrorCode::TaxelStuck00;
116 for (
int tax = 0; tax < 12; ++tax) {
117 errorTaxels[tax] = ((errorCode & errorMask) != 0);
118 errorMask = errorMask << 1;
122 if (errorTaxels.size() > 0) {
125 ss <<
"ERROR: Net ID (" << (*data)[0] <<
"): Board ID (" << (*data)[1]
126 <<
"): Sensor ID (" << (*data)[2] <<
"): The following taxels are stuck/faulty: \t";
127 for (
size_t i = 0; i < errorTaxels.size(); ++i) {
128 if (errorTaxels[i]) {
133 out.addString(ss.str().c_str());
138 if (errorCode & SkinErrorCode::ErrorReading12C) {
139 ss <<
"ERROR: Net ID (" << (*data)[0] <<
"): Board ID (" << (*data)[1]
140 <<
"): Sensor ID (" << (*data)[2] <<
"): Cannot read from this sensor.";
141 }
else if (errorCode & SkinErrorCode::ErrorACK4C) {
142 ss <<
"ERROR: Net ID (" << (*data)[0] <<
"): Board ID (" << (*data)[1]
143 <<
"): Sensor ID (" << (*data)[2] <<
"): This sensor does not respond to the initialisation message (0x4C).";
146 ss.seekg(0, ios::end);
148 ss.seekg(0, ios::beg);
149 out.addString(ss.str().c_str());
154 ss <<
"DEBUG: Skin is working fine.";
155 out.addString(ss.str().c_str());
160 if (
out.size() > 0) {
161 portSkinManagerErrorsOut.write();
172 cout << dbgTag <<
"Releasing. \n";
175 portSkinDiagnosticsErrorsIn.interrupt();
176 portSkinManagerErrorsOut.interrupt();
179 portSkinDiagnosticsErrorsIn.close();
180 portSkinManagerErrorsOut.close();
182 cout << dbgTag <<
"Released. \n";
virtual ~SkinDiagnosticsReadThread()
virtual void threadRelease(void)
virtual bool threadInit(void)
Enum to provide intelligible error codes for the skin.