Debian Codegraph @

Hardware/Protocols/MaerklinCANCommon.cpp

raw symbols SCIP
1 /*
2 RailControl - Model Railway Control Software
3
4 Copyright (c) 2017-2025 by Teddy / Dominik Mahrer - www.railcontrol.org
5
6 RailControl is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
10
11 RailControl is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with RailControl; see the file LICENCE. If not see
18 <http://www.gnu.org/licenses/>.
19 */
20
21 #include <cstring>
22 #include <deque>
23
24 #include "Hardware/Protocols/MaerklinCANCommon.h"
25 #include "Hardware/ZLib.h"
26
27 using std::deque;
28 using std::string;
29 using std::vector;
30
31 namespace Hardware { namespace Protocols
32 {
33 void MaerklinCANCommon::Init()
34 {
35 run = true;
36 receiverThread = std::thread(&MaerklinCANCommon::ReceiverInternal, this);
37 pingThread = std::thread(&MaerklinCANCommon::PingSender, this);
38 }
39
40 MaerklinCANCommon::~MaerklinCANCommon()
41 {
42 run = false;
43 receiverThread.join();
44 pingThread.join();
45 if (canFileData != nullptr)
46 {
47 free(canFileData);
48 canFileData = nullptr;
49 }
50 }
51
52 void MaerklinCANCommon::Wait(const unsigned int duration) const
53 {
54 unsigned int wait = duration;
55 while (run && (!hasCs2Main || isCs2Main) && wait)
56 {
57 Utils::Utils::SleepForSeconds(1);
58 --wait;
59 }
60 }
61
62 void MaerklinCANCommon::ReceiverInternal()
63 {
64 Utils::Utils::SetThreadName("Maerklin CAN Receiver");
65 logger->Info(Languages::TextReceiverThreadStarted);
66 Receiver();
67 logger->Info(Languages::TextTerminatingReceiverThread);
68 }
69
70 void MaerklinCANCommon::PingSender()
71 {
72 Utils::Utils::SetThreadName("Maerklin CAN Ping");
73 logger->Info(Languages::TextPingSenderStarted);
74
75 Wait(1);
76
77 while (run && (!hasCs2Main || isCs2Main))
78 {
79 Ping();
80 Wait(10);
81 }
82
83 if (run && hasCs2Main && !isCs2Main)
84 {
85 RequestLoks();
86 }
87 logger->Info(Languages::TextTerminatingPingSender);
88 }
89
90 void MaerklinCANCommon::CreateCommandHeader(unsigned char* const buffer,
91 const CanCommand command,
92 const CanResponse response,
93 const CanLength length)
94 {
95 const CanPrio prio = 0;
96 buffer[0] = (prio << 1) | (command >> 7);
97 buffer[1] = (command << 1) | (response & 0x01);
98 Utils::Integer::ShortToDataBigEndian(hash, buffer + 2);
99 buffer[4] = length;
100 buffer[5] = 0;
101 buffer[6] = 0;
102 buffer[7] = 0;
103 buffer[8] = 0;
104 buffer[9] = 0;
105 buffer[10] = 0;
106 buffer[11] = 0;
107 buffer[12] = 0;
108 }
109
110 void MaerklinCANCommon::ParseAddressProtocol(const Address input,
111 Address& address,
112 Protocol& protocol,
113 LocoType& type)
114 {
115 address = input;
116 Address maskedAddress = address & 0xFC00;
117 type = LocoTypeLoco;
118
119 if ((maskedAddress == 0x0000) // MM Loco
120 || (maskedAddress == 0x1000) // MM Loco (unused by CS2)
121 || (maskedAddress == 0x2000) // MM Accessory (unused by CS2)
122 || (maskedAddress == 0x3000)) // MM Accessory
123 {
124 protocol = ProtocolMM;
125 address &= 0x03FF;
126 return;
127 }
128
129 // 0x0800 is SX1 Loco (unused by CS2)
130 // 0x2800 is SX1 Accessory (unused by CS2)
131
132 if (maskedAddress == 0x2C00) // Multiple Unit
133 {
134 protocol = ProtocolMultipleUnit;
135 type = LocoTypeMultipleUnit;
136 address &= 0x03FF;
137 return;
138 }
139
140 if ((maskedAddress == 0x3800) // DCC Accessory
141 || (maskedAddress == 0x3C00)) // DCC Accessory
142 {
143 protocol = ProtocolDCC;
144 address &= 0x03FF;
145 return;
146 }
147
148 maskedAddress = address & 0xC000;
149 address &= 0x3FFF;
150 if (maskedAddress == 0x4000) // MFX Loco
151 {
152 protocol = ProtocolMFX;
153 return;
154 }
155 if (maskedAddress == 0xC000) // DCC Loco
156 {
157 protocol = ProtocolDCC;
158 return;
159 }
160
161 protocol = ProtocolNone;
162 address = 0;
163 }
164
165 MaerklinCANCommon::CanFileCrc MaerklinCANCommon::CalcCrc(const unsigned char *data, const size_t length)
166 {
167 // Maerklin uses CRC-16-CCITT with seed 0xffff and with polynom 0x1021 -> x^16 + x^12 +x^5 + 1
168 static const CanFileCrc CrcTable[256] = {
169 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
170 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
171 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
172 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
173 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
174 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
175 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
176 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
177 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
178 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
179 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
180 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
181 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
182 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
183 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
184 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
185 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
186 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
187 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
188 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
189 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
190 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
191 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
192 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
193 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
194 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
195 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
196 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
197 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
198 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
199 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
200 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
201 };
202
203 CanFileCrc crc = 0xffff; // seed
204
205 for (size_t count = 0; count < length; ++count)
206 {
207 const CanFileCrc temp = (*data++ ^ (crc >> 8)) & 0xff;
208 crc = CrcTable[temp] ^ (crc << 8);
209 }
210 return crc;
211 }
212
213 MaerklinCANCommon::CanHash MaerklinCANCommon::CalcHash(const CanUid uid)
214 {
215 const CanHash calc = (uid >> 16) ^ (uid & 0xFFFF);
216 CanHash hash = ((calc << 3) | 0x0300) & 0xFF00;
217 hash |= (calc & 0x007F);
218 return hash;
219 }
220
221 void MaerklinCANCommon::GenerateUidHash()
222 {
223 uid = rand();
224 string uidString = Utils::Integer::IntegerToHex(uid);
225 // FIXME: params->SetArg5(uidString);
226 hash = CalcHash(uid);
227 logger->Info(Languages::TextMyUidHash, uidString, Utils::Integer::IntegerToHex(hash));
228 }
229
230 void MaerklinCANCommon::CreateLocalIDLoco(unsigned char* buffer,
231 const Protocol protocol,
232 const Address address) const
233 {
234 uint32_t localID = address;
235 if (protocol == ProtocolDCC)
236 {
237 localID |= 0xC000;
238 }
239 else if (protocol == ProtocolMFX)
240 {
241 localID |= 0x4000;
242 }
243 else if (protocol == ProtocolMultipleUnit)
244 {
245 localID |= 0x2000;
246 }
247 // else expect PROTOCOL_MM2: do nothing
248 Utils::Integer::IntToDataBigEndian(localID, buffer + 5);
249 }
250
251 void MaerklinCANCommon::CreateLocalIDAccessory(unsigned char* buffer,
252 const Protocol protocol,
253 const Address address) const
254 {
255 uint32_t localID = address - 1; // GUI-address is 1-based, protocol-address is 0-based
256 if (protocol == ProtocolDCC)
257 {
258 localID |= 0x3800;
259 }
260 else // ProtocolMM
261 {
262 localID |= 0x3000;
263 }
264 Utils::Integer::IntToDataBigEndian(localID, buffer + 5);
265 }
266
267 void MaerklinCANCommon::Booster(const BoosterState status)
268 {
269 unsigned char buffer[CANCommandBufferLength];
270 logger->Info(status ? Languages::TextTurningBoosterOn : Languages::TextTurningBoosterOff);
271 CreateCommandHeader(buffer, CanCommandSystem, CanResponseCommand, 5);
272 buffer[9] = status;
273 SendInternal(buffer);
274 }
275
276 void MaerklinCANCommon::LocoSpeed(const Protocol protocol, const Address address, const Speed speed)
277 {
278 unsigned char buffer[CANCommandBufferLength];
279 logger->Info(Languages::TextSettingSpeedWithProtocol, Utils::Utils::ProtocolToString(protocol), address, speed);
280 CreateCommandHeader(buffer, CanCommandLocoSpeed, CanResponseCommand, 6);
281 CreateLocalIDLoco(buffer, protocol, address);
282 Utils::Integer::ShortToDataBigEndian(speed, buffer + 9);
283 SendInternal(buffer);
284 }
285
286 void MaerklinCANCommon::LocoOrientation(const Protocol protocol, const Address address,
287 const Orientation orientation)
288 {
289 unsigned char buffer[CANCommandBufferLength];
290 logger->Info(Languages::TextSettingDirectionOfTravelWithProtocol, Utils::Utils::ProtocolToString(protocol), address, Languages::GetLeftRight(orientation));
291 CreateCommandHeader(buffer, CanCommandLocoDirection, CanResponseCommand, 5);
292 CreateLocalIDLoco(buffer, protocol, address);
293 buffer[9] = (orientation ? 1 : 2);
294 SendInternal(buffer);
295 }
296
297 void MaerklinCANCommon::LocoFunction(const Protocol protocol,
298 const Address address,
299 const DataModel::LocoFunctionNr function,
300 const DataModel::LocoFunctionState on)
301 {
302 unsigned char buffer[CANCommandBufferLength];
303 logger->Info(Languages::TextSettingFunctionWithProtocol, static_cast<int>(function), Utils::Utils::ProtocolToString(protocol), address, Languages::GetOnOff(on));
304 CreateCommandHeader(buffer, CanCommandLocoFunction, CanResponseCommand, 6);
305 CreateLocalIDLoco(buffer, protocol, address);
306 buffer[9] = function;
307 buffer[10] = (on == DataModel::LocoFunctionStateOn);
308 SendInternal(buffer);
309 }
310
311 void MaerklinCANCommon::Accessory(const Protocol protocol,
312 const Address address,
313 const DataModel::AccessoryState state,
314 const bool on)
315 {
316 unsigned char buffer[CANCommandBufferLength];
317 logger->Info(Languages::TextSettingAccessoryWithProtocol, Utils::Utils::ProtocolToString(protocol), address, Languages::GetGreenRed(state), Languages::GetOnOff(on));
318 CreateCommandHeader(buffer, CanCommandAccessory, CanResponseCommand, 6);
319 CreateLocalIDAccessory(buffer, protocol, address);
320 buffer[9] = state & 0x03;
321 buffer[10] = static_cast<unsigned char>(on);
322 SendInternal(buffer);
323 }
324
325 void MaerklinCANCommon::ProgramRead(const ProgramMode mode, const Address address, const CvNumber cv)
326 {
327 Address addressInternal = address;
328 Protocol protocol = ProtocolNone;
329 switch (mode)
330 {
331 case ProgramModeDccDirect:
332 logger->Info(Languages::TextProgramDccDirectRead, cv);
333 protocol = ProtocolDCC;
334 break;
335
336 case ProgramModeMfx:
337 logger->Info(Languages::TextProgramMfxRead, address, cv);
338 protocol = ProtocolMFX;
339 break;
340
341 default:
342 return;
343 }
344 unsigned char buffer[CANCommandBufferLength];
345 CreateCommandHeader(buffer, CanCommandReadConfig, CanResponseCommand, 7);
346 CreateLocalIDLoco(buffer, protocol, addressInternal);
347 Utils::Integer::ShortToDataBigEndian(cv, buffer + 9);
348 buffer[11] = 1;
349 SendInternal(buffer);
350 }
351
352 void MaerklinCANCommon::ProgramWrite(const ProgramMode mode, const Address address, const CvNumber cv,
353 const CvValue value)
354 {
355 Address addressInternal = address;
356 Protocol protocol = ProtocolNone;
357 unsigned char controlFlags = 0;
358 switch (mode)
359 {
360 case ProgramModeMm:
361 logger->Info(Languages::TextProgramMm, cv, value);
362 protocol = ProtocolMM;
363 addressInternal = 80;
364 break;
365
366 case ProgramModeMmPom:
367 logger->Info(Languages::TextProgramMmPom, address, cv, value);
368 protocol = ProtocolMM;
369 controlFlags = 1 << 7;
370 break;
371
372 case ProgramModeDccDirect:
373 logger->Info(Languages::TextProgramDccDirectWrite, cv, value);
374 protocol = ProtocolDCC;
375 addressInternal = 0;
376 break;
377
378 case ProgramModeDccPomLoco:
379 logger->Info(Languages::TextProgramDccPomLocoWrite, address, cv, value);
380 protocol = ProtocolDCC;
381 controlFlags = 1 << 7;
382 break;
383
384 case ProgramModeMfx:
385 logger->Info(Languages::TextProgramMfxWrite, address, cv, value);
386 protocol = ProtocolMFX;
387 controlFlags = 1 << 7;
388 break;
389
390 default:
391 return;
392 }
393 unsigned char buffer[CANCommandBufferLength];
394 CreateCommandHeader(buffer, CanCommandWriteConfig, CanResponseCommand, 8);
395 CreateLocalIDLoco(buffer, protocol, addressInternal);
396 Utils::Integer::ShortToDataBigEndian(cv, buffer + 9);
397 buffer[11] = value;
398 buffer[12] = controlFlags;
399 SendInternal(buffer);
400 }
401
402 void MaerklinCANCommon::Ping()
403 {
404 unsigned char buffer[CANCommandBufferLength];
405 CreateCommandHeader(buffer, CanCommandPing, CanResponseCommand, 0);
406 SendInternal(buffer);
407 }
408
409 void MaerklinCANCommon::RequestLoks()
410 {
411 unsigned char buffer[CANCommandBufferLength];
412 CreateCommandHeader(buffer, CanCommandRequestConfigData, CanResponseCommand, 8);
413 buffer[5] = 'l';
414 buffer[6] = 'o';
415 buffer[7] = 'k';
416 buffer[8] = 's';
417 buffer[9] = 0;
418 buffer[10] = 0;
419 buffer[11] = 0;
420 buffer[12] = 0;
421 SendInternal(buffer);
422 }
423
424 void MaerklinCANCommon::Parse(const unsigned char* buffer)
425 {
426 CanResponse response = ParseResponse(buffer);
427 CanCommand command = ParseCommand(buffer);
428 CanLength length = ParseLength(buffer);
429 logger->HexIn(buffer, 5 + length);
430 const CanHash receivedHash = ParseHash(buffer);
431 if (receivedHash == hash)
432 {
433 uint16_t deviceType = Utils::Integer::DataBigEndianToShort(buffer + 11);
434 if (command == CanCommandPing && response == true)
435 {
436 if (deviceType == CanDeviceCs2Main)
437 {
438 hasCs2Main = true;
439 logger->Info(Languages::TextCs2MainFound);
440 }
441 }
442 else if (command != CanCommandConfigData)
443 {
444 GenerateUidHash();
445 }
446 }
447
448 if (response)
449 {
450 switch (command)
451 {
452 case CanCommandS88Event:
453 ParseResponseS88Event(buffer);
454 return;
455
456 case CanCommandReadConfig:
457 ParseResponseReadConfig(buffer);
458 return;
459
460 case CanCommandPing:
461 ParseResponsePing(buffer);
462 return;
463
464 case CanCommandLocoSpeed:
465 ParseResponseLocoSpeed(buffer);
466 return;
467
468 case CanCommandLocoDirection:
469 ParseResponseLocoDirection(buffer);
470 return;
471
472 case CanCommandLocoFunction:
473 ParseResponseLocoFunction(buffer);
474 return;
475
476 case CanCommandAccessory:
477 ParseResponseAccessory(buffer);
478 return;
479
480 default:
481 return;
482 }
483 }
484
485 switch (command)
486 {
487 case CanCommandSystem:
488 ParseCommandSystem(buffer);
489 return;
490
491 case CanCommandRequestConfigData:
492 ParseCommandRequestConfigData(buffer);
493 return;
494
495 case CanCommandConfigData:
496 ParseCommandConfigData(buffer);
497 return;
498
499 case CanCommandPing:
500 ParseCommandPing(buffer);
501 return;
502
503 default:
504 return;
505 }
506 }
507
508 void MaerklinCANCommon::ParseCommandSystem(const unsigned char* const buffer)
509 {
510 if (ParseLength(buffer) != 5)
511 {
512 return;
513 }
514 CanSubCommand subcmd = ParseSubCommand(buffer);
515 switch (subcmd)
516 {
517 case CanSubCommandStop:
518 // system stop
519 manager->Booster(ControlTypeHardware, BoosterStateStop);
520 return;
521
522 case CanSubCommandGo:
523 // system go
524 manager->Booster(ControlTypeHardware, BoosterStateGo);
525 return;
526 }
527 }
528
529 void MaerklinCANCommon::ParseResponseLocoSpeed(const unsigned char* const buffer)
530 {
531 if (ParseLength(buffer) != 6)
532 {
533 return;
534 }
535 Address address;
536 Protocol protocol;
537 LocoType type;
538 ParseAddressProtocol(buffer, address, protocol, type);
539 Speed speed = Utils::Integer::DataBigEndianToShort(buffer + 9);
540 logger->Info(Languages::TextReceivedSpeedCommand, Utils::Utils::ProtocolToString(protocol), address, speed);
541 manager->LocoSpeed(ControlTypeHardware, controlID, protocol, address, speed);
542 }
543
544 void MaerklinCANCommon::ParseResponseLocoDirection(const unsigned char* const buffer)
545 {
546 if (ParseLength(buffer) != 5)
547 {
548 return;
549 }
550 Address address;
551 Protocol protocol;
552 LocoType type;
553 ParseAddressProtocol(buffer, address, protocol, type);
554 Orientation orientation = (buffer[9] == 1 ? OrientationRight : OrientationLeft);
555 logger->Info(Languages::TextReceivedDirectionCommand, Utils::Utils::ProtocolToString(protocol), address, orientation);
556 // changing direction implies speed = 0
557 manager->LocoSpeed(ControlTypeHardware, controlID, protocol, address, MinSpeed);
558 manager->LocoOrientation(ControlTypeHardware, controlID, protocol, address, orientation);
559 }
560
561 void MaerklinCANCommon::ParseResponseLocoFunction(const unsigned char* const buffer)
562 {
563 if (ParseLength(buffer) != 6)
564 {
565 return;
566 }
567 Address address;
568 Protocol protocol;
569 LocoType type;
570 ParseAddressProtocol(buffer, address, protocol, type);
571 DataModel::LocoFunctionNr function = buffer[9];
572 DataModel::LocoFunctionState on = (buffer[10] != 0 ? DataModel::LocoFunctionStateOn : DataModel::LocoFunctionStateOff);
573 logger->Info(Languages::TextReceivedFunctionCommand, Utils::Utils::ProtocolToString(protocol), address, function, on);
574 manager->LocoFunctionState(ControlTypeHardware, controlID, protocol, address, function, on);
575 }
576
577 void MaerklinCANCommon::ParseResponseAccessory(const unsigned char* const buffer)
578 {
579 if (ParseLength(buffer) != 6 || buffer[10] != 1)
580 {
581 return;
582 }
583 Address address;
584 Protocol protocol;
585 LocoType type;
586 ParseAddressProtocol(buffer, address, protocol, type);
587 DataModel::AccessoryState state = (buffer[9] ? DataModel::AccessoryStateOn : DataModel::AccessoryStateOff);
588 // GUI-address is 1-based, protocol-address is 0-based
589 ++address;
590 logger->Info(Languages::TextReceivedAccessoryCommand, Utils::Utils::ProtocolToString(protocol), address, state);
591 manager->AccessoryBaseState(ControlTypeHardware, controlID, protocol, address, state);
592 }
593
594 void MaerklinCANCommon::ParseCommandPing(const unsigned char* const buffer)
595 {
596 if ((buffer[4] == 8) && (Utils::Integer::DataBigEndianToInt(buffer + 5) != uid))
597 {
598 return;
599 }
600 unsigned char sendBuffer[CANCommandBufferLength];
601 CreateCommandHeader(sendBuffer, CanCommandPing, CanResponseResponse, 8);
602 Utils::Integer::IntToDataBigEndian(uid, sendBuffer + 5);
603 // version 4.3
604 sendBuffer[9] = 4;
605 sendBuffer[10] = 3;
606 // CS2 device type: Main = 0xffff, Secondary = 0xfff0
607 sendBuffer[11] = 0xff;
608 sendBuffer[12] = isCs2Main ? 0xff : 0xf0;
609 SendInternal(sendBuffer);
610 }
611
612 void MaerklinCANCommon::ParseCommandRequestConfigData(const unsigned char* const buffer)
613 {
614 if ((buffer[5] == 'l')
615 && (buffer[6] == 'o')
616 && (buffer[7] == 'k')
617 && (buffer[8] == 's')
618 && (buffer[9] == 0x00)
619 && (buffer[10] == 0x00)
620 && (buffer[11] == 0x00)
621 && (buffer[12] == 0x00))
622 {
623 const string dataPlain = manager->GetCs2Lokomotive();
624 SendCompressedFile(dataPlain, buffer + 5);
625 }
626 else if ((buffer[5] == 'm')
627 && (buffer[6] == 'a')
628 && (buffer[7] == 'g')
629 && (buffer[8] == 's')
630 && (buffer[9] == 0x00)
631 && (buffer[10] == 0x00)
632 && (buffer[11] == 0x00)
633 && (buffer[12] == 0x00))
634 {
635 const string dataPlain = manager->GetCs2Magnetartikel();
636 SendCompressedFile(dataPlain, buffer + 5);
637 }
638 else if ((buffer[5] == 'g')
639 && (buffer[6] == 'b')
640 && (buffer[7] == 's')
641 && (buffer[12] == 0x00)) // we need a null here to prevent parsing errors
642 {
643 if ((buffer[8] == 0x00)
644 && (buffer[9] == 0x00)
645 && (buffer[10] == 0x00)
646 && (buffer[11] == 0x00))
647 {
648 const string dataPlain = manager->GetCs2GBS();
649 SendCompressedFile(dataPlain, buffer + 5);
650 }
651 else if (buffer[8] == '-')
652 {
653 const string gbsAsString(reinterpret_cast<const char*>(buffer + 9));
654 const unsigned int gbs = Utils::Integer::StringToInteger(gbsAsString);
655 const string dataPlain = manager->GetCs2GBS(gbs);
656 SendCompressedFile(dataPlain, buffer + 5);
657 }
658 }
659 else if ((buffer[5] == 'f')
660 && (buffer[6] == 's')
661 && (buffer[7] == 0x00)
662 && (buffer[8] == 0x00)
663 && (buffer[9] == 0x00)
664 && (buffer[10] == 0x00)
665 && (buffer[11] == 0x00)
666 && (buffer[12] == 0x00))
667 {
668 // we send an empty configuration
669 const string dataPlain = "[fahrstrassen]\nversion\n .minor=4\n";
670 SendCompressedFile(dataPlain, buffer + 5);
671 }
672 }
673
674 void MaerklinCANCommon::SendCompressedFile(const string& dataPlain, const unsigned char* fileName)
675 {
676 logger->Debug(dataPlain);
677 const uint32_t dataPlainSize = dataPlain.size();
678
679 unsigned char sendBuffer[CANCommandBufferLength];
680 if (fileName)
681 {
682 // send filename as response
683 CreateCommandHeader(sendBuffer, CanCommandRequestConfigData, CanResponseResponse, 8);
684 Utils::Utils::Copy8Bytes(fileName, sendBuffer + 5);
685 SendInternal(sendBuffer);
686 }
687
688 const string dataCompressed = ZLib::Compress(dataPlain);
689 const unsigned char* const dataCompressedPtr = reinterpret_cast<const unsigned char*>(dataCompressed.c_str());
690 const uint32_t dataCompressedSize = dataCompressed.size();
691
692 // prepare data
693 const uint32_t dataToSendSize = (4 + dataCompressedSize + 8) & 0xFFFFFFF8;
694 unsigned char* const dataToSend = reinterpret_cast<unsigned char*>(malloc(dataToSendSize));
695
696 // set last 8 bytes to 0 (fill up last data packet)
697 const uint64_t eightBytes = 0;
698 Utils::Utils::Copy8Bytes(&eightBytes, dataToSend + dataToSendSize - 8);
699
700 // set first 4 bytes to length of uncompressed data size
701 Utils::Integer::IntToDataBigEndian(dataPlainSize, dataToSend);
702
703 // copy compressed data to out buffer
704 std::memcpy(dataToSend + 4, dataCompressedPtr, dataCompressedSize);
705
706 const CanFileCrc crc = CalcCrc(dataToSend, dataToSendSize);
707
708 // send first data packet
709 CreateCommandHeader(sendBuffer, CanCommandConfigData, CanResponseCommand, 6);
710 Utils::Integer::IntToDataBigEndian(dataCompressedSize + 4, sendBuffer + 5);
711 Utils::Integer::ShortToDataBigEndian(crc, sendBuffer + 9);
712 SendInternal(sendBuffer);
713
714 // send following data packets
715 CreateCommandHeader(sendBuffer, CanCommandConfigData, CanResponseCommand, 8);
716 for(size_t sent = 0; sent < dataToSendSize; sent += 8)
717 {
718 Utils::Utils::Copy8Bytes(dataToSend + sent, sendBuffer + 5);
719 Utils::Utils::SleepForMilliseconds(2); // do not overload CS2 with too much data
720 SendInternal(sendBuffer);
721 }
722
723 free(dataToSend);
724 }
725
726 void MaerklinCANCommon::ParseCommandConfigData(const unsigned char* const buffer)
727 {
728 CanLength length = ParseLength(buffer);
729 switch (length)
730 {
731 case 6:
732 case 7:
733 ParseCommandConfigDataFirst(buffer);
734 return;
735
736 case 8:
737 ParseCommandConfigDataNext(buffer);
738 return;
739
740 default:
741 return;
742 }
743 return;
744 }
745
746 void MaerklinCANCommon::ParseCommandConfigDataFirst(const unsigned char* const buffer)
747 {
748 if (canFileData != nullptr)
749 {
750 free(canFileData);
751 }
752 canFileDataSize = Utils::Integer::DataBigEndianToInt(buffer + 5);
753 canFileCrc = Utils::Integer::DataBigEndianToShort(buffer + 9);
754 canFileCrcSize = (canFileDataSize + 8) & 0xFFFFFFF8;
755 canFileData = reinterpret_cast<unsigned char*>(malloc(canFileCrcSize));
756 canFileDataPointer = canFileData;
757 }
758
759 void MaerklinCANCommon::ParseCommandConfigDataNext(const unsigned char* const buffer)
760 {
761 if (canFileData == nullptr)
762 {
763 return;
764 }
765
766 Utils::Utils::Copy8Bytes(buffer + 5, canFileDataPointer);
767 canFileDataPointer += 8;
768 if (canFileDataSize > static_cast<size_t>(canFileDataPointer - canFileData))
769 {
770 return;
771 }
772
773 const CanFileCrc calculatedCrc = CalcCrc(canFileData, canFileCrcSize);
774 if (canFileCrc != calculatedCrc)
775 {
776 logger->Info(Languages::TextCrcMissmatch, Utils::Integer::IntegerToHex(canFileCrc), Utils::Integer::IntegerToHex(calculatedCrc));
777 CleanUpCanFileData();
778 return;
779 }
780
781 size_t canFileUncompressedSize = Utils::Integer::DataBigEndianToInt(canFileData);
782 logger->Info(Languages::TextConfigFileReceivedWithSize, canFileUncompressedSize);
783 string file = ZLib::UnCompress(reinterpret_cast<char*>(canFileData + 4), canFileDataSize, canFileUncompressedSize);
784 deque<string> lines;
785 Utils::Utils::SplitString(file, "\n", lines);
786 for (std::string& line : lines)
787 {
788 logger->Debug(line);
789 }
790
791 ParseCs2File(lines);
792 CleanUpCanFileData();
793 }
794
795 void MaerklinCANCommon::ParseResponseS88Event(const unsigned char* const buffer)
796 {
797 if (ParseLength(buffer) != 8)
798 {
799 return;
800 }
801 const char* onOff;
802 DataModel::Feedback::FeedbackState state;
803 if (buffer[10])
804 {
805 onOff = Languages::GetText(Languages::TextOn);
806 state = DataModel::Feedback::FeedbackStateOccupied;
807 }
808 else
809 {
810 onOff = Languages::GetText(Languages::TextOff);
811 state = DataModel::Feedback::FeedbackStateFree;
812 }
813 FeedbackPin pin = ParseFeedbackPin(buffer);
814 logger->Info(Languages::TextFeedbackChange, pin & 0x000F, pin >> 4, onOff);
815 manager->FeedbackState(controlID, pin, state);
816 }
817
818 void MaerklinCANCommon::ParseResponseReadConfig(const unsigned char* const buffer)
819 {
820 if (ParseLength(buffer) != 7)
821 {
822 return;
823 }
824 CvNumber cv = Utils::Integer::DataBigEndianToShort(buffer + 9);
825 CvValue value = buffer[11];
826 logger->Info(Languages::TextProgramReadValue, cv, value);
827 manager->ProgramValue(cv, value);
828 }
829
830 void MaerklinCANCommon::ParseResponsePing(const unsigned char* const buffer)
831 {
832 const uint16_t deviceType = Utils::Integer::DataBigEndianToShort(buffer + 11);
833 char* deviceString = nullptr;
834 switch (deviceType)
835 {
836 case CanDeviceGfp:
837 deviceString = const_cast<char*>("Gleisformat Prozessor");
838 break;
839
840 case CanDeviceGleisbox:
841 case CanDeviceGleisbox_2:
842 deviceString = const_cast<char*>("Gleisbox");
843 break;
844
845 case CanDeviceConnect6021:
846 deviceString = const_cast<char*>("Connect 6021");
847 break;
848
849 case CanDeviceMs2:
850 case CanDeviceMs2_2:
851 case CanDeviceMs2_3:
852 case CanDeviceMs2_4:
853 deviceString = const_cast<char*>("MS2");
854 break;
855
856 case CanDeviceWireless:
857 deviceString = const_cast<char*>("Wireless");
858 break;
859
860 case CanDeviceCs2Main:
861 deviceString = const_cast<char*>("CS2 Main");
862 hasCs2Main = true;
863 break;
864
865 case CanDeviceCs2Secondary:
866 case CanDeviceCs2Secondary_2:
867 deviceString = const_cast<char*>("CS2 Secondary");
868 break;
869
870 case CanDeviceLinkS88:
871 deviceString = const_cast<char*>("Link S88");
872 hasCs2Main = true;
873 break;
874
875 default:
876 deviceString = const_cast<char*>("unknown");
877 break;
878 }
879 const string hash = Utils::Integer::IntegerToHex(Utils::Integer::DataBigEndianToShort(buffer + 2));
880 const unsigned char deviceId = buffer[8];
881 const unsigned char majorVersion = buffer[9];
882 const unsigned char minorVersion = buffer[10];
883 logger->Debug(Languages::TextDeviceOnCanBus, deviceString, hash, deviceId, majorVersion, minorVersion);
884 }
885
886 bool MaerklinCANCommon::ParseCs2FileKeyValue(const string& line, string& key, string& value)
887 {
888 if (line.length() < 4 || line[0] != ' ' || line[1] != '.')
889 {
890 return false;
891 }
892 const string stripedLine = line.substr(2);
893 Utils::Utils::SplitString(stripedLine, "=", key, value);
894 return (key.compare(stripedLine) != 0);
895 }
896
897 bool MaerklinCANCommon::ParseCs2FileSubkeyValue(const string& line, string& key, string& value)
898 {
899 if (line.length() < 5 || line[0] != ' ' || line[1] != '.' || line[2] != '.')
900 {
901 return false;
902 }
903 const string stripedLine = line.substr(3);
904 Utils::Utils::SplitString(stripedLine, "=", key, value);
905 return (key.compare(stripedLine) != 0);
906 }
907
908 void MaerklinCANCommon::ParseCs2FileLocomotiveFunction(deque<string>& lines, LocoCacheEntry& cacheEntry)
909 {
910 lines.pop_front();
911 DataModel::LocoFunctionNr nr = 0;
912 DataModel::LocoFunctionType type = DataModel::LocoFunctionTypeNone;
913 DataModel::LocoFunctionIcon icon = DataModel::LocoFunctionIconNone;
914 DataModel::LocoFunctionTimer timer = 0;
915 while (lines.size())
916 {
917 string& line = lines.front();
918 string key;
919 string value;
920 bool ok = ParseCs2FileSubkeyValue(line, key, value);
921 if (ok == false)
922 {
923 break;
924 }
925 if (key.compare("nr") == 0)
926 {
927 nr = Utils::Integer::StringToInteger(value);
928 }
929 else if (key.compare("typ") == 0 || key.compare("typ2") == 0)
930 {
931 uint8_t valueInt = Utils::Integer::StringToInteger(value);
932 icon = MapLocoFunctionCs2ToRailControl(static_cast<LocoFunctionCs2Icon>(valueInt & 0x7F));
933 type = static_cast<DataModel::LocoFunctionType>((valueInt >> 7) + 1); // CS2: 1 = permanent, 2 = once
934 }
935 else if (key.compare("dauer") == 0 || key.compare("dauer2") == 0)
936 {
937 type = DataModel::LocoFunctionTypeTimer;
938 timer = Utils::Integer::StringToInteger(value);
939 }
940 lines.pop_front();
941 }
942 if (type == DataModel::LocoFunctionTypeNone)
943 {
944 icon = DataModel::LocoFunctionIconNone;
945 timer = 0;
946 cacheEntry.ClearFunction(nr);
947 return;
948 }
949 cacheEntry.SetFunction(nr, type, icon, timer);
950 if (type == DataModel::LocoFunctionTypeTimer)
951 {
952 logger->Info(Languages::TextCs2MainLocoFunctionIconTypeTimer, nr, icon, timer);
953 }
954 else
955 {
956 logger->Info(Languages::TextCs2MainLocoFunctionIconType, nr, icon, type);
957 }
958 }
959
960 void MaerklinCANCommon::ParseCs2FileLocomotiveTraktion(deque<string>& lines, LocoCacheEntry& cacheEntry)
961 {
962 lines.pop_front();
963 Protocol protocol = ProtocolNone;
964 Address address = AddressNone;
965 string name;
966 while (lines.size())
967 {
968 string& line = lines.front();
969 string key;
970 string value;
971 bool ok = ParseCs2FileSubkeyValue(line, key, value);
972 if (ok == false)
973 {
974 break;
975 }
976 if (key.compare("lok") == 0)
977 {
978 Address input = Utils::Integer::HexToInteger(value);
979 LocoType type;
980 ParseAddressProtocol(input, address, protocol, type);
981 logger->Info(Languages::TextCs2MainLocoSlaveProtocolAddress, Utils::Utils::ProtocolToString(protocol), address);
982 }
983 else if (key.compare("lokname") == 0)
984 {
985 name = value;
986 logger->Info(Languages::TextCs2MainLocoSlaveName, name);
987 }
988 lines.pop_front();
989 }
990 cacheEntry.AddSlave(protocol, address, name);
991 }
992
993 void MaerklinCANCommon::ParseCs2FileLocomotive(deque<string>& lines)
994 {
995 lines.pop_front();
996 LocoCacheEntry cacheEntry(controlID);
997 std::string name;
998 std::string oldName;
999 bool remove = false;
1000 while (lines.size())
1001 {
1002 string& line = lines.front();
1003 if ((line.length() == 0) || (line[0] != ' '))
1004 {
1005 break;
1006 }
1007 string key;
1008 string value;
1009 ParseCs2FileKeyValue(line, key, value);
1010 if (key.compare("name") == 0)
1011 {
1012 name = value;
1013 cacheEntry.SetName(value);
1014 cacheEntry.SetMatchKey(value);
1015 logger->Info(Languages::TextCs2MainLocoName, value);
1016 }
1017 else if (key.compare("vorname") == 0)
1018 {
1019 oldName = value;
1020 logger->Info(Languages::TextCs2MainLocoOldName, value);
1021 }
1022 else if (key.compare("toRemove") == 0)
1023 {
1024 remove = true;
1025 }
1026 else if (key.compare("uid") == 0)
1027 {
1028 Address input = Utils::Integer::HexToInteger(value);
1029 Address address = AddressNone;
1030 Protocol protocol = ProtocolNone;
1031 LocoType type;
1032 ParseAddressProtocol(input, address, protocol, type);
1033 cacheEntry.SetAddress(address);
1034 cacheEntry.SetProtocol(protocol);
1035 cacheEntry.SetType(type);
1036 logger->Info(Languages::TextCs2MainLocoProtocolAddress, Utils::Utils::ProtocolToString(protocol), address);
1037 }
1038 else if ((key.compare("funktionen") == 0)
1039 || (key.compare("funktionen_2") == 0)
1040 || (key.compare("fkt") == 0)
1041 || (key.compare("fkt2") == 0))
1042 {
1043 ParseCs2FileLocomotiveFunction(lines, cacheEntry);
1044 continue;
1045 }
1046 else if (key.compare("traktion") == 0)
1047 {
1048 ParseCs2FileLocomotiveTraktion(lines, cacheEntry);
1049 continue;
1050 }
1051 lines.pop_front();
1052 }
1053
1054 if (remove)
1055 {
1056 logger->Info(Languages::TextCs2MainLocoRemove, name);
1057 LocoID locoId = CacheDelete(name);
1058 manager->LocoDelete(locoId);
1059 }
1060 else if (oldName.size() > 0)
1061 {
1062 CacheSave(cacheEntry, oldName);
1063 }
1064 else
1065 {
1066 CacheSave(cacheEntry);
1067 }
1068 }
1069
1070 void MaerklinCANCommon::ParseCs2FileLocomotivesSession(deque<string>& lines)
1071 {
1072 lines.pop_front();
1073 while (lines.size())
1074 {
1075 string& line = lines.front();
1076 string key;
1077 string value;
1078 bool ok = ParseCs2FileKeyValue(line, key, value);
1079 if (ok == false)
1080 {
1081 return;
1082 }
1083 // we do not parse any data in session
1084 lines.pop_front();
1085 }
1086 }
1087
1088 void MaerklinCANCommon::ParseCs2FileLocomotivesVersion(deque<string>& lines)
1089 {
1090 lines.pop_front();
1091 while (lines.size())
1092 {
1093 string& line = lines.front();
1094 string key;
1095 string value;
1096 bool ok = ParseCs2FileKeyValue(line, key, value);
1097 if (ok == false)
1098 {
1099 return;
1100 }
1101 if ((key.compare("minor") == 0) && (value.compare("3") != 0) && (value.compare("4") != 0))
1102 {
1103 logger->Warning(Languages::TextCs2MinorVersionIsUnknown);
1104 }
1105 lines.pop_front();
1106 }
1107 }
1108
1109 void MaerklinCANCommon::ParseCs2FileLocomotives(deque<string>& lines)
1110 {
1111 lines.pop_front();
1112 while (lines.size())
1113 {
1114 string& line = lines.front();
1115 if (line.length() == 0)
1116 {
1117 return;
1118 }
1119 if (line.compare("version") == 0)
1120 {
1121 ParseCs2FileLocomotivesVersion(lines);
1122 continue;
1123 }
1124 else if (line.compare("session") == 0)
1125 {
1126 ParseCs2FileLocomotivesSession(lines);
1127 continue;
1128 }
1129 else if (line.compare("lokomotive") == 0)
1130 {
1131 ParseCs2FileLocomotive(lines);
1132 continue;
1133 }
1134 return;
1135 }
1136 }
1137
1138 void MaerklinCANCommon::ParseCs2File(deque<string>& lines)
1139 {
1140 while (lines.size())
1141 {
1142 string& line = lines.front();
1143 if (line.length() == 0 || line[0] != '[')
1144 {
1145 return;
1146 }
1147 if (line.compare("[lokomotive]") == 0)
1148 {
1149 ParseCs2FileLocomotives(lines);
1150 CacheUpdateSlaves();
1151 continue;
1152 }
1153 return;
1154 }
1155 }
1156
1157 const DataModel::LocoFunctionIcon MaerklinCANCommon::LocoFunctionMapCs2ToRailControl[MaxNrOfCs2FunctionIcons] =
1158 {
1159 DataModel::LocoFunctionIconNone,
1160 DataModel::LocoFunctionIconLight,
1161 DataModel::LocoFunctionIconInteriorLight1,
1162 DataModel::LocoFunctionIconBacklightForward,
1163 DataModel::LocoFunctionIconHeadlightHighBeamForward,
1164 DataModel::LocoFunctionIconSoundGeneral,
1165 DataModel::LocoFunctionIconPanto12,
1166 DataModel::LocoFunctionIconSmokeGenerator,
1167 DataModel::LocoFunctionIconShuntingMode,
1168 DataModel::LocoFunctionIconTelex12,
1169 DataModel::LocoFunctionIconHorn1,
1170 DataModel::LocoFunctionIconWhistle1,
1171 DataModel::LocoFunctionIconWhistle2,
1172 DataModel::LocoFunctionIconBell,
1173 DataModel::LocoFunctionIconLeftRight,
1174 DataModel::LocoFunctionIconUpDown1,
1175 DataModel::LocoFunctionIconTurnLeft,
1176 DataModel::LocoFunctionIconUpDown2,
1177 DataModel::LocoFunctionIconInertia,
1178 DataModel::LocoFunctionIconFan2,
1179 DataModel::LocoFunctionIconBreak1,
1180 DataModel::LocoFunctionIconGearBox,
1181 DataModel::LocoFunctionIconGenerator,
1182 DataModel::LocoFunctionIconRunning1,
1183 DataModel::LocoFunctionIconEngine1,
1184 DataModel::LocoFunctionIconStationAnnouncement1,
1185 DataModel::LocoFunctionIconShovelCoal,
1186 DataModel::LocoFunctionIconCloseDoor,
1187 DataModel::LocoFunctionIconOpenDoor,
1188 DataModel::LocoFunctionIconFan1,
1189 DataModel::LocoFunctionIconFan,
1190 DataModel::LocoFunctionIconFireBox,
1191 DataModel::LocoFunctionIconInteriorLight2,
1192 DataModel::LocoFunctionIconTableLight3,
1193 DataModel::LocoFunctionIconTableLight2,
1194 DataModel::LocoFunctionIconTableLight1,
1195 DataModel::LocoFunctionIconShakingRust,
1196 DataModel::LocoFunctionIconRailJoint,
1197 DataModel::LocoFunctionIconLocomotiveNumberIndicator,
1198 DataModel::LocoFunctionIconMusic1,
1199 DataModel::LocoFunctionIconTrainDestinationIndicator,
1200 DataModel::LocoFunctionIconCabLight2,
1201 DataModel::LocoFunctionIconCabLight1,
1202 DataModel::LocoFunctionIconCoupler,
1203 DataModel::LocoFunctionIconBufferPush,
1204 DataModel::LocoFunctionIconStationAnnouncement3,
1205 DataModel::LocoFunctionIconCraneHook,
1206 DataModel::LocoFunctionIconBlinkingLight,
1207 DataModel::LocoFunctionIconCabLight12,
1208 DataModel::LocoFunctionIconCompressedAir,
1209 DataModel::LocoFunctionIconDefault,
1210 DataModel::LocoFunctionIconDefault,
1211 DataModel::LocoFunctionIconDefault,
1212 DataModel::LocoFunctionIconDefault,
1213 DataModel::LocoFunctionIconDefault,
1214 DataModel::LocoFunctionIconDefault,
1215 DataModel::LocoFunctionIconDefault,
1216 DataModel::LocoFunctionIconDefault,
1217 DataModel::LocoFunctionIconDefault,
1218 DataModel::LocoFunctionIconDefault,
1219 DataModel::LocoFunctionIconDefault,
1220 DataModel::LocoFunctionIconDefault,
1221 DataModel::LocoFunctionIconDefault,
1222 DataModel::LocoFunctionIconDefault,
1223 DataModel::LocoFunctionIconDefault,
1224 DataModel::LocoFunctionIconDefault,
1225 DataModel::LocoFunctionIconDefault,
1226 DataModel::LocoFunctionIconDefault,
1227 DataModel::LocoFunctionIconDefault,
1228 DataModel::LocoFunctionIconDefault,
1229 DataModel::LocoFunctionIconDefault,
1230 DataModel::LocoFunctionIconDefault,
1231 DataModel::LocoFunctionIconDefault,
1232 DataModel::LocoFunctionIconDefault,
1233 DataModel::LocoFunctionIconDefault,
1234 DataModel::LocoFunctionIconDefault,
1235 DataModel::LocoFunctionIconDefault,
1236 DataModel::LocoFunctionIconDefault,
1237 DataModel::LocoFunctionIconDefault,
1238 DataModel::LocoFunctionIconDefault,
1239 DataModel::LocoFunctionIconDefault,
1240 DataModel::LocoFunctionIconDefault,
1241 DataModel::LocoFunctionIconTelex2,
1242 DataModel::LocoFunctionIconTelex1,
1243 DataModel::LocoFunctionIconPanto2,
1244 DataModel::LocoFunctionIconPanto1,
1245 DataModel::LocoFunctionIconHeadlightLowBeamReverse,
1246 DataModel::LocoFunctionIconHeadlightLowBeamForward,
1247 DataModel::LocoFunctionIconUp,
1248 DataModel::LocoFunctionIconFan3,
1249 DataModel::LocoFunctionIconEngineLight,
1250 DataModel::LocoFunctionIconSteamBlowOut,
1251 DataModel::LocoFunctionIconSteamBlow,
1252 DataModel::LocoFunctionIconCrane,
1253 DataModel::LocoFunctionIconUp,
1254 DataModel::LocoFunctionIconDown,
1255 DataModel::LocoFunctionIconLeft,
1256 DataModel::LocoFunctionIconRight,
1257 DataModel::LocoFunctionIconTurnRight,
1258 DataModel::LocoFunctionIconMagnet,
1259 DataModel::LocoFunctionIconDefault,
1260 DataModel::LocoFunctionIconPanto,
1261 DataModel::LocoFunctionIconDefault,
1262 DataModel::LocoFunctionIconRadio,
1263 DataModel::LocoFunctionIconStationAnnouncement2,
1264 DataModel::LocoFunctionIconBacklightReverse,
1265 DataModel::LocoFunctionIconAirPump,
1266 DataModel::LocoFunctionIconSpeak,
1267 DataModel::LocoFunctionIconEngine2,
1268 DataModel::LocoFunctionIconNoSound,
1269 DataModel::LocoFunctionIconStairsLight,
1270 DataModel::LocoFunctionIconFillWater,
1271 DataModel::LocoFunctionIconBreak2,
1272 DataModel::LocoFunctionIconDefault,
1273 DataModel::LocoFunctionIconDefault,
1274 DataModel::LocoFunctionIconDefault,
1275 DataModel::LocoFunctionIconDefault,
1276 DataModel::LocoFunctionIconDefault,
1277 DataModel::LocoFunctionIconDefault,
1278 DataModel::LocoFunctionIconDefault,
1279 DataModel::LocoFunctionIconDefault,
1280 DataModel::LocoFunctionIconDefault,
1281 DataModel::LocoFunctionIconDefault,
1282 DataModel::LocoFunctionIconDefault,
1283 DataModel::LocoFunctionIconDefault,
1284 DataModel::LocoFunctionIconDefault,
1285 DataModel::LocoFunctionIconDefault,
1286 DataModel::LocoFunctionIconDefault
1287 };
1288
1289 const MaerklinCANCommon::LocoFunctionCs2Icon MaerklinCANCommon::LocoFunctionMapRailControlToCs2[DataModel::MaxLocoFunctionIcons] =
1290 {
1291 LocoFunctionCs2IconNone,
1292 LocoFunctionCs2IconDefault,
1293 LocoFunctionCs2IconShuntingMode,
1294 LocoFunctionCs2IconInertia,
1295 LocoFunctionCs2IconDefault,
1296 LocoFunctionCs2IconDefault,
1297 LocoFunctionCs2IconDefault,
1298 LocoFunctionCs2IconDefault,
1299 LocoFunctionCs2IconDefault,
1300 LocoFunctionCs2IconDefault,
1301 LocoFunctionCs2IconDefault,
1302 LocoFunctionCs2IconDefault,
1303 LocoFunctionCs2IconDefault,
1304 LocoFunctionCs2IconDefault,
1305 LocoFunctionCs2IconDefault,
1306 LocoFunctionCs2IconDefault,
1307 LocoFunctionCs2IconDefault,
1308 LocoFunctionCs2IconDefault,
1309 LocoFunctionCs2IconDefault,
1310 LocoFunctionCs2IconDefault,
1311 LocoFunctionCs2IconDefault,
1312 LocoFunctionCs2IconDefault,
1313 LocoFunctionCs2IconDefault,
1314 LocoFunctionCs2IconDefault,
1315 LocoFunctionCs2IconDefault,
1316 LocoFunctionCs2IconDefault,
1317 LocoFunctionCs2IconDefault,
1318 LocoFunctionCs2IconDefault,
1319 LocoFunctionCs2IconDefault,
1320 LocoFunctionCs2IconDefault,
1321 LocoFunctionCs2IconDefault,
1322 LocoFunctionCs2IconDefault,
1323 LocoFunctionCs2IconLight,
1324 LocoFunctionCs2IconLight,
1325 LocoFunctionCs2IconLight,
1326 LocoFunctionCs2IconHeadlightHighBeamForward,
1327 LocoFunctionCs2IconLight,
1328 LocoFunctionCs2IconHeadlightForward,
1329 LocoFunctionCs2IconHeadlightReverse,
1330 LocoFunctionCs2IconBackLightForward,
1331 LocoFunctionCs2IconBackLightReverse,
1332 LocoFunctionCs2IconLight,
1333 LocoFunctionCs2IconBlinkingLight,
1334 LocoFunctionCs2IconInteriorLight1,
1335 LocoFunctionCs2IconInteriorLight2,
1336 LocoFunctionCs2IconTableLight1,
1337 LocoFunctionCs2IconTableLight2,
1338 LocoFunctionCs2IconTableLight3,
1339 LocoFunctionCs2IconCabLight1,
1340 LocoFunctionCs2IconCabLight2,
1341 LocoFunctionCs2IconCabLight12,
1342 LocoFunctionCs2IconDefault,
1343 LocoFunctionCs2IconTrainDestinationIndicator,
1344 LocoFunctionCs2IconLocomotiveNumberIndicator,
1345 LocoFunctionCs2IconEngineLight,
1346 LocoFunctionCs2IconFireBox,
1347 LocoFunctionCs2IconStairsLight,
1348 LocoFunctionCs2IconDefault,
1349 LocoFunctionCs2IconDefault,
1350 LocoFunctionCs2IconDefault,
1351 LocoFunctionCs2IconDefault,
1352 LocoFunctionCs2IconDefault,
1353 LocoFunctionCs2IconDefault,
1354 LocoFunctionCs2IconDefault,
1355 LocoFunctionCs2IconSmokeGenerator,
1356 LocoFunctionCs2IconTelex1,
1357 LocoFunctionCs2IconTelex2,
1358 LocoFunctionCs2IconTelex12,
1359 LocoFunctionCs2IconPanto1,
1360 LocoFunctionCs2IconPanto2,
1361 LocoFunctionCs2IconPanto12,
1362 LocoFunctionCs2IconUp1,
1363 LocoFunctionCs2IconDown,
1364 LocoFunctionCs2IconUpDown1,
1365 LocoFunctionCs2IconUpDown2,
1366 LocoFunctionCs2IconLeft,
1367 LocoFunctionCs2IconRight,
1368 LocoFunctionCs2IconLeftRight,
1369 LocoFunctionCs2IconTurnLeft,
1370 LocoFunctionCs2IconTurnRight,
1371 LocoFunctionCs2IconDefault,
1372 LocoFunctionCs2IconCrane,
1373 LocoFunctionCs2IconMagnet,
1374 LocoFunctionCs2IconCraneHook,
1375 LocoFunctionCs2IconFan,
1376 LocoFunctionCs2IconDefault,
1377 LocoFunctionCs2IconDefault,
1378 LocoFunctionCs2IconDefault,
1379 LocoFunctionCs2IconDefault,
1380 LocoFunctionCs2IconDefault,
1381 LocoFunctionCs2IconDefault,
1382 LocoFunctionCs2IconDefault,
1383 LocoFunctionCs2IconDefault,
1384 LocoFunctionCs2IconDefault,
1385 LocoFunctionCs2IconDefault,
1386 LocoFunctionCs2IconDefault,
1387 LocoFunctionCs2IconNoSound,
1388 LocoFunctionCs2IconSoundGeneral,
1389 LocoFunctionCs2IconRunning1,
1390 LocoFunctionCs2IconSoundGeneral,
1391 LocoFunctionCs2IconEngine1,
1392 LocoFunctionCs2IconEngine2,
1393 LocoFunctionCs2IconBreak1,
1394 LocoFunctionCs2IconBreak2,
1395 LocoFunctionCs2IconSoundGeneral,
1396 LocoFunctionCs2IconHorn1,
1397 LocoFunctionCs2IconSoundGeneral,
1398 LocoFunctionCs2IconWhistle1,
1399 LocoFunctionCs2IconWhistle2,
1400 LocoFunctionCs2IconBell,
1401 LocoFunctionCs2IconStationAnnouncement1,
1402 LocoFunctionCs2IconStationAnnouncement2,
1403 LocoFunctionCs2IconStationAnnouncement3,
1404 LocoFunctionCs2IconSpeak,
1405 LocoFunctionCs2IconRadio,
1406 LocoFunctionCs2IconMusic1,
1407 LocoFunctionCs2IconSoundGeneral,
1408 LocoFunctionCs2IconOpenDoor,
1409 LocoFunctionCs2IconCloseDoor,
1410 LocoFunctionCs2IconFan1,
1411 LocoFunctionCs2IconFan2,
1412 LocoFunctionCs2IconFan3,
1413 LocoFunctionCs2IconShovelCoal,
1414 LocoFunctionCs2IconCompressedAir,
1415 LocoFunctionCs2IconSoundGeneral,
1416 LocoFunctionCs2IconSteamBlowOut,
1417 LocoFunctionCs2IconSteamBlow,
1418 LocoFunctionCs2IconSoundGeneral,
1419 LocoFunctionCs2IconShakingRust,
1420 LocoFunctionCs2IconAirPump,
1421 LocoFunctionCs2IconSoundGeneral,
1422 LocoFunctionCs2IconBufferPush,
1423 LocoFunctionCs2IconGenerator,
1424 LocoFunctionCs2IconGearBox,
1425 LocoFunctionCs2IconSoundGeneral,
1426 LocoFunctionCs2IconSoundGeneral,
1427 LocoFunctionCs2IconFillWater,
1428 LocoFunctionCs2IconSoundGeneral,
1429 LocoFunctionCs2IconSoundGeneral,
1430 LocoFunctionCs2IconSoundGeneral,
1431 LocoFunctionCs2IconRailJoint,
1432 LocoFunctionCs2IconCoupler,
1433 LocoFunctionCs2IconPanto,
1434 LocoFunctionCs2IconSoundGeneral,
1435 LocoFunctionCs2IconSoundGeneral,
1436 LocoFunctionCs2IconNoSound,
1437 LocoFunctionCs2IconNoSound
1438 };
1439 }} // namespace