MIRA
ErrorMemory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) MetraLabs GmbH (MLAB), GERMANY.
3  * All rights reserved.
4  * Contact: info@MetraLabs.com
5  *
6  * Commercial Usage:
7  * Licensees holding valid commercial licenses may use this file in
8  * accordance with the commercial license agreement provided with the
9  * software or, alternatively, in accordance with the terms contained in
10  * a written agreement between you and MetraLabs.
11  *
12  * GNU General Public License Usage:
13  * Alternatively, this file may be used under the terms of the GNU
14  * General Public License version 3.0 as published by the Free Software
15  * Foundation and appearing in the file LICENSE.GPL3 included in the
16  * packaging of this file. Please review the following information to
17  * ensure the GNU General Public License version 3.0 requirements will be
18  * met: http://www.gnu.org/copyleft/gpl.html.
19  * Alternatively you may (at your option) use any later version of the GNU
20  * General Public License if such license has been publicly approved by
21  * MetraLabs (or its successors, if any).
22  *
23  * IN NO EVENT SHALL "MLAB" BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
24  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE
25  * OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLABS" HAS BEEN
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * "MLAB" SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
31  * "AS IS" BASIS, AND "MLAB" HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
32  * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
33  */
34 
43 #ifndef _MLAB_SCITOS_FUNCTION_BLOCK_ERROR_MEMORY_H_
44 #define _MLAB_SCITOS_FUNCTION_BLOCK_ERROR_MEMORY_H_
45 
46 #include <FunctionBlock.h>
47 
48 namespace mira { namespace robot {
49 
51 
52 class ErrorMemory : public FunctionBlock
53 {
55 
56 public:
58 
60  struct ErrorInfo
61  {
63  timeUnix(0), code(0)
64  {
65  memset(&data, 0x00, sizeof(data));
66  }
67 
68  template <typename Reflector>
69  void reflect(Reflector& r)
70  {
71  r.version(1, this);
72  r.member("TimeUnix", timeUnix, "");
73  r.member("TimeLocal", timeLocal, "");
74  r.member("ErrorCode", code, "");
75  r.member("ErrorName", name, "");
76  r.member("ErrorData", data, "");
77  }
78 
79  uint32 timeUnix;
80  std::string timeLocal;
81  uint32 code;
82  std::string name;
83  uint32 data[8];
84  };
85 
87  struct ModuleInfo {
88  uint8 node;
91  uint32 serialNumber;
92  uint32 productID;
93 
96  serialNumber(0), productID(0)
97  {}
98 
99  template <typename Reflector>
100  void reflect(Reflector& r)
101  {
102  r.member("Node", node, "");
103  r.member("HardwareVersion", hardwareVersion, "");
104  r.member("SoftwareVersion", softwareVersion, "");
105  r.member("SerialNumber", serialNumber, "");
106  r.member("ProductID", productID, "");
107  };
108  };
109 
111  struct Report {
112  template <typename Reflector>
113  void reflect(Reflector& r)
114  {
115  r.version(1, this);
116  r.member("ReportTime", reportTime, "");
117  r.member("ReportTimeStr", reportTimeStr, "");
118  r.member("ModuleInfo", moduleInfo, "");
119  r.member("ErrorList", errors, "");
120  }
121 
123  std::string reportTimeStr;
125  std::vector<ErrorInfo> errors;
126  };
127 
129 
130 public:
133 
135  {
136  functionBlockID = 0xF0000001;
137  }
138 
139  ErrorMemory(const std::string& rpcPrefix) :
140  FunctionBlock(), mRPCPrefix(rpcPrefix)
141  {
142  functionBlockID = 0xF0000001;
143  }
144 
145  virtual ~ErrorMemory() {}
146 
148  template <typename Reflector>
149  void reflect(Reflector& r)
150  {
152 
153  r.roproperty("ErrorCount",
154  getter<uint32>(boost::bind(&ErrorMemory::getErrorCount, this)),
155  "Number of errors in error memory");
156  r.roproperty("LastErrorTime",
157  getter<Time>(boost::bind(&ErrorMemory::getLastErrorTime, this)),
158  "The time of the last error in local time.");
159 
160  std::string methodPrefix;
161  if (mRPCPrefix.size() > 0)
162  methodPrefix = mRPCPrefix+"_";
163 
164  r.method((methodPrefix+"getErrorInfo").c_str(),
166  "Read out a single error from the error memory.",
167  "index", "Error index", 0);
168  r.method((methodPrefix+"readoutErrorMemory").c_str(),
170  "Readout the error memory.");
171  r.method((methodPrefix+"exportErrorMemoryToFile").c_str(),
173  "Readout the error memory and export to a json file.",
174  "filename", "Report file name", "report.json");
175  r.method((methodPrefix+"clearErrorMemory").c_str(),
177  "Clear the error memory.");
178  }
179 
181 
182 public:
183  uint32 getErrorCount() const;
184 
185  Time getLastErrorTime() const;
186 
187  ErrorInfo getErrorInfo(uint32 idx) const;
188 
189  Report readoutErrorMemory() const;
190 
191  void exportErrorMemoryToFile(const std::string& path);
192 
193  void clearErrorMemory();
194 
195 public:
196  void addErrorCode(uint32 code, const std::string& name);
197 
198 private:
199  std::string mRPCPrefix;
200  std::map<uint32, std::string> mErrorCodes;
201 };
202 
204 
205 }}
206 
207 #endif
std::vector< ErrorInfo > errors
Definition: ErrorMemory.h:125
virtual ~ErrorMemory()
Definition: ErrorMemory.h:145
ErrorMemory(const std::string &rpcPrefix)
Definition: ErrorMemory.h:139
ModuleInfo moduleInfo
Definition: ErrorMemory.h:124
ErrorInfo()
Definition: ErrorMemory.h:62
uint32 code
Definition: ErrorMemory.h:81
#define MIRA_REFLECT_BASE(reflector, BaseClass)
std::string reportTimeStr
Definition: ErrorMemory.h:123
Information for one error in the error memory.
Definition: ErrorMemory.h:60
Time reportTime
Definition: ErrorMemory.h:122
void addErrorCode(uint32 code, const std::string &name)
void exportErrorMemoryToFile(const std::string &path)
void reflect(Reflector &r)
Definition: ErrorMemory.h:69
uint32 serialNumber
Definition: ErrorMemory.h:91
uint32 data[8]
Definition: ErrorMemory.h:83
ErrorInfo getErrorInfo(uint32 idx) const
uint32 timeUnix
Definition: ErrorMemory.h:79
std::string timeLocal
Definition: ErrorMemory.h:80
ErrorMemory()
Definition: ErrorMemory.h:134
#define MIRA_OBJECT(classIdentifier)
Report readoutErrorMemory() const
uint32 functionBlockID
ID of the function block.
Definition: FunctionBlock.h:84
ModuleInfo()
Definition: ErrorMemory.h:94
Definition: FunctionBlock.h:53
uint32 getErrorCount() const
uint32 hardwareVersion
Definition: ErrorMemory.h:89
uint32 softwareVersion
Definition: ErrorMemory.h:90
Basic module information (versions, etc.) for an error report.
Definition: ErrorMemory.h:87
Base class for different SCITOS CAN function blocks.
std::string name
Definition: ErrorMemory.h:82
Definition: ErrorMemory.h:52
An error report.
Definition: ErrorMemory.h:111
void reflect(Reflector &r)
Definition: ErrorMemory.h:113
void reflect(Reflector &r)
Definition: ErrorMemory.h:100
uint32 productID
Definition: ErrorMemory.h:92
void reflect(Reflector &r)
Reflect for serialization.
Definition: ErrorMemory.h:149
uint8 node
Definition: ErrorMemory.h:88
Time getLastErrorTime() const