war kein bug
This commit is contained in:
parent
f403b407cc
commit
4364b39f63
BIN
driver/cli
BIN
driver/cli
Binary file not shown.
|
@ -71,6 +71,23 @@ void signal_handler(int signal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void abort_handler(std::exception& ex)
|
||||||
|
{
|
||||||
|
ViewInfo* view = new ViewInfo();
|
||||||
|
view->setTitle("Fehler");
|
||||||
|
std::string msg(ex.what());
|
||||||
|
msg += "\n\nBeende in 5 Sekunden.";
|
||||||
|
view->setText(msg.c_str());
|
||||||
|
view->setLabelClose("");
|
||||||
|
view->repaint();
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
|
||||||
|
cleanup();
|
||||||
|
std::cerr << std::endl << "*** EXCEPTION ***" << std::endl << ex.what() << std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
void init()
|
void init()
|
||||||
{
|
{
|
||||||
// init b15 driver
|
// init b15 driver
|
||||||
|
@ -79,6 +96,7 @@ void init()
|
||||||
std::cout << std::endl << "Starte in 3s ..." << std::endl;
|
std::cout << std::endl << "Starte in 3s ..." << std::endl;
|
||||||
sleep(3);
|
sleep(3);
|
||||||
#endif
|
#endif
|
||||||
|
B15F::setAbortHandler(&abort_handler);
|
||||||
|
|
||||||
// init all ncurses stuff
|
// init all ncurses stuff
|
||||||
initscr();
|
initscr();
|
||||||
|
@ -366,8 +384,11 @@ int main()
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
int exit_code = EXIT_SUCCESS;
|
||||||
|
|
||||||
show_main(0);
|
show_main(0);
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "b15f.h"
|
#include "b15f.h"
|
||||||
|
|
||||||
B15F* B15F::instance = nullptr;
|
B15F* B15F::instance = nullptr;
|
||||||
|
errorhandler_t B15F::errorhandler = nullptr;
|
||||||
|
|
||||||
B15F::B15F()
|
B15F::B15F()
|
||||||
{
|
{
|
||||||
|
@ -228,7 +229,7 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
uint16_t adc = usart.readInt();
|
uint16_t adc = usart.readInt();
|
||||||
|
|
||||||
if(adc > 1023)
|
if(adc > 1023)
|
||||||
throw DriverException("Bad ADC data detected");
|
throw DriverException("Bad ADC data detected (1)");
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +252,7 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
|
||||||
buffer_a[i] = usart.readInt();
|
buffer_a[i] = usart.readInt();
|
||||||
buffer_b[i] = usart.readInt();
|
buffer_b[i] = usart.readInt();
|
||||||
if(buffer_a[i] > 1023 || buffer_b[i] > 1023)
|
if(buffer_a[i] > 1023 || buffer_b[i] > 1023)
|
||||||
throw DriverException("Bad ADC data detected");
|
throw DriverException("Bad ADC data detected (2)");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t aw = usart.readByte();
|
uint8_t aw = usart.readByte();
|
||||||
|
@ -271,6 +272,14 @@ void B15F::delay_us(uint16_t us)
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(us));
|
std::this_thread::sleep_for(std::chrono::microseconds(us));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
B15F& B15F::getInstance(void)
|
||||||
|
{
|
||||||
|
if(!instance)
|
||||||
|
instance = new B15F();
|
||||||
|
|
||||||
|
return *instance;
|
||||||
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/a/478960
|
// https://stackoverflow.com/a/478960
|
||||||
std::string B15F::exec(std::string cmd) {
|
std::string B15F::exec(std::string cmd) {
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
|
@ -285,10 +294,25 @@ std::string B15F::exec(std::string cmd) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
B15F& B15F::getInstance(void)
|
|
||||||
{
|
|
||||||
if(!instance)
|
|
||||||
instance = new B15F();
|
|
||||||
|
|
||||||
return *instance;
|
void B15F::abort(std::string msg)
|
||||||
|
{
|
||||||
|
DriverException ex(msg);
|
||||||
|
abort(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void B15F::abort(std::exception& ex)
|
||||||
|
{
|
||||||
|
if(errorhandler)
|
||||||
|
errorhandler(ex);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void B15F::setAbortHandler(errorhandler_t func)
|
||||||
|
{
|
||||||
|
errorhandler = func;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
#include "driverexception.h"
|
#include "driverexception.h"
|
||||||
#include "timeoutexception.h"
|
#include "timeoutexception.h"
|
||||||
|
|
||||||
|
typedef std::function<void(std::exception&)> errorhandler_t;
|
||||||
|
|
||||||
|
|
||||||
class B15F
|
class B15F
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -89,6 +92,24 @@ public:
|
||||||
*/
|
*/
|
||||||
static std::string exec(std::string cmd);
|
static std::string exec(std::string cmd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multithread sicherer Abbruch des B15F-Treibers
|
||||||
|
* \param msg Beschreibung der Abbruchursache
|
||||||
|
*/
|
||||||
|
static void abort(std::string msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Multithread sicherer Abbruch des B15F-Treibers
|
||||||
|
* \param ex Exception als Abbruchursache
|
||||||
|
*/
|
||||||
|
static void abort(std::exception& ex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt eine Fehlerbehandlungsroutine für den Treiberabbruch (abort)
|
||||||
|
* \param func Funktion, die Exception als Parameter bekommt
|
||||||
|
*/
|
||||||
|
static void setAbortHandler(errorhandler_t func);
|
||||||
|
|
||||||
/*************************************/
|
/*************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,6 +205,7 @@ private:
|
||||||
|
|
||||||
USART usart;
|
USART usart;
|
||||||
static B15F* instance;
|
static B15F* instance;
|
||||||
|
static errorhandler_t errorhandler;
|
||||||
|
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
|
|
|
@ -30,3 +30,4 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DRIVEREXCEPTION_H
|
#endif // DRIVEREXCEPTION_H
|
||||||
|
|
||||||
|
|
BIN
driver/main
BIN
driver/main
Binary file not shown.
|
@ -124,8 +124,16 @@ void ViewMonitor::worker()
|
||||||
drv.delay_ms(1000);
|
drv.delay_ms(1000);
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
drv.reconnect();
|
drv.reconnect();
|
||||||
}
|
}
|
||||||
|
catch(...)
|
||||||
|
{
|
||||||
|
B15F::abort("yoho meine dudes");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue