Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Committer:
JimCarver
Date:
Thu Oct 25 14:00:12 2018 +0000
Revision:
4:e518dde96e59
Parent:
0:6b753f761943
Simulated dispenser

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCarver 0:6b753f761943 1 // ----------------------------------------------------------------------------
JimCarver 0:6b753f761943 2 // Copyright 2016-2018 ARM Ltd.
JimCarver 0:6b753f761943 3 //
JimCarver 0:6b753f761943 4 // SPDX-License-Identifier: Apache-2.0
JimCarver 0:6b753f761943 5 //
JimCarver 0:6b753f761943 6 // Licensed under the Apache License, Version 2.0 (the "License");
JimCarver 0:6b753f761943 7 // you may not use this file except in compliance with the License.
JimCarver 0:6b753f761943 8 // You may obtain a copy of the License at
JimCarver 0:6b753f761943 9 //
JimCarver 0:6b753f761943 10 // http://www.apache.org/licenses/LICENSE-2.0
JimCarver 0:6b753f761943 11 //
JimCarver 0:6b753f761943 12 // Unless required by applicable law or agreed to in writing, software
JimCarver 0:6b753f761943 13 // distributed under the License is distributed on an "AS IS" BASIS,
JimCarver 0:6b753f761943 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JimCarver 0:6b753f761943 15 // See the License for the specific language governing permissions and
JimCarver 0:6b753f761943 16 // limitations under the License.
JimCarver 0:6b753f761943 17 // ----------------------------------------------------------------------------
JimCarver 0:6b753f761943 18
JimCarver 0:6b753f761943 19 #ifndef MBED_CLOUD_CLIENT_RESOURCE_H
JimCarver 0:6b753f761943 20 #define MBED_CLOUD_CLIENT_RESOURCE_H
JimCarver 0:6b753f761943 21
JimCarver 0:6b753f761943 22 #include "mbed.h"
JimCarver 0:6b753f761943 23 #include "simple-mbed-cloud-client.h"
JimCarver 0:6b753f761943 24 #include "mbed-client/m2mstring.h"
JimCarver 0:6b753f761943 25
JimCarver 0:6b753f761943 26 namespace M2MMethod {
JimCarver 0:6b753f761943 27
JimCarver 0:6b753f761943 28 enum M2MMethod {
JimCarver 0:6b753f761943 29 GET = 0x01,
JimCarver 0:6b753f761943 30 PUT = 0x02,
JimCarver 0:6b753f761943 31 POST = 0x04,
JimCarver 0:6b753f761943 32 DELETE = 0x08
JimCarver 0:6b753f761943 33 };
JimCarver 0:6b753f761943 34
JimCarver 0:6b753f761943 35 };
JimCarver 0:6b753f761943 36
JimCarver 0:6b753f761943 37 struct mcc_resource_def {
JimCarver 0:6b753f761943 38 unsigned int object_id;
JimCarver 0:6b753f761943 39 unsigned int instance_id;
JimCarver 0:6b753f761943 40 unsigned int resource_id;
JimCarver 0:6b753f761943 41 String name;
JimCarver 0:6b753f761943 42 unsigned int method_mask;
JimCarver 0:6b753f761943 43 String value;
JimCarver 0:6b753f761943 44 bool observable;
JimCarver 0:6b753f761943 45 Callback<void(const char*)> *put_callback;
JimCarver 0:6b753f761943 46 Callback<void(void*)> *post_callback;
JimCarver 0:6b753f761943 47 Callback<void(const M2MBase&, const NoticationDeliveryStatus)> *notification_callback;
JimCarver 0:6b753f761943 48 };
JimCarver 0:6b753f761943 49
JimCarver 0:6b753f761943 50 class SimpleMbedCloudClient;
JimCarver 0:6b753f761943 51
JimCarver 0:6b753f761943 52 class MbedCloudClientResource {
JimCarver 0:6b753f761943 53 public:
JimCarver 0:6b753f761943 54 MbedCloudClientResource(SimpleMbedCloudClient *client, const char *path, const char *name);
JimCarver 0:6b753f761943 55
JimCarver 0:6b753f761943 56 void observable(bool observable);
JimCarver 0:6b753f761943 57 void methods(unsigned int methodMask);
JimCarver 0:6b753f761943 58 void attach_put_callback(Callback<void(MbedCloudClientResource*, m2m::String)> callback);
JimCarver 0:6b753f761943 59 void attach_post_callback(Callback<void(MbedCloudClientResource*, const uint8_t*, uint16_t)> callback);
JimCarver 0:6b753f761943 60 void attach_notification_callback(Callback<void(MbedCloudClientResource*, const NoticationDeliveryStatus)> callback);
JimCarver 0:6b753f761943 61 void detach_put_callback();
JimCarver 0:6b753f761943 62 void detach_post_callback();
JimCarver 0:6b753f761943 63 void detach_notification_callback();
JimCarver 0:6b753f761943 64 void set_value(int value);
JimCarver 0:6b753f761943 65 void set_value(const char *value);
JimCarver 0:6b753f761943 66 void set_value(float value);
JimCarver 0:6b753f761943 67 m2m::String get_value();
JimCarver 0:6b753f761943 68 int get_value_int();
JimCarver 0:6b753f761943 69 float get_value_float();
JimCarver 0:6b753f761943 70
JimCarver 0:6b753f761943 71 void get_data(mcc_resource_def *resourceDef);
JimCarver 0:6b753f761943 72 void set_m2m_resource(M2MResource *res);
JimCarver 0:6b753f761943 73 M2MResource* get_m2m_resource();
JimCarver 0:6b753f761943 74
JimCarver 0:6b753f761943 75 static const char * delivery_status_to_string(const NoticationDeliveryStatus status);
JimCarver 0:6b753f761943 76
JimCarver 0:6b753f761943 77 private:
JimCarver 0:6b753f761943 78 void internal_post_callback(void* params);
JimCarver 0:6b753f761943 79 void internal_put_callback(const char* resource);
JimCarver 0:6b753f761943 80 void internal_notification_callback(const M2MBase& m2mbase, const NoticationDeliveryStatus status);
JimCarver 0:6b753f761943 81
JimCarver 0:6b753f761943 82 SimpleMbedCloudClient *client;
JimCarver 0:6b753f761943 83 M2MResource *resource;
JimCarver 0:6b753f761943 84 m2m::String path;
JimCarver 0:6b753f761943 85 m2m::String name;
JimCarver 0:6b753f761943 86 m2m::String value;
JimCarver 0:6b753f761943 87 bool isObservable;
JimCarver 0:6b753f761943 88 unsigned int methodMask;
JimCarver 0:6b753f761943 89
JimCarver 0:6b753f761943 90 Callback<void(MbedCloudClientResource*, m2m::String)> putCallback;
JimCarver 0:6b753f761943 91 Callback<void(MbedCloudClientResource*, const uint8_t*, uint16_t)> postCallback;
JimCarver 0:6b753f761943 92 Callback<void(MbedCloudClientResource*, const NoticationDeliveryStatus)> notificationCallback;
JimCarver 0:6b753f761943 93 Callback<void(void*)> internalPostCallback;
JimCarver 0:6b753f761943 94 Callback<void(const char*)> internalPutCallback;
JimCarver 0:6b753f761943 95 Callback<void(const M2MBase&, const NoticationDeliveryStatus)> internalNotificationCallback;
JimCarver 0:6b753f761943 96 };
JimCarver 0:6b753f761943 97
JimCarver 0:6b753f761943 98 #endif // MBED_CLOUD_CLIENT_RESOURCE_H