Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: NWSWeather.h
- Revision:
- 18:699590fd8856
- Parent:
- 17:99f09cc697fb
--- a/NWSWeather.h Wed Jan 09 12:39:06 2019 +0000 +++ b/NWSWeather.h Mon Jan 14 03:21:13 2019 +0000 @@ -123,11 +123,32 @@ char * sValue; ///< the string value } Value_T; - /// The internal maintenance structure. + /// The array that defines what XML information to extract. + /// + /// It will not honor heirarchical XML tagging, each parsed + /// tag must be in the same text line. + /// + /// Given two types of XML structure: + /// 1) <sunrise>6:45 am</sunrise> + /// 2) <sun rise="6:45 am" set="4:52 pm"> + /// + /// The key-value pairs can be defines to support either: + /// "sunrise", NULL, NWSWeather::isString + /// "sun", "rise", NWSWeather::isString + /// + /// @code + /// static NWSWeather::XMLItem_T WeatherData[] = { + /// {"weather", "value", NWSWeather::isString}, //<weather number="802" value="scattered clouds" icon="03n"/> + /// {"temperature", "value", NWSWeather::isFloat}, //<temperature value="27.3" min="21.2" max="32" unit="fahrenheit"/> + /// {"sun", "rise", NWSWeather::isString}, + /// {"sun", "set", NWSWeather::isString}, + /// }; + /// @endcode typedef struct { - const char * name; - TypeOf_T typeis; + const char * key; ///< pointer to the XML key of interest + const char * param; ///< pointer to the parameter, or NULL if the key defines it + TypeOf_T typeis; ///< the type of data bool updated; Value_T value; } XMLItem_T; @@ -183,7 +204,7 @@ /// http://forecast.weather.gov/MapClick.php?lat=42.47508&lon=-92.36704926700929 // &unit=0&lg=english&FcstType=dwml /// - NWSWeather(const char * baseurl = DEF_URL); + NWSWeather(XMLItem_T * pList, int count); /// Destructor. ~NWSWeather(); @@ -209,7 +230,7 @@ /// @returns success/failure code. @see NWSReturnCode_T. /// NWSReturnCode_T get(const char * site, int responseSize = 2500); - #elif OPEN_WEATHER == 1 + #elif OPEN_WEATHER == 1 /// get the current conditions weather data from the specified site. /// /// This does the work to fetch the weather data from openweathermap.org, @@ -222,9 +243,9 @@ /// should temporarily allocate to receive and process the data. /// @returns success/failure code. @see NWSReturnCode_T. /// - NWSReturnCode_T get(const char * site, const char * userid, int responseSize = 2500); + NWSReturnCode_T get(const char * site, const char * userid, int responseSize = 1000); #endif - + /// get the count of the number of weather parameters. /// /// @returns the count of the number of parameters for which @@ -280,6 +301,28 @@ /// NWSReturnCode_T getParam(uint16_t i, char *name, Value_T *value = NULL, TypeOf_T *typeis = NULL); + + /// get one of the weather parameters. + /// + /// This searchs the parameter set for the named parameter, and if found + /// it will set the user supplied pointers to the value and type information + /// for that parameter. + /// + /// @code + /// char sunrise[30]; TypeOf_T type; + /// if (wx.getParam("sun", "rise", &sunrise, &type) == noerror) { + /// // print the values + /// } + /// @endcode + /// + /// @param[in] name is a const pointer to a string naming the parameter of interest. + /// @param[in] param is the secondary part of the parameter. + /// @param[out] value is a pointer that is set to point to the value of parameter i. + /// @param[out] typeis is a pointer that is set to indicate the type of the value. + /// @returns success/failure code. @see NWSReturnCode_T. + /// + NWSReturnCode_T getParam(const char *name, const char * param, Value_T *value, TypeOf_T *typeis = NULL); + /// get one of the weather parameters. /// /// This searchs the parameter set for the named parameter, and if found @@ -322,6 +365,11 @@ private: char * m_baseurl; NWSReturnCode_T ParseWeatherRecord(char * p); + NWSReturnCode_T ExtractParam(int i, char * pValue, char * pEnd); void ParseWeatherXML(char * message); + + XMLItem_T * WeatherData; + int WeatherItemCount; + }; #endif // NWSWEATHER_H \ No newline at end of file