Rev 991 | Rev 999 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 991 | Rev 997 | ||
|---|---|---|---|
| Line 42... | Line 42... | ||
| 42 | throw new CanMessageException("Malformed can message received from canDaemon"); |
42 | throw new CanMessageException("Malformed can message received from canDaemon"); |
| 43 | } |
43 | } |
| 44 | 44 | ||
| 45 | string rawHeaderBin = hex2bin(parts[1]); |
45 | string rawHeaderBin = hex2bin(parts[1]); |
| 46 | 46 | ||
| - | 47 | try |
|
| - | 48 | { |
|
| 47 | myClassName = translator.lookupClassName(bin2uint(rawHeaderBin.substr(3, 4))); |
49 | myClassName = translator.lookupClassName(bin2uint(rawHeaderBin.substr(3, 4))); |
| - | 50 | } |
|
| - | 51 | catch (std::out_of_range& e) |
|
| - | 52 | { |
|
| - | 53 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 54 | cout << "DEBUG: A rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 55 | } |
|
| - | 56 | ||
| 48 | 57 | ||
| 49 | if (myClassName == "") |
58 | if (myClassName == "") |
| 50 | { |
59 | { |
| 51 | myIsUnknown = true; |
60 | myIsUnknown = true; |
| 52 | return; |
61 | return; |
| 53 | } |
62 | } |
| - | 63 | else |
|
| - | 64 | { |
|
| - | 65 | myIsUnknown = false; |
|
| - | 66 | } |
|
| 54 | 67 | ||
| 55 | string rawHexData = ""; |
68 | string rawHexData = ""; |
| 56 | for (int n = 4; n < parts.size(); n++) |
69 | for (int n = 4; n < parts.size(); n++) |
| 57 | { |
70 | { |
| 58 | rawHexData += parts[n]; |
71 | rawHexData += parts[n]; |
| 59 | } |
72 | } |
| 60 | 73 | ||
| 61 | if (myClassName == "nmt") |
74 | if (myClassName == "nmt") |
| 62 | { |
75 | { |
| - | 76 | int commandId; |
|
| - | 77 | ||
| - | 78 | try |
|
| - | 79 | { |
|
| 63 |
|
80 | commandId = bin2uint(rawHeaderBin.substr(8, 8)); |
| - | 81 | } |
|
| - | 82 | catch (std::out_of_range& e) |
|
| - | 83 | { |
|
| - | 84 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 85 | cout << "DEBUG: B rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 86 | } |
|
| - | 87 | ||
| 64 | myCommandName = translator.lookupNMTCommandName(commandId); |
88 | myCommandName = translator.lookupNMTCommandName(commandId); |
| 65 | 89 | ||
| 66 | myData = translator.translateNMTData(commandId, rawHexData); |
90 | myData = translator.translateNMTData(commandId, rawHexData); |
| 67 | } |
91 | } |
| 68 | else |
92 | else |
| - | 93 | { |
|
| - | 94 | try |
|
| 69 | { |
95 | { |
| 70 | myDirectionFlag = translator.lookupDirectionFlag(bin2uint(rawHeaderBin.substr(7, 1))); |
96 | myDirectionFlag = translator.lookupDirectionFlag(bin2uint(rawHeaderBin.substr(7, 1))); |
| - | 97 | } |
|
| - | 98 | catch (std::out_of_range& e) |
|
| - | 99 | { |
|
| - | 100 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 101 | cout << "DEBUG: C rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 102 | } |
|
| - | 103 | ||
| - | 104 | try |
|
| - | 105 | { |
|
| 71 | myModuleName = translator.lookupModuleName(bin2uint(rawHeaderBin.substr(8, 8))); |
106 | myModuleName = translator.lookupModuleName(bin2uint(rawHeaderBin.substr(8, 8))); |
| - | 107 | } |
|
| - | 108 | catch (std::out_of_range& e) |
|
| - | 109 | { |
|
| - | 110 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 111 | cout << "DEBUG: D rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 112 | } |
|
| 72 | 113 | ||
| - | 114 | try |
|
| - | 115 | { |
|
| 73 | myModuleId = bin2uint(rawHeaderBin.substr(16, 8)); |
116 | myModuleId = bin2uint(rawHeaderBin.substr(16, 8)); |
| - | 117 | } |
|
| - | 118 | catch (std::out_of_range& e) |
|
| - | 119 | { |
|
| - | 120 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 121 | cout << "DEBUG: E rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 122 | } |
|
| - | 123 | ||
| - | 124 | int commandId; |
|
| - | 125 | ||
| - | 126 | try |
|
| - | 127 | { |
|
| - | 128 | commandId = bin2uint(rawHeaderBin.substr(24, 8)); |
|
| - | 129 | } |
|
| - | 130 | catch (std::out_of_range& e) |
|
| - | 131 | { |
|
| - | 132 | cout << "DEBUG: setRaw exception: " << e.what() << "\n"; |
|
| - | 133 | cout << "DEBUG: F rawHeaderBin=" << rawHeaderBin << endl; |
|
| - | 134 | } |
|
| 74 | 135 | ||
| 75 | int commandId = bin2uint(rawHeaderBin.substr(24, 8)); |
- | |
| 76 | myCommandName = translator.lookupCommandName(commandId, myModuleName); |
136 | myCommandName = translator.lookupCommandName(commandId, myModuleName); |
| 77 | 137 | ||
| 78 | myData = translator.translateData(commandId, myModuleName, rawHexData); |
138 | myData = translator.translateData(commandId, myModuleName, rawHexData); |
| 79 | } |
139 | } |
| 80 | } |
140 | } |
| 81 | 141 | ||
| 82 | string CanMessage::getRaw() |
142 | string CanMessage::getRaw() |
| 83 | { |
143 | { |
| 84 | CanIdTranslator &translator = CanIdTranslator::getInstance(); |
144 | CanIdTranslator &translator = CanIdTranslator::getInstance(); |
| 85 | 145 | ||
| 86 | string dataHex; |
146 | string dataHex; |
| 87 | 147 | ||
| 88 | string rawHex = "PKT "; |
148 | string rawHex = "PKT "; |
| 89 | 149 | ||
| 90 | string bin = "000"; |
150 | string bin = "000"; |
| 91 | 151 | ||
| 92 | int classId = translator.resolveClassId(myClassName); |
152 | int classId = translator.resolveClassId(myClassName); |
| 93 | if (classId == -1) |
153 | if (classId == -1) |
| 94 | bin += "0000"; |
154 | bin += "0000"; |
| 95 | else |
155 | else |
| 96 | bin += uint2bin(classId, 4); |
156 | bin += uint2bin(classId, 4); |
| 97 | 157 | ||
| 98 | if (myClassName == "nmt") |
158 | if (myClassName == "nmt") |
| 99 | { |
159 | { |
| 100 | bin +="0"; |
160 | bin +="0"; |
| 101 | 161 | ||
| 102 | int commandNameId = translator.resolveNMTCommandId(myCommandName); |
162 | int commandNameId = translator.resolveNMTCommandId(myCommandName); |
| 103 | if (commandNameId == -1) |
163 | if (commandNameId == -1) |
| 104 | bin += "00000000"; |
164 | bin += "00000000"; |
| 105 | else |
165 | else |
| 106 | bin += uint2bin(commandNameId, 8); |
166 | bin += uint2bin(commandNameId, 8); |
| 107 | 167 | ||
| 108 | bin += "0000000000000000"; |
168 | bin += "0000000000000000"; |
| 109 | 169 | ||
| 110 | dataHex = translator.translateNMTDataToHex(commandNameId, myData); |
170 | dataHex = translator.translateNMTDataToHex(commandNameId, myData); |
| 111 | } |
171 | } |
| 112 | else |
172 | else |
| 113 | { |
173 | { |
| 114 | bin += uint2bin(translator.resolveDirectionFlag(myDirectionFlag), 1); |
174 | bin += uint2bin(translator.resolveDirectionFlag(myDirectionFlag), 1); |
| 115 | 175 | ||
| 116 | 176 | ||
| 117 | int moduleTypeId = translator.resolveModuleId(myModuleName); |
177 | int moduleTypeId = translator.resolveModuleId(myModuleName); |
| 118 | if (moduleTypeId == -1) |
178 | if (moduleTypeId == -1) |
| 119 | bin += "00000000"; |
179 | bin += "00000000"; |
| 120 | else |
180 | else |
| 121 | bin += uint2bin(moduleTypeId, 8); |
181 | bin += uint2bin(moduleTypeId, 8); |
| 122 | 182 | ||
| 123 | 183 | ||
| 124 | int moduleId = myModuleId; |
184 | int moduleId = myModuleId; |
| 125 | bin += uint2bin(moduleId, 8); |
185 | bin += uint2bin(moduleId, 8); |
| 126 | 186 | ||
| 127 | 187 | ||
| 128 | int commandNameId = translator.resolveCommandId(myCommandName, myModuleName); |
188 | int commandNameId = translator.resolveCommandId(myCommandName, myModuleName); |
| 129 | if (commandNameId == -1) |
189 | if (commandNameId == -1) |
| 130 | bin += "00000000"; |
190 | bin += "00000000"; |
| 131 | else |
191 | else |
| 132 | bin += uint2bin(commandNameId, 8); |
192 | bin += uint2bin(commandNameId, 8); |
| 133 | 193 | ||
| 134 | dataHex = translator.translateDataToHex(commandNameId, myModuleName, myData); |
194 | dataHex = translator.translateDataToHex(commandNameId, myModuleName, myData); |
| 135 | } |
195 | } |
| 136 | 196 | ||
| 137 | rawHex += bin2hex(bin); |
197 | rawHex += bin2hex(bin); |
| 138 | 198 | ||
| 139 | rawHex += " 1 0"; |
199 | rawHex += " 1 0"; |
| 140 | 200 | ||
| 141 | while (dataHex.size() > 0) |
201 | while (dataHex.size() > 0) |
| 142 | { |
202 | { |
| - | 203 | string hex; |
|
| - | 204 | ||
| - | 205 | try |
|
| - | 206 | { |
|
| 143 |
|
207 | hex = dataHex.substr(0, 2); |
| - | 208 | } |
|
| - | 209 | catch (std::out_of_range& e) |
|
| - | 210 | { |
|
| - | 211 | cout << "DEBUG: getRaw exception: " << e.what() << "\n"; |
|
| - | 212 | cout << "DEBUG: A dataHex=" << dataHex << endl; |
|
| - | 213 | continue; |
|
| - | 214 | } |
|
| - | 215 | ||
| - | 216 | ||
| 144 | dataHex.erase(0, 2); |
217 | dataHex.erase(0, 2); |
| 145 | rawHex += " " + hex; |
218 | rawHex += " " + hex; |
| 146 | } |
219 | } |
| 147 | 220 | ||
| 148 | rawHex += "\n"; |
221 | rawHex += "\n"; |
| 149 | 222 | ||
| 150 | return rawHex; |
223 | return rawHex; |
| 151 | } |
224 | } |
| 152 | 225 | ||
| 153 | void CanMessage::setData(map<string, CanVariable> data) |
226 | void CanMessage::setData(map<string, CanVariable> data) |
| 154 | { |
227 | { |
| 155 | myData = data; |
228 | myData = data; |
| 156 | 229 | ||
| 157 | CanIdTranslator &translator = CanIdTranslator::getInstance(); |
230 | CanIdTranslator &translator = CanIdTranslator::getInstance(); |
| 158 | 231 | ||
| 159 | int commandNameId = translator.resolveNMTCommandId(myCommandName); |
232 | int commandNameId = translator.resolveNMTCommandId(myCommandName); |
| 160 | 233 | ||
| 161 | if (myClassName == "nmt") |
234 | if (myClassName == "nmt") |
| 162 | { |
235 | { |
| 163 | translator.makeNMTDataValid(commandNameId, data); |
236 | translator.makeNMTDataValid(commandNameId, data); |
| 164 | } |
237 | } |
| 165 | else |
238 | else |
| 166 | { |
239 | { |
| 167 | translator.makeDataValid(commandNameId, myModuleName, data); |
240 | translator.makeDataValid(commandNameId, myModuleName, data); |
| Line 195... | Line 268... | ||
| 195 | } |
268 | } |
| 196 | 269 | ||
| 197 | json = trim(json, ','); |
270 | json = trim(json, ','); |
| 198 | 271 | ||
| 199 | return json + " }"; |
272 | return json + " }"; |
| - | 273 | } |
|
| - | 274 | ||
| - | 275 | string CanMessage::toString() |
|
| - | 276 | { |
|
| - | 277 | string result = "[CanMessage] ClassName: " + myClassName + "\n"; |
|
| - | 278 | result += " DirectionFlag: " + myDirectionFlag + "\n"; |
|
| - | 279 | result += " ModuleName: " + myModuleName + "\n"; |
|
| - | 280 | result += " ModuleId: " + itos(myModuleId) + "\n"; |
|
| - | 281 | result += " CommandName: " + myCommandName + "\n"; |
|
| - | 282 | result += " Data: " + getJSONData() + "\n"; |
|
| - | 283 | ||
| - | 284 | return result; |
|
| 200 | } |
285 | } |