diff --git a/src/AntFr310XT.cpp b/src/AntFr310XT.cpp index dad2bc4..9805518 100644 --- a/src/AntFr310XT.cpp +++ b/src/AntFr310XT.cpp @@ -437,11 +437,12 @@ AntFr310XT::handleEvents() LOG(LOG_RAW) << "\n\nFound client \"" << clientDevName << "\" SN=0x" << toString(clientSN,8,'0') << " SN=" << clientSN << "\n\n\n"; - m_ds.reset(new DeviceSettings(toStringDec(clientSN).c_str())); + m_ds.reset(new DeviceSettings(clientDevName, toStringDec(clientSN))); assert(m_ds.get()); m_ds->loadDefaultValues(); LOG_VAR(m_ds->getConfigFileName()); m_ds->loadFromFile(m_ds->getConfigFileName()); + mkDir(m_ds->getFolder().c_str()); m_ds->saveToFile(m_ds->getConfigFileName()); m_serial->setWriteDelay(m_ds->SerialWriteDelayMs); diff --git a/src/AntMessenger.cpp b/src/AntMessenger.cpp index a32713a..6eb4b7a 100644 --- a/src/AntMessenger.cpp +++ b/src/AntMessenger.cpp @@ -1135,7 +1135,7 @@ AntMessenger::onMessage(std::vector v) } else { - lprintf(antpm::LOG_WARN, "unhandled 0x%0x\n", (int)m.getMsgId()); + lprintf(antpm::LOG_WARN, "unhandled 0x%0x %s\n", (int)m.getMsgId(), m.msgId2Str(m.getMsgId()).c_str()); } } diff --git a/src/DeviceSettings.cpp b/src/DeviceSettings.cpp index 39a25a4..ac43511 100644 --- a/src/DeviceSettings.cpp +++ b/src/DeviceSettings.cpp @@ -35,8 +35,9 @@ namespace fs=boost::filesystem; namespace antpm { -DeviceSettings::DeviceSettings(const char *devId) - : mDevId(devId) +DeviceSettings::DeviceSettings(const std::string &devName, const std::string &devSN) + : mDevName(devName) + , mDevSN(devSN) { loadDefaultValues(); } @@ -64,7 +65,7 @@ DeviceSettings::getConfigFileName() const const std::string DeviceSettings::getFolder() const { - return getConfigFolder() + "/" + mDevId + "/"; + return getConfigFolder() + "/" + mDevSN + "/"; } // std::vector @@ -217,6 +218,8 @@ bool DeviceSettings::saveToFile(const char *fname) { boost::property_tree::ptree pt; + pt.put("antpm.DeviceName", mDevName); + pt.put("antpm.DeviceSN", mDevSN); pt.put("antpm.MaxFileDownloads", MaxFileDownloads); pt.put("antpm.LastUserProfileTime", time2str(LastUserProfileTime)); pt.put("antpm.LastTransferredTime", time2str(LastTransferredTime)); diff --git a/src/DeviceSettings.hpp b/src/DeviceSettings.hpp index 340b74e..68214cb 100644 --- a/src/DeviceSettings.hpp +++ b/src/DeviceSettings.hpp @@ -40,7 +40,7 @@ typedef std::pair DatabaseEntity; class DeviceSettings { public: - DeviceSettings(const char* devId); + DeviceSettings(const std::string& devName, const std::string& devSN); void loadDefaultValues(); const std::string getConfigFileName() const; @@ -63,7 +63,8 @@ class DeviceSettings std::time_t LastTransferredTime; // last timepoint, communication happened with the device, represented as GMT/UTC size_t SerialWriteDelayMs; private: - std::string mDevId; + std::string mDevName; + std::string mDevSN; }; } diff --git a/src/tests/testDeviceSettings.cpp b/src/tests/testDeviceSettings.cpp index 8920421..1db4178 100644 --- a/src/tests/testDeviceSettings.cpp +++ b/src/tests/testDeviceSettings.cpp @@ -107,12 +107,13 @@ BOOST_AUTO_TEST_CASE(convert) BOOST_AUTO_TEST_CASE(load_save) { boost::scoped_ptr m_ds; + std::string clientName = "TestDevice"; uint clientSN = 1279010136; const char* fname = TEST_ROOT"/config.ini"; std::cout << fname << "\n"; const char* fname_tmp = TEST_ROOT"/config_tmp.ini"; - m_ds.reset(new DeviceSettings(toStringDec(clientSN).c_str())); + m_ds.reset(new DeviceSettings(clientName, toStringDec(clientSN))); assert(m_ds.get()); m_ds->loadDefaultValues(); boost::filesystem::remove(fname_tmp); @@ -157,7 +158,7 @@ BOOST_AUTO_TEST_CASE(load_db) { boost::scoped_ptr ds; //ds.reset(new DeviceSettings(toStringDec(clientSN).c_str())); - ds.reset(new DeviceSettings(devices[i].c_str())); + ds.reset(new DeviceSettings("UnknownName", devices[i])); assert(ds.get()); BOOST_CHECK(ds); Database db = ds->getDatabaseFiles();