Machine Cloud
MachineCloud.h@1:f5eafb42e9e4, 2013-08-15 (annotated)
- Committer:
- ddollar
- Date:
- Thu Aug 15 23:54:25 2013 +0000
- Revision:
- 1:f5eafb42e9e4
- Parent:
- 0:260d7796eb25
- Child:
- 2:3fb7c06efa1e
models
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ddollar | 0:260d7796eb25 | 1 | /* Copyright (C) 2013 David Dollar, MIT License |
ddollar | 0:260d7796eb25 | 2 | * |
ddollar | 0:260d7796eb25 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ddollar | 0:260d7796eb25 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
ddollar | 0:260d7796eb25 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ddollar | 0:260d7796eb25 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ddollar | 0:260d7796eb25 | 7 | * furnished to do so, subject to the following conditions: |
ddollar | 0:260d7796eb25 | 8 | * |
ddollar | 0:260d7796eb25 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ddollar | 0:260d7796eb25 | 10 | * substantial portions of the Software. |
ddollar | 0:260d7796eb25 | 11 | * |
ddollar | 0:260d7796eb25 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ddollar | 0:260d7796eb25 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ddollar | 0:260d7796eb25 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ddollar | 0:260d7796eb25 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ddollar | 0:260d7796eb25 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ddollar | 0:260d7796eb25 | 17 | */ |
ddollar | 0:260d7796eb25 | 18 | |
ddollar | 0:260d7796eb25 | 19 | #ifndef MACHINECLOUD_H_ |
ddollar | 0:260d7796eb25 | 20 | #define MACHINECLOUD_H_ |
ddollar | 0:260d7796eb25 | 21 | |
ddollar | 0:260d7796eb25 | 22 | #include <stdint.h> |
ddollar | 0:260d7796eb25 | 23 | #include "rtos.h" |
ddollar | 0:260d7796eb25 | 24 | #include "XBee.h" |
ddollar | 0:260d7796eb25 | 25 | |
ddollar | 0:260d7796eb25 | 26 | typedef void MachineCloudCallback(char *, char *); |
ddollar | 0:260d7796eb25 | 27 | |
ddollar | 0:260d7796eb25 | 28 | class MachineCloudReceiver { |
ddollar | 0:260d7796eb25 | 29 | public: |
ddollar | 0:260d7796eb25 | 30 | virtual void receive(char *, char *) = NULL; |
ddollar | 0:260d7796eb25 | 31 | }; |
ddollar | 0:260d7796eb25 | 32 | |
ddollar | 0:260d7796eb25 | 33 | class MachineCloud { |
ddollar | 0:260d7796eb25 | 34 | |
ddollar | 0:260d7796eb25 | 35 | public: |
ddollar | 0:260d7796eb25 | 36 | |
ddollar | 0:260d7796eb25 | 37 | // constructor |
ddollar | 1:f5eafb42e9e4 | 38 | MachineCloud(char *model); |
ddollar | 1:f5eafb42e9e4 | 39 | MachineCloud(char *model, uint16_t router); |
ddollar | 0:260d7796eb25 | 40 | |
ddollar | 0:260d7796eb25 | 41 | // connect to the machine cloud |
ddollar | 0:260d7796eb25 | 42 | int connect(); |
ddollar | 0:260d7796eb25 | 43 | int disconnect(); |
ddollar | 0:260d7796eb25 | 44 | |
ddollar | 0:260d7796eb25 | 45 | // receive callback |
ddollar | 0:260d7796eb25 | 46 | int on_receive(MachineCloudCallback *function); |
ddollar | 0:260d7796eb25 | 47 | int on_receive(MachineCloudReceiver *object); |
ddollar | 0:260d7796eb25 | 48 | |
ddollar | 0:260d7796eb25 | 49 | // send a message |
ddollar | 0:260d7796eb25 | 50 | int send(char *key, char *value); |
ddollar | 0:260d7796eb25 | 51 | |
ddollar | 0:260d7796eb25 | 52 | // runloop |
ddollar | 0:260d7796eb25 | 53 | int loop(); |
ddollar | 0:260d7796eb25 | 54 | |
ddollar | 0:260d7796eb25 | 55 | private: |
ddollar | 0:260d7796eb25 | 56 | |
ddollar | 1:f5eafb42e9e4 | 57 | void init(char *model, uint16_t router); |
ddollar | 0:260d7796eb25 | 58 | void receive(char *key, char *value); |
ddollar | 0:260d7796eb25 | 59 | |
ddollar | 0:260d7796eb25 | 60 | Mutex m_lock; |
ddollar | 1:f5eafb42e9e4 | 61 | char *m_model; |
ddollar | 0:260d7796eb25 | 62 | MachineCloudCallback *m_receiverFunction; |
ddollar | 0:260d7796eb25 | 63 | MachineCloudReceiver *m_receiverObject; |
ddollar | 0:260d7796eb25 | 64 | uint16_t m_router; |
ddollar | 0:260d7796eb25 | 65 | XBee *m_xbee; |
ddollar | 0:260d7796eb25 | 66 | }; |
ddollar | 0:260d7796eb25 | 67 | |
ddollar | 0:260d7796eb25 | 68 | #endif /* MACHINECLOUD_H_ */ |