feat: implement MTR Next Train Handler with arrival and line info parsing
This commit is contained in:
28
main/external/mtr/station_info.cpp
vendored
Normal file
28
main/external/mtr/station_info.cpp
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
#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());
|
||||
}
|
||||
Reference in New Issue
Block a user