joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers m2mreporthandler.h Source File

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 
00027 //FORWARD DECLARATION
00028 class M2MReportObserver;
00029 class M2MTimer;
00030 class M2MResourceInstance;
00031 
00032 /**
00033  *  @brief M2MReportHandler.
00034  *  This class is handles all the observation related operations.
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      * @param obj_instance_id, Object instance id that has changed
00082      */
00083     void set_notification_trigger(uint16_t obj_instance_id = 0);
00084 
00085     /**
00086      * @brief Parses the received query for notification
00087      * attribute.
00088      * @param query Query to be parsed for attributes.
00089      * @param type Type of the Base Object.
00090      * @param resource_type Type of the Resource.
00091      * @return true if required attributes are present else false.
00092      */
00093     virtual bool parse_notification_attribute(char *&query,
00094                                               M2MBase::BaseType type,
00095                                               M2MResourceInstance::ResourceType resource_type = M2MResourceInstance::OPAQUE);
00096 
00097     /**
00098     * @brief Set back to default values.
00099     */
00100     void set_default_values();
00101 
00102     /**
00103      * @brief Return write attribute flags.
00104      */
00105     uint8_t attribute_flags();
00106 
00107 protected : // from M2MTimerObserver
00108 
00109     virtual void timer_expired(M2MTimerObserver::Type type =
00110                                M2MTimerObserver::Notdefined);
00111 
00112 private:
00113 
00114 
00115 
00116     bool set_notification_attribute(char* option,
00117             M2MBase::BaseType type,
00118             M2MResourceInstance::ResourceType resource_type);
00119 
00120     /**
00121      * @brief Schedule a report, if the pmin is exceeded
00122      * then report immediately else store the state to be
00123      * reported once the time fires.
00124      */
00125     void schedule_report();
00126 
00127     /**
00128     * @brief Reports a sample that satisfies the reporting criteria.
00129     */
00130     void report();
00131 
00132     /**
00133     * @brief Manage timers for pmin and pmax.
00134     */
00135     void handle_timers();
00136 
00137     /**
00138     * @brief Check whether notification params can be accepted.
00139     */
00140     bool check_attribute_validity();
00141 
00142     /**
00143     * @brief Stop pmin & pmax timers.
00144     */
00145     void stop_timers();
00146 
00147     /**
00148      * @brief Check if current value match threshold values.
00149      * @return True if notify can be send otherwise false.
00150      */
00151     bool check_threshold_values();
00152 
00153     /**
00154      * @brief Check whether current value matches with GT & LT.
00155      * @return True if current value match with GT or LT values.
00156      */
00157     bool check_gt_lt_params();
00158 
00159 private:
00160     M2MReportObserver           &_observer;
00161     int                         _pmax;
00162     int                         _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     m2m::Vector<uint16_t>       _changed_instance_ids;
00177 
00178 friend class Test_M2MReportHandler;
00179 
00180 };
00181 
00182 #endif // M2MREPORTHANDLER_H