bessere Fehlerbehandlung
This commit is contained in:
parent
9ca804ec3d
commit
4f62b06209
BIN
driver/cli
BIN
driver/cli
Binary file not shown.
|
@ -19,9 +19,6 @@
|
||||||
#include "ui/view_monitor.h"
|
#include "ui/view_monitor.h"
|
||||||
#include "ui/view_promt.h"
|
#include "ui/view_promt.h"
|
||||||
|
|
||||||
// global error message
|
|
||||||
std::string ERR_MSG;
|
|
||||||
|
|
||||||
volatile int win_changed_cooldown = 0;
|
volatile int win_changed_cooldown = 0;
|
||||||
volatile bool t_refresh_active = false;
|
volatile bool t_refresh_active = false;
|
||||||
|
|
||||||
|
@ -54,8 +51,6 @@ void signal_handler(int signal)
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
std::cout << "SIGINT - Abbruch." << std::endl;
|
std::cout << "SIGINT - Abbruch." << std::endl;
|
||||||
if(ERR_MSG.length())
|
|
||||||
std::cout << "ERR_MSG: " << ERR_MSG << std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ void B15F::init()
|
||||||
device.pop_back();
|
device.pop_back();
|
||||||
|
|
||||||
if(device.length() == 0)
|
if(device.length() == 0)
|
||||||
throw DriverException("Adapter nicht gefunden");
|
abort("Adapter nicht gefunden");
|
||||||
|
|
||||||
std::cout << PRE << "Verwende Adapter: " << device << std::endl;
|
std::cout << PRE << "Verwende Adapter: " << device << std::endl;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ void B15F::init()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(tries == 0)
|
if(tries == 0)
|
||||||
throw DriverException("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
|
abort("Verbindungstest fehlgeschlagen. Neueste Version im Einsatz?");
|
||||||
std::cout << "OK" << std::endl;
|
std::cout << "OK" << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ void B15F::reconnect()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw DriverException("Verbindung kann nicht repariert werden");
|
abort("Verbindung kann nicht repariert werden");
|
||||||
}
|
}
|
||||||
|
|
||||||
void B15F::discard(void)
|
void B15F::discard(void)
|
||||||
|
@ -131,7 +131,7 @@ std::vector<std::string> B15F::getBoardInfo(void)
|
||||||
|
|
||||||
uint8_t aw = usart.readByte();
|
uint8_t aw = usart.readByte();
|
||||||
if(aw != MSG_OK)
|
if(aw != MSG_OK)
|
||||||
throw DriverException("Board Info fehlerhalft: code " + std::to_string((int) aw));
|
abort("Board Info fehlerhalft: code " + std::to_string((int) aw));
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
{
|
{
|
||||||
usart.clearInputBuffer();
|
usart.clearInputBuffer();
|
||||||
if(channel > 7)
|
if(channel > 7)
|
||||||
throw DriverException("Bad ADC channel: " + std::to_string(channel));
|
abort("Bad ADC channel: " + std::to_string(channel));
|
||||||
|
|
||||||
uint8_t rq[] = {
|
uint8_t rq[] = {
|
||||||
RQ_ADC,
|
RQ_ADC,
|
||||||
|
@ -224,12 +224,12 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
|
|
||||||
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
|
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
|
||||||
if(n_sent != sizeof(rq))
|
if(n_sent != sizeof(rq))
|
||||||
throw DriverException("Sent failed");
|
abort("Sent failed");
|
||||||
|
|
||||||
uint16_t adc = usart.readInt();
|
uint16_t adc = usart.readInt();
|
||||||
|
|
||||||
if(adc > 1023)
|
if(adc > 1023)
|
||||||
throw DriverException("Bad ADC data detected (1)");
|
abort("Bad ADC data detected (1)");
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,12 +252,12 @@ 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 (2)");
|
abort("Bad ADC data detected (2)");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t aw = usart.readByte();
|
uint8_t aw = usart.readByte();
|
||||||
if(aw != MSG_OK)
|
if(aw != MSG_OK)
|
||||||
throw DriverException("Sequenz unterbrochen");
|
abort("Sequenz unterbrochen");
|
||||||
|
|
||||||
delay_us(10);
|
delay_us(10);
|
||||||
}
|
}
|
||||||
|
@ -294,21 +294,20 @@ std::string B15F::exec(std::string cmd) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void B15F::abort(std::string msg)
|
void B15F::abort(std::string msg)
|
||||||
{
|
{
|
||||||
DriverException ex(msg);
|
DriverException ex(msg);
|
||||||
abort(ex);
|
abort(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void B15F::abort(std::exception& ex)
|
void B15F::abort(std::exception& ex)
|
||||||
{
|
{
|
||||||
if(errorhandler)
|
if(errorhandler)
|
||||||
errorhandler(ex);
|
errorhandler(ex);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
|
std::cerr << "NOTICE: B15F::errorhandler not set" << std::endl;
|
||||||
throw ex;
|
std::cout << ex.what() << std::endl;
|
||||||
|
throw DriverException(ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ View::View()
|
||||||
{
|
{
|
||||||
if(!win)
|
if(!win)
|
||||||
{
|
{
|
||||||
ERR_MSG = "View::win not initialized, missing context!";
|
B15F::abort("View::win not initialized, missing context");
|
||||||
raise(SIGINT);
|
|
||||||
}
|
}
|
||||||
getmaxyx(win, height, width); // init width and height
|
getmaxyx(win, height, width); // init width and height
|
||||||
keypad(win, TRUE);
|
keypad(win, TRUE);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include "../drv/b15f.h"
|
||||||
|
|
||||||
extern std::string ERR_MSG;
|
extern std::string ERR_MSG;
|
||||||
typedef std::function<void(int)> call_t;
|
typedef std::function<void(int)> call_t;
|
||||||
|
|
Loading…
Reference in a new issue