Files
ink-board/main/external/mtr/station_info.cpp

29 lines
828 B
C++

#include "external/mtr/station_info.h"
#include "cJSON.h"
#include "esp_log.h"
StationInfo::StationInfo(cJSON* station_json) {
if (!station_json) {
ESP_LOGE(STATION_INFO_TAG, "station_json is null");
return;
}
// Parse station code
cJSON* code_json = cJSON_GetObjectItem(station_json, "code");
if (code_json && cJSON_IsString(code_json)) {
_code = code_json->valuestring;
} else {
ESP_LOGW(STATION_INFO_TAG, "Missing or invalid 'code' field");
}
// Parse station name
cJSON* name_json = cJSON_GetObjectItem(station_json, "name");
if (name_json && cJSON_IsString(name_json)) {
_name = name_json->valuestring;
} else {
ESP_LOGW(STATION_INFO_TAG, "Missing or invalid 'name' field");
}
ESP_LOGD(STATION_INFO_TAG, "Created StationInfo: %s (%s)", _name.c_str(), _code.c_str());
}