Skip to content
Snippets Groups Projects
Commit 91b92264 authored by fxk8y's avatar fxk8y :spider:
Browse files

Polishing get_type API entpoint

parent c562a70b
No related branches found
No related tags found
No related merge requests found
...@@ -603,6 +603,12 @@ namespace SiliconTorch { ...@@ -603,6 +603,12 @@ namespace SiliconTorch {
} )); } ));
qthing::add_binary_message_callback(requestTopic("get_type/+/+"), wrapMessageHandler(
[&](std::vector<std::string>& topic, qthing::multipart_message_t msg) {
qthing::publish_message(responseTopic("get_type", topic[1], topic[2]), getTypeStr(topic[1], topic[2]));
} ));
} }
...@@ -1096,6 +1102,85 @@ namespace SiliconTorch { ...@@ -1096,6 +1102,85 @@ namespace SiliconTorch {
} }
/**
* Converts IDF NVS types to strings
*/
std::string NVSExplorer::type2str(nvs_type_t typ) {
switch (typ) {
case NVS_TYPE_U8: return "u8";
case NVS_TYPE_U16: return "u16";
case NVS_TYPE_U32: return "u32";
case NVS_TYPE_U64: return "u64";
case NVS_TYPE_I8: return "i8";
case NVS_TYPE_I16: return "i16";
case NVS_TYPE_I32: return "i32";
case NVS_TYPE_I64: return "i64";
case NVS_TYPE_STR: return "str";
case NVS_TYPE_BLOB: return "blob";
default: return "any";
}
}
/**
* Get the type of the entry, NVS_TYPE_ANY if not found
*/
nvs_type_t NVSExplorer::getType(const std::string& nameSpace, const std::string& key) {
nvs_type_t entryType = NVS_TYPE_ANY;
nvs_iterator_t it = nvs_entry_find("nvs", nameSpace.c_str(), NVS_TYPE_ANY);
while (it != NULL) {
nvs_entry_info_t entry;
nvs_entry_info(it, &entry);
if (key.compare(entry.key) == 0) {
entryType = entry.type;
nvs_release_iterator(it);
return entryType;
}
it = nvs_entry_next(it);
}
return entryType;
}
/**
* Like getType but converts them to string
* non-existing keys are converted to `void` instead of `any`
*/
std::string NVSExplorer::getTypeStr(const std::string& nameSpace, const std::string& key) {
bool entryFound = false;
nvs_type_t entryType = NVS_TYPE_ANY;
nvs_iterator_t it = nvs_entry_find("nvs", nameSpace.c_str(), NVS_TYPE_ANY);
while (it != NULL) {
nvs_entry_info_t entry;
nvs_entry_info(it, &entry);
if (key.compare(entry.key) == 0) {
entryFound = true;
entryType = entry.type;
nvs_release_iterator(it);
break;
}
it = nvs_entry_next(it);
}
std::string typ;
if (entryFound) typ = type2str(entryType);
else typ = "void";
return typ;
}
std::string NVSExplorer::deviceTopic(const std::string& suffix) { std::string NVSExplorer::deviceTopic(const std::string& suffix) {
return std::string(DEVICE_NAMESPACE + "NVS/") + suffix; return std::string(DEVICE_NAMESPACE + "NVS/") + suffix;
} }
......
...@@ -88,6 +88,11 @@ namespace SiliconTorch { ...@@ -88,6 +88,11 @@ namespace SiliconTorch {
bool setString(const std::string& nameSpace, const std::string& key, const std::string& value); bool setString(const std::string& nameSpace, const std::string& key, const std::string& value);
std::string type2str(nvs_type_t typ);
nvs_type_t getType(const std::string& nameSpace, const std::string& key);
std::string getTypeStr(const std::string& nameSpace, const std::string& key);
std::string deviceTopic(const std::string& suffix); std::string deviceTopic(const std::string& suffix);
std::string requestTopic(const std::string& cmd); std::string requestTopic(const std::string& cmd);
......
...@@ -51,6 +51,11 @@ In the following list, `argument` stands for the message content received on the ...@@ -51,6 +51,11 @@ In the following list, `argument` stands for the message content received on the
response: `RESPONSE/get/NS/KEY` response: `RESPONSE/get/NS/KEY`
description: reads the value and returns it in its natural form description: reads the value and returns it in its natural form
- `get_type` - **get type of key**
request: `REQUEST/get_type/NS/KEY`
response: `RESPONSE/get_type/NS/KEY`
description: reads the type and converts it to `string`; returns `void` in case of non-existing `key`
- `get_raw` - **get generic value** - `get_raw` - **get generic value**
request: `REQUEST/get_raw/NS/KEY` request: `REQUEST/get_raw/NS/KEY`
response: `RESPONSE/get_raw/NS/KEY` response: `RESPONSE/get_raw/NS/KEY`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment