1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include <string.h>
#include <strings.h>
#include "errors.h"
#include <time.h>
// 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_00.json"
class localtemp {
public:
enum ESky
{
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);
bool fetch_latest_time(std::string &yyyymmdd, std::string &hhmm, time_t &obs_utc);
bool extract_json_number(const std::string &json, const std::string &key, double &value);
};
|