Version 0.3
This commit is contained in:
parent
bb5d16ca88
commit
f403b407cc
17
README.md
Normal file
17
README.md
Normal 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
|
BIN
driver/cli
BIN
driver/cli
Binary file not shown.
|
@ -1,8 +1,4 @@
|
||||||
/** TODO
|
#define B15F_CLI_DEBUG
|
||||||
*
|
|
||||||
* - throw exception -> raise SIGINT
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ncurses.h> // sudo apt-get install libncurses5-dev
|
#include <ncurses.h> // sudo apt-get install libncurses5-dev
|
||||||
|
@ -79,8 +75,10 @@ void init()
|
||||||
{
|
{
|
||||||
// init b15 driver
|
// init b15 driver
|
||||||
B15F::getInstance();
|
B15F::getInstance();
|
||||||
|
#ifndef B15F_CLI_DEBUG
|
||||||
std::cout << std::endl << "Starte in 3s ..." << std::endl;
|
std::cout << std::endl << "Starte in 3s ..." << std::endl;
|
||||||
sleep(3);
|
sleep(3);
|
||||||
|
#endif
|
||||||
|
|
||||||
// init all ncurses stuff
|
// init all ncurses stuff
|
||||||
initscr();
|
initscr();
|
||||||
|
|
|
@ -215,12 +215,20 @@ 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));
|
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();
|
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(50);
|
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ private:
|
||||||
constexpr static uint8_t MSG_FAIL = 0xFE;
|
constexpr static uint8_t MSG_FAIL = 0xFE;
|
||||||
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
|
constexpr static uint16_t RECONNECT_TIMEOUT = 64; // ms
|
||||||
constexpr static uint8_t RECONNECT_TRIES = 3;
|
constexpr static uint8_t RECONNECT_TRIES = 3;
|
||||||
constexpr static uint32_t BAUDRATE = 115200;
|
constexpr static uint32_t BAUDRATE = 57600;
|
||||||
|
|
||||||
// REQUESTS
|
// REQUESTS
|
||||||
constexpr static uint8_t RQ_DISC = 0;
|
constexpr static uint8_t RQ_DISC = 0;
|
||||||
|
|
|
@ -49,6 +49,13 @@ void USART::clearOutputBuffer()
|
||||||
if(code)
|
if(code)
|
||||||
throw USARTException("Fehler beim Leeren des Ausgangspuffers");
|
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()
|
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)
|
while(elapsed < timeout)
|
||||||
{
|
{
|
||||||
n_sent = write(file_desc, buffer + offset, len);
|
n_sent = write(file_desc, buffer + offset, len);
|
||||||
|
flushOutputBuffer();
|
||||||
if (n_sent == len)
|
if (n_sent == len)
|
||||||
return n_sent;
|
return n_sent;
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void clearOutputBuffer(void);
|
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
|
* Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an
|
||||||
*/
|
*/
|
||||||
|
@ -130,7 +136,7 @@ public:
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int file_desc = -1; // Linux Dateideskriptor
|
int file_desc = -1; // Linux Dateideskriptor
|
||||||
uint32_t baudrate = 9600;
|
uint32_t baudrate = 9600; // Standard-Baudrate, sollte mit setBaudrate() überschrieben werden!
|
||||||
int TEST = 0;
|
int TEST = 0;
|
||||||
uint8_t timeout = 10; // in Dezisekunden
|
uint8_t timeout = 10; // in Dezisekunden
|
||||||
uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
|
uint8_t block_buffer[MAX_BLOCK_SIZE + 3];
|
||||||
|
|
BIN
driver/main
Executable file
BIN
driver/main
Executable file
Binary file not shown.
|
@ -121,8 +121,6 @@ void kennlinieZweiterQuadrant()
|
||||||
void testFunktionen()
|
void testFunktionen()
|
||||||
{
|
{
|
||||||
B15F& drv = B15F::getInstance();
|
B15F& drv = B15F::getInstance();
|
||||||
drv.activateSelfTestMode();
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::cout << "DIP-Switch: " << (int) drv.readDipSwitch() << std::endl;
|
std::cout << "DIP-Switch: " << (int) drv.readDipSwitch() << std::endl;
|
||||||
|
|
||||||
|
@ -159,7 +157,22 @@ int main()
|
||||||
{
|
{
|
||||||
//testFunktionen();
|
//testFunktionen();
|
||||||
//kennlinieZweiterQuadrant();
|
//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;
|
std::cout << "Schluss." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ void ViewMonitor::worker()
|
||||||
{
|
{
|
||||||
try
|
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 be0 = drv.digitalRead0();
|
||||||
uint8_t be1 = drv.digitalRead1();
|
uint8_t be1 = drv.digitalRead1();
|
||||||
|
@ -118,6 +118,11 @@ void ViewMonitor::worker()
|
||||||
text = str.str();
|
text = str.str();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
catch(DriverException& ex)
|
||||||
|
{
|
||||||
|
std::cout << "DriverException: " << ex.what() << std::endl;
|
||||||
|
drv.delay_ms(1000);
|
||||||
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
drv.reconnect();
|
drv.reconnect();
|
||||||
|
|
Binary file not shown.
|
@ -124,7 +124,7 @@ private:
|
||||||
volatile bool active = false;
|
volatile bool active = false;
|
||||||
|
|
||||||
// constants
|
// 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 CRC7_POLY = 0x91;
|
||||||
constexpr static uint8_t MAX_BLOCK_SIZE = 64;
|
constexpr static uint8_t MAX_BLOCK_SIZE = 64;
|
||||||
constexpr static uint8_t BLOCK_END = 0x80;
|
constexpr static uint8_t BLOCK_END = 0x80;
|
||||||
|
|
Loading…
Reference in a new issue