#define CRC = 1 #ifndef LICENCE_COMMON_H_ #define LICENCE_COMMON_H_ //---------------- společná hlavička pro všechny licence ---------------- #include #include #include #include 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, LicenceCRCMismatch = 54, ItemsCountMismatch = 61 }; enum class ELCType { ELC1 = 1, //starý původní licenční soubor ELC2 = 2, //modifikovaný starý licenční soubor umoznující modifikace dle paramatetrů ELC3 = 3 //budoucí softwarový licenční soubor, který není zalození na existenci CID a CSD }; 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 }; //indexy musí být velká písmena ze základní ASCI tabulky struct Mapping { unordered_map licMapTypes = {{"EOV_OSV", LicenceType::EOS_EOV}, {"DDTS", LicenceType::DDTS}, {"DRT", LicenceType::DRT}}; unordered_map licMapEncryption = {{"CID_AES256", EncryptionType::CID_AES256}, {"FIX_AES256", EncryptionType::FIX_AES256}}; unordered_map licMapPlcType = {{"WAGO", PlcType::WAGO}, {"TECO", PlcType::TECO}}; }; struct ErrorMessage { int code = 0; string message = ""; }; struct LicenceIdentification { ELCType licElcType = ELCType::ELC2; //hlavní typ licenčního souboru LicenceType licLicenceType; string licTypeName = ""; PlcType licPlcType; uint8_t licenceVersion = 1; // verze licence, určuje kodování, pojmenování souborů uint8_t licenceIndex = 0; //index licenčního souboru v případě, ze jich je víc uint8_t revision; uint8_t licCompatibility = 0; // identikator hlavního ELC. 0 = nedefinová a vrací se defaultní k danému ELC uint16_t licItemsCount = 0; string cid_cds_path = ""; string licenceFilePath = ""; }; /// @brief obecná struktura pro reader struct LicenceInfoGeneral { int reqDataPointsCount = 0; unordered_map licences = {}; }; /// @brief obecná struktura polozky licence, defaultní kompatibilita struct LicenceItem { int protocolId = -1; int dataPointsCount = 0; }; /* struktury pro ELC 1 */ //defaultní struktura pro ELC 1 struct LicenceELC1Info { bool isValid {false}; }; //struktura ELC1, kompatibilita 1 struct LicenceELC1Info_1 { unordered_map licences = {}; }; //defaultni struktura polozky licence ELC 1 struct LicenceELC1Item { int protocolId = -1; int dataPointsCount = 0; }; /* struktury pro ELC 2 */ //defaultní struktura pro ELC 2 struct LicenceELC2Info { unordered_map licences = {}; }; struct LicenceELC2Info_1 { unordered_map licences = {}; }; //defaultni struktura polozky ELC 2 struct LicenceELC2Item { int protocolId = -1; int dataPointsCount = 0; }; //struktura polozky ELC 2, struct LicenceELC2Item_1 { int protocolId = -1; int dataPointsCount = 0; }; 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