Fixed the global error level check, started working on device class.
This commit is contained in:
+44
-41
@@ -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 "CyUSBCommon.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdlib>
|
||||||
using namespace std;
|
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;
|
errorLevel_t globalErrLvl = error;
|
||||||
struct errorEngineCreds
|
|
||||||
{
|
struct errorEngineCreds {
|
||||||
string errorLocation;
|
string errorLocation;
|
||||||
string errorName;
|
string errorName;
|
||||||
int8_t errorValue;
|
int8_t errorValue;
|
||||||
errorLevel_t errorLevel;
|
errorLevel_t errorLevel;
|
||||||
bool isCyErrVal;
|
bool isCyErrVal;
|
||||||
};
|
};
|
||||||
void handleErrors(errorEngineCreds eecToEval)
|
|
||||||
{
|
void handleErrors(errorEngineCreds eecToEval) {
|
||||||
switch(eecToEval.errorLevel)
|
switch (eecToEval.errorLevel) {
|
||||||
{
|
|
||||||
case debug:
|
case debug:
|
||||||
if (globalErrLvl == debug)
|
if (globalErrLvl <= debug) {
|
||||||
{
|
cerr << "Debug: " << eecToEval.errorLocation << ": "
|
||||||
cerr << "Debug: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
|
<< eecToEval.errorName << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
case warning:
|
case warning:
|
||||||
if (globalErrLvl == warning)
|
if (globalErrLvl <= warning) {
|
||||||
{
|
cerr << "Warning: " << eecToEval.errorLocation << ": "
|
||||||
cerr << "Warning: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
|
<< eecToEval.errorName << endl;
|
||||||
}
|
}
|
||||||
case error:
|
case error:
|
||||||
if (globalErrLvl == error)
|
if (globalErrLvl <= error) {
|
||||||
{
|
cerr << "ERROR: " << eecToEval.errorLocation << ": "
|
||||||
cerr << "ERROR: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
|
<< eecToEval.errorName << endl;
|
||||||
}
|
}
|
||||||
case crash:
|
case crash:
|
||||||
if (globalErrLvl == crash)
|
if (globalErrLvl <= crash) {
|
||||||
{
|
cerr << "FATAL ERROR: " << eecToEval.errorLocation << ": "
|
||||||
cerr << "FATAL ERROR: " << eecToEval.errorLocation << ": " << eecToEval.errorName << endl;
|
<< eecToEval.errorName << endl;
|
||||||
cerr << "REQUESTING CRASH!" <<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:
|
private:
|
||||||
errorEngine::errorEngineCreds localErrorCreds{"Device handler class", "", 0, };
|
errorEngine::errorEngineCreds localErrorCreds {
|
||||||
|
"Device handler class", "", 0, errorEngine::errorLevel_t::debug, false
|
||||||
|
};
|
||||||
CY_HANDLE localDeviceHandle;
|
CY_HANDLE localDeviceHandle;
|
||||||
accessNums_t localAccessNums;
|
accessNums_t localAccessNums;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Device(CY_HANDLE deviceHandle, accessNums_t accessNums)
|
Device(CY_HANDLE deviceHandle, accessNums_t accessNums) {
|
||||||
{
|
|
||||||
localDeviceHandle = deviceHandle;
|
localDeviceHandle = deviceHandle;
|
||||||
localAccessNums = accessNums;
|
localAccessNums = accessNums;
|
||||||
}
|
}
|
||||||
Device(void);
|
Device(void);
|
||||||
void deviceSet()
|
void deviceSet(accessNums_t deviceAccessNums) {
|
||||||
{
|
CyOpen(deviceAccessNums.deviceNumber, deviceAccessNums.deviceInterfaceNumber, &localDeviceHandle);
|
||||||
|
|
||||||
}
|
}
|
||||||
void deviceDestroy();
|
void deviceDestroy();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user