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

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?

UserRevisionLine numberNew contents of line
WGorniak 2:8d8295a51f68 1 #include <sstream>
WGorniak 2:8d8295a51f68 2 #include <limits>
WGorniak 2:8d8295a51f68 3 #include "Variable.h"
WGorniak 2:8d8295a51f68 4
WGorniak 2:8d8295a51f68 5 Variable::ValueDescription Variable::none[] = {{0,0}};
WGorniak 2:8d8295a51f68 6
WGorniak 2:8d8295a51f68 7 int32_t Variable::nonSetValue()
WGorniak 2:8d8295a51f68 8 {
WGorniak 2:8d8295a51f68 9 return std::numeric_limits<int32_t>::min();
WGorniak 2:8d8295a51f68 10 }
WGorniak 2:8d8295a51f68 11
WGorniak 2:8d8295a51f68 12 Variable::Variable()
WGorniak 2:8d8295a51f68 13 : name_("")
WGorniak 2:8d8295a51f68 14 , description_("")
WGorniak 2:8d8295a51f68 15 , pValueDescriptions_(none)
WGorniak 2:8d8295a51f68 16 , value_(nonSetValue())
WGorniak 2:8d8295a51f68 17 {
WGorniak 2:8d8295a51f68 18 }
WGorniak 2:8d8295a51f68 19
WGorniak 2:8d8295a51f68 20 bool Variable::endGuard() const
WGorniak 2:8d8295a51f68 21 {
WGorniak 2:8d8295a51f68 22 return value_ == nonSetValue();
WGorniak 2:8d8295a51f68 23 }
WGorniak 2:8d8295a51f68 24
WGorniak 2:8d8295a51f68 25 Variable::Variable(const char* name, const char* description, int32_t value, const ValueDescription* const pValueDescriptions)
WGorniak 2:8d8295a51f68 26 : name_(name)
WGorniak 2:8d8295a51f68 27 , description_(description)
WGorniak 2:8d8295a51f68 28 , pValueDescriptions_(pValueDescriptions)
WGorniak 2:8d8295a51f68 29 , value_(value)
WGorniak 2:8d8295a51f68 30 {
WGorniak 2:8d8295a51f68 31 }
WGorniak 2:8d8295a51f68 32
WGorniak 2:8d8295a51f68 33 std::string Variable::name() const
WGorniak 2:8d8295a51f68 34 {
WGorniak 2:8d8295a51f68 35 return name_;
WGorniak 2:8d8295a51f68 36 }
WGorniak 2:8d8295a51f68 37
WGorniak 2:8d8295a51f68 38 std::string Variable::help() const
WGorniak 2:8d8295a51f68 39 {
WGorniak 2:8d8295a51f68 40 std::ostringstream temp;
WGorniak 2:8d8295a51f68 41
WGorniak 2:8d8295a51f68 42 temp << description_ << "\r\n";
WGorniak 2:8d8295a51f68 43
WGorniak 2:8d8295a51f68 44 for (const ValueDescription* p = pValueDescriptions_; !p->isEnd(); ++p)
WGorniak 2:8d8295a51f68 45 {
WGorniak 2:8d8295a51f68 46 if (p->isEndRange())
WGorniak 2:8d8295a51f68 47 {
WGorniak 2:8d8295a51f68 48 continue;
WGorniak 2:8d8295a51f68 49 }
WGorniak 2:8d8295a51f68 50
WGorniak 2:8d8295a51f68 51 temp << " ";
WGorniak 2:8d8295a51f68 52
WGorniak 2:8d8295a51f68 53 if ((p+1)->isEndRange())
WGorniak 2:8d8295a51f68 54 {
WGorniak 2:8d8295a51f68 55 temp << p->value << "..." << (p+1)->value << " " << p->description;
WGorniak 2:8d8295a51f68 56 }
WGorniak 2:8d8295a51f68 57 else
WGorniak 2:8d8295a51f68 58 {
WGorniak 2:8d8295a51f68 59 temp << p->value << ": " << p->description << " ";
WGorniak 2:8d8295a51f68 60 }
WGorniak 2:8d8295a51f68 61
WGorniak 2:8d8295a51f68 62 temp << "\r\n";
WGorniak 2:8d8295a51f68 63 }
WGorniak 2:8d8295a51f68 64
WGorniak 2:8d8295a51f68 65 std::string s = temp.str();
WGorniak 2:8d8295a51f68 66 return s;
WGorniak 2:8d8295a51f68 67 }
WGorniak 2:8d8295a51f68 68
WGorniak 2:8d8295a51f68 69 std::string Variable::describe(int32_t value) const
WGorniak 2:8d8295a51f68 70 {
WGorniak 2:8d8295a51f68 71 for (const ValueDescription* p = pValueDescriptions_; !p->isEnd(); ++p)
WGorniak 2:8d8295a51f68 72 {
WGorniak 2:8d8295a51f68 73 if (p->value > value || p->isEndRange())
WGorniak 2:8d8295a51f68 74 {
WGorniak 2:8d8295a51f68 75 continue;
WGorniak 2:8d8295a51f68 76 }
WGorniak 2:8d8295a51f68 77
WGorniak 2:8d8295a51f68 78 if ((p+1)->isEndRange())
WGorniak 2:8d8295a51f68 79 {
WGorniak 2:8d8295a51f68 80 if ((p->value <= value) && (value <= (p+1)->value))
WGorniak 2:8d8295a51f68 81 {
WGorniak 2:8d8295a51f68 82 std::ostringstream temp;
WGorniak 2:8d8295a51f68 83 temp << value << " " << p->description;
WGorniak 2:8d8295a51f68 84 return temp.str();
WGorniak 2:8d8295a51f68 85 }
WGorniak 2:8d8295a51f68 86 } else
WGorniak 2:8d8295a51f68 87 if (p->value == value)
WGorniak 2:8d8295a51f68 88 {
WGorniak 2:8d8295a51f68 89 std::ostringstream temp;
WGorniak 2:8d8295a51f68 90 temp << value << " - " << p->description;
WGorniak 2:8d8295a51f68 91 return temp.str();
WGorniak 2:8d8295a51f68 92 }
WGorniak 2:8d8295a51f68 93 }
WGorniak 2:8d8295a51f68 94 return "";
WGorniak 2:8d8295a51f68 95 }
WGorniak 2:8d8295a51f68 96
WGorniak 2:8d8295a51f68 97 bool Variable::set(int32_t value)
WGorniak 2:8d8295a51f68 98 {
WGorniak 2:8d8295a51f68 99 if (describe(value).size() == 0)
WGorniak 2:8d8295a51f68 100 {
WGorniak 2:8d8295a51f68 101 return false;
WGorniak 2:8d8295a51f68 102 }
WGorniak 2:8d8295a51f68 103 value_ = value;
WGorniak 2:8d8295a51f68 104 return true;
WGorniak 2:8d8295a51f68 105 }
WGorniak 2:8d8295a51f68 106
WGorniak 2:8d8295a51f68 107 int32_t Variable::get() const
WGorniak 2:8d8295a51f68 108 {
WGorniak 2:8d8295a51f68 109 return value_;
WGorniak 2:8d8295a51f68 110 }
WGorniak 2:8d8295a51f68 111
WGorniak 2:8d8295a51f68 112 std::string Variable::describe() const
WGorniak 2:8d8295a51f68 113 {
WGorniak 2:8d8295a51f68 114 return describe(get());
WGorniak 2:8d8295a51f68 115 }