base_schilling
Error.hpp
Go to the documentation of this file.
1 #ifndef MARUM_ORO_ERROR_HPP
2 #define MARUM_ORO_ERROR_HPP
3 
4 #include <stdexcept>
5 #include <base/Time.hpp>
6 
7 #define MARALARM_BASE 0x1000
8 
9 #define ACTALARM_BASE 0x2000
10 #define UCMALARM_BASE 0x3000
11 #define LCUALARM_BASE 0x4000
12 #define VISALARM_BASE 0x6000
13 #define ALTALARM_BASE 0x7000
14 #define CANALARM_BASE 0x8000
15 
16 #define MARERROR_BASE 0x5000
17 
18 #define MARALARM_COMMS MARALARM_BASE + 1
19 
20 #define MARERROR_CHECKSUM MARERROR_BASE + 1
21 #define MARERROR_DEVNAK MARERROR_BASE + 2
22 #define MARERROR_PARAMINV MARERROR_BASE + 3
23 #define MARERROR_DEVREPINV MARERROR_BASE + 4
24 
25 #define ACTALARM_ENC_LIN_ALARM ACTALARM_BASE + 1
26 #define ACTALARM_ENC_RANGE_ERR ACTALARM_BASE + 2
27 #define ACTALARM_CTRL_WD_TIME ACTALARM_BASE + 3
28 #define ACTALARM_CTRL_EXT_ENC_MAG ACTALARM_BASE + 4
29 #define ACTALARM_CTRL_EXT_ENC_COMM ACTALARM_BASE + 5
30 #define ACTALARM_CTRL_SH_ENC_MAG ACTALARM_BASE + 6
31 #define ACTALARM_CTRL_WATER ACTALARM_BASE + 7
32 #define ACTALARM_CTRL_SH_ENC_COMM ACTALARM_BASE + 8
33 #define ACTALARM_DRV_CMD_INC ACTALARM_BASE + 9
34 #define ACTALARM_DRV_CMD_INV ACTALARM_BASE + 10
35 #define ACTALARM_DRV_FRAME_ERR ACTALARM_BASE + 11
36 #define ACTALARM_DRV_VOLT_TEMP ACTALARM_BASE + 12
37 
38 #define UCMALARM_AD UCMALARM_BASE + 1
39 #define UCMALARM_DA UCMALARM_BASE + 2
40 #define UCMALARM_EEPROM UCMALARM_BASE + 3
41 
42 #define LCUALARM_FAULT LCUALARM_BASE + 1
43 #define LCUALARM_WATER LCUALARM_BASE + 2
44 #define LCUALARM_WATERLATCH LCUALARM_BASE + 3
45 #define LCUALARM_ACJB LCUALARM_BASE + 4
46 #define LCUALARM_ACJB_WATER LCUALARM_BASE + 5
47 #define LCUALARM_ACJB_WATERLATCH LCUALARM_BASE + 6
48 
49 #define VISALARM_SYNTAX VISALARM_BASE + 1
50 #define VISALARM_BUFF_FULL VISALARM_BASE + 2
51 #define VISALARM_CMD_CANCEL VISALARM_BASE + 3
52 #define VISALARM_NOSOCK VISALARM_BASE + 4
53 #define VISALARM_CMD_NOEXEC VISALARM_BASE + 5
54 
55 #define ALTALARM_SERIAL ALTALARM_BASE + 1
56 
57 #define CANALARM_XMTFULL CANALARM_BASE + 1
58 #define CANALARM_OVERRUN CANALARM_BASE + 2
59 #define CANALARM_BUSERR CANALARM_BASE + 3
60 #define CANALARM_BUSOFF CANALARM_BASE + 4
61 #define CANALARM_RX_OVERFLOW CANALARM_BASE + 5
62 #define CANALARM_TX_OVERFLOW CANALARM_BASE + 6
63 
64 #define MARSTR_COMMS "Communication failure"
65 #define MARSTR_CHECKSUM "checksum error"
66 #define MARSTR_DEVNAK "device Nak"
67 #define MARSTR_PARAMINV "invalid param"
68 #define MARSTR_DEVREPINV "invalid device response"
69 
70 #define ACTSTR_ENC_LIN_ALARM "Encoder Linearity Alarm"
71 #define ACTSTR_ENC_RANGE_ERR "Encoder Out of Range Error"
72 #define ACTSTR_CTRL_WD_TIME "Controller Watchdog Timeout"
73 #define ACTSTR_CTRL_EXT_ENC_MAG "Controller Ext. Enc. Magnet Loss"
74 #define ACTSTR_CTRL_EXT_ENC_COMM "Controller Ext. Enc. Comm Fail"
75 #define ACTSTR_CTRL_SH_ENC_MAG "Controller Shaft Enc. Magnet Loss"
76 #define ACTSTR_CTRL_WATER "Controller Water Detection"
77 #define ACTSTR_CTRL_SH_ENC_COMM "Controller Shaft Enc. Comm Fail"
78 #define ACTSTR_DRV_CMD_INC "Drive Cmd Incomplete"
79 #define ACTSTR_DRV_CMD_INV "Drive Invalid Cmd"
80 #define ACTSTR_DRV_FRAME_ERR "Drive Frame Error"
81 #define ACTSTR_DRV_VOLT_TEMP "Drive U/O Volt or Temp"
82 
83 #define UCMSTR_AD "AD Failure"
84 #define UCMSTR_DA "DA Failure"
85 #define UCMSTR_EEPROM "EEPROM Failure"
86 
87 #define LCUSTR_FAULT "Fault, over-current in channel"
88 #define LCUSTR_WATER "Water Leak detected"
89 #define LCUSTR_WATERLATCH "Water Leak Latch"
90 #define LCUSTR_ACJB "AC J-Box communication failure"
91 #define LCUSTR_ACJB_WATER "AC J-Box Water Leak detected"
92 #define LCUSTR_ACJB_WATERLATCH "AC J-Box Water Leak Latch"
93 
94 #define VISSTR_SYNTAX "syntax error"
95 #define VISSTR_BUFF_FULL "command buffer full"
96 #define VISSTR_CMD_CANCEL "command cancel"
97 #define VISSTR_NOSOCK "no sockets"
98 #define VISSTR_CMD_NOEXEC "command not executable"
99 
100 #define ALTSTR_SERIAL "serial failure, no switches accepted"
101 
102 #define CANSTR_XMTFULL "controller send buffer is full, can be ignored"
103 #define CANSTR_OVERRUN "receive buffer overrun"
104 #define CANSTR_BUSERR "error count at limit"
105 #define CANSTR_BUSOFF "bus error, controller switched to bus-off"
106 #define CANSTR_RX_OVERFLOW "receive buffer overflow"
107 #define CANSTR_TX_OVERFLOW "transmit buffer overflow"
108 
109 
110 
111 namespace oro_marum{
112 
113  enum LogLevel {
115  };
116 
117  class MarError : public std::runtime_error
118  {
119  int mId;
120  LogLevel mLogLevel;
121  public:
122  MarError (const std::string& what, const int& id = 0, const LogLevel& level = Error)
123  : runtime_error(what),mId(id),mLogLevel(level)
124  {}
125  int id(){
126  return mId;
127  }
129  return mLogLevel;
130  }
131  };
132 
133  struct LogMessage {
134  base::Time time;
136  int error_id;
137  std::string message;
139  : log_level(None),error_id(0) {};
140  LogMessage(LogLevel level, std::string msg, int error = 0)
141  : log_level(level), error_id(error)
142  {
143  time = base::Time::now();
144  message = msg;
145  }
146  LogMessage(std::runtime_error& error)
147  {
148  time = base::Time::now();
149  message = error.what();
150  MarError *marError = dynamic_cast<MarError*>(&error);
151  if(marError){
152  log_level = marError->level();
153  error_id = marError->id();
154  }
155  else{
156  log_level = Debug;
157  error_id = 0;
158  }
159  }
160  };
161 
162 
163 }
164 
165 
166 #endif
Definition: Error.hpp:133
LogLevel log_level
Definition: Error.hpp:135
int id()
Definition: Error.hpp:125
Definition: Error.hpp:117
base::Time time
Definition: Error.hpp:134
Definition: Error.hpp:114
LogMessage()
Definition: Error.hpp:138
LogLevel
Definition: Error.hpp:113
Definition: Error.hpp:114
Definition: Error.hpp:114
LogLevel level()
Definition: Error.hpp:128
int error_id
Definition: Error.hpp:136
Definition: Error.hpp:114
LogMessage(std::runtime_error &error)
Definition: Error.hpp:146
Definition: Error.hpp:111
Definition: Error.hpp:114
MarError(const std::string &what, const int &id=0, const LogLevel &level=Error)
Definition: Error.hpp:122
LogMessage(LogLevel level, std::string msg, int error=0)
Definition: Error.hpp:140
Definition: Error.hpp:114
std::string message
Definition: Error.hpp:137
Definition: Error.hpp:114