Projekt

Obecné

Profil

Stáhnout (1.83 KB) Statistiky
| Větev: | Tag: | Revize:
1 4a9e70db silhavyj
// t32rem.exe localhost port=20000 VERSION.HARDWARE
2
#include <chrono>
3
#include <thread>
4
#include <random>
5
#include <fstream>
6
#include <iostream>
7
#include <cstring>
8
9
static constexpr int EXPECTED_NUMBER_OF_ARGUMENTS = 4;
10 6dab0250 silhavyj
static constexpr const char *OUTPUT_FILE_NAME = "ldResult.txt";
11 4a9e70db silhavyj
static constexpr const char *DEBUGGER_INFO =
12
        "B::version.hardware\n"
13
        "PowerDebug USB 3.0 via USB 3.0\n"
14
        "   Serial Number: C21070308132\n"
15
        "   Firmware R.2021.02 (136263)\n"
16
        "   Instance: 1.\n"
17
        "   Automotive Debug Cable\n"
18
        "      Serial Number: C17040231820\n";
19
20
static constexpr int MIN_SEC_DELAY = 1;
21
static constexpr int MAX_SEC_DELAY = 10;
22
23
int main(int argc, char *argv[]) {
24
    if (argc != EXPECTED_NUMBER_OF_ARGUMENTS) {
25
        std::cout << "Invalid number of arguments\n";
26
        std::cout << "The mock is meant to be called with the following arguments: localhost port=20000 VERSION.HARDWARE\n";
27
        return 1;
28
    }
29
    if (strcmp(argv[1], "localhost") != 0) {
30
        std::cout << "Invalid first argument (expected 'localhost')\n";
31
        return 2;
32
    }
33
    if (strcmp(argv[2], "port=20000") != 0) {
34
        std::cout << "Invalid second argument (expected 'port=20000')\n";
35
        return 2;
36
    }
37
    if (strcmp(argv[3], "VERSION.HARDWARE") != 0) {
38
        std::cout << "Invalid third argument (expected 'VERSION.HARDWARE')\n";
39
        return 2;
40
    }
41
42
    std::random_device rd;
43
    std::mt19937 mt(rd());
44
    std::uniform_int_distribution<uint32_t> distribution(MIN_SEC_DELAY, MAX_SEC_DELAY);
45
    uint32_t delay_s = distribution(mt);
46
    std::this_thread::sleep_for(std::chrono::milliseconds(delay_s * 1000));
47
48
    std::ofstream file(OUTPUT_FILE_NAME);
49
    if (!file) {
50
        std::cout << "Fail to open the output file\n";
51
        return 3;
52
    }
53
    file << DEBUGGER_INFO;
54
    file.close();
55
56
    return 0;
57
}