statistics
This commit is contained in:
parent
84fe8b72eb
commit
86da74bed0
|
@ -30,7 +30,10 @@ void B15F::init()
|
||||||
// Temporärer Test
|
// Temporärer Test
|
||||||
uint8_t block[] = {0, 1, 2, 3};
|
uint8_t block[] = {0, 1, 2, 3};
|
||||||
while(1)
|
while(1)
|
||||||
|
{
|
||||||
usart.writeBlock(&block[0], 0, sizeof(block));
|
usart.writeBlock(&block[0], 0, sizeof(block));
|
||||||
|
usart.printStatistics();
|
||||||
|
}
|
||||||
throw std::runtime_error("SCHLUSS");
|
throw std::runtime_error("SCHLUSS");
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,13 +86,13 @@ void B15F::reconnect()
|
||||||
|
|
||||||
void B15F::discard(void)
|
void B15F::discard(void)
|
||||||
{
|
{
|
||||||
usart.flushOutputBuffer();
|
usart.clearOutputBuffer();
|
||||||
for(uint8_t i = 0; i < 8; i++)
|
for(uint8_t i = 0; i < 8; 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((16000 / BAUDRATE) + 1); // warte mindestens eine Millisekunde, gegebenenfalls mehr
|
||||||
}
|
}
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool B15F::testConnection()
|
bool B15F::testConnection()
|
||||||
|
@ -147,7 +150,7 @@ std::vector<std::string> B15F::getBoardInfo(void)
|
||||||
|
|
||||||
bool B15F::digitalWrite0(uint8_t port)
|
bool B15F::digitalWrite0(uint8_t port)
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_BA0);
|
usart.writeByte(RQ_BA0);
|
||||||
usart.writeByte(port);
|
usart.writeByte(port);
|
||||||
|
|
||||||
|
@ -157,7 +160,7 @@ bool B15F::digitalWrite0(uint8_t port)
|
||||||
|
|
||||||
bool B15F::digitalWrite1(uint8_t port)
|
bool B15F::digitalWrite1(uint8_t port)
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_BA1);
|
usart.writeByte(RQ_BA1);
|
||||||
usart.writeByte(port);
|
usart.writeByte(port);
|
||||||
|
|
||||||
|
@ -167,21 +170,21 @@ bool B15F::digitalWrite1(uint8_t port)
|
||||||
|
|
||||||
uint8_t B15F::digitalRead0()
|
uint8_t B15F::digitalRead0()
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_BE0);
|
usart.writeByte(RQ_BE0);
|
||||||
return usart.readByte();
|
return usart.readByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t B15F::digitalRead1()
|
uint8_t B15F::digitalRead1()
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_BE1);
|
usart.writeByte(RQ_BE1);
|
||||||
return usart.readByte();
|
return usart.readByte();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool B15F::analogWrite0(uint16_t value)
|
bool B15F::analogWrite0(uint16_t value)
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_AA0);
|
usart.writeByte(RQ_AA0);
|
||||||
usart.writeInt(value);
|
usart.writeInt(value);
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ bool B15F::analogWrite0(uint16_t value)
|
||||||
|
|
||||||
bool B15F::analogWrite1(uint16_t value)
|
bool B15F::analogWrite1(uint16_t value)
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_AA1);
|
usart.writeByte(RQ_AA1);
|
||||||
usart.writeInt(value);
|
usart.writeInt(value);
|
||||||
|
|
||||||
|
@ -201,7 +204,7 @@ bool B15F::analogWrite1(uint16_t value)
|
||||||
|
|
||||||
uint16_t B15F::analogRead(uint8_t channel)
|
uint16_t B15F::analogRead(uint8_t channel)
|
||||||
{
|
{
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_ADC);
|
usart.writeByte(RQ_ADC);
|
||||||
usart.writeByte(channel);
|
usart.writeByte(channel);
|
||||||
return usart.readInt();
|
return usart.readInt();
|
||||||
|
@ -212,7 +215,7 @@ bool B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
|
||||||
buffer_a += offset_a;
|
buffer_a += offset_a;
|
||||||
buffer_b += offset_b;
|
buffer_b += offset_b;
|
||||||
|
|
||||||
usart.flushInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_ADC_DAC_STROKE);
|
usart.writeByte(RQ_ADC_DAC_STROKE);
|
||||||
usart.writeByte(channel_a);
|
usart.writeByte(channel_a);
|
||||||
usart.writeByte(channel_b);
|
usart.writeByte(channel_b);
|
||||||
|
|
Binary file not shown.
|
@ -25,8 +25,8 @@ void USART::openDevice(std::string device)
|
||||||
if(code)
|
if(code)
|
||||||
throw USARTException("Fehler beim Setzen der Geräteparameter");
|
throw USARTException("Fehler beim Setzen der Geräteparameter");
|
||||||
|
|
||||||
flushOutputBuffer();
|
clearOutputBuffer();
|
||||||
flushInputBuffer();
|
clearInputBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART::closeDevice()
|
void USART::closeDevice()
|
||||||
|
@ -36,20 +36,27 @@ void USART::closeDevice()
|
||||||
throw USARTException("Fehler beim Schließen des Gerätes");
|
throw USARTException("Fehler beim Schließen des Gerätes");
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART::flushInputBuffer()
|
void USART::clearInputBuffer()
|
||||||
{
|
{
|
||||||
int code = tcflush(file_desc, TCIFLUSH);
|
int code = tcflush(file_desc, TCIFLUSH);
|
||||||
if(code)
|
if(code)
|
||||||
throw USARTException("Fehler beim Leeren des Eingangspuffers");
|
throw USARTException("Fehler beim Leeren des Eingangspuffers");
|
||||||
}
|
}
|
||||||
|
|
||||||
void USART::flushOutputBuffer()
|
void USART::clearOutputBuffer()
|
||||||
{
|
{
|
||||||
int code = tcflush(file_desc, TCOFLUSH);
|
int code = tcflush(file_desc, TCOFLUSH);
|
||||||
if(code)
|
if(code)
|
||||||
throw USARTException("Fehler beim Leeren des Ausgangspuffers");
|
throw USARTException("Fehler beim Leeren des Ausgangspuffers");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void USART::printStatistics()
|
||||||
|
{
|
||||||
|
double pz = 1e2 * n_blocks_failed / n_blocks_total;
|
||||||
|
pz = std::round(pz * 1e2) / 1e2;
|
||||||
|
std::cout << "blocks total: " << n_blocks_total << " ok: " << (n_blocks_total - n_blocks_failed) << " failed: " << n_blocks_failed << " (" << pz << "%)" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void USART::writeByte(uint8_t b)
|
void USART::writeByte(uint8_t b)
|
||||||
{
|
{
|
||||||
int sent = write(file_desc, &b, 1);
|
int sent = write(file_desc, &b, 1);
|
||||||
|
@ -118,6 +125,9 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
|
||||||
const uint16_t us_per_bit = (1000000 / baudrate) * 16;
|
const uint16_t us_per_bit = (1000000 / baudrate) * 16;
|
||||||
const uint16_t n_total = len + 3;
|
const uint16_t n_total = len + 3;
|
||||||
|
|
||||||
|
n_blocks_total++;
|
||||||
|
bool failed = false;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
// calc crc
|
// calc crc
|
||||||
|
@ -163,10 +173,14 @@ void USART::writeBlock(uint8_t* buffer, uint16_t offset, uint8_t len)
|
||||||
if(n_read != 1)
|
if(n_read != 1)
|
||||||
throw std::runtime_error("fatal: " + std::to_string(n_read));
|
throw std::runtime_error("fatal: " + std::to_string(n_read));
|
||||||
|
|
||||||
//flushInputBuffer();
|
//clearInputBuffer();
|
||||||
|
|
||||||
if(aw != 0xFF)
|
if(aw != 0xFF) {
|
||||||
|
if(!failed)
|
||||||
|
n_blocks_failed++;
|
||||||
|
failed = true;
|
||||||
std::cout << "block failed, retry" << std::endl;
|
std::cout << "block failed, retry" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while(aw != 0xFF);
|
while(aw != 0xFF);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <cmath>
|
||||||
#include "usartexception.h"
|
#include "usartexception.h"
|
||||||
#include "timeoutexception.h"
|
#include "timeoutexception.h"
|
||||||
|
|
||||||
|
@ -37,13 +38,18 @@ public:
|
||||||
* Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gelesen wurden
|
* Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gelesen wurden
|
||||||
* \throws USARTException
|
* \throws USARTException
|
||||||
*/
|
*/
|
||||||
void flushInputBuffer(void);
|
void clearInputBuffer(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden
|
* Verwirft Daten, die bereits im Puffer liegen, aber noch nicht gesendet wurden
|
||||||
* \throws USARTException
|
* \throws USARTException
|
||||||
*/
|
*/
|
||||||
void flushOutputBuffer(void);
|
void clearOutputBuffer(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt Anzahl an erfolgreichen und fehlgeschlagenen Block-Übertragungen an
|
||||||
|
*/
|
||||||
|
void printStatistics(void);
|
||||||
|
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
|
|
||||||
|
@ -128,6 +134,10 @@ private:
|
||||||
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];
|
||||||
|
|
||||||
|
// debug statistics
|
||||||
|
uint32_t n_blocks_total = 0;
|
||||||
|
uint32_t n_blocks_failed = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
BIN
driver/main
BIN
driver/main
Binary file not shown.
Loading…
Reference in a new issue