Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
ConfigChar Class Reference
Inheritance diagram for ConfigChar:
ConfigNumber< char > ConfigItem

Public Member Functions

 ConfigChar (const char *name, Storage &s, uint64_t addr, char min, char max, void(*onSet)(char)=nullptr)
bool handleCommand (const char *input, Print &p) override
void print (Print &p) override
Public Member Functions inherited from ConfigNumber< char >
 ConfigNumber (const char *name, Storage &s, uint64_t addr, char min, char max, void(*onSet)(char)=nullptr)
const char * getName () override
virtual char getValue ()
virtual error_t setValue (char newValue)
virtual bool isValid () override
virtual void printHelp (Print &p) override

Additional Inherited Members

Protected Member Functions inherited from ConfigNumber< char >
virtual void onValueSet () override
Protected Attributes inherited from ConfigNumber< char >
char * name
Storage & flash
const uint64_t addr
char min
char max
void(* onSet )(char)

Constructor & Destructor Documentation

◆ ConfigChar()

ConfigChar::ConfigChar ( const char * name,
Storage & s,
uint64_t addr,
char min,
char max,
void(* onSet )(char) = nullptr )
inline
9 : ConfigNumber<char>(name, s, addr, min, max, onSet) {
10 };

Member Function Documentation

◆ handleCommand()

bool ConfigChar::handleCommand ( const char * input,
Print & p )
inlineoverridevirtual

Reimplemented from ConfigNumber< char >.

12 {
13 std::string command = "get ";
14 command += this->name;
15
16 if (command == input) {
17 p.printf("\"result\":\"OK\",\"%s\":", this->name);
18 this->print(p);
19 return true;
20 }
21
22 command = "set ";
23 command += this->name;
24 command += ' ';
25
26 std::string inputCommand = input;
27 if (inputCommand.find(command) == 0) {
28 inputCommand = inputCommand.substr(command.length());
29 char v;
30 if (inputCommand.size() == 1) {
31 v = inputCommand[0];
32 } else {
33 p.printf("\"result\":\"parsing error: %s\"", inputCommand.c_str());
34 return true;
35 }
36
37 error_t err = this->setValue(v);
38 if (err == ERROR_SUCCESS) {
39 p.printf("\"result\":\"OK\",\"%s\":", this->name);
40 this->print(p);
41 this->onValueSet();
42 } else {
43 p.printf("\"result\":\"error '%c' -> (%d)\"", v, err);
44 }
45 return true;
46 }
47
48 return false;
49 };
virtual int printf(const char *,...)
printf 출력을 내보냅니다.
Definition Print.hpp:234
@ ERROR_SUCCESS
Definition nola-common.h:119

◆ print()

void ConfigChar::print ( Print & p)
inlineoverridevirtual

Reimplemented from ConfigNumber< char >.

51 {
52 char val = this->getValue();
53 if (isprint(val)) {
54 p.printf("'%c'", val);
55 } else {
56 p.printf("'\x02x'", val);
57 }
58
59 if (!this->isValid()) {
60 p.print(" /* invalid */");
61 }
62 };
size_t print(const __FlashStringHelper *)
프로그램 메모리(읽기 전용 플래시) 영역에 저장된 문자열을 출력합니다.

The documentation for this class was generated from the following file: