Version 0.3

This commit is contained in:
Tristan Krause 2019-04-05 15:59:05 +02:00
parent bb5d16ca88
commit f403b407cc
12 changed files with 70 additions and 15 deletions

17
README.md Normal file
View file

@ -0,0 +1,17 @@
# B15F - Board 15 Famulus Edition
## TODO / Ideen
- CLI: Exception catchen, set global error message, raise SIGINT --> ncurses wird richtig beendet
- Monitor: Refresh visualisieren, z.B. - / - \ |
- Main Menu: Informationen ergänzen
- Selbsttest bei discard richtig beenden (momentan wird wahrscheinlich WDT angeschmissen, besser global bool für selbsttest-loop)
- Lizenz
- gitignore checken
- readme schreiben
- CLI: Farbe?
- globale strings / msg klasse für treiber, ui (z.B. B15F info)
- drv: requests als array organisieren
- drv/usart überarbeiten, evtl iotl select
- dreipol dil schalter ansprechbar machen
- die vier buttons ansprechbar machen
- Kommentieren

Binary file not shown.

View file

@ -1,8 +1,4 @@
/** TODO
*
* - throw exception -> raise SIGINT
*/
#define B15F_CLI_DEBUG
#include <stdio.h>
#include <ncurses.h> // sudo apt-get install libncurses5-dev
@ -79,8 +75,10 @@ void init()
{
// init b15 driver
B15F::getInstance();
#ifndef B15F_CLI_DEBUG
std::cout << std::endl << "Starte in 3s ..." << std::endl;
sleep(3);
#endif
// init all ncurses stuff
initscr();

View file

@ -215,12 +215,20 @@ uint16_t B15F::analogRead(uint8_t channel)
usart.clearInputBuffer();
if(channel > 7)
throw DriverException("Bad ADC channel: " + std::to_string(channel));
usart.writeByte(RQ_ADC);
usart.writeByte(channel);
uint8_t rq[] = {
RQ_ADC,
channel
};
int n_sent = usart.write_timeout(&rq[0], 0, sizeof(rq), 1000);
if(n_sent != sizeof(rq))
throw DriverException("Sent failed");
uint16_t adc = usart.readInt();
if(adc > 1023)
throw DriverException("Bad ADC data detected");
delay_us(50);
return adc;
}

View file

@ -192,7 +192,7 @@ private:
constexpr static uint8_t MSG_FAIL = 0xFE;
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
constexpr static uint8_t RECONNECT_TRIES = 3;
constexpr static uint32_t BAUDRATE = 115200;
constexpr static uint32_t BAUDRATE = 57600;
// REQUESTS
constexpr static uint8_t RQ_DISC = 0;

View file

@ -49,6 +49,13 @@ void USART::clearOutputBuffer()
if(code)
throw USARTException("Fehler beim Leeren des Ausgangspuffers");
}
void USART::flushOutputBuffer()
{
int code = tcdrain(file_desc);
if(code)
throw USARTException("Fehler beim Versenden des Ausgangspuffers");
}
void USART::printStatistics()
{
@ -108,6 +115,7 @@ int USART::write_timeout(uint8_t* buffer, uint16_t offset, uint8_t len, uint32_t
while(elapsed < timeout)
{
n_sent = write(file_desc, buffer + offset, len);
flushOutputBuffer();
if (n_sent == len)
return n_sent;

View file

@ -46,6 +46,12 @@ public:
*/
void clearOutputBuffer(void);
/**
* Schreibt Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden
* \throws USARTException
*/
void flushOutputBuffer(void);
/**
* Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an
*/
@ -130,7 +136,7 @@ public:
private:
int file_desc = -1; // Linux Dateideskriptor
uint32_t baudrate = 9600;
uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden!
int TEST = 0;
uint8_t timeout = 10; // in Dezisekunden
uint8_t block_buffer[MAX_BLOCK_SIZE + 3];

BIN
driver/main Executable file

Binary file not shown.

View file

@ -121,8 +121,6 @@ void kennlinieZweiterQuadrant()
void testFunktionen()
{
B15F& drv = B15F::getInstance();
drv.activateSelfTestMode();
return;
std::cout << "DIP-Switch: " << (int) drv.readDipSwitch() << std::endl;
@ -159,7 +157,22 @@ int main()
{
//testFunktionen();
//kennlinieZweiterQuadrant();
kennlinieErsterQuadrant();
B15F& drv = B15F::getInstance();
while(1)
{
//uint8_t be0 = drv.digitalRead0();
//uint8_t be1 = drv.digitalRead1();
//uint8_t dsw = drv.readDipSwitch();
drv.analogRead(0);
drv.analogRead(1);
drv.analogRead(2);
drv.analogRead(3);
drv.analogRead(4);
drv.analogRead(5);
drv.analogRead(6);
drv.analogRead(7);
}
std::cout << "Schluss." << std::endl;
}

View file

@ -75,7 +75,7 @@ void ViewMonitor::worker()
{
try
{
std::this_thread::sleep_for(std::chrono::milliseconds(200));
std::this_thread::sleep_for(std::chrono::milliseconds(100));
uint8_t be0 = drv.digitalRead0();
uint8_t be1 = drv.digitalRead1();
@ -118,6 +118,11 @@ void ViewMonitor::worker()
text = str.str();
repaint();
}
catch(DriverException& ex)
{
std::cout << "DriverException: " << ex.what() << std::endl;
drv.delay_ms(1000);
}
catch(...)
{
drv.reconnect();

Binary file not shown.

View file

@ -124,7 +124,7 @@ private:
volatile bool active = false;
// constants
constexpr static uint32_t BAUDRATE = 115200; // 38400
constexpr static uint32_t BAUDRATE = 57600; // 38400
constexpr static uint8_t CRC7_POLY = 0x91;
constexpr static uint8_t MAX_BLOCK_SIZE = 64;
constexpr static uint8_t BLOCK_END = 0x80;