Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ralovich/antpm
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristof Ralovich committed Aug 2, 2023
2 parents f009c4e + 0f66aa7 commit de919a4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/AntFr310XT.cpp
Expand Up @@ -437,11 +437,12 @@ AntFr310XT::handleEvents()

LOG(LOG_RAW) << "\n\nFound client \"" << clientDevName << "\" SN=0x" << toString<uint>(clientSN,8,'0') << " SN=" << clientSN << "\n\n\n";

m_ds.reset(new DeviceSettings(toStringDec<uint>(clientSN).c_str()));
m_ds.reset(new DeviceSettings(clientDevName, toStringDec<uint>(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);

Expand Down
2 changes: 1 addition & 1 deletion src/AntMessenger.cpp
Expand Up @@ -1135,7 +1135,7 @@ AntMessenger::onMessage(std::vector<AntMessage> 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());
}

}
Expand Down
9 changes: 6 additions & 3 deletions src/DeviceSettings.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -64,7 +65,7 @@ DeviceSettings::getConfigFileName() const
const std::string
DeviceSettings::getFolder() const
{
return getConfigFolder() + "/" + mDevId + "/";
return getConfigFolder() + "/" + mDevSN + "/";
}

// std::vector<DatabaseEntity>
Expand Down Expand Up @@ -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));
Expand Down
5 changes: 3 additions & 2 deletions src/DeviceSettings.hpp
Expand Up @@ -40,7 +40,7 @@ typedef std::pair<uint16_t, FITEntity> DatabaseEntity;
class DeviceSettings
{
public:
DeviceSettings(const char* devId);
DeviceSettings(const std::string& devName, const std::string& devSN);

void loadDefaultValues();
const std::string getConfigFileName() const;
Expand All @@ -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;
};

}
5 changes: 3 additions & 2 deletions src/tests/testDeviceSettings.cpp
Expand Up @@ -107,12 +107,13 @@ BOOST_AUTO_TEST_CASE(convert)
BOOST_AUTO_TEST_CASE(load_save)
{
boost::scoped_ptr<DeviceSettings> 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<uint>(clientSN).c_str()));
m_ds.reset(new DeviceSettings(clientName, toStringDec<uint>(clientSN)));
assert(m_ds.get());
m_ds->loadDefaultValues();
boost::filesystem::remove(fname_tmp);
Expand Down Expand Up @@ -157,7 +158,7 @@ BOOST_AUTO_TEST_CASE(load_db)
{
boost::scoped_ptr<DeviceSettings> ds;
//ds.reset(new DeviceSettings(toStringDec<uint>(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();
Expand Down

0 comments on commit de919a4

Please sign in to comment.