Moved command_wait into common implementation for wmbus devices.

pull/156/head
Fredrik Öhrström 2020-09-25 21:47:21 +02:00
rodzic 371a3c3cf1
commit 467d15845a
7 zmienionych plików z 15 dodań i 18 usunięć

Wyświetl plik

@ -22,6 +22,7 @@
#include"wmbus_utils.h"
#include"dvparser.h"
#include<assert.h>
#include<semaphore.h>
#include<stdarg.h>
#include<string.h>
#include<sys/stat.h>
@ -3275,7 +3276,7 @@ WMBusCommonImplementation::WMBusCommonImplementation(WMBusDeviceType t,
{
// Initialize timeout from now.
last_received_ = time(NULL);
sem_init(&command_wait_, 0, 0);
}
WMBusDeviceType WMBusCommonImplementation::type()

Wyświetl plik

@ -78,7 +78,6 @@ private:
pthread_mutex_t amb8465_command_lock_ = PTHREAD_MUTEX_INITIALIZER;
const char *amb8465_command_lock_func_ = "";
pid_t amb8465_command_lock_pid_ {};
sem_t command_wait_ {};
int sent_command_ {};
int received_command_ {};
LinkModeSet link_modes_ {};
@ -112,7 +111,6 @@ shared_ptr<WMBus> openAMB8465(string device, shared_ptr<SerialCommunicationManag
WMBusAmber::WMBusAmber(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_AMB8465, manager, serial)
{
sem_init(&command_wait_, 0, 0);
manager_->listenTo(this->serial(),call(this,processSerialData));
manager_->onDisappear(this->serial(),call(this,disconnectedFromDevice));
rssi_expected_ = true;

Wyświetl plik

@ -69,7 +69,6 @@ private:
LinkModeSet link_modes_ {};
vector<uchar> read_buffer_;
vector<uchar> received_payload_;
sem_t command_wait_;
string sent_command_;
string received_response_;
@ -98,7 +97,6 @@ shared_ptr<WMBus> openCUL(string device, shared_ptr<SerialCommunicationManager>
WMBusCUL::WMBusCUL(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_CUL, manager, serial)
{
sem_init(&command_wait_, 0, 0);
manager_->listenTo(this->serial(),call(this,processSerialData));
manager_->onDisappear(this->serial(),call(this,disconnectedFromDevice));
reset();

Wyświetl plik

@ -47,7 +47,6 @@ struct WMBusD1TC : public virtual WMBusCommonImplementation
private:
vector<uchar> read_buffer_;
sem_t command_wait_;
LinkModeSet link_modes_;
vector<uchar> received_payload_;
@ -73,7 +72,6 @@ shared_ptr<WMBus> openD1TC(string device, shared_ptr<SerialCommunicationManager>
WMBusD1TC::WMBusD1TC(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_D1TC, manager, serial)
{
sem_init(&command_wait_, 0, 0);
manager_->listenTo(this->serial(),call(this,processSerialData));
reset();
}

Wyświetl plik

@ -72,7 +72,6 @@ private:
pthread_mutex_t im871a_command_lock_ = PTHREAD_MUTEX_INITIALIZER;
const char *im871a_command_lock_func_ = "";
pid_t im871a_command_lock_pid_ {};
sem_t im871a_command_wait_;
int sent_command_ {};
int received_command_ {};
vector<uchar> received_payload_;
@ -104,7 +103,6 @@ shared_ptr<WMBus> openIM871A(string device, shared_ptr<SerialCommunicationManage
WMBusIM871A::WMBusIM871A(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_IM871A, manager, serial)
{
sem_init(&im871a_command_wait_, 0, 0);
manager_->listenTo(this->serial(),call(this,processSerialData));
manager_->onDisappear(this->serial(),call(this,disconnectedFromDevice));
reset();
@ -400,9 +398,9 @@ void WMBusIM871A::waitForResponse()
{
while (manager_->isRunning())
{
trace("[IM871A] waitForResponse sem_wait im871a_command_wait_\n");
int rc = sem_wait(&im871a_command_wait_);
trace("[IM871A] waitForResponse waited im871a_command_wait_\n");
trace("[IM871A] waitForResponse sem_wait command_wait_\n");
int rc = sem_wait(&command_wait_);
trace("[IM871A] waitForResponse waited command_wait_\n");
if (rc==0) break;
if (rc==-1) {
if (errno==EINTR) continue;
@ -603,28 +601,28 @@ void WMBusIM871A::handleDevMgmt(int msgid, vector<uchar> &payload)
case DEVMGMT_MSG_PING_RSP: // 0x02
verbose("(im871a) pong\n");
received_command_ = msgid;
sem_post(&im871a_command_wait_);
sem_post(&command_wait_);
break;
case DEVMGMT_MSG_SET_CONFIG_RSP: // 0x04
verbose("(im871a) set config completed\n");
received_command_ = msgid;
received_payload_.clear();
received_payload_.insert(received_payload_.end(), payload.begin(), payload.end());
sem_post(&im871a_command_wait_);
sem_post(&command_wait_);
break;
case DEVMGMT_MSG_GET_CONFIG_RSP: // 0x06
verbose("(im871a) get config completed\n");
received_command_ = msgid;
received_payload_.clear();
received_payload_.insert(received_payload_.end(), payload.begin(), payload.end());
sem_post(&im871a_command_wait_);
sem_post(&command_wait_);
break;
case DEVMGMT_MSG_GET_DEVICEINFO_RSP: // 0x10
verbose("(im871a) device info completed\n");
received_command_ = msgid;
received_payload_.clear();
received_payload_.insert(received_payload_.end(), payload.begin(), payload.end());
sem_post(&im871a_command_wait_);
sem_post(&command_wait_);
break;
default:
verbose("(im871a) Unhandled device management message %d\n", msgid);

Wyświetl plik

@ -47,7 +47,6 @@ struct WMBusRawTTY : public virtual WMBusCommonImplementation
private:
vector<uchar> read_buffer_;
sem_t command_wait_;
LinkModeSet link_modes_;
vector<uchar> received_payload_;
@ -69,7 +68,6 @@ shared_ptr<WMBus> openRawTTY(string device, int baudrate, shared_ptr<SerialCommu
WMBusRawTTY::WMBusRawTTY(shared_ptr<SerialDevice> serial, shared_ptr<SerialCommunicationManager> manager) :
WMBusCommonImplementation(DEVICE_RAWTTY, manager, serial)
{
sem_init(&command_wait_, 0, 0);
manager_->listenTo(this->serial(),call(this,processSerialData));
reset();
}

Wyświetl plik

@ -21,6 +21,8 @@
#include "util.h"
#include "wmbus.h"
#include<semaphore.h>
bool decrypt_ELL_AES_CTR(Telegram *t, vector<uchar> &frame, vector<uchar>::iterator &pos, vector<uchar> &aeskey);
bool decrypt_TPL_AES_CBC_IV(Telegram *t, vector<uchar> &frame, vector<uchar>::iterator &pos, vector<uchar> &aeskey);
bool decrypt_TPL_AES_CBC_NO_IV(Telegram *t, vector<uchar> &frame, vector<uchar>::iterator &pos, vector<uchar> &aeskey);
@ -71,6 +73,10 @@ struct WMBusCommonImplementation : public virtual WMBus
LinkModeSet link_modes_ {};
shared_ptr<SerialDevice> serial_;
protected:
sem_t command_wait_;
};
#endif