Elmo Terminal provides functionality to test Lora radio and access SX1272 chip registers delivered with Elmo board. This firmware allows the user to control the LoRa radio parameters (eg. frequency, bandwidth, spreading factor etc.) by entering console commands via serial terminal. Application also contains "Ping-Pong" and data transmission functionalities.

Dependencies:   SX1272lib mbed

Fork of Elmo-Terminal by Michal Leksinski

Settings/Settings.cpp

Committer:
WGorniak
Date:
2015-10-01
Revision:
2:8d8295a51f68
Child:
3:bb58d4e78e68

File content as of revision 2:8d8295a51f68:

#include <sstream>
#include <cassert>
#include "Settings.h"

Settings::Settings(Variable* variables)
    : variables_(variables)
{
}

Variable& Settings::find(const std::string& variableName) const
{
    Variable* p  = variables_;
    for (;  !p->endGuard(); ++p)
    {
        if (p->name() == variableName)
        {
            return *p;
        }
    }
    return *p;
}

std::string Settings::describe(std::string variable) const
{
    const Variable& r = find(variable);

    std::ostringstream temp;
    temp << r.name() << ": " << r.describe();
    return temp.str();
}

int32_t Settings::get(std::string variable) const
{
    return find(variable).get();
}

int32_t Settings::aget(std::string variable) const
{
    int32_t v = get(variable);
    assert (v!=Variable::nonSetValue());
    return v;
}


bool Settings::set(std::string variable, int32_t value)
{
    return find(variable).set(value);
}

std::string Settings::help(std::string variable) const
{
    return find(variable).help();
}

std::string Settings::help() const
{
    std::ostringstream temp;
    for (Variable* p  = variables_;  !p->endGuard(); ++p)
    {
        temp << p->name() << ": " << p->help() << "\r\n";
    }
    return temp.str();
}

std::string Settings::values() const
{
    std::ostringstream temp;

    for (Variable* p  = variables_;  !p->endGuard(); ++p)
    {
        temp << p->name() << ": " << p->describe() << "\r\n";
    }
    return temp.str();
}