From 8558ef7aea21aee58e3bbd95611bbdd9e29143ed Mon Sep 17 00:00:00 2001 From: "Piotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/Samsung Electronics" Date: Wed, 27 Nov 2019 14:16:11 +0100 Subject: [PATCH] [ham] Fixed sleep recorder, returned value [Bug] there was missing conversion from numerical value from database to string value used in Web API [Verification] TCT passrate 100% on wearable TW3. Below code works when activity added manually to database. var data = []; date = new Date(), startTime = date.getTime(), endTime = date.setDate(date.getDate() + 1), query = { startTime: startTime/1000, endTime: endTime/1000, interval: 1440 }; tizen.humanactivitymonitor.readRecorderData("SLEEP_MONITOR", query, (s) => console.log(data = s), (s) => console.log(s)) returns one of values of "ASLEEP", "AWAKE", or "UNKNOWN" Change-Id: I86b6bead534638bafcb5abcb16512bb462c79374 --- .../humanactivitymonitor_manager.cc | 56 ++++++++++++++-------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 13f3a0c..4a4519b 100644 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -1410,6 +1410,29 @@ class HumanActivityMonitorManager::ActivityRecognition { std::map> activity_data_; }; +PlatformResult SleepStateToString(int state, std::string* sleep_state) { + ScopeLogger("%d", state); + if (sleep_state) { + switch (state) { + case SENSOR_SLEEP_STATE_WAKE: + *sleep_state = kSleepStateAwake; + break; + case SENSOR_SLEEP_STATE_SLEEP: + *sleep_state = kSleepStateAsleep; + break; + case SENSOR_SLEEP_STATE_UNKNOWN: + *sleep_state = kSleepStateUnknown; + break; + default: + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown sleep state", + ("Unknown sleep state: %d", state)); + } + return PlatformResult(ErrorCode::NO_ERROR); + } + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Cannot return sleep state, return pointer is null"); +} + HumanActivityMonitorManager::HumanActivityMonitorManager() : activity_recognition_(std::make_shared()) { ScopeLogger(); @@ -1454,23 +1477,9 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() sensor_sleep_state_e state = static_cast(event->values[0]); std::string sleep_state; - - switch (state) { - case SENSOR_SLEEP_STATE_WAKE: - sleep_state = kSleepStateAwake; - break; - - case SENSOR_SLEEP_STATE_SLEEP: - sleep_state = kSleepStateAsleep; - break; - - case SENSOR_SLEEP_STATE_UNKNOWN: - sleep_state = kSleepStateUnknown; - break; - - default: - return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown sleep state", - ("Unknown sleep state: %d", state)); + PlatformResult result = SleepStateToString(state, &sleep_state); + if (!result) { + return result; } data->insert(std::make_pair(kStatus, picojson::value(sleep_state))); @@ -1498,13 +1507,22 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() auto convert_recorded_sleep_monitor = [](void* data, picojson::object* obj) -> PlatformResult { ScopeLogger("Entered into asynchronous function, convert_recorded_sleep_monitor"); - SensorRecorderDataMap map_int{{SENSOR_RECORDER_DATA_SLEEP_STATE, kStatus}}; + int state = 0; + int ret = sensor_recorder_data_get_int(data, SENSOR_RECORDER_DATA_SLEEP_STATE, &state); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult( + getErrorCode(ret), "Failed to get int value", + ("Failed to get int value, error: %d (%s)", ret, get_error_message(ret))); + } - auto result = ConvertRecordedInt(data, obj, map_int); + std::string sleep_state; + PlatformResult result = SleepStateToString(state, &sleep_state); if (!result) { return result; } + obj->insert(std::make_pair(kStatus, picojson::value(sleep_state))); + return ConvertRecordedTime(data, obj); }; -- 2.7.4