|
1 | 1 | #ifndef LINKERHAND_HAND_FACTORY_H |
2 | 2 | #define LINKERHAND_HAND_FACTORY_H |
3 | 3 |
|
| 4 | +#include <iostream> |
| 5 | +#include <string> |
| 6 | +#include <algorithm> |
| 7 | +#include <cctype> |
| 8 | + |
4 | 9 | #include "IHand.h" |
5 | 10 | #include "LinkerHandL6.h" |
6 | 11 | #include "LinkerHandL7.h" |
|
10 | 15 | #include "ModbusLinkerHandL10.h" |
11 | 16 | #include "Common.h" |
12 | 17 |
|
| 18 | + |
| 19 | + |
13 | 20 | namespace linkerhand { |
14 | 21 | namespace factory { |
15 | 22 |
|
@@ -100,6 +107,70 @@ class HandFactory { |
100 | 107 |
|
101 | 108 | return nullptr; |
102 | 109 | } |
| 110 | + |
| 111 | + |
| 112 | + static std::unique_ptr<hand::IHand> createHand(LINKER_HAND type, uint32_t handId, const std::string canChannel, const int baudrate) { |
| 113 | + |
| 114 | + if (handId != static_cast<uint32_t>(LEFT) && |
| 115 | + handId != static_cast<uint32_t>(RIGHT)) |
| 116 | + { |
| 117 | + throw std::invalid_argument("Unsupported hand type"); |
| 118 | + } |
| 119 | + |
| 120 | + if (containsIgnoreCase(canChannel, "can")) { |
| 121 | + switch (type) { |
| 122 | + case O6: |
| 123 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L6Hand>(handId, canChannel, baudrate)); |
| 124 | + break; |
| 125 | + case L6: |
| 126 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L6Hand>(handId, canChannel, baudrate)); |
| 127 | + break; |
| 128 | + case L7: |
| 129 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L7Hand>(handId, canChannel, baudrate)); |
| 130 | + break; |
| 131 | + case L10: |
| 132 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L10Hand>(handId, canChannel, baudrate)); |
| 133 | + break; |
| 134 | + case L20: |
| 135 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L20Hand>(handId, canChannel, baudrate)); |
| 136 | + break; |
| 137 | + case L21: |
| 138 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L25Hand>(handId, canChannel, baudrate, 1)); |
| 139 | + break; |
| 140 | + case L25: |
| 141 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::L25Hand>(handId, canChannel, baudrate, 0)); |
| 142 | + break; |
| 143 | + default: |
| 144 | + throw std::invalid_argument("Unknown hand type"); |
| 145 | + } |
| 146 | + } else if (canChannel == "modbus") { |
| 147 | + #if USE_RMAN |
| 148 | + switch (type) { |
| 149 | + case L10: |
| 150 | + return std::unique_ptr<hand::IHand>(std::make_unique<hand::ModbusL10Hand>(handId)); |
| 151 | + default: |
| 152 | + throw std::invalid_argument("Unknown hand type"); |
| 153 | + break; |
| 154 | + } |
| 155 | + #else |
| 156 | + throw std::runtime_error("ModBus support is disabled (USE_RMAN=0)"); |
| 157 | + #endif |
| 158 | + } |
| 159 | + |
| 160 | + return nullptr; |
| 161 | + } |
| 162 | + |
| 163 | +private: |
| 164 | + |
| 165 | + static std::string toLower(const std::string& str) { |
| 166 | + std::string result = str; |
| 167 | + std::transform(result.begin(), result.end(), result.begin(), ::tolower); |
| 168 | + return result; |
| 169 | + } |
| 170 | + |
| 171 | + static bool containsIgnoreCase(const std::string& str, const std::string& target) { |
| 172 | + return toLower(str).find(toLower(target)) != std::string::npos; |
| 173 | + } |
103 | 174 | }; |
104 | 175 |
|
105 | 176 | } // namespace factory |
|
0 commit comments