mbed client on ethernet with LWIP
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client/source/include/m2mreporthandler.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | #ifndef M2MREPORTHANDLER_H |
mbedAustin | 11:cada08fc8a70 | 17 | #define M2MREPORTHANDLER_H |
mbedAustin | 11:cada08fc8a70 | 18 | |
mbedAustin | 11:cada08fc8a70 | 19 | // Support for std args |
mbedAustin | 11:cada08fc8a70 | 20 | #include <stdint.h> |
mbedAustin | 11:cada08fc8a70 | 21 | #include "mbed-client/m2mconfig.h" |
mbedAustin | 11:cada08fc8a70 | 22 | #include "mbed-client/m2mbase.h" |
mbedAustin | 11:cada08fc8a70 | 23 | #include "mbed-client/m2mtimerobserver.h" |
mbedAustin | 11:cada08fc8a70 | 24 | #include "mbed-client/m2mresourceinstance.h" |
mbedAustin | 11:cada08fc8a70 | 25 | |
mbedAustin | 11:cada08fc8a70 | 26 | //FORWARD DECLARATION |
mbedAustin | 11:cada08fc8a70 | 27 | class M2MReportObserver; |
mbedAustin | 11:cada08fc8a70 | 28 | class M2MTimer; |
mbedAustin | 11:cada08fc8a70 | 29 | class M2MResourceInstance; |
mbedAustin | 11:cada08fc8a70 | 30 | |
mbedAustin | 11:cada08fc8a70 | 31 | /** |
mbedAustin | 11:cada08fc8a70 | 32 | * @brief M2MReportHandler. |
mbedAustin | 11:cada08fc8a70 | 33 | * This class is handles all the observation related operations. |
mbedAustin | 11:cada08fc8a70 | 34 | */ |
mbedAustin | 11:cada08fc8a70 | 35 | |
mbedAustin | 11:cada08fc8a70 | 36 | class M2MReportHandler: public M2MTimerObserver |
mbedAustin | 11:cada08fc8a70 | 37 | { |
mbedAustin | 11:cada08fc8a70 | 38 | private: |
mbedAustin | 11:cada08fc8a70 | 39 | // Prevents the use of assignment operator by accident. |
mbedAustin | 11:cada08fc8a70 | 40 | M2MReportHandler& operator=( const M2MReportHandler& /*other*/ ); |
mbedAustin | 11:cada08fc8a70 | 41 | |
mbedAustin | 11:cada08fc8a70 | 42 | public: |
mbedAustin | 11:cada08fc8a70 | 43 | |
mbedAustin | 11:cada08fc8a70 | 44 | M2MReportHandler(M2MReportObserver &observer); |
mbedAustin | 11:cada08fc8a70 | 45 | |
mbedAustin | 11:cada08fc8a70 | 46 | public: |
mbedAustin | 11:cada08fc8a70 | 47 | |
mbedAustin | 11:cada08fc8a70 | 48 | /** |
mbedAustin | 11:cada08fc8a70 | 49 | * Enum defining which write attributes are set. |
mbedAustin | 11:cada08fc8a70 | 50 | */ |
mbedAustin | 11:cada08fc8a70 | 51 | enum { |
mbedAustin | 11:cada08fc8a70 | 52 | Cancel = 1, |
mbedAustin | 11:cada08fc8a70 | 53 | Pmin = 2, |
mbedAustin | 11:cada08fc8a70 | 54 | Pmax = 4, |
mbedAustin | 11:cada08fc8a70 | 55 | Lt = 8, |
mbedAustin | 11:cada08fc8a70 | 56 | Gt = 16, |
mbedAustin | 11:cada08fc8a70 | 57 | St = 32 |
mbedAustin | 11:cada08fc8a70 | 58 | }; |
mbedAustin | 11:cada08fc8a70 | 59 | |
mbedAustin | 11:cada08fc8a70 | 60 | /** |
mbedAustin | 11:cada08fc8a70 | 61 | * Destructor |
mbedAustin | 11:cada08fc8a70 | 62 | */ |
mbedAustin | 11:cada08fc8a70 | 63 | virtual ~M2MReportHandler(); |
mbedAustin | 11:cada08fc8a70 | 64 | |
mbedAustin | 11:cada08fc8a70 | 65 | /** |
mbedAustin | 11:cada08fc8a70 | 66 | * @brief Sets that object is under observation. |
mbedAustin | 11:cada08fc8a70 | 67 | * @param Value for the observation. |
mbedAustin | 11:cada08fc8a70 | 68 | * @param handler, Handler object for sending |
mbedAustin | 11:cada08fc8a70 | 69 | * observation callbacks. |
mbedAustin | 11:cada08fc8a70 | 70 | */ |
mbedAustin | 11:cada08fc8a70 | 71 | virtual void set_under_observation(bool observed); |
mbedAustin | 11:cada08fc8a70 | 72 | |
mbedAustin | 11:cada08fc8a70 | 73 | /** |
mbedAustin | 11:cada08fc8a70 | 74 | * @brief Sets the value of the given resource. |
mbedAustin | 11:cada08fc8a70 | 75 | * @param value, Value of the observed resource. |
mbedAustin | 11:cada08fc8a70 | 76 | */ |
mbedAustin | 11:cada08fc8a70 | 77 | virtual void set_value(float value); |
mbedAustin | 11:cada08fc8a70 | 78 | |
mbedAustin | 11:cada08fc8a70 | 79 | /** |
mbedAustin | 11:cada08fc8a70 | 80 | * @brief Sets notification trigger. |
mbedAustin | 11:cada08fc8a70 | 81 | */ |
mbedAustin | 11:cada08fc8a70 | 82 | void set_notification_trigger(); |
mbedAustin | 11:cada08fc8a70 | 83 | |
mbedAustin | 11:cada08fc8a70 | 84 | /** |
mbedAustin | 11:cada08fc8a70 | 85 | * @brief Parses the received query for notification |
mbedAustin | 11:cada08fc8a70 | 86 | * attribute. |
mbedAustin | 11:cada08fc8a70 | 87 | * @param query Query to be parsed for attributes. |
mbedAustin | 11:cada08fc8a70 | 88 | * @param type Type of the Base Object. |
mbedAustin | 11:cada08fc8a70 | 89 | * @param resource_type Type of the Resource. |
mbedAustin | 11:cada08fc8a70 | 90 | * @return true if required attributes are present else false. |
mbedAustin | 11:cada08fc8a70 | 91 | */ |
mbedAustin | 11:cada08fc8a70 | 92 | virtual bool parse_notification_attribute(char *&query, |
mbedAustin | 11:cada08fc8a70 | 93 | M2MBase::BaseType type, |
mbedAustin | 11:cada08fc8a70 | 94 | M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE); |
mbedAustin | 11:cada08fc8a70 | 95 | |
mbedAustin | 11:cada08fc8a70 | 96 | /** |
mbedAustin | 11:cada08fc8a70 | 97 | * @brief Set back to default values. |
mbedAustin | 11:cada08fc8a70 | 98 | */ |
mbedAustin | 11:cada08fc8a70 | 99 | void set_default_values(); |
mbedAustin | 11:cada08fc8a70 | 100 | |
mbedAustin | 11:cada08fc8a70 | 101 | /** |
mbedAustin | 11:cada08fc8a70 | 102 | * @brief Return write attribute flags. |
mbedAustin | 11:cada08fc8a70 | 103 | */ |
mbedAustin | 11:cada08fc8a70 | 104 | uint8_t attribute_flags(); |
mbedAustin | 11:cada08fc8a70 | 105 | |
mbedAustin | 11:cada08fc8a70 | 106 | protected : // from M2MTimerObserver |
mbedAustin | 11:cada08fc8a70 | 107 | |
mbedAustin | 11:cada08fc8a70 | 108 | virtual void timer_expired(M2MTimerObserver::Type type = |
mbedAustin | 11:cada08fc8a70 | 109 | M2MTimerObserver::Notdefined); |
mbedAustin | 11:cada08fc8a70 | 110 | |
mbedAustin | 11:cada08fc8a70 | 111 | private: |
mbedAustin | 11:cada08fc8a70 | 112 | |
mbedAustin | 11:cada08fc8a70 | 113 | |
mbedAustin | 11:cada08fc8a70 | 114 | |
mbedAustin | 11:cada08fc8a70 | 115 | bool set_notification_attribute(char* option, |
mbedAustin | 11:cada08fc8a70 | 116 | M2MBase::BaseType type, |
mbedAustin | 11:cada08fc8a70 | 117 | M2MResourceInstance::ResourceType resource_type); |
mbedAustin | 11:cada08fc8a70 | 118 | |
mbedAustin | 11:cada08fc8a70 | 119 | /** |
mbedAustin | 11:cada08fc8a70 | 120 | * @brief Schedule a report, if the pmin is exceeded |
mbedAustin | 11:cada08fc8a70 | 121 | * then report immediately else store the state to be |
mbedAustin | 11:cada08fc8a70 | 122 | * reported once the time fires. |
mbedAustin | 11:cada08fc8a70 | 123 | */ |
mbedAustin | 11:cada08fc8a70 | 124 | void schedule_report(); |
mbedAustin | 11:cada08fc8a70 | 125 | |
mbedAustin | 11:cada08fc8a70 | 126 | /** |
mbedAustin | 11:cada08fc8a70 | 127 | * @brief Reports a sample that satisfies the reporting criteria. |
mbedAustin | 11:cada08fc8a70 | 128 | */ |
mbedAustin | 11:cada08fc8a70 | 129 | void report(); |
mbedAustin | 11:cada08fc8a70 | 130 | |
mbedAustin | 11:cada08fc8a70 | 131 | /** |
mbedAustin | 11:cada08fc8a70 | 132 | * @brief Manage timers for pmin and pmax. |
mbedAustin | 11:cada08fc8a70 | 133 | */ |
mbedAustin | 11:cada08fc8a70 | 134 | void handle_timers(); |
mbedAustin | 11:cada08fc8a70 | 135 | |
mbedAustin | 11:cada08fc8a70 | 136 | /** |
mbedAustin | 11:cada08fc8a70 | 137 | * @brief Check whether notification params can be accepted. |
mbedAustin | 11:cada08fc8a70 | 138 | */ |
mbedAustin | 11:cada08fc8a70 | 139 | bool check_attribute_validity(); |
mbedAustin | 11:cada08fc8a70 | 140 | |
mbedAustin | 11:cada08fc8a70 | 141 | /** |
mbedAustin | 11:cada08fc8a70 | 142 | * @brief Stop pmin & pmax timers. |
mbedAustin | 11:cada08fc8a70 | 143 | */ |
mbedAustin | 11:cada08fc8a70 | 144 | void stop_timers(); |
mbedAustin | 11:cada08fc8a70 | 145 | |
mbedAustin | 11:cada08fc8a70 | 146 | /** |
mbedAustin | 11:cada08fc8a70 | 147 | * @brief Check if current value match threshold values. |
mbedAustin | 11:cada08fc8a70 | 148 | * @return True if notify can be send otherwise false. |
mbedAustin | 11:cada08fc8a70 | 149 | */ |
mbedAustin | 11:cada08fc8a70 | 150 | bool check_threshold_values(); |
mbedAustin | 11:cada08fc8a70 | 151 | |
mbedAustin | 11:cada08fc8a70 | 152 | /** |
mbedAustin | 11:cada08fc8a70 | 153 | * @brief Check whether current value matches with GT & LT. |
mbedAustin | 11:cada08fc8a70 | 154 | * @return True if current value match with GT or LT values. |
mbedAustin | 11:cada08fc8a70 | 155 | */ |
mbedAustin | 11:cada08fc8a70 | 156 | bool check_gt_lt_params(); |
mbedAustin | 11:cada08fc8a70 | 157 | |
mbedAustin | 11:cada08fc8a70 | 158 | private: |
mbedAustin | 11:cada08fc8a70 | 159 | |
mbedAustin | 11:cada08fc8a70 | 160 | M2MReportObserver &_observer; |
mbedAustin | 11:cada08fc8a70 | 161 | float _pmax; |
mbedAustin | 11:cada08fc8a70 | 162 | float _pmin; |
mbedAustin | 11:cada08fc8a70 | 163 | float _gt; |
mbedAustin | 11:cada08fc8a70 | 164 | float _lt; |
mbedAustin | 11:cada08fc8a70 | 165 | float _st; |
mbedAustin | 11:cada08fc8a70 | 166 | bool _pmin_exceeded; |
mbedAustin | 11:cada08fc8a70 | 167 | bool _pmax_exceeded; |
mbedAustin | 11:cada08fc8a70 | 168 | M2MTimer *_pmin_timer; |
mbedAustin | 11:cada08fc8a70 | 169 | M2MTimer *_pmax_timer; |
mbedAustin | 11:cada08fc8a70 | 170 | float _high_step; |
mbedAustin | 11:cada08fc8a70 | 171 | float _low_step; |
mbedAustin | 11:cada08fc8a70 | 172 | float _current_value; |
mbedAustin | 11:cada08fc8a70 | 173 | float _last_value; |
mbedAustin | 11:cada08fc8a70 | 174 | uint8_t _attribute_state; |
mbedAustin | 11:cada08fc8a70 | 175 | bool _notify; |
mbedAustin | 11:cada08fc8a70 | 176 | |
mbedAustin | 11:cada08fc8a70 | 177 | friend class Test_M2MReportHandler; |
mbedAustin | 11:cada08fc8a70 | 178 | |
mbedAustin | 11:cada08fc8a70 | 179 | }; |
mbedAustin | 11:cada08fc8a70 | 180 | |
mbedAustin | 11:cada08fc8a70 | 181 | #endif // M2MREPORTHANDLER_H |