| 294 | } |
| 295 | |
| 296 | int main(int argc, char** argv) { |
| 297 | if (argc < 2) { |
| 298 | std::cerr << "To few arguments, please see the help with : " << argv[0] << " --help" << std::endl; |
| 299 | exit(EXIT_FAILURE); |
| 300 | } |
| 301 | |
| 302 | std::vector<vsomeip::byte_t> user_message; |
| 303 | vsomeip::instance_t instance(vsomeip::ANY_INSTANCE); |
| 304 | bool use_tcp(false); |
| 305 | |
| 306 | for (int i = 1; i < argc; i++) { |
| 307 | std::string arg(argv[i]); |
| 308 | if (arg == "--help" || arg == "-h") { |
| 309 | print_help(argv[0]); |
| 310 | exit(EXIT_SUCCESS); |
| 311 | break; |
| 312 | } else if (arg == "--message" || arg == "-m") { |
| 313 | std::string message(argv[i + 1]); |
| 314 | for (unsigned int i = 0; i < message.length(); i += 2) { |
| 315 | vsomeip::byte_t its_byte; |
| 316 | try { |
| 317 | std::uint64_t tmp = std::stoul(message.substr(i, 2), 0, 16); |
| 318 | tmp = (tmp > (std::numeric_limits<std::uint8_t>::max)()) ? (std::numeric_limits<std::uint8_t>::max)() : tmp; |
| 319 | its_byte = static_cast<vsomeip::byte_t>(tmp); |
| 320 | } catch (std::invalid_argument& e) { |
| 321 | std::cerr << e.what() << ": Couldn't convert '" << message.substr(i, 2) << "' to hex, exiting: " << std::endl; |
| 322 | exit(EXIT_FAILURE); |
| 323 | } |
| 324 | user_message.push_back(its_byte); |
| 325 | } |
| 326 | } |
| 327 | if (arg == "--tcp" || arg == "-t") { |
| 328 | use_tcp = true; |
| 329 | } else if (arg == "--instance" || arg == "-i") { |
| 330 | std::string instance_str(argv[i + 1]); |
| 331 | if (instance_str.length() > 4) { |
| 332 | std::cerr << "provided instance is to long, exiting." << std::endl; |
| 333 | exit(EXIT_FAILURE); |
| 334 | } |
| 335 | if (instance_str.length() < 4) { |
| 336 | while (instance_str.size() != 4) { |
| 337 | instance_str = std::string("0") += instance_str; |
| 338 | } |
| 339 | } |
| 340 | vsomeip::byte_t high(0x0); |
| 341 | vsomeip::byte_t low(0x0); |
| 342 | std::cout << "Instance: " << instance_str << std::endl; |
| 343 | for (unsigned int i = 0; i < instance_str.length(); i += 2) { |
| 344 | try { |
| 345 | std::uint64_t tmp = std::stoul(instance_str.substr(i, 2), 0, 16); |
| 346 | tmp = (tmp > (std::numeric_limits<std::uint8_t>::max)()) ? (std::numeric_limits<std::uint8_t>::max)() : tmp; |
| 347 | |
| 348 | vsomeip::byte_t its_byte = static_cast<vsomeip::byte_t>(tmp); |
| 349 | if (i == 0) { |
| 350 | high = its_byte; |
| 351 | } else { |
| 352 | low = its_byte; |
| 353 | } |
nothing calls this directly
no test coverage detected