diff --git a/include/create/packet.h b/include/create/packet.h index 8f2f426..da0a6e2 100644 --- a/include/create/packet.h +++ b/include/create/packet.h @@ -41,6 +41,10 @@ namespace create { mutable boost::mutex dataMutex; mutable boost::mutex tmpDataMutex; + protected: + // Thread safe + void setData(const uint16_t& d); + public: const uint8_t nbytes; const std::string info; @@ -48,10 +52,11 @@ namespace create { Packet(const uint8_t& nbytes, const std::string& info); ~Packet(); - // All of the following are thread safe - void setTempData(const uint16_t& td); + // Thread safe + void setDataToValidate(const uint16_t& td); + // Thread safe void validate(); - void setData(const uint16_t& d); + // Thread safe uint16_t getData() const; }; diff --git a/src/packet.cpp b/src/packet.cpp index 799d9f7..9b65305 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -10,7 +10,7 @@ namespace create { Packet::~Packet() { } - void Packet::setTempData(const uint16_t& tmp) { + void Packet::setDataToValidate(const uint16_t& tmp) { boost::mutex::scoped_lock lock(tmpDataMutex); tmpData = tmp; } diff --git a/src/serial_query.cpp b/src/serial_query.cpp index 1cc23d2..a0b7c00 100644 --- a/src/serial_query.cpp +++ b/src/serial_query.cpp @@ -54,7 +54,7 @@ namespace create { --packetByte; } else if (packetID < maxPacketID) { // New packet - data->getPacket(packetID)->setTempData(packetData); + data->getPacket(packetID)->setDataToValidate(packetData); packetData = 0; ++packetID; packetByte = data->getPacket(packetID)->nbytes - 1; diff --git a/src/serial_stream.cpp b/src/serial_stream.cpp index 8674718..aac3184 100644 --- a/src/serial_stream.cpp +++ b/src/serial_stream.cpp @@ -77,7 +77,7 @@ namespace create { packetBytes += byteRead; } if (numDataBytesRead >= expectedNumDataBytes) { - data->getPacket(packetID)->setTempData(packetBytes); + data->getPacket(packetID)->setDataToValidate(packetBytes); if (numBytesRead >= expectedNumBytes) readState = READ_CHECKSUM; else