Files
sd_gen/include/common/licenceCommon.h
2024-02-01 15:07:33 +01:00

262 lines
5.2 KiB
C++

#ifndef LICENCE_COMMON_H_
#define LICENCE_COMMON_H_
//---------------- společná hlavička pro všechny licence ----------------
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <stdint.h>
using namespace std;
#define XML_VERSION 1
#define SOFTWARE_VERSION 1
#define SUCCES 0;
const int cidSize = 32;
const int csdSize = 32;
const int generatorVersion = 1;
typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD;
typedef uint32_t DATE;
enum class GeneralError
{
GeneralError = 1,
FileOpenError = 2,
FileReadError = 3,
FileWriteError = 4,
ELCNotImplemented = 5,
LicenceTypeNotImplemented = 6,
CompatibilityTypeNotImplemented = 7,
ELCMismatch = 8,
CRCMismatch = 9,
EncryptError = 10,
DecryptError = 11,
ParamMissing = 12,
IvanlidParam = 13,
SDCardReadError = 50,
LicenceReadError = 51,
LicenceSizeMismatch = 52,
LicenceSizeCardMismatch = 53,
LicenceMismatch = 54,
ItemsCountMismatch = 61
};
// unordered_map<GeneralError, string> mapGeneralErrors = {
// {GeneralError::SDCardReadError, "Nepodařilo se načíst SD kartu."},
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."},
// {GeneralError::LicenceSizeMismatch, "Nesouhlasí velikost souboru licence."},
// {GeneralError::LicenceSizeCardMismatch, "Nesouhlasí velikost SD karty."},
// {GeneralError::LicenceMismatch, "Nesouhlasí licence."},
// {GeneralError::ItemsCountMismatch, "Nesouhlasí počet položek licence."}
// };
enum class ELCType
{
ELC1 = 1,
ELC2 = 2,
ELC3 = 3
};
enum class ELCSubType
{
DEFAULT = 1
}; // subtype = dataVersion
enum class LicenceType
{
EOS_EOV,
DDTS,
DRT
}; //
enum class HeaderType
{
DEFAULT = 0
}; ////subtype = version
enum class EncryptionType
{
CID_AES256 = 10,
FIX_AES256 = 20
};
enum class BinaryType
{
FILE = 1,
BASE64 = 2
};
enum class PlcType
{
WAGO = 1,
TECO = 2
};
enum class FileNameGenerationType
{
DEFAULT = 1
};
struct Mapping
{
std::map<string, LicenceType> licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}};
std::map<string, EncryptionType> licMapEncryption = {{"CID_AES256", EncryptionType::CID_AES256}, {"FIX_AES256", EncryptionType::FIX_AES256}};
std::map<string, PlcType> licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}};
};
struct ErrorMessage
{
int code = 0;
string message = "";
};
struct LicenceIdentification
{
ELCType licElcType = ELCType::ELC2;
LicenceType licLicenceType;
string licTypeName = "";
PlcType licPlcType;
uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů
uint8_t licenceIndex = 0;
uint8_t revision;
uint8_t licCompatibility = 1; // identikator hlavního ELC
uint16_t licItemsCount = 0;
string cid_cds_path = "";
string licenceFilePath = "";
};
/// @brief obecná struktura polozky licence, defaultní kompatibilita
struct LicenceItem
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 1
struct LicenceItemCompatibility1
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 2
struct LicenceItemCompatibility2
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief struktura polozky licence, kompatibilita 3
struct LicenceItemCompatibility3
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem11
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem21
{
int protocolId = -1;
int dataPointsCount = 0;
};
struct LicenceItem31
{
int protocolId = -1;
int dataPointsCount = 0;
};
/// @brief základní struktura, seznam polozek licencí
struct LicenceInfo
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
struct LicenceInfoCompatibility1
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 2
struct LicenceInfoCompatibility2
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
struct LicenceInfoCompatibility3
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
struct LicenceInfo1
{
bool isValid {false};
};
struct LicenceInfo11
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
struct LicenceInfo21
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
struct LicenceInfo31
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
struct LicenceInfoGeneral
{
int reqDataPointsCount = 0;
unordered_map<int, int> licences = {};
};
class LicenceException : public std::exception
{
public:
LicenceException(int errorCode, const std::string &errorMessage)
: errorCode_(errorCode), errorMessage_(errorMessage) {}
const char *what() const noexcept override
{
return errorMessage_.c_str();
}
int getErrorCode() const
{
return errorCode_;
}
const std::string &getErrorMessage() const
{
return errorMessage_;
}
private:
int errorCode_;
std::string errorMessage_;
};
#endif