#define LINUX 1

#ifndef UTILS_H_
#define UTILS_H_

#include <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include <chrono>
#include <bitset>
#include <unordered_map>
#include <filesystem>
#include <vector>

#define PEM_BUFSIZE_TEXT 1024
#define BitVal(data, y) ((data >> y) & 1)     /** Return Data.Y value   **/
#define SetBit(data, y) data |= (1 << y)      /** Set Data.Y   to 1    **/
#define ClearBit(data, y) data &= ~(1 << y)   /** Clear Data.Y to 0    **/
#define TogleBit(data, y) (data ^= BitVal(y)) /** Togle Data.Y  value  **/
#define Togle(data) (data = ~data)            /** Togle Data value     **/

#define PEM_BUFSIZE_TEXT 1024


typedef uint8_t BYTE;
typedef uint16_t WORD;
typedef uint32_t DWORD; 
typedef uint32_t DATE;

using namespace std;

struct DateAndTime {
    uint16_t date; // DATE data type in CODESYS
    uint16_t time; // TIME data type in CODESYS
};

void TestFunction(int);
void generatePause();
string getXmlContentFromString(string source, string xmlTag);
float byteArrayToFloat(const BYTE* byteArray);
std::string right(const std::string& sourceString, size_t numChars);
std::tm dt_to_date(const std::chrono::system_clock::time_point& tp);
void getCharsFromString(string source, char *charArray);
std::string parseCID(const std::string& cidHex);
void bitsToCharArray(const std::string& bitsStr, char* charArray);
uint16_t calculateCRC16(const uint8_t* data, size_t length);
uint16_t calculateCrc(const uint8_t* data, size_t length);
WORD getCurrentDateAsCODESYSDate();
DWORD getCurrentDateAsCODESYSDateDword();
DateAndTime getCurrentDateTimeAsCODESYSDateTime();
uint16_t convertToCODESYSDate(int day, int month, int year);
uint16_t convertToCODESYSTime(int hour, int minute);
DATE getLicDate();
string getDate();
int encrypt(const unsigned char *plaintext, int plaintext_len, unsigned char *key, unsigned char *iv, unsigned char *ciphertext);
bool CompareFiles(const char *fileName, const char *fileName1);
unsigned short crc16(const unsigned char* data_p, unsigned char length);
int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *key, unsigned char *iv, unsigned char *plaintext);
string convertToString(char* a, int size);
std::string base64_encode_ai(const std::string &input);
std::string base64_decode_ai(const std::string &encoded);
unordered_map<string, string> getArguments(int argc, char *argv[]);
unordered_map<string, const char*> mapArguments(int argc, char *argv[]);
char* getCharArray(string source);
void getCharsFromString1(string source, char *charArray);
void getCharsFromString(string& source, char *charArray, int length);
string getCompletePath(string fileName);
char* getFileContent(string fileName);
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
void coutVector (std::vector<unsigned char>& charVector);
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
uint32_t bytesToWord(uint8_t byte1, uint8_t byte2);
vector<unsigned char> joinVectors(const std::vector<unsigned char>& vector1, const std::vector<unsigned char>& vector2);
string readFileToString(const std::string& filename, std::size_t sizeS);
bool readFile(string fileName, vector<char> &output);

#endif






















