Kristof T'Jonck / Mbed 2 deprecated CYS_Receiver

Dependencies:   xtoff2 RF24Network mbed

Fork of xtoff3 by pieter Berteloot

Committer:
akashvibhute
Date:
Mon Jul 06 03:17:33 2015 +0000
Revision:
0:3982c0e9eda1
First mbed-arduino working program!; mbed is able to receive data from arduino nodes 0 or 1 depending on address set

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akashvibhute 0:3982c0e9eda1 1 /*
akashvibhute 0:3982c0e9eda1 2 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
akashvibhute 0:3982c0e9eda1 3
akashvibhute 0:3982c0e9eda1 4 This program is free software; you can redistribute it and/or
akashvibhute 0:3982c0e9eda1 5 modify it under the terms of the GNU General Public License
akashvibhute 0:3982c0e9eda1 6 version 2 as published by the Free Software Foundation.
akashvibhute 0:3982c0e9eda1 7 */
akashvibhute 0:3982c0e9eda1 8
akashvibhute 0:3982c0e9eda1 9 #ifndef __SYNC_H__
akashvibhute 0:3982c0e9eda1 10 #define __SYNC_H__
akashvibhute 0:3982c0e9eda1 11
akashvibhute 0:3982c0e9eda1 12 // STL headers
akashvibhute 0:3982c0e9eda1 13 // C headers
akashvibhute 0:3982c0e9eda1 14 #include <stdlib.h>
akashvibhute 0:3982c0e9eda1 15 #include <string.h>
akashvibhute 0:3982c0e9eda1 16 // Framework headers
akashvibhute 0:3982c0e9eda1 17 // Library headers
akashvibhute 0:3982c0e9eda1 18 #include <RF24Network_config.h>
akashvibhute 0:3982c0e9eda1 19 // Project headers
akashvibhute 0:3982c0e9eda1 20
akashvibhute 0:3982c0e9eda1 21 class RF24Network;
akashvibhute 0:3982c0e9eda1 22
akashvibhute 0:3982c0e9eda1 23 /**
akashvibhute 0:3982c0e9eda1 24 * Synchronizes a shared set of variables between multiple nodes
akashvibhute 0:3982c0e9eda1 25 */
akashvibhute 0:3982c0e9eda1 26
akashvibhute 0:3982c0e9eda1 27 class Sync
akashvibhute 0:3982c0e9eda1 28 {
akashvibhute 0:3982c0e9eda1 29 private:
akashvibhute 0:3982c0e9eda1 30 RF24Network& network;
akashvibhute 0:3982c0e9eda1 31 uint8_t* app_data; /**< Application's copy of the data */
akashvibhute 0:3982c0e9eda1 32 uint8_t* internal_data; /**< Our copy of the data */
akashvibhute 0:3982c0e9eda1 33 size_t len; /**< Length of the data in bytes */
akashvibhute 0:3982c0e9eda1 34 uint16_t to_node; /**< The other node we're syncing with */
akashvibhute 0:3982c0e9eda1 35
akashvibhute 0:3982c0e9eda1 36 protected:
akashvibhute 0:3982c0e9eda1 37 public:
akashvibhute 0:3982c0e9eda1 38 /**
akashvibhute 0:3982c0e9eda1 39 * Constructor
akashvibhute 0:3982c0e9eda1 40 *
akashvibhute 0:3982c0e9eda1 41 * @param _network Which network to syncrhonize over
akashvibhute 0:3982c0e9eda1 42 */
akashvibhute 0:3982c0e9eda1 43 Sync(RF24Network& _network): network(_network), app_data(NULL),
akashvibhute 0:3982c0e9eda1 44 internal_data(NULL), len(0), to_node(0)
akashvibhute 0:3982c0e9eda1 45 {
akashvibhute 0:3982c0e9eda1 46 }
akashvibhute 0:3982c0e9eda1 47 /**
akashvibhute 0:3982c0e9eda1 48 * Begin the object
akashvibhute 0:3982c0e9eda1 49 *
akashvibhute 0:3982c0e9eda1 50 * @param _to_node Which node we are syncing with
akashvibhute 0:3982c0e9eda1 51 */
akashvibhute 0:3982c0e9eda1 52 void begin(uint16_t _to_node)
akashvibhute 0:3982c0e9eda1 53 {
akashvibhute 0:3982c0e9eda1 54 to_node = _to_node;
akashvibhute 0:3982c0e9eda1 55 }
akashvibhute 0:3982c0e9eda1 56 /**
akashvibhute 0:3982c0e9eda1 57 * Declare the shared data set
akashvibhute 0:3982c0e9eda1 58 *
akashvibhute 0:3982c0e9eda1 59 * @param _data Location of shared data to be syncrhonized
akashvibhute 0:3982c0e9eda1 60 */
akashvibhute 0:3982c0e9eda1 61 template <class T>
akashvibhute 0:3982c0e9eda1 62 void register_me(T& _data)
akashvibhute 0:3982c0e9eda1 63 {
akashvibhute 0:3982c0e9eda1 64 app_data = reinterpret_cast<uint8_t*>(&_data);
akashvibhute 0:3982c0e9eda1 65 len = sizeof(_data);
akashvibhute 0:3982c0e9eda1 66 internal_data = reinterpret_cast<uint8_t*>(malloc(len));
akashvibhute 0:3982c0e9eda1 67 reset();
akashvibhute 0:3982c0e9eda1 68 }
akashvibhute 0:3982c0e9eda1 69
akashvibhute 0:3982c0e9eda1 70 /**
akashvibhute 0:3982c0e9eda1 71 * Reset the internal copy of the shared data set
akashvibhute 0:3982c0e9eda1 72 */
akashvibhute 0:3982c0e9eda1 73 void reset(void)
akashvibhute 0:3982c0e9eda1 74 {
akashvibhute 0:3982c0e9eda1 75 memcpy(internal_data,app_data,len);
akashvibhute 0:3982c0e9eda1 76 }
akashvibhute 0:3982c0e9eda1 77
akashvibhute 0:3982c0e9eda1 78 /**
akashvibhute 0:3982c0e9eda1 79 * Update the network and the shared data set
akashvibhute 0:3982c0e9eda1 80 */
akashvibhute 0:3982c0e9eda1 81 void update(void);
akashvibhute 0:3982c0e9eda1 82 };
akashvibhute 0:3982c0e9eda1 83
akashvibhute 0:3982c0e9eda1 84 #endif // __SYNC_H__
akashvibhute 0:3982c0e9eda1 85 // vim:cin:ai:sts=2 sw=2 ft=cpp