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.
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
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 00026 //FORWARD DECLARATION 00027 class M2MReportObserver; 00028 class M2MTimer; 00029 class M2MResourceInstance; 00030 00031 /** 00032 * @brief M2MReportHandler. 00033 * This class is handles all the observation related operations. 00034 */ 00035 00036 class M2MReportHandler: public M2MTimerObserver 00037 { 00038 private: 00039 // Prevents the use of assignment operator by accident. 00040 M2MReportHandler& operator=( const M2MReportHandler& /*other*/ ); 00041 00042 public: 00043 00044 M2MReportHandler(M2MReportObserver &observer); 00045 00046 public: 00047 00048 /** 00049 * Enum defining which write attributes are set. 00050 */ 00051 enum { 00052 Cancel = 1, 00053 Pmin = 2, 00054 Pmax = 4, 00055 Lt = 8, 00056 Gt = 16, 00057 St = 32 00058 }; 00059 00060 /** 00061 * Destructor 00062 */ 00063 virtual ~M2MReportHandler(); 00064 00065 /** 00066 * @brief Sets that object is under observation. 00067 * @param Value for the observation. 00068 * @param handler, Handler object for sending 00069 * observation callbacks. 00070 */ 00071 virtual void set_under_observation(bool observed); 00072 00073 /** 00074 * @brief Sets the value of the given resource. 00075 * @param value, Value of the observed resource. 00076 */ 00077 virtual void set_value(float value); 00078 00079 /** 00080 * @brief Sets notification trigger. 00081 */ 00082 void set_notification_trigger(); 00083 00084 /** 00085 * @brief Parses the received query for notification 00086 * attribute. 00087 * @param query Query to be parsed for attributes. 00088 * @param type Type of the Base Object. 00089 * @param resource_type Type of the Resource. 00090 * @return true if required attributes are present else false. 00091 */ 00092 virtual bool parse_notification_attribute(char *&query, 00093 M2MBase::BaseType type, 00094 M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE); 00095 00096 /** 00097 * @brief Set back to default values. 00098 */ 00099 void set_default_values(); 00100 00101 /** 00102 * @brief Return write attribute flags. 00103 */ 00104 uint8_t attribute_flags(); 00105 00106 protected : // from M2MTimerObserver 00107 00108 virtual void timer_expired(M2MTimerObserver::Type type = 00109 M2MTimerObserver::Notdefined); 00110 00111 private: 00112 00113 00114 00115 bool set_notification_attribute(char* option, 00116 M2MBase::BaseType type, 00117 M2MResourceInstance::ResourceType resource_type); 00118 00119 /** 00120 * @brief Schedule a report, if the pmin is exceeded 00121 * then report immediately else store the state to be 00122 * reported once the time fires. 00123 */ 00124 void schedule_report(); 00125 00126 /** 00127 * @brief Reports a sample that satisfies the reporting criteria. 00128 */ 00129 void report(); 00130 00131 /** 00132 * @brief Manage timers for pmin and pmax. 00133 */ 00134 void handle_timers(); 00135 00136 /** 00137 * @brief Check whether notification params can be accepted. 00138 */ 00139 bool check_attribute_validity(); 00140 00141 /** 00142 * @brief Stop pmin & pmax timers. 00143 */ 00144 void stop_timers(); 00145 00146 /** 00147 * @brief Check if current value match threshold values. 00148 * @return True if notify can be send otherwise false. 00149 */ 00150 bool check_threshold_values(); 00151 00152 /** 00153 * @brief Check whether current value matches with GT & LT. 00154 * @return True if current value match with GT or LT values. 00155 */ 00156 bool check_gt_lt_params(); 00157 00158 private: 00159 00160 M2MReportObserver &_observer; 00161 float _pmax; 00162 float _pmin; 00163 float _gt; 00164 float _lt; 00165 float _st; 00166 bool _pmin_exceeded; 00167 bool _pmax_exceeded; 00168 M2MTimer *_pmin_timer; 00169 M2MTimer *_pmax_timer; 00170 float _high_step; 00171 float _low_step; 00172 float _current_value; 00173 float _last_value; 00174 uint8_t _attribute_state; 00175 bool _notify; 00176 00177 friend class Test_M2MReportHandler; 00178 00179 }; 00180 00181 #endif // M2MREPORTHANDLER_H
Generated on Tue Jul 12 2022 13:53:46 by
1.7.2
