Version 0.3
This commit is contained in:
parent
bb5d16ca88
commit
f403b407cc
12 changed files with 70 additions and 15 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue