comparison LossyCom.h @ 1:826448e34e80

added data to message handler
author Merten Sach <msach@mailbox.tu-berlin.de>
date Thu, 08 Mar 2012 20:06:00 +0100
parents 29d8b41926f0
children b6dd31dbab8c
comparison
equal deleted inserted replaced
0:b07c8ec4360a 1:8165e6b9dff0
19 * number of entities is fixed at initialization. 19 * number of entities is fixed at initialization.
20 */ 20 */
21 21
22 #include <stdint.h> 22 #include <stdint.h>
23 23
24 24 /***********************************
25 * General Defines
26 ***********************************/
27 //never use this number as a endpoint!
28 #define BROADCAST_ID 65535
25 29
26 /*********************************** 30 /***********************************
27 * Type Definitions 31 * Type Definitions
28 ***********************************/ 32 ***********************************/
29 33
30 #define BROADCAST_ID 65535
31 #define ENDPOINT_ID_SHIFT 32
32 #define TRIGGER_SHIFT 48
33
34 /* 34 /*
35 * A message consists of the 35 * A message consists of the
36 * 16bit saved trigger value when the message was sent 36 * 16bit saved trigger value +1 when the message was sent
37 * 16bit receiver identifier, this is the index of the slot in the array 37 * 16bit receiver identifier, this is the index of the slot in the array
38 * 65536 is the broadcast identifier 38 * 65536 is the broadcast identifier
39 * 32bit message body, the message format is defined by the endpoints 39 * 32bit message body, the message format is defined by the endpoints
40 *
41 * | 16bit trigger value | 16bit receiverID | 32bit message body |
40 */ 42 */
43 #define ENDPOINT_ID_SHIFT 32
44 #define TRIGGER_SHIFT 48
41 typedef uint64_t lossyCom__msg_t; 45 typedef uint64_t lossyCom__msg_t;
42 typedef uint32_t lossyCom__msgBody_t; 46 typedef uint32_t lossyCom__msgBody_t;
43 typedef uint16_t lossyCom__endpointID_t; 47 typedef uint16_t lossyCom__endpointID_t;
44 48
45 /* 49 /*
46 * Message Handler that has two arguments the sender endpoint ID and the Msg 50 * Message Handler that has two arguments the sender endpoint ID and the Msg
47 * Example: 51 * Example:
48 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg); 52 * void handler_func(lossyCom__endpointID_t senderID, lossyCom__msgBody_t msg);
49 */ 53 */
50 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t); 54 typedef void (*lossyCom__msgHandler) (lossyCom__endpointID_t, lossyCom__msgBody_t, void*);
51 55
52 /* 56 /*
53 * Central communication structure. 57 * Central communication structure.
54 */ 58 */
55 typedef struct{ 59 typedef struct{
62 * Endpoint data structure. 66 * Endpoint data structure.
63 */ 67 */
64 typedef struct { 68 typedef struct {
65 uint16_t localTriggerCopy; 69 uint16_t localTriggerCopy;
66 lossyCom__endpointID_t endpointID; 70 lossyCom__endpointID_t endpointID;
67 lossyCom__exchange_t* centralExchangePtr; 71 lossyCom__exchange_t* centralExchange;
68 lossyCom__msgHandler* msgHandler; 72 lossyCom__msgHandler msgHandler;
73 void* msgHandlerData;
69 } lossyCom__endpoint_t; 74 } lossyCom__endpoint_t;
70 75
71 /*********************************** 76 /***********************************
72 * Function Declarations 77 * Function Declarations
73 ***********************************/ 78 ***********************************/
75 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints); 80 lossyCom__exchange_t* lossyCom__initialize(uint16_t numEndpoints);
76 81
77 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint, 82 void lossyCom__initialize_endpoint(lossyCom__endpoint_t* localEndpoint,
78 lossyCom__exchange_t* exchange, 83 lossyCom__exchange_t* exchange,
79 lossyCom__endpointID_t endpointID, 84 lossyCom__endpointID_t endpointID,
80 lossyCom__msgHandler* msgHandler); 85 lossyCom__msgHandler msgHandler,
86 void* msgHandlerData);
81 87
82 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint, 88 void lossyCom__broadcastMsg(lossyCom__endpoint_t* localEndpoint,
83 lossyCom__msgBody_t msg); 89 lossyCom__msgBody_t msg);
84 90
85 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint, 91 void lossyCom__sendMsg(lossyCom__endpoint_t* localEndpoint,