Rev 991 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 991 | Rev 997 | ||
|---|---|---|---|
| Line 41... | Line 41... | ||
| 41 | //slog << "Malformed can message received from canDaemon: \"" << rawHex << "\"\n"; |
41 | //slog << "Malformed can message received from canDaemon: \"" << rawHex << "\"\n"; |
| 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 | ||
| - | 47 | try |
|
| - | 48 | { |
|
| - | 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 | } |
|
| 46 | 56 | ||
| 47 | myClassName = translator.lookupClassName(bin2uint(rawHeaderBin.substr(3, 4))); |
- | |
| 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 |
| 69 | { |
93 | { |
| - | 94 | try |
|
| - | 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 | } |
|
| 74 | 123 | ||
| - | 124 | int commandId; |
|
| - | 125 | ||
| - | 126 | try |
|
| - | 127 | { |
|
| 75 |
|
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 | } |
|
| - | 135 | ||
| 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 | } |
| Line 98... | Line 158... | ||
| 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"; |
| Line 132... | Line 192... | ||
| 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"; |
| 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 | } |