#include #include #include "errors.h" #include // Old URL #define METAR_URL "http://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT" // JMA Amedas data. #define AMEDAS_LATEST_URL "https://www.jma.go.jp/bosai/amedas/data/latest_time.txt" #define AMEDAS_POINT_URL "https://www.jma.go.jp/bosai/amedas/data/point/%s/%s_%s.json" class localtemp { public: enum ESky { undef_sky, clear, // Fine weather (no precipitation reported) cloudy, // Reserved (not reported by Amedas) brkovc, // Reserved (not reported by Amedas) tcu // Reserved (not reported by Amedas) }; enum ERain { undef_rain, rain, // precipitation10m > 0, temperature > 2C snow, // precipitation10m > 0, temperature <= 2C hail // Reserved (not reported by Amedas) }; enum EFog { undef_fog, fog, // Reserved (not reported by Amedas) dust, // Reserved (not reported by Amedas) other // Reserved (not reported by Amedas) }; struct TMetar { ESky sky; bool CB; // Cumulonimbus (unused, kept for compatibility) ERain rain; EFog fog; }; std::string metar; std::string location_name; std::string long_location; std::string ob; // Raw "HHMM" observation block extracted from the JSON int error, celsius, fahrenheit; int theme; // º theme to use short humidity; bool loaded; string sky; TMetar mInfo; time_t info_time; // Time stored in file time_t get_time; // Time when we got the file localtemp(char* metar, char* location_name); bool getInfo(); private: void set_temp(double temp_c); void set_humidity(int hum); void get_ob_info(double precip10m, double sun10m, time_t observation_time); bool fetch_latest_time(std::string &yyyymmdd, std::string &hhmmss, std::string &block3h, time_t &obs_utc); bool extract_json_number(const std::string &json, const std::string &key, double &value); };