| 3157 | #endif |
| 3158 | |
| 3159 | void getTemplate(JsonDocument &json, const uint8_t id, const uint8_t hwtype) { |
| 3160 | JsonDocument filter; |
| 3161 | JsonDocument doc; |
| 3162 | |
| 3163 | const String idstr = String(id); |
| 3164 | constexpr const char *templateKey = "template"; |
| 3165 | |
| 3166 | char filename[20]; |
| 3167 | snprintf(filename, sizeof(filename), "/tagtypes/%02X.json", hwtype); |
| 3168 | File jsonFile = contentFS->open(filename, "r"); |
| 3169 | |
| 3170 | if (jsonFile) { |
| 3171 | filter[templateKey][idstr] = true; |
| 3172 | filter["usetemplate"] = true; |
| 3173 | const DeserializationError error = deserializeJson(doc, jsonFile, DeserializationOption::Filter(filter)); |
| 3174 | jsonFile.close(); |
| 3175 | if (!error && doc[templateKey].is<JsonVariant>() && doc[templateKey][idstr].is<JsonVariant>()) { |
| 3176 | json.set(doc[templateKey][idstr]); |
| 3177 | return; |
| 3178 | } |
| 3179 | if (!error && doc["usetemplate"].is<uint8_t>()) { |
| 3180 | getTemplate(json, id, doc["usetemplate"]); |
| 3181 | return; |
| 3182 | } |
| 3183 | Serial.println("json error in " + String(filename)); |
| 3184 | Serial.println(error.c_str()); |
| 3185 | } else { |
| 3186 | Serial.println("Failed to open " + String(filename)); |
| 3187 | } |
| 3188 | } |
no test coverage detected