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.
m2mreporthandler.h
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #ifndef M2MREPORTHANDLER_H 00017 #define M2MREPORTHANDLER_H 00018 00019 // Support for std args 00020 #include <stdint.h> 00021 #include "mbed-client/m2mconfig.h" 00022 #include "mbed-client/m2mbase.h" 00023 #include "mbed-client/m2mtimerobserver.h" 00024 #include "mbed-client/m2mresourceinstance.h" 00025 #include "mbed-client/m2mvector.h" 00026 #include "mbed-client/m2mtimer.h" 00027 00028 //FORWARD DECLARATION 00029 class M2MReportObserver; 00030 class M2MTimer; 00031 class M2MResourceInstance; 00032 00033 /** 00034 * @brief M2MReportHandler. 00035 * This class is handles all the observation related operations. 00036 */ 00037 class M2MReportHandler: public M2MTimerObserver 00038 { 00039 private: 00040 // Prevents the use of assignment operator by accident. 00041 M2MReportHandler& operator=( const M2MReportHandler& /*other*/ ); 00042 00043 public: 00044 00045 M2MReportHandler(M2MReportObserver &observer); 00046 00047 public: 00048 00049 /** 00050 * Enum defining which write attributes are set. 00051 */ 00052 enum { 00053 Cancel = 1, 00054 Pmin = 2, 00055 Pmax = 4, 00056 Lt = 8, 00057 Gt = 16, 00058 St = 32 00059 }; 00060 00061 /** 00062 * Destructor 00063 */ 00064 virtual ~M2MReportHandler(); 00065 00066 /** 00067 * @brief Sets that object is under observation. 00068 * @param Value for the observation. 00069 * @param handler, Handler object for sending 00070 * observation callbacks. 00071 */ 00072 void set_under_observation(bool observed); 00073 00074 /** 00075 * @brief Sets the value of the given resource. 00076 * @param value, Value of the observed resource. 00077 */ 00078 void set_value(float value); 00079 00080 /** 00081 * @brief Sets notification trigger. 00082 * @param obj_instance_id, Object instance id that has changed 00083 */ 00084 void set_notification_trigger(uint16_t obj_instance_id = 0); 00085 00086 /** 00087 * @brief Parses the received query for notification 00088 * attribute. 00089 * @param query Query to be parsed for attributes. 00090 * @param type Type of the Base Object. 00091 * @param resource_type Type of the Resource. 00092 * @return true if required attributes are present else false. 00093 */ 00094 bool parse_notification_attribute(const char *query, 00095 M2MBase::BaseType type, 00096 M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE); 00097 00098 /** 00099 * @brief Set back to default values. 00100 */ 00101 void set_default_values(); 00102 00103 /** 00104 * @brief Return write attribute flags. 00105 */ 00106 uint8_t attribute_flags(); 00107 00108 protected : // from M2MTimerObserver 00109 00110 virtual void timer_expired(M2MTimerObserver::Type type = 00111 M2MTimerObserver::Notdefined); 00112 00113 private: 00114 00115 00116 00117 bool set_notification_attribute(const char* option, 00118 M2MBase::BaseType type, 00119 M2MResourceInstance::ResourceType resource_type); 00120 00121 /** 00122 * @brief Schedule a report, if the pmin is exceeded 00123 * then report immediately else store the state to be 00124 * reported once the time fires. 00125 */ 00126 void schedule_report(); 00127 00128 /** 00129 * @brief Reports a sample that satisfies the reporting criteria. 00130 */ 00131 void report(); 00132 00133 /** 00134 * @brief Manage timers for pmin and pmax. 00135 */ 00136 void handle_timers(); 00137 00138 /** 00139 * @brief Check whether notification params can be accepted. 00140 */ 00141 bool check_attribute_validity(); 00142 00143 /** 00144 * @brief Stop pmin & pmax timers. 00145 */ 00146 void stop_timers(); 00147 00148 /** 00149 * @brief Check if current value match threshold values. 00150 * @return True if notify can be send otherwise false. 00151 */ 00152 bool check_threshold_values(); 00153 00154 /** 00155 * @brief Check whether current value matches with GT & LT. 00156 * @return True if current value match with GT or LT values. 00157 */ 00158 bool check_gt_lt_params(); 00159 00160 private: 00161 M2MReportObserver &_observer; 00162 uint8_t _attribute_state; 00163 bool _notify; 00164 bool _pmin_exceeded; 00165 bool _pmax_exceeded; 00166 M2MTimer _pmin_timer; 00167 M2MTimer _pmax_timer; 00168 int32_t _pmax; 00169 int32_t _pmin; 00170 float _current_value; 00171 float _gt; 00172 float _lt; 00173 float _st; 00174 float _high_step; 00175 float _low_step; 00176 float _last_value; 00177 m2m::Vector<uint16_t> _changed_instance_ids; 00178 00179 friend class Test_M2MReportHandler; 00180 00181 }; 00182 00183 #endif // M2MREPORTHANDLER_H
Generated on Tue Jul 12 2022 19:06:59 by
