mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-11 06:42:13 +02:00
don't kill serial when polling too quickly
This commit is contained in:
parent
fd73b8de82
commit
9774dd5874
2 changed files with 14 additions and 15 deletions
|
@ -27,7 +27,7 @@ char serial_buffer[MAX_BUFFER];
|
|||
int serial_buffer_pos = 0;
|
||||
|
||||
const int ZERO_OFFSET = 2048;
|
||||
const short NO_READ_MAXIMUM = 10;
|
||||
const short NO_READ_MAXIMUM_MSECS = 3000;
|
||||
const short SAMPLES_TO_DISCARD = 100;
|
||||
|
||||
void SerialInterface::pair() {
|
||||
|
@ -166,14 +166,12 @@ void SerialInterface::readData() {
|
|||
|
||||
int initialSamples = totalSamples;
|
||||
|
||||
while (read(serial_fd, &bufchar, 1) > 0)
|
||||
{
|
||||
while (read(serial_fd, &bufchar, 1) > 0) {
|
||||
//std::cout << bufchar[0];
|
||||
serial_buffer[serial_buffer_pos] = bufchar[0];
|
||||
serial_buffer_pos++;
|
||||
// Have we reached end of a line of input?
|
||||
if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER))
|
||||
{
|
||||
if ((bufchar[0] == '\n') || (serial_buffer_pos >= MAX_BUFFER)) {
|
||||
std::string serialLine(serial_buffer, serial_buffer_pos-1);
|
||||
//std::cout << serialLine << "\n";
|
||||
int spot;
|
||||
|
@ -204,26 +202,27 @@ void SerialInterface::readData() {
|
|||
}
|
||||
}
|
||||
|
||||
if (initialSamples == totalSamples) {
|
||||
noReadCount++;
|
||||
std::cout << "#" << noReadCount << " blank read from serial.\n";
|
||||
if (initialSamples == totalSamples) {
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
if (noReadCount >= NO_READ_MAXIMUM) {
|
||||
if (diffclock(&lastGoodRead, &now) > NO_READ_MAXIMUM_MSECS) {
|
||||
std::cout << "No data coming over serial. Shutting down SerialInterface.\n";
|
||||
resetSerial();
|
||||
}
|
||||
} else {
|
||||
gettimeofday(&lastGoodRead, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void SerialInterface::resetSerial() {
|
||||
std::cout << "Reached maximum blank read count. Shutting down serial.\n";
|
||||
|
||||
active = false;
|
||||
noReadCount = 0;
|
||||
totalSamples = 0;
|
||||
|
||||
gettimeofday(&lastGoodRead, NULL);
|
||||
|
||||
// Clear the measured and average channel data
|
||||
for (int i = 0; i < NUM_CHANNELS; i++)
|
||||
{
|
||||
for (int i = 0; i < NUM_CHANNELS; i++) {
|
||||
lastMeasured[i] = 0;
|
||||
trailingAverage[i] = 0.0;
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ private:
|
|||
float trailingAverage[NUM_CHANNELS];
|
||||
int samplesAveraged;
|
||||
int LED;
|
||||
int noReadCount;
|
||||
int totalSamples;
|
||||
timeval lastGoodRead;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue