Files
sd_gen/src/ReadLicence.cpp
2024-10-03 11:44:03 +02:00

282 lines
11 KiB
C++

#include "licenceReader.h"
#ifndef EZ_APPLICATION_LICENCE_DISABLE
/// @brief hlavní funkce
/// @param argc
/// @param argv parametry pro generování licence
/// @return
int main()
{
// buffer,850client,104client, 104server, web
// kouknout na unikatní klíc pro linux (native uid, i openssl neco má)
try
{
InitStructure initStructure = {};
initStructure.licenceType = (int)LicenceType::DRT;
initStructure.licenceVersion = 1;
initStructure.licenceIndex = 0;
initStructure.licenceFilePath = ""; //c://_projects//sd_gen//output//"; // cesta k licenčnímu souboru
// initStructure.compatibility = 0; v případě kompatibility 0 či nezadané je výstup defaultní.
// pro ELC 1 LicenceELC1Info je to isValid, pro ELC 2 strukura { int protocolId = -1; int dataPointsCount = 0; }
initStructure.cid_csd_filePath = ""; // cesta k cidu/csd pro načtení a kontrolu licence
initStructure.uid_filePath = ""; // cesta k souboru machine-id. (/etc/machine-id), takze by mělo být /etc/.
//verze původní ELC 1, zatím zůstává staré řešení
LicenceReader licenceReaderELC1{};
if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
{
LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
if (licenceReaderELC1.getLicenceInfo(&info))
{
if (info.isValid)
cout << "Platna licence ELC1 \n";
else
cout << "Neplatna licence ELC1\n";
}
else
cout << "CHYBA: " << licenceReaderELC1.error.message;
}
else
{
cout << "CHYBA: " << licenceReaderELC1.error.message;
}
// verze ELC 2 pro jeden protokol
LicenceReader licenceReaderELC2{};
if (licenceReaderELC2.initread(2, initStructure)) // iniciacni nacteni
{
// v případě kompatibility 0, či nezadané výstup nativně je defaultní.
// v případně nenulové kompatibility, třeba 1, přidáme číslo kompatibility.
// Tedy pro ELC1 to bude LicenceELC1_1, pro ELC LicenceELC2_1
LicenceELC2Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
// if ()
int protocolId = 4;
// ukazka dat SD karty
cout << "SD přečteno: " << licenceReaderELC2.sdCardInfo.isLoaded << "\n";
cout << "Card size: " << licenceReaderELC2.sdCardInfo.cardSize << "\n";
cout << "serial: " << licenceReaderELC2.sdCardInfo.serialNumber << "\n";
cout << "date: " << licenceReaderELC2.sdCardInfo.date << "\n";
cout << "name: " << licenceReaderELC2.sdCardInfo.name << "\n";
cout << "oemID: " << licenceReaderELC2.sdCardInfo.oemID << "\n";
cout << "název licenčního souboru: " << licenceReaderELC2.licInfo.licenceFileName << "\n";
cout << "cesta k licenčnímu souboru: " << licenceReaderELC2.licInfo.licenceFilePath << "\n";
// if (initStructure.compatibility == 1) //ukazka kompatibilita 1
// {
// LicenceELC2Item_1 info; //jiná struktura, zbytek stejný
// if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
// {
// cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
// }
//...........
// }
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
{
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
}
else
cout << "Tento protokol nemá body";
}
else
{
cout << "CHYBA: " << licenceReaderELC2.error.message;
}
//---------------------------------------- ELC3 ----------------------------------------------------------
//verze ELC 3 pro jeden protokol. Oproti ELC2 je potřeba přidat cestu k uid/machine-id v initStructure
LicenceReader licenceReaderELC3{};
if (licenceReaderELC3.initread(3, initStructure)) // iniciacni nacteni
{
LicenceELC3Item info; // podle ELC a kompatibility určit strukuru (LicenceInfo1, LicenceInfo2, LicenceInfo3)
// if ()
int protocolId = 7;
if (licenceReaderELC3.getLicenceItemInfo(protocolId, &info))
{
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
}
else
cout << "Tento protokol nemá body";
}
else
{
cout << "CHYBA: " << licenceReaderELC3.error.message;
}
//---------------------------------------- ELC3 ----------------------------------------------------------
// verze ELC 2 kompletní načtení
/*
LicenceReader licenceReaderCompleteELC2{};
if (licenceReaderCompleteELC2.init(2, initStructure)) // iniciacni nacteni
{
LicenceELC2Info info;
int protocolId = 2;
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
{
if (info.licences.count(protocolId) > 0)
cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
else
cout << "Pro tento protokol nejsou definovay licencni body\n";
cout << "Vypis vsech licencnich bodu: " << endl;
// for (const auto &pair : info.licences)
// {
// std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
// }
}
else
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
}
else
{
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
}
*/
}
catch (...)
{
cout << "Obecna chyba\n";
}
system("pause");
return SUCCES;
// verze původní ELC 1, zatím zůstává staré řešení
// LicenceReader licenceReaderELC1{};
// if (licenceReaderELC1.initread(1, initStructure)) // iniciacni nacteni
// {
// LicenceELC1Info info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
// if (licenceReaderELC1.getLicenceInfo(&info))
// {
// if (info.isValid)
// cout << "Platna licence ELC1 \n";
// else
// cout << "Neplatna licence ELC1\n";
// }
// else
// cout << "CHYBA: " << licenceReaderELC1.error.message;
// }
// else
// {
// cout << "CHYBA: " << licenceReaderELC1.error.message;
// }
// return SUCCES;
}
// buffer,web, 850client,104client, 104server,
//
/*
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
pt_Ez_buffer, // 1 - datovy Buffer
pt_Ez_webs, // 2 - Ez www conectivity server
pt_Ez_dblogc, // 3 - Ez database log client
pt_Ez_sysinfoc, // 4 - Systemove informace systemu
pt_Ez_iec104c, // 5 - IEC-104 client
pt_Ez_iec104s, // 6 - IEC-104 server
pt_Ez_iec61850c, // 7 - IEC-61850 client
pt_Ez_iec61850s, // 8 - IEC-61850 server
pt_Ez_mdbipc, // 9 - Modbus IP client
pt_Ez_mdbips, // 10 - Modbus IP server
pt_Ez_mdbrtum, // 11 - Modbus RTU master
pt_Ez_mdbrtul, // 12 - Modbus RTU slave
pt_Ez_mdbasciim, // 13 - Modbus ASCII master
pt_Ez_mdbasciil, // 14 - Modbus ASCII slave
pt_Ez_gsmm, // 15 - GSM master
pt_Ez_gsml, // 16 - GSM slave
pt_Ez_iec101m, // 17 - IEC-101 master
pt_Ez_iec101l, // 18 - IEC-101 slave
pt_Ez_iec103m, // 19 - IEC-103 master
pt_Ext_snmpc, // 20 - SNMP client
pt_Ext_snmps, // 21 - SNMP server
pt_Ez_siadc09c, // 22 - ANSI/SIA DC-09 client
pt_Ez_honeywellgxyc, // 23 - Honeywell Galaxy smart client
pt_Ez_contactidm, // 24 - Ademco Contact ID - SIA DC-05 master
pt_Ez_litesm, // 25 - EPS Lites master
pt_Ez_epsnetmpcc, // 26 - Tecomat Epsnet MPC client
pt_Ez_epsnetmpcs, // 27 - Tecomat Epsnet MPC server
pt_Ez_epsnetmpcm, // 28 - Tecomat Epsnet MPC master
pt_Ez_epsnetmpcl, // 29 - Tecomat Epsnet MPC slave
pt_Ez_epsnetplc, // 30 - Tecomat Epsnet PLC
pt_Ez_amitdbnetipc, // 31 - AMiT DB-Net/IP client
pt_Ez_amitdbnetm, // 32 - AMiT DB-Net master
pt_Ez_fatekm, // 33 - Fatek master
pt_Ez_canm, // 34 - CAN master
pt_Ez_iec6205621m, // 35 - IEC 62056.21 master
pt_Ez_mbusm, // 36 - MBus master
pt_Ez_azddakm, // 37 - AZD DAK master
pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP)
pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol)
Pro index 0 (pt_Ez_interHW) jsou možné hodnoty (počet licenčních bodů):
#define EZ_HW_TECOMAT 1
#define EZ_HW_WAGO 2
#define EZ_HW_NATIVE_LINUX 3
#define EZ_HW_NATIVE_LINUX_DOCKER 4
#define EZ_HW_ARM64_LINUX 5
#define EZ_HW_ARM64_LINUX_DOCKER 6
Pro ostatní je uveden skutečný požadovaný počet licenčních bodů pro daný protokol.
U protokolů pt_Ez_buffer a pt_Ez_webs nastavovat defaultně EZ_PROTO_INFINITE = 4294967295
*/
/*
pt_Ez_interHW, // 0 - interni virtualni typ pro urceni licence na dany HW
pt_Ez_buffer, // 1 - datovy Buffer
pt_Ez_webs, // 2 - Ez www conectivity server
pt_Ez_dblogc, // 3 - Ez database log client
pt_Ez_mdbipc, // 4 - Modbus IP client
pt_Ez_mdbips, // 5 - Modbus IP server
pt_Ext_snmpc, // 6 - SNMP client
pt_Ext_snmps, // 7 - SNMP server
pt_Ez_iec104s, // 8 - IEC-104 server
pt_Ez_iec104c, // 9 - IEC-104 client
pt_Ez_sysinfoc, // 10 - Systemove informace systemu
pt_Ez_siadc09c, // 11 - ANSI/SIA DC-09 client
pt_Ez_honeywellgxyc, // 12 - Honeywell Galaxy smart client
pt_Ez_iec61850s, // 13 - IEC-61850 server
pt_Ez_iec61850c, // 14 - IEC-61850 client
pt_Ez_mdbrtum, // 15 - Modbus RTU master
pt_Ez_mdbrtul, // 16 - Modbus RTU slave
pt_Ez_mdbasciim, // 17 - Modbus ASCII master
pt_Ez_mdbasciil, // 18 - Modbus ASCII slave
pt_Ez_epsnetmpcc, // 19 - Tecomat Epsnet MPC client
pt_Ez_epsnetmpcs, // 20 - Tecomat Epsnet MPC server
pt_Ez_epsnetmpcl, // 21 - Tecomat Epsnet MPC slave
pt_Ez_epsnetmpcm, // 22 - Tecomat Epsnet MPC master
pt_Ez_epsnetplc, // 23 - Tecomat Epsnet PLC
pt_Ez_litesm, // 24 - EPS Lites master
pt_Ez_contactidm, // 25 - Ademco Contact ID - SIA DC-05 master
pt_Ez_amitdbnetipc, // 26 - AMiT DB-Net/IP client
pt_Ez_amitdbnetm, // 27 - AMiT DB-Net master
pt_Ez_fatekm, // 28 - Fatek master
pt_Ez_canm, // 29 - CAN master
pt_Ez_iec6205621m, // 30 - IEC 62056.21 master
pt_Ez_mbusm, // 31 - MBus master
pt_Ez_gsmm, // 32 - GSM master
pt_Ez_gsml, // 33 - GSM slave
pt_Ez_iec101m, // 34 - IEC-101 master
pt_Ez_iec101l, // 35 - IEC-101 slave
pt_Ez_iec103m, // 36 - IEC-103 master
pt_Ez_azddakm, // 37 - AZD DAK master
pt_Ez_rwaytechc, // 38 - RwayTech client (modbus IP)
pt_Ez_weinteksl, // 39 - Weintek touch screen server/slave (modbus protokol)
*/
#endif