Elmo Terminal provides functionality to test Lora radio and access SX1272 chip registers delivered with Elmo board. Also contains example ping-pong application.
Dependencies: SX1272lib mbed-src
Settings/Settings.cpp@2:8d8295a51f68, 2015-10-01 (annotated)
- Committer:
- WGorniak
- Date:
- Thu Oct 01 09:40:30 2015 +0200
- Revision:
- 2:8d8295a51f68
- Child:
- 3:bb58d4e78e68
added terminal app
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WGorniak | 2:8d8295a51f68 | 1 | #include <sstream> |
WGorniak | 2:8d8295a51f68 | 2 | #include <cassert> |
WGorniak | 2:8d8295a51f68 | 3 | #include "Settings.h" |
WGorniak | 2:8d8295a51f68 | 4 | |
WGorniak | 2:8d8295a51f68 | 5 | Settings::Settings(Variable* variables) |
WGorniak | 2:8d8295a51f68 | 6 | : variables_(variables) |
WGorniak | 2:8d8295a51f68 | 7 | { |
WGorniak | 2:8d8295a51f68 | 8 | } |
WGorniak | 2:8d8295a51f68 | 9 | |
WGorniak | 2:8d8295a51f68 | 10 | Variable& Settings::find(const std::string& variableName) const |
WGorniak | 2:8d8295a51f68 | 11 | { |
WGorniak | 2:8d8295a51f68 | 12 | Variable* p = variables_; |
WGorniak | 2:8d8295a51f68 | 13 | for (; !p->endGuard(); ++p) |
WGorniak | 2:8d8295a51f68 | 14 | { |
WGorniak | 2:8d8295a51f68 | 15 | if (p->name() == variableName) |
WGorniak | 2:8d8295a51f68 | 16 | { |
WGorniak | 2:8d8295a51f68 | 17 | return *p; |
WGorniak | 2:8d8295a51f68 | 18 | } |
WGorniak | 2:8d8295a51f68 | 19 | } |
WGorniak | 2:8d8295a51f68 | 20 | return *p; |
WGorniak | 2:8d8295a51f68 | 21 | } |
WGorniak | 2:8d8295a51f68 | 22 | |
WGorniak | 2:8d8295a51f68 | 23 | std::string Settings::describe(std::string variable) const |
WGorniak | 2:8d8295a51f68 | 24 | { |
WGorniak | 2:8d8295a51f68 | 25 | const Variable& r = find(variable); |
WGorniak | 2:8d8295a51f68 | 26 | |
WGorniak | 2:8d8295a51f68 | 27 | std::ostringstream temp; |
WGorniak | 2:8d8295a51f68 | 28 | temp << r.name() << ": " << r.describe(); |
WGorniak | 2:8d8295a51f68 | 29 | return temp.str(); |
WGorniak | 2:8d8295a51f68 | 30 | } |
WGorniak | 2:8d8295a51f68 | 31 | |
WGorniak | 2:8d8295a51f68 | 32 | int32_t Settings::get(std::string variable) const |
WGorniak | 2:8d8295a51f68 | 33 | { |
WGorniak | 2:8d8295a51f68 | 34 | return find(variable).get(); |
WGorniak | 2:8d8295a51f68 | 35 | } |
WGorniak | 2:8d8295a51f68 | 36 | |
WGorniak | 2:8d8295a51f68 | 37 | int32_t Settings::aget(std::string variable) const |
WGorniak | 2:8d8295a51f68 | 38 | { |
WGorniak | 2:8d8295a51f68 | 39 | int32_t v = get(variable); |
WGorniak | 2:8d8295a51f68 | 40 | assert (v!=Variable::nonSetValue()); |
WGorniak | 2:8d8295a51f68 | 41 | return v; |
WGorniak | 2:8d8295a51f68 | 42 | } |
WGorniak | 2:8d8295a51f68 | 43 | |
WGorniak | 2:8d8295a51f68 | 44 | |
WGorniak | 2:8d8295a51f68 | 45 | bool Settings::set(std::string variable, int32_t value) |
WGorniak | 2:8d8295a51f68 | 46 | { |
WGorniak | 2:8d8295a51f68 | 47 | return find(variable).set(value); |
WGorniak | 2:8d8295a51f68 | 48 | } |
WGorniak | 2:8d8295a51f68 | 49 | |
WGorniak | 2:8d8295a51f68 | 50 | std::string Settings::help(std::string variable) const |
WGorniak | 2:8d8295a51f68 | 51 | { |
WGorniak | 2:8d8295a51f68 | 52 | return find(variable).help(); |
WGorniak | 2:8d8295a51f68 | 53 | } |
WGorniak | 2:8d8295a51f68 | 54 | |
WGorniak | 2:8d8295a51f68 | 55 | std::string Settings::help() const |
WGorniak | 2:8d8295a51f68 | 56 | { |
WGorniak | 2:8d8295a51f68 | 57 | std::ostringstream temp; |
WGorniak | 2:8d8295a51f68 | 58 | for (Variable* p = variables_; !p->endGuard(); ++p) |
WGorniak | 2:8d8295a51f68 | 59 | { |
WGorniak | 2:8d8295a51f68 | 60 | temp << p->name() << ": " << p->help() << "\r\n"; |
WGorniak | 2:8d8295a51f68 | 61 | } |
WGorniak | 2:8d8295a51f68 | 62 | return temp.str(); |
WGorniak | 2:8d8295a51f68 | 63 | } |
WGorniak | 2:8d8295a51f68 | 64 | |
WGorniak | 2:8d8295a51f68 | 65 | std::string Settings::values() const |
WGorniak | 2:8d8295a51f68 | 66 | { |
WGorniak | 2:8d8295a51f68 | 67 | std::ostringstream temp; |
WGorniak | 2:8d8295a51f68 | 68 | |
WGorniak | 2:8d8295a51f68 | 69 | for (Variable* p = variables_; !p->endGuard(); ++p) |
WGorniak | 2:8d8295a51f68 | 70 | { |
WGorniak | 2:8d8295a51f68 | 71 | temp << p->name() << ": " << p->describe() << "\r\n"; |
WGorniak | 2:8d8295a51f68 | 72 | } |
WGorniak | 2:8d8295a51f68 | 73 | return temp.str(); |
WGorniak | 2:8d8295a51f68 | 74 | } |
WGorniak | 2:8d8295a51f68 | 75 |