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.
Fork of mbed-client by
Diff: source/m2mreporthandler.cpp
- Revision:
- 4:ae5178938864
- Parent:
- 1:79b6cc67d8b4
--- a/source/m2mreporthandler.cpp Fri Feb 19 17:44:50 2016 +0000 +++ b/source/m2mreporthandler.cpp Sat Apr 02 00:31:13 2016 +0300 @@ -17,10 +17,12 @@ #include "mbed-client/m2mconstants.h" #include "mbed-client/m2mtimer.h" #include "include/m2mreporthandler.h" -#include "ns_trace.h" +#include "mbed-trace/mbed_trace.h" #include <stdio.h> #include <string.h> +#define TRACE_GROUP "mClt" + M2MReportHandler::M2MReportHandler(M2MReportObserver &observer) : _observer(observer), _pmax(-1.0f), @@ -93,9 +95,23 @@ } } -void M2MReportHandler::set_notification_trigger() +void M2MReportHandler::set_notification_trigger(uint16_t obj_instance_id) { - tr_debug("M2MReportHandler::set_notification_trigger()"); + tr_debug("M2MReportHandler::set_notification_trigger(): %d", obj_instance_id); + // Add to array if not there yet + m2m::Vector<uint16_t>::const_iterator it; + it = _changed_instance_ids.begin(); + bool found = false; + for ( ; it != _changed_instance_ids.end(); it++) { + if ((*it) == obj_instance_id) { + found = true; + break; + } + } + if (!found) { + _changed_instance_ids.push_back(obj_instance_id); + } + _current_value = 0.0f; _last_value = 1.0f; schedule_report(); @@ -214,65 +230,60 @@ memset(&value, 0, 20); char* pos = strstr(option, EQUAL.c_str()); - if( pos != NULL ){ + if( pos != NULL ){ memcpy(attribute, option, (size_t)(pos-option)); pos++; - memcpy(value, pos, 20); + memcpy(value, pos, strlen(pos)); }else{ memcpy(attribute, option, (size_t)strlen(option) + 1); } - if (strcmp(attribute, PMIN.c_str()) == 0) { - sscanf(value, "%f", &_pmin); - success = true; - _attribute_state |= M2MReportHandler::Pmin; - tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _pmin); - } - else if(strcmp(attribute, PMAX.c_str()) == 0) { - sscanf(value, "%f", &_pmax); - success = true; - _attribute_state |= M2MReportHandler::Pmax; - tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _pmax); - } - else if(strcmp(attribute, GT.c_str()) == 0 && - (M2MBase::Resource == type)){ - sscanf(value, "%f", &_gt); - success = true; - _attribute_state |= M2MReportHandler::Gt; - tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _gt); - } - else if(strcmp(attribute, LT.c_str()) == 0 && - (M2MBase::Resource == type)){ - sscanf(value, "%f", &_lt); - success = true; - _attribute_state |= M2MReportHandler::Lt; - tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _lt); + if (strlen(value)) { + if (strcmp(attribute, PMIN.c_str()) == 0) { + _pmin = atoi(value); + success = true; + _attribute_state |= M2MReportHandler::Pmin; + tr_debug("M2MReportHandler::set_notification_attribute %s to %d", attribute, _pmin); + } + else if(strcmp(attribute, PMAX.c_str()) == 0) { + _pmax = atoi(value); + success = true; + _attribute_state |= M2MReportHandler::Pmax; + tr_debug("M2MReportHandler::set_notification_attribute %s to %d", attribute, _pmax); + } + else if(strcmp(attribute, GT.c_str()) == 0 && + (M2MBase::Resource == type)){ + _gt = atof(value); + success = true; + _attribute_state |= M2MReportHandler::Gt; + tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _gt); + } + else if(strcmp(attribute, LT.c_str()) == 0 && + (M2MBase::Resource == type)){ + _lt = atof(value); + success = true; + _attribute_state |= M2MReportHandler::Lt; + tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _lt); + } + else if((strcmp(attribute, ST.c_str()) == 0 || (strcmp(attribute, STP.c_str()) == 0)) + && (M2MBase::Resource == type)){ + _st = atof(value); + success = true; + _high_step = _current_value + _st; + _low_step = _current_value - _st; + _attribute_state |= M2MReportHandler::St; + tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _st); + } + // Return false if try to set gt,lt or st when the resource type is something else than numerical + if ((resource_type != M2MResourceInstance::INTEGER && + resource_type != M2MResourceInstance::FLOAT) && + ((_attribute_state & M2MReportHandler::Gt) == M2MReportHandler::Gt || + (_attribute_state & M2MReportHandler::Lt) == M2MReportHandler::Lt || + (_attribute_state & M2MReportHandler::St) == M2MReportHandler::St)) { + tr_debug("M2MReportHandler::set_notification_attribute - not numerical resource"); + success = false; + } } - else if(strcmp(attribute, ST.c_str()) == 0 && - (M2MBase::Resource == type)){ - sscanf(value, "%f", &_st); - success = true; - _high_step = _current_value + _st; - _low_step = _current_value - _st; - _attribute_state |= M2MReportHandler::St; - tr_debug("M2MReportHandler::set_notification_attribute %s to %f", attribute, _st); - } - else if(strcmp(attribute, CANCEL.c_str()) == 0) { - success = true; - _attribute_state |= M2MReportHandler::Cancel; - tr_debug("M2MReportHandler::set_notification_attribute cancel"); - } - - // Return false if try to set gt,lt or st when the resource type is something else than numerical - if ((resource_type != M2MResourceInstance::INTEGER && - resource_type != M2MResourceInstance::FLOAT) && - ((_attribute_state & M2MReportHandler::Gt) == M2MReportHandler::Gt || - (_attribute_state & M2MReportHandler::Lt) == M2MReportHandler::Lt || - (_attribute_state & M2MReportHandler::St) == M2MReportHandler::St)) { - tr_debug("M2MReportHandler::set_notification_attribute - not numerical resource"); - success = false; - } - return success; } @@ -281,7 +292,7 @@ tr_debug("M2MReportHandler::schedule_report()"); _notify = true; if ((_attribute_state & M2MReportHandler::Pmin) != M2MReportHandler::Pmin || - _pmin_exceeded) { + _pmin_exceeded) { report(); } } @@ -293,16 +304,18 @@ tr_debug("M2MReportHandler::report()- send with PMIN"); _pmin_exceeded = false; _pmax_exceeded = false; - _notify = false; - _observer.observation_to_be_sent(); + _notify = false; + _observer.observation_to_be_sent(_changed_instance_ids); + _changed_instance_ids.clear(); if (_pmax_timer) { _pmax_timer->stop_timer(); } } else { if (_pmax_exceeded) { - tr_debug("M2MReportHandler::report()- send with PMAX"); - _observer.observation_to_be_sent(); + tr_debug("M2MReportHandler::report()- send with PMAX"); + _observer.observation_to_be_sent(_changed_instance_ids, true); + _changed_instance_ids.clear(); } else { tr_debug("M2MReportHandler::report()- no need to send"); @@ -393,6 +406,7 @@ _pmax_exceeded = false; _last_value = 0.0f; _attribute_state = 0; + _changed_instance_ids.clear(); } bool M2MReportHandler::check_threshold_values()