forked from compAIR/libcreate
Refactor Packet API
Declare setData member as protected Rename 'setTempData' to 'setDataToValidate'
This commit is contained in:
parent
6a8702f4e1
commit
a70dee6605
4 changed files with 11 additions and 6 deletions
|
@ -41,6 +41,10 @@ namespace create {
|
||||||
mutable boost::mutex dataMutex;
|
mutable boost::mutex dataMutex;
|
||||||
mutable boost::mutex tmpDataMutex;
|
mutable boost::mutex tmpDataMutex;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Thread safe
|
||||||
|
void setData(const uint16_t& d);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const uint8_t nbytes;
|
const uint8_t nbytes;
|
||||||
const std::string info;
|
const std::string info;
|
||||||
|
@ -48,10 +52,11 @@ namespace create {
|
||||||
Packet(const uint8_t& nbytes, const std::string& info);
|
Packet(const uint8_t& nbytes, const std::string& info);
|
||||||
~Packet();
|
~Packet();
|
||||||
|
|
||||||
// All of the following are thread safe
|
// Thread safe
|
||||||
void setTempData(const uint16_t& td);
|
void setDataToValidate(const uint16_t& td);
|
||||||
|
// Thread safe
|
||||||
void validate();
|
void validate();
|
||||||
void setData(const uint16_t& d);
|
// Thread safe
|
||||||
uint16_t getData() const;
|
uint16_t getData() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace create {
|
||||||
|
|
||||||
Packet::~Packet() { }
|
Packet::~Packet() { }
|
||||||
|
|
||||||
void Packet::setTempData(const uint16_t& tmp) {
|
void Packet::setDataToValidate(const uint16_t& tmp) {
|
||||||
boost::mutex::scoped_lock lock(tmpDataMutex);
|
boost::mutex::scoped_lock lock(tmpDataMutex);
|
||||||
tmpData = tmp;
|
tmpData = tmp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ namespace create {
|
||||||
--packetByte;
|
--packetByte;
|
||||||
} else if (packetID < maxPacketID) {
|
} else if (packetID < maxPacketID) {
|
||||||
// New packet
|
// New packet
|
||||||
data->getPacket(packetID)->setTempData(packetData);
|
data->getPacket(packetID)->setDataToValidate(packetData);
|
||||||
packetData = 0;
|
packetData = 0;
|
||||||
++packetID;
|
++packetID;
|
||||||
packetByte = data->getPacket(packetID)->nbytes - 1;
|
packetByte = data->getPacket(packetID)->nbytes - 1;
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace create {
|
||||||
packetBytes += byteRead;
|
packetBytes += byteRead;
|
||||||
}
|
}
|
||||||
if (numDataBytesRead >= expectedNumDataBytes) {
|
if (numDataBytesRead >= expectedNumDataBytes) {
|
||||||
data->getPacket(packetID)->setTempData(packetBytes);
|
data->getPacket(packetID)->setDataToValidate(packetBytes);
|
||||||
if (numBytesRead >= expectedNumBytes)
|
if (numBytesRead >= expectedNumBytes)
|
||||||
readState = READ_CHECKSUM;
|
readState = READ_CHECKSUM;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue