Simple Weather Service

Fix code formatting.
This commit is contained in:
Jean-François Milants 2023-12-23 17:22:32 +01:00 committed by JF
parent e5b73212f6
commit 6f83a3bade
3 changed files with 15 additions and 22 deletions

View file

@ -29,19 +29,12 @@ namespace {
enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown }; enum class MessageType : uint8_t { CurrentWeather, Forecast, Unknown };
uint64_t ToUInt64(const uint8_t* data) { uint64_t ToUInt64(const uint8_t* data) {
return data[0] + return data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24) + (static_cast<uint64_t>(data[4]) << 32) +
(data[1] << 8) + (static_cast<uint64_t>(data[5]) << 48) + (static_cast<uint64_t>(data[6]) << 48) + (static_cast<uint64_t>(data[7]) << 56);
(data[2] << 16) +
(data[3] << 24) +
(static_cast<uint64_t>(data[4]) << 32) +
(static_cast<uint64_t>(data[5]) << 48) +
(static_cast<uint64_t>(data[6]) << 48) +
(static_cast<uint64_t>(data[7]) << 56);
} }
int16_t ToInt16(const uint8_t* data) { int16_t ToInt16(const uint8_t* data) {
return data[0] + return data[0] + (data[1] << 8);
(data[1] << 8);
} }
SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) { SimpleWeatherService::CurrentWeather CreateCurrentWeather(const uint8_t* dataBuffer) {
@ -63,8 +56,7 @@ namespace {
const uint8_t nbDaysInBuffer = dataBuffer[10]; const uint8_t nbDaysInBuffer = dataBuffer[10];
const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer); const uint8_t nbDays = std::min(SimpleWeatherService::MaxNbForecastDays, nbDaysInBuffer);
for (int i = 0; i < nbDays; i++) { for (int i = 0; i < nbDays; i++) {
days[i] = SimpleWeatherService::Forecast::Day { days[i] = SimpleWeatherService::Forecast::Day {ToInt16(&dataBuffer[11 + (i * 5)]),
ToInt16(&dataBuffer[11 + (i * 5)]),
ToInt16(&dataBuffer[13 + (i * 5)]), ToInt16(&dataBuffer[13 + (i * 5)]),
SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}}; SimpleWeatherService::Icons {dataBuffer[15 + (i * 5)]}};
} }

View file

@ -62,6 +62,7 @@ namespace Pinetime {
}; };
using Location = std::array<char, 33>; // 32 char + \0 (end of string) using Location = std::array<char, 33>; // 32 char + \0 (end of string)
struct CurrentWeather { struct CurrentWeather {
CurrentWeather(uint64_t timestamp, CurrentWeather(uint64_t timestamp,
int16_t temperature, int16_t temperature,