Skip to content

Commit

Permalink
progress; need to look at setDeviceId some more
Browse files Browse the repository at this point in the history
Signed-off-by: Brenton Poke <[email protected]>
  • Loading branch information
BrentonPoke committed Oct 21, 2024
1 parent f46e2dc commit afd5bb7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/CdpPacket.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class CdpPacket {
std::array<byte,8>().swap(sduid);
std::array<byte,8>().swap(muid);
//std::array<byte,8>().swap(path);
std::array<byte,229>().swap(data);
data.clear();
duckType = DuckType::UNKNOWN;
hopCount = 0;
topic = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/DuckPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int DuckPacket::prepareForSending(BloomFilter *filter,
std::array<byte,8> targetDevice, byte duckType,
byte topic, std::vector<byte> app_data) {

std::vector<byte> encryptedData;
std::vector<uint8_t> encryptedData;
uint8_t app_data_length = app_data.size();

this->reset();
Expand Down
12 changes: 5 additions & 7 deletions src/Ducks/Duck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ void Duck::logIfLowMemory() {
}
}

int Duck::setDeviceId(std::vector<byte> id) {
int Duck::setDeviceId(std::array<byte,8> id) {
if (id.size() != DUID_LENGTH) {
logerr_ln("ERROR device id too long rc = %d", DUCK_ERR_ID_TOO_LONG);
return DUCK_ERR_ID_TOO_LONG;
}

duid.clear();
duid.assign(id.begin(), id.end());
std::copy(id.begin(), id.end(),duid.begin());
loginfo_ln("setupDeviceId rc = %d",DUCK_ERR_NONE);
return DUCK_ERR_NONE;
}
Expand Down Expand Up @@ -251,18 +249,18 @@ int Duck::sendData(byte topic, std::vector<byte> data,
}

lastMessageAck = false;
lastMessageMuid.assign(packet.muid.begin(), packet.muid.end());
std::copy(packet.muid.begin(),packet.muid.end(),lastMessageMuid.begin());
assert(lastMessageMuid.size() == MUID_LENGTH);
if (outgoingMuid != NULL) {
outgoingMuid->assign(packet.muid.begin(), packet.muid.end());
std::copy(packet.muid.cbegin(),packet.muid.cend(),outgoingMuid->begin());
assert(outgoingMuid->size() == MUID_LENGTH);
}
txPacket->reset();

return err;
}

muidStatus Duck::getMuidStatus(const std::vector<byte> & muid) const {
muidStatus Duck::getMuidStatus(const std::array<byte,8> & muid) const {
if (duckutils::isEqual(muid, lastMessageMuid)) {
if (lastMessageAck) {
return muidStatus::acked;
Expand Down
6 changes: 3 additions & 3 deletions src/include/Duck.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Duck {
* @param an 8 byte unique id
* @return DUCK_ERR_NONE if successful, an error code otherwise
*/
int setDeviceId(std::vector<byte> id);
int setDeviceId(std::array<byte,8> id);

/**
* @brief setup the duck unique ID
Expand Down Expand Up @@ -198,7 +198,7 @@ class Duck {
/**
* @brief Get the status of an MUID
*/
muidStatus getMuidStatus(const std::vector<byte> & muid) const;
muidStatus getMuidStatus(const std::array<byte,8> & muid) const;

/**
* @brief Check wifi connection status
Expand Down Expand Up @@ -304,7 +304,7 @@ class Duck {

DuckPacket* txPacket = NULL;
DuckPacket* rxPacket = NULL;
std::vector<byte> lastMessageMuid;
std::array<byte,8> lastMessageMuid;

bool lastMessageAck = true;
// Since this may be used to throttle outgoing packets, start out in a state
Expand Down
19 changes: 19 additions & 0 deletions src/include/DuckUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,25 @@ std::string toString(const std::vector<T>& vec) {
return result;
}

/**
* @brief Convert a array into an ASCII string.
*
* @param arr A vector to convert
* @returns A std::string representing the byte array in ASCII.
*
*/
template<typename T>
std::string toString(const std::array<T,8>& arr) {
std::string result;
for (const auto& element : arr) {
if (!std::isprint(element)) {
return "ERROR: Non-printable character";
}
result += static_cast<char>(element);
}
return result;
}

/**
* @brief Compare two vectors with regard to both size and contents.
*
Expand Down

0 comments on commit afd5bb7

Please sign in to comment.