bugsuche+

This commit is contained in:
Tristan Krause 2019-04-05 15:04:59 +02:00
parent e0a4be7685
commit bb5d16ca88
4 changed files with 22 additions and 31 deletions

Binary file not shown.

View file

@ -1,7 +1,6 @@
/** TODO /** TODO
* *
* - throw exception -> raise SIGINT * - throw exception -> raise SIGINT
* - delete view stack
*/ */
@ -81,7 +80,7 @@ void init()
// init b15 driver // init b15 driver
B15F::getInstance(); B15F::getInstance();
std::cout << std::endl << "Starte in 3s ..." << std::endl; std::cout << std::endl << "Starte in 3s ..." << std::endl;
//sleep(3); sleep(3);
// init all ncurses stuff // init all ncurses stuff
initscr(); initscr();
@ -262,7 +261,7 @@ void show_digital_output0(int)
{ {
ViewPromt* view = new ViewPromt(); ViewPromt* view = new ViewPromt();
view->setTitle("Digitale Ausgabe BE0"); view->setTitle("Digitale Ausgabe BE0");
view->setMessage("\nEingabe Port-Wert (hex): 0x"); view->setMessage("\nAusgabe Port-Wert (hex): 0x");
view->setCancel("[ Zurueck ]", true); view->setCancel("[ Zurueck ]", true);
view->setConfirm("[ OK ]", &write_digital_output0); view->setConfirm("[ OK ]", &write_digital_output0);
view->repaint(); view->repaint();
@ -275,7 +274,7 @@ void show_digital_output1(int)
{ {
ViewPromt* view = new ViewPromt(); ViewPromt* view = new ViewPromt();
view->setTitle("Digitale Ausgabe BE1"); view->setTitle("Digitale Ausgabe BE1");
view->setMessage("\nEingabe Port-Wert (hex): 0x"); view->setMessage("\nAusgabe Port-Wert (hex): 0x");
view->setCancel("[ Zurueck ]", true); view->setCancel("[ Zurueck ]", true);
view->setConfirm("[ OK ]", &write_digital_output1); view->setConfirm("[ OK ]", &write_digital_output1);
view->repaint(); view->repaint();
@ -288,7 +287,7 @@ void show_analog_output0(int)
{ {
ViewPromt* view = new ViewPromt(); ViewPromt* view = new ViewPromt();
view->setTitle("Analoge Ausgabe AA0"); view->setTitle("Analoge Ausgabe AA0");
view->setMessage("\nEingabe 10-Bit-Wert (0...1023): "); view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
view->setCancel("[ Zurueck ]", true); view->setCancel("[ Zurueck ]", true);
view->setConfirm("[ OK ]", &write_analog_output0); view->setConfirm("[ OK ]", &write_analog_output0);
view->repaint(); view->repaint();
@ -301,7 +300,7 @@ void show_analog_output1(int)
{ {
ViewPromt* view = new ViewPromt(); ViewPromt* view = new ViewPromt();
view->setTitle("Analoge Ausgabe AA1"); view->setTitle("Analoge Ausgabe AA1");
view->setMessage("\nEingabe 10-Bit-Wert (0...1023): "); view->setMessage("\nAusgabe 10-Bit-Wert (0...1023): ");
view->setCancel("[ Zurueck ]", true); view->setCancel("[ Zurueck ]", true);
view->setConfirm("[ OK ]", &write_analog_output1); view->setConfirm("[ OK ]", &write_analog_output1);
view->repaint(); view->repaint();

View file

@ -56,17 +56,14 @@ void B15F::init()
void B15F::reconnect() void B15F::reconnect()
{ {
uint8_t tries = RECONNECT_TRIES; uint8_t tries = RECONNECT_TRIES;
while(tries--) while(tries-- && false)
{ {
delay_ms(RECONNECT_TIMEOUT); delay_ms(RECONNECT_TIMEOUT);
discard(); discard();
if(testConnection()) if(testConnection())
{
std::cout << "OK" << std::endl << std::flush;
return; return;
}
} }
@ -76,10 +73,10 @@ void B15F::reconnect()
void B15F::discard(void) void B15F::discard(void)
{ {
usart.clearOutputBuffer(); usart.clearOutputBuffer();
for(uint8_t i = 0; i < 8; i++) for(uint8_t i = 0; i < 16; i++)
{ {
usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input) usart.writeByte(RQ_DISC); // sende discard Befehl (verwerfe input)
delay_ms((16000 / BAUDRATE) + 1); // warte mindestens eine Millisekunde, gegebenenfalls mehr delay_ms(4);
} }
usart.clearInputBuffer(); usart.clearInputBuffer();
} }
@ -140,7 +137,6 @@ std::vector<std::string> B15F::getBoardInfo(void)
bool B15F::activateSelfTestMode() bool B15F::activateSelfTestMode()
{ {
//usart.clearInputBuffer();
usart.writeByte(RQ_ST); usart.writeByte(RQ_ST);
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
@ -149,86 +145,82 @@ bool B15F::activateSelfTestMode()
bool B15F::digitalWrite0(uint8_t port) bool B15F::digitalWrite0(uint8_t port)
{ {
//usart.clearInputBuffer();
usart.writeByte(RQ_BA0); usart.writeByte(RQ_BA0);
usart.writeByte(port); usart.writeByte(port);
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
delay_us(1); delay_us(10);
return aw == MSG_OK; return aw == MSG_OK;
} }
bool B15F::digitalWrite1(uint8_t port) bool B15F::digitalWrite1(uint8_t port)
{ {
//usart.clearInputBuffer();
usart.writeByte(RQ_BA1); usart.writeByte(RQ_BA1);
usart.writeByte(port); usart.writeByte(port);
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
delay_us(1); delay_us(10);
return aw == MSG_OK; return aw == MSG_OK;
} }
uint8_t B15F::digitalRead0() uint8_t B15F::digitalRead0()
{ {
//usart.clearInputBuffer(); usart.clearInputBuffer();
usart.writeByte(RQ_BE0); usart.writeByte(RQ_BE0);
uint8_t byte = usart.readByte(); uint8_t byte = usart.readByte();
delay_us(1); delay_us(10);
return byte; return byte;
} }
uint8_t B15F::digitalRead1() uint8_t B15F::digitalRead1()
{ {
//usart.clearInputBuffer(); usart.clearInputBuffer();
usart.writeByte(RQ_BE1); usart.writeByte(RQ_BE1);
uint8_t byte = usart.readByte(); uint8_t byte = usart.readByte();
delay_us(1); delay_us(10);
return byte; return byte;
} }
uint8_t B15F::readDipSwitch() uint8_t B15F::readDipSwitch()
{ {
//usart.clearInputBuffer(); usart.clearInputBuffer();
usart.writeByte(RQ_DSW); usart.writeByte(RQ_DSW);
uint8_t byte = usart.readByte(); uint8_t byte = usart.readByte();
delay_us(1); delay_us(10);
return byte; return byte;
} }
bool B15F::analogWrite0(uint16_t value) bool B15F::analogWrite0(uint16_t value)
{ {
//usart.clearInputBuffer();
usart.writeByte(RQ_AA0); usart.writeByte(RQ_AA0);
usart.writeInt(value); usart.writeInt(value);
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
delay_us(1); delay_us(10);
return aw == MSG_OK; return aw == MSG_OK;
} }
bool B15F::analogWrite1(uint16_t value) bool B15F::analogWrite1(uint16_t value)
{ {
//usart.clearInputBuffer();
usart.writeByte(RQ_AA1); usart.writeByte(RQ_AA1);
usart.writeInt(value); usart.writeInt(value);
uint8_t aw = usart.readByte(); uint8_t aw = usart.readByte();
delay_us(1); delay_us(10);
return aw == MSG_OK; return aw == MSG_OK;
} }
uint16_t B15F::analogRead(uint8_t channel) uint16_t B15F::analogRead(uint8_t channel)
{ {
usart.clearInputBuffer();
if(channel > 7) if(channel > 7)
throw DriverException("Bad ADC channel: " + std::to_string(channel)); throw DriverException("Bad ADC channel: " + std::to_string(channel));
//usart.clearInputBuffer();
usart.writeByte(RQ_ADC); usart.writeByte(RQ_ADC);
usart.writeByte(channel); usart.writeByte(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");
delay_us(1); delay_us(50);
return adc; return adc;
} }
@ -258,7 +250,7 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
if(aw != MSG_OK) if(aw != MSG_OK)
throw DriverException("Sequenz unterbrochen"); throw DriverException("Sequenz unterbrochen");
delay_us(1); delay_us(10);
} }
void B15F::delay_ms(uint16_t ms) void B15F::delay_ms(uint16_t ms)

View file

@ -132,7 +132,7 @@ private:
int file_desc = -1; // Linux Dateideskriptor int file_desc = -1; // Linux Dateideskriptor
uint32_t baudrate = 9600; uint32_t baudrate = 9600;
int TEST = 0; int TEST = 0;
uint8_t timeout = 5; // in Dezisekunden uint8_t timeout = 10; // in Dezisekunden
uint8_t block_buffer[MAX_BLOCK_SIZE + 3]; uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
// debug statistics // debug statistics