Fixed the global error level check, started working on device class.

This commit is contained in:
[ Kristjan Komloši HomePC ]
2016-12-25 17:24:31 +01:00
parent afff7bb849
commit 66a7a0b61b

View File

@@ -1,77 +1,80 @@
//Tinio - A tool to connect to Tinio USB IO controllers.
// Tinio - A tool to connect to Tinio USB IO controllers.
#include "CyUSBCommon.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
namespace errorEngine {
namespace errorEngine
{
enum errorLevel_t { debug = 0, warning, error, crash };
enum errorLevel_t {debug = 0,warning,error,crash};
errorLevel_t globalErrLvl = error;
struct errorEngineCreds
{
struct errorEngineCreds {
string errorLocation;
string errorName;
int8_t errorValue;
errorLevel_t errorLevel;
bool isCyErrVal;
};
void handleErrors(errorEngineCreds eecToEval)
{
switch(eecToEval.errorLevel)
{
void handleErrors(errorEngineCreds eecToEval) {
switch (eecToEval.errorLevel) {
case debug:
if (globalErrLvl == debug)
{
cerr << "Debug: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
}
if (globalErrLvl <= debug) {
cerr << "Debug: " << eecToEval.errorLocation << ": "
<< eecToEval.errorName << endl;
}
case warning:
if (globalErrLvl == warning)
{
cerr << "Warning: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
}
if (globalErrLvl <= warning) {
cerr << "Warning: " << eecToEval.errorLocation << ": "
<< eecToEval.errorName << endl;
}
case error:
if (globalErrLvl == error)
{
cerr << "ERROR: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
}
if (globalErrLvl <= error) {
cerr << "ERROR: " << eecToEval.errorLocation << ": "
<< eecToEval.errorName << endl;
}
case crash:
if (globalErrLvl == crash)
{
cerr << "FATAL ERROR: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
cerr << "REQUESTING CRASH!" <<endl;
}
if (globalErrLvl <= crash) {
cerr << "FATAL ERROR: " << eecToEval.errorLocation << ": "
<< eecToEval.errorName << endl;
cerr << "REQUESTING CRASH!" << endl;
}
}
}
void controlledCrash() {
cerr << "Triggering a controlled crash..." << endl;
int i = 3 / 0; // triggers a floating point error
return;
}
}
struct accessNums_t
{
uint8_t deviceNumber=0;
uint8_t deviceInterfaceNumber=0;
struct accessNums_t {
uint8_t deviceNumber = 0;
uint8_t deviceInterfaceNumber = 0;
};
class Device
{
class Device {
private:
errorEngine::errorEngineCreds localErrorCreds{"Device handler class", "", 0, };
errorEngine::errorEngineCreds localErrorCreds {
"Device handler class", "", 0, errorEngine::errorLevel_t::debug, false
};
CY_HANDLE localDeviceHandle;
accessNums_t localAccessNums;
public:
Device(CY_HANDLE deviceHandle, accessNums_t accessNums)
{
Device(CY_HANDLE deviceHandle, accessNums_t accessNums) {
localDeviceHandle = deviceHandle;
localAccessNums = accessNums;
}
Device(void);
void deviceSet()
{
void deviceSet(accessNums_t deviceAccessNums) {
CyOpen(deviceAccessNums.deviceNumber, deviceAccessNums.deviceInterfaceNumber, &localDeviceHandle);
}
void deviceDestroy();
};