summaryrefslogtreecommitdiff
path: root/src/components/ble/weather/WeatherService.cpp
diff options
context:
space:
mode:
authorAvamander <avamander@gmail.com>2021-06-20 21:37:53 +0300
committerAvamander <avamander@gmail.com>2021-12-04 22:03:40 +0200
commit4b2dcbb4f053a89faab50c03083c71fabf9f288a (patch)
tree6fc3aba5c8c2c3fbe5cf893479d30d748814ca1c /src/components/ble/weather/WeatherService.cpp
parent4349657f799bed04538d95c8d54653586100e82e (diff)
Fixed a few bugs, enabled UsefulBuf library optimizations
Diffstat (limited to 'src/components/ble/weather/WeatherService.cpp')
-rw-r--r--src/components/ble/weather/WeatherService.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/components/ble/weather/WeatherService.cpp b/src/components/ble/weather/WeatherService.cpp
index 60e608e7..30d274b2 100644
--- a/src/components/ble/weather/WeatherService.cpp
+++ b/src/components/ble/weather/WeatherService.cpp
@@ -33,7 +33,7 @@ namespace Pinetime {
void WeatherService::Init() {
uint8_t res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
- ASSERT(res == 0)
+ ASSERT(res == 0);
res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
@@ -64,13 +64,13 @@ namespace Pinetime {
QCBORDecode_GetInt64InMapSZ(&decodeContext, "Timestamp", &tmpTimestamp);
int64_t tmpExpires = 0;
QCBORDecode_GetInt64InMapSZ(&decodeContext, "Expires", &tmpExpires);
- if (tmpExpires > 4294967295) {
+ if (tmpExpires < 0 || tmpExpires > 4294967295) {
// TODO: Return better error?
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
int64_t tmpEventType = 0;
QCBORDecode_GetInt64InMapSZ(&decodeContext, "EventType", &tmpEventType);
- if (tmpEventType > static_cast<int64_t>(WeatherData::eventtype::Length)) {
+ if (tmpEventType < 0 || tmpEventType > static_cast<int64_t>(WeatherData::eventtype::Length)) {
// TODO: Return better error?
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
@@ -82,7 +82,18 @@ namespace Pinetime {
airquality->timestamp = tmpTimestamp;
airquality->eventType = static_cast<WeatherData::eventtype>(tmpEventType);
airquality->expires = tmpExpires;
-
+ UsefulBufC String;
+ QCBORDecode_GetTextStringInMapSZ(&decodeContext, "Polluter", &String);
+ if (UsefulBuf_IsNULLOrEmptyC(String) != 0) {
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+ }
+ airquality->polluter = std::make_unique<std::string>(static_cast<const char*>(String.ptr), String.len);
+ int64_t tmpAmount = 0;
+ QCBORDecode_GetInt64InMapSZ(&decodeContext, "Amount", &tmpAmount);
+ if (tmpAmount < 0 || tmpAmount > 4294967295) {
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+ }
+ airquality->amount = tmpAmount;
timeline.push_back(std::move(airquality));
break;
}