-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moving XNCP version storage into a dedicated class NSEZSP::EzspAdapterVersion * Creating a getter API in libezsp to retrieve XNCP info (fw+hw versions) * Adding EZSP version details to EzspAdapterVersion class * Implementing EzspAdapterVersion::toString() and using it as example in mainEzspTest
- Loading branch information
1 parent
c34c534
commit 8571574
Showing
18 changed files
with
361 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @file ezsp-adapter-version.h | ||
* | ||
* @brief Handling EZSP adapter versions (firmware and hardware) | ||
*/ | ||
|
||
#ifndef __EZSP_ADAPTER_VERSION_H__ | ||
#define __EZSP_ADAPTER_VERSION_H__ | ||
|
||
#include <string> | ||
#include <cstdint> | ||
|
||
#include <ezsp/export.h> | ||
|
||
namespace NSEZSP { | ||
|
||
/** | ||
* @brief Class storing information about the EZSP adapter | ||
*/ | ||
class LIBEXPORT EzspAdapterVersion { | ||
public: | ||
enum class Manufacturer { | ||
UNKNOWN = 0, | ||
LEGRAND = 0x1021 | ||
}; | ||
|
||
EzspAdapterVersion(); | ||
~EzspAdapterVersion() = default; | ||
|
||
/** | ||
* @brief Store the EZSP stack version present inside an EZSP version info packet | ||
* | ||
* @param ezspStackVersion The EZSP stack version | ||
*/ | ||
void setEzspVersionInfo(uint16_t ezspStackVersion); | ||
|
||
/** | ||
* @brief Store EZSP version data present inside an EZSP version info packet | ||
* | ||
* @param ezspStackVersion The EZSP stack version | ||
* @param ezspProtocolVersion The EZSP protocol version (EZSPv7, EZSPv8) | ||
* @param ezspStackType The EZSP stack type | ||
*/ | ||
void setEzspVersionInfo(uint16_t ezspStackVersion, uint8_t ezspProtocolVersion, uint8_t ezspStackType); | ||
|
||
/** | ||
* @brief Store EZSP XNCP data present inside an EZSP XNCP info packet | ||
* | ||
* @param xncpManufacturerId The manufacturer ID (16-bit ID) | ||
* @param xncpVersionNumber The Legrand XNCP 16-bit encoded hardware+firmware version (encoding is proprietary from Legrand) | ||
*/ | ||
void setXncpData(uint16_t xncpManufacturerId, uint16_t xncpVersionNumber); | ||
|
||
/** | ||
* @brief Get a string representation of the XNCP firmware version data | ||
* | ||
* @return The firmware version as a string | ||
*/ | ||
std::string getFirmwareVersionAsString() const; | ||
|
||
/** | ||
* @brief Get a string representation of the embedded stack version data | ||
* | ||
* @return The stack version as a string | ||
*/ | ||
std::string getStackVersionAsString() const; | ||
|
||
/** | ||
* @brief Represent the information stored by this instance as a string | ||
* | ||
* @result The resulting string | ||
*/ | ||
std::string toString() const; | ||
|
||
/** | ||
* @brief Serialize to an iostream | ||
* | ||
* @param out The original output stream | ||
* @param data The object to serialize | ||
* | ||
* @return The new output stream with serialized data appended | ||
*/ | ||
friend std::ostream& operator<< (std::ostream& out, const EzspAdapterVersion& data){ | ||
out << data.toString(); | ||
return out; | ||
} | ||
|
||
unsigned int ezspProtocolVersion; /*<! The EZSP protocol version EZSPv7, EZSPv8 */ | ||
uint8_t ezspStackType; /*<! The EZSP stack type (2 being mesh stack) */ | ||
unsigned int ezspStackMajorVersion; /*<! The EZSP adapter embedded stack major version */ | ||
unsigned int ezspStackMinorVersion; /*<! The EZSP adapter embedded stack minor version */ | ||
unsigned int ezspStackRevisionVersion; /*<! The EZSP adapter embedded stack revision version */ | ||
unsigned int ezspStackBugfixVersion; /*<! The EZSP adapter embedded stack bugfix version */ | ||
uint16_t xncpManufacturerId; /*<! The manufacturer ID (16-bit ID). 0x1021 is the ID registered for Legrand at the Zigbee Alliance */ | ||
unsigned int xncpAdapterHardwareVersion; /*<! The Legrand XNCP EZSP adapter hardware version (valid only if manufacturer is Legrand) */ | ||
unsigned int xncpAdapterMajorVersion; /*<! The Legrand XNCP EZSP adapter firmware major version (valid only if manufacturer is Legrand) */ | ||
unsigned int xncpAdapterMinorVersion; /*<! The Legrand XNCP EZSP adapter firmware minor version (valid only if manufacturer is Legrand) */ | ||
unsigned int xncpAdapterRevisionVersion; /*<! The Legrand XNCP EZSP adapter firmware revision version (valid only if manufacturer is Legrand) */ | ||
}; | ||
|
||
} // namespace NSEZSP | ||
|
||
#endif // __EZSP_ADAPTER_VERSION_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @file ezsp-adapter-version.cpp | ||
* | ||
* @brief Handling EZSP adapter versions (firmware and hardware) | ||
*/ | ||
|
||
#include <sstream> | ||
#include <iomanip> | ||
|
||
#include <ezsp/ezsp-adapter-version.h> | ||
|
||
#include "ezsp/byte-manip.h" | ||
|
||
using NSEZSP::EzspAdapterVersion; | ||
|
||
EzspAdapterVersion::EzspAdapterVersion() : | ||
ezspProtocolVersion(0), | ||
ezspStackType(0), | ||
ezspStackMajorVersion(0), | ||
ezspStackMinorVersion(0), | ||
ezspStackRevisionVersion(0), | ||
ezspStackBugfixVersion(0), | ||
xncpManufacturerId(static_cast<uint16_t>(Manufacturer::UNKNOWN)), | ||
xncpAdapterHardwareVersion(0), | ||
xncpAdapterMajorVersion(0), | ||
xncpAdapterMinorVersion(0), | ||
xncpAdapterRevisionVersion(0) { | ||
} | ||
|
||
void EzspAdapterVersion::setEzspVersionInfo(uint16_t ezspStackVersion) { | ||
this->ezspStackMajorVersion = u8_get_hi_nibble(u16_get_hi_u8(ezspStackVersion)); | ||
this->ezspStackMinorVersion = u8_get_lo_nibble(u16_get_hi_u8(ezspStackVersion)); | ||
this->ezspStackRevisionVersion = u8_get_hi_nibble(u16_get_lo_u8(ezspStackVersion)); | ||
this->ezspStackBugfixVersion = u8_get_lo_nibble(u16_get_lo_u8(ezspStackVersion)); | ||
} | ||
|
||
void EzspAdapterVersion::setEzspVersionInfo(uint16_t ezspStackVersion, uint8_t ezspProtocolVersion, uint8_t ezspStackType) { | ||
this->setEzspVersionInfo(ezspStackVersion); | ||
this->ezspProtocolVersion = ezspProtocolVersion; | ||
this->ezspStackType = ezspStackType; | ||
} | ||
|
||
void EzspAdapterVersion::setXncpData(uint16_t xncpManufacturerId, uint16_t xncpVersionNumber) { | ||
this->xncpManufacturerId = xncpManufacturerId; | ||
this->xncpAdapterHardwareVersion = u8_get_hi_nibble(u16_get_hi_u8(xncpVersionNumber)); /* High nibble of MSB */ | ||
this->xncpAdapterMajorVersion = u8_get_lo_nibble(u16_get_hi_u8(xncpVersionNumber)); /* Low nibble of MSB */ | ||
this->xncpAdapterMinorVersion = u8_get_hi_nibble(u16_get_lo_u8(xncpVersionNumber)); /* High nibble of LSB */ | ||
this->xncpAdapterRevisionVersion = u8_get_lo_nibble(u16_get_lo_u8(xncpVersionNumber)); /* Low nibble of LSB */ | ||
} | ||
|
||
std::string EzspAdapterVersion::getFirmwareVersionAsString() const { | ||
std::stringstream result; | ||
result << this->xncpAdapterMajorVersion << "." << this->xncpAdapterMinorVersion << "." << this->xncpAdapterRevisionVersion; | ||
return result.str(); | ||
} | ||
|
||
std::string EzspAdapterVersion::getStackVersionAsString() const { | ||
std::stringstream result; | ||
result << static_cast<unsigned int>(this->ezspStackMajorVersion) << "."; | ||
result << static_cast<unsigned int>(this->ezspStackMinorVersion) << "."; | ||
result << static_cast<unsigned int>(this->ezspStackRevisionVersion) << "."; | ||
result << static_cast<unsigned int>(this->ezspStackBugfixVersion); | ||
return result.str(); | ||
} | ||
|
||
std::string EzspAdapterVersion::toString() const { | ||
std::stringstream buf; | ||
|
||
buf << "EzspAdapterVersion : { "; | ||
if (this->xncpManufacturerId != static_cast<uint16_t>(Manufacturer::UNKNOWN)) { | ||
buf << "[Manufacturer: 0x" << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned int>(this->xncpManufacturerId); | ||
if (this->xncpManufacturerId == static_cast<uint16_t>(Manufacturer::LEGRAND)) { | ||
buf << " (LEGRAND)"; | ||
} | ||
buf << "]"; | ||
} | ||
if (this->ezspProtocolVersion) { | ||
buf << "[EZSPv" << std::dec << std::setw(0) << static_cast<unsigned int>(this->ezspProtocolVersion); | ||
buf << " running stack type " << static_cast<unsigned int>(this->ezspStackType); | ||
if (this->ezspStackType == 2) { | ||
buf << " (mesh)"; | ||
} | ||
buf << "]"; | ||
} | ||
if (this->ezspStackMajorVersion || this->ezspStackMinorVersion || this->ezspStackRevisionVersion || this->ezspStackBugfixVersion) { | ||
buf << "[stack v" << this->getStackVersionAsString() << "]"; | ||
} | ||
/* XNCP can only be properly decoded if manufacturer is Legrand */ | ||
if (this->xncpManufacturerId == static_cast<uint16_t>(Manufacturer::LEGRAND)) { | ||
if (this->xncpAdapterHardwareVersion || this->xncpAdapterMajorVersion || this->xncpAdapterMinorVersion || this->xncpAdapterRevisionVersion) { | ||
buf << "[hw v" << this->xncpAdapterHardwareVersion; | ||
buf << ", fw v" << this->getFirmwareVersionAsString() << "]"; | ||
} | ||
} | ||
buf << " }"; | ||
|
||
return buf.str(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.