Commit 57731113 authored by Roberta De Viti's avatar Roberta De Viti
Browse files

fix: strToHex in Logger to avoid printing rubbish (jni code)

parent 28983c0f
......@@ -138,7 +138,7 @@ JNIEXPORT void JNICALL Java_org_mpisws_encounters_encounterformation_SDDR_1Nativ
jobject arraylistObjMsgs = env->GetStaticObjectField(jni_cache.clsNative, jni_cache.fidc_EncounterMsgs);
jbyteArray bytes;
for (std::string m : msgs) {
LOG_P(TAG, "-- Adding msg %s to encounter msgs", m.c_str());
LOG_P(TAG, "-- Adding msg %s to encounter msgs", (strToHex(m, true)).c_str());
bytes = env->NewByteArray(m.length());
env->SetByteArrayRegion(bytes, 0, m.length(), (jbyte*)m.c_str());
env->CallBooleanMethod(arraylistObjMsgs, jni_cache.addArray, bytes);
......
......@@ -5,6 +5,7 @@
#include <unordered_map>
#include "EbNDevice.h"
#include "Logger.h"
// Maps adverts and device IDs to particular devices
template<typename TDevice>
......@@ -77,7 +78,7 @@ TDevice* EbNDeviceMap<TDevice>::get(const std::string &advert)
return it->second;
} else {
LOG_P("Device", "Didn't find advert %s in %d entries",
advert.c_str(), advertToDevice_.size());
(strToHex(advert, true)).c_str(), advertToDevice_.size());
return NULL;
}
}
......@@ -88,7 +89,7 @@ void EbNDeviceMap<TDevice>::add(const std::string &advert, TDevice *device)
advertToDevice_.insert(std::make_pair(advert, device));
idToDevice_.insert(std::make_pair(device->getID(), device));
LOG_P("ADDRESS", "Inserting addr %s vs. %s id %d",
advert.c_str(), device->getAdvert().c_str(), device->getID());
(strToHex(advert, true)).c_str(), (strToHex(device->getAdvert(), true)).c_str(), device->getID());
}
template<typename TDevice>
......
......@@ -103,5 +103,7 @@ extern Logger *logger;
// Logging for any messages required in parsing scripts (e.g. simulations)
#define LOG_P(tag, format, args...) if(IS_LOG_P_ENABLED) { logger->write(Logger::MESSAGE_PARSE, tag, format , ##args); }
std::string strToHex(const std::string& s, bool upper_case /* = true */);
#endif // LOGGER_H
......@@ -99,3 +99,14 @@ void Logger::write(MessageType type, const char *tag, const char *format, ...)
va_end(args);
}
std::string strToHex(const std::string& s, bool upper_case /* = true */)
{
std::ostringstream ret;
for (std::string::size_type i = 0; i < s.length(); ++i)
ret << std::hex << std::setfill('0') << std::setw(2) << (upper_case ? std::uppercase : std::nouppercase) << (int)s[i];
return ret.str();
}
#include "SDDRRadio.h"
#include "Logger.h"
using namespace std;
......@@ -49,8 +50,9 @@ void SDDRRadio::preDiscovery()
long SDDRRadio::processScanResponse(int8_t rssi, std::string advert, long scanTime)
{
LOG_P(TAG, "Processing scan response with rssi %d, and data %s", rssi, advert.c_str());
//LOG_P(TAG, "Processing scan response with RSSI %d, and data %s", rssi, advert.c_str());
LOG_P(TAG, "Processing scan response with RSSI %d, and data (advert) %s", rssi, (strToHex(advert_, true)).c_str());
//uint64_t scanTime = getTimeMS();
EbNDevice *device = deviceMap_.get(advert);
if(device == NULL)
......@@ -60,7 +62,7 @@ long SDDRRadio::processScanResponse(int8_t rssi, std::string advert, long scanTi
device = new EbNDevice(generateDeviceID(), advert);
deviceMap_.add(advert, device);
LOG_P("ENCOUNTERS_TEST", "-- Discovered new SDDR device (ID %ld, Advert %s)",
device->getID(), device->getAdvert().c_str());
device->getID(), (strToHex(device->getAdvert(), true)).c_str());
}
device->addRSSIMeasurement(scanTime, rssi);
......@@ -220,7 +222,8 @@ void SDDRRadio::setAdvert()
advert_dhkey_ = advert_dhExchange_.getSerializedKey();
advert_ = std::string((const char*) hash, SHA_DIGEST_LENGTH);
LOG_P("c_sddr", "Advert is %s: ", advert_.c_str());
//LOG_P("c_sddr", "Advert is %s: ", advert_.c_str());
LOG_P("c_sddr", "Advert is %s ", (strToHex(advert_, true)).c_str());
}
void SDDRRadio::addRecentDevice(EbNDevice *device)
......@@ -289,7 +292,7 @@ std::string SDDRRadio::computeSecretKey(std::string myDHKey, std::string SHA1DHK
(const uint8_t*)otherDHKey.substr(0, messageSize).c_str(),
keySize_
);
LOG_P("c_sddr", "shared secret!!!! %s ", std::string(dest, keySize_/8).c_str());
LOG_P("c_sddr", "shared secret!!!! %s ", (strToHex(std::string(dest, keySize_/8), true)).c_str());
return std::string(dest, keySize_/8);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment