![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test _oliver
Diff: parse_keys.h
- Revision:
- 0:20fbd6f66b11
- Child:
- 2:ff17ce021cfb
diff -r 000000000000 -r 20fbd6f66b11 parse_keys.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parse_keys.h Tue Jan 03 13:20:36 2017 +0000 @@ -0,0 +1,57 @@ +#ifndef DISPENSER_PARSE_KEYS_H +#define DISPENSER_PARSE_KEYS_H + +#include "mDot.h" + +class ParseKeys { +public: + static bool initialize(mDot* dot, const char* aDevAddr, const char* aNwkSKey, const char* aAppSKey) { + int32_t ret; + + // parse devkey + std::vector<uint8_t> loriot_nwk_skey(16); + for (uint8_t ni = 0; ni < 16; ni++) + { + const char hex[] = { '0', 'x', aNwkSKey[ni * 2], aNwkSKey[ni * 2 + 1], '\0' }; + loriot_nwk_skey[ni] = strtoul(hex, NULL, 16); + } + + // parse appkey + std::vector<uint8_t> loriot_app_skey(16); + for (uint8_t ai = 0; ai < 16; ai++) + { + const char hex[] = { '0', 'x', aAppSKey[ai * 2], aAppSKey[ai * 2 + 1], '\0' }; + loriot_app_skey[ai] = strtoul(hex, NULL, 16); + } + + // parse dev addr + std::vector<uint8_t> loriot_dev_addr(4); + for (uint8_t ai = 0; ai < 4; ai++) + { + const char hex[] = { '0', 'x', aDevAddr[ai * 2], aDevAddr[ai * 2 + 1], '\0' }; + loriot_dev_addr[ai] = strtoul(hex, NULL, 16); + } + + logInfo("setting network address"); + if ((ret = dot->setNetworkAddress(loriot_dev_addr)) != mDot::MDOT_OK) { + logError("failed to set network address %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + logInfo("setting network session key"); + if ((ret = dot->setNetworkSessionKey(loriot_nwk_skey)) != mDot::MDOT_OK) { + logError("failed to set network session key %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + logInfo("setting app session key"); + if ((ret = dot->setDataSessionKey(loriot_app_skey)) != mDot::MDOT_OK) { + logError("failed to set app session key %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + return true; + } +}; + +#endif // DISPENSER_PARSE_KEYS_H