Files
sd_gen/src/CreateLicence.cpp
2023-08-17 14:30:11 +02:00

141 lines
3.9 KiB
C++

#include <stdio.h>
#include <map>
#include <cstring>
#include "plcLicence.h"
#include "utils.h"
#include <csignal>
#define FILEBUFFER 300
#define TWO_HOURSE_SECONDS 7200
void signalHandler(int signum)
{
if (signum == SIGSEGV)
{
std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl;
// You can perform some recovery actions here if needed
}
}
/// @brief hlavní funkce
/// @param argc
/// @param argv parametry pro generování licence
/// 1-cid, 2-csd, 3-stanice 4-rozvadec 5-typ licence
/// @return
int main(int argc, char *argv[])
{
std::signal(SIGSEGV, signalHandler);
// a segmentation fault
// int* ptr = nullptr;
//*ptr = 42; // This will trigger a segmentation fault
// map<string, const char *> arguments = mapArguments(argc, argv);
map<string, string> argumentsString = getArguments(argc, argv);
// std::cout << "Number of arguments: " << argc << std::endl;
// if (argc > 1)
// {
// for (int i = 1; i < argc; ++i)
// {
// arguments.insert(make_pair(to_string(i), argv[i]));
// }
// }
// else
// cerr << "Invalid arguments count";
// for (auto it = argumentsString.begin(); it != argumentsString.end(); ++it)
// {
// std::cout << "Key: " << it->first << ", Value: " << it->second << std::endl;
// std::cout << it->second.length() << std::endl;
// }
// generatePause();
// return 1;
// for (int i = 0; i < argc; ++i)
// {
// std::cout << "Argument " << i << ": " << argv[i] << std::endl;
// cout << "size: " << strlen(argv[i]);
// }
// generatePause();
// return 1;
// if (argc >= 5)
// {
// cid = argv[1];
// csd = argv[2];
// stationName = argv[3];
// switchName = argv[4];
// licenceType = argv[5];
// }
// else
// {
// cout << "Par count error" << endl;
// }
// if (argc <= 1)
// {
// cid = "9f544930303030300000000b47015423";
// csd = "400e00325b5900003a0d7f800a40008d";
// stationName = "ceskatrebova";
// switchName = "RO1";
// licenceType = "2";
// binaryType = "2";
// }
// else
// {
// cid = argv[1];
// csd = argv[2];
// }
// cid = "9f544930303030300000000b47015423";
// csd = "400e00325b5900003a0d7f800a40008d";
// stationName = "ceskatrebova";
// switchName = "RO1";
// licenceType = "2";
// binaryType = "2";
// cout << "binaryType: " << binaryType;
// cout << "CID:" << argumentsString["-cid"];
// cout << "final-cids: " << argumentsString["-cid"].length() << endl;
// cout << "final-cds: " << argumentsString["-csd"].length() << endl;
// cout << "-----------------------------------\n";
const int csdLength = argumentsString["-csd"].length();
char csdArg[32] = {};
getCharsFromString(argumentsString["-csd"], csdArg, csdLength);
//cout << "csd delka pred: " << strlen(csdArg) << "\n";
//cout << "csd delka po: " << strlen(csdArg) << "\n";
//cout << "csd:" << csdArg << "\n";
const int cidLength = argumentsString["-cid"].length();
char cidArg[32] = {};
getCharsFromString(argumentsString["-cid"], cidArg, cidLength);
//cout << "cid delka pred: " << strlen(cidArg) << "\n";
//for (int i=0;i<32;i++) cidArg[i]=argumentsString["-cid"][i];
//cout << "cid delka po: " << strlen(cidArg) << "\n";
//cout << "cid delka sizeof po: " << sizeof(cidArg) << "\n";
//cout << "cid:" << cidArg;
// char cidTest = getCharArray(argumentsString["-cid"]);
// PlcLicence plcWriteLicence = PlcLicence(argumentsString);
// PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, stationName, switchName, licenceType, binaryType, nullptr);
// PlcLicence plcWriteLicence = PlcLicence(arguments["-cid"], arguments["-csd"], stationName, switchName, licenceType, binaryType, nullptr);
PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, argumentsString["-outputType"], argumentsString["-configFileName"]);
if (plcWriteLicence.CreateLicence() == false)
{
cerr << "Licence creation failed";
}
return EXIT_SUCCESS;
}