Fix bug that caused crash when dongle was reset.

pull/324/head
Fredrik Öhrström 2021-08-08 23:07:34 +02:00
rodzic c490c92fdf
commit 0d830bad59
5 zmienionych plików z 21 dodań i 6 usunięć

Wyświetl plik

@ -47,8 +47,8 @@ ifeq "$(DEBUG)" "true"
GCOV?=gcov
endif
else
DEBUG_FLAGS=-Os
STRIP_BINARY=$(STRIP) $(BUILD)/wmbusmeters
DEBUG_FLAGS=-Os -g
STRIP_BINARY=echo FOO
GCOV=To_run_gcov_add_DEBUG=true
endif

Wyświetl plik

@ -146,6 +146,7 @@ struct SerialDeviceImp : public SerialDevice
int receive(vector<uchar> *data);
bool waitFor(uchar c);
bool working() { return resetting_ || fd_ != -1; }
bool resetting() { return resetting_; }
bool opened() { return resetting_ || fd_ != -2; }
bool isClosed() { return fd_ == -1 && !resetting_; }
bool readonly() { return is_stdin_ || is_file_; }
@ -958,8 +959,11 @@ void *SerialCommunicationManagerImp::eventLoop()
{
if (sd->opened() && sd->working() && !sd->skippingCallbacks())
{
trace("[SERIAL] select read on fd %d\n", sd->fd());
FD_SET(sd->fd(), &readfds);
if (!sd->resetting() && sd->fd() >= 0)
{
trace("[SERIAL] select read on fd %d\n", sd->fd());
FD_SET(sd->fd(), &readfds);
}
}
if (sd->opened() && !sd->working()) all_working = false;
}

Wyświetl plik

@ -53,6 +53,7 @@ struct SerialDevice
virtual int fd() = 0;
virtual bool opened() = 0;
virtual bool working() = 0;
virtual bool resetting() = 0; // The serial device is working but can lack a valid file descriptor.
// Used when connecting stdin to a tty driver for testing.
virtual bool readonly() = 0;
// Mark this device so that it is ignored by the select/callback event loop.

Wyświetl plik

@ -1952,5 +1952,5 @@ size_t findBytes(vector<uchar> &v, uchar a, uchar b, uchar c)
}
p++;
}
return 0;
return (size_t)-1;
}

Wyświetl plik

@ -55,6 +55,11 @@ struct ConfigAMB8465
return ids;
}
bool enoughBytes(vector<uchar> &bytes, size_t offset)
{
return false;
}
bool decode(vector<uchar> &bytes)
{
size_t o = 5;
@ -612,6 +617,11 @@ AccessCheck detectAMB8465(Detected *detected, shared_ptr<SerialCommunicationMana
continue;
}
response.insert(response.end(), data.begin(), data.end());
//size_t skip = findBytes(response, 0xff, 0x8A, 0x7A);
/*if (skip == ((size_t)-1) || (response.size()-skip)
{
}*/
}
serial->close();
@ -620,7 +630,7 @@ AccessCheck detectAMB8465(Detected *detected, shared_ptr<SerialCommunicationMana
size_t skip = findBytes(response, 0xff, 0x8A, 0x7A);
debug("(amb8465) skipping %zu bytes\n", skip);
while (skip > 0)
while (skip > 0 && skip != ((size_t)-1))
{
// Sometimes there seems to be a leading 00 noise byte. Skip those.
response.erase(response.begin());