UniSaSA  1.0
Embedded Library
unisasa.h
Go to the documentation of this file.
1 
30 #ifndef _UNISASA_HEADER_
31 #define _UNISASA_HEADER_
32 
33 #include "unisasa_types.h"
34 
35 //=================== CONFIGURATION ==========================//
41 // Custom:
42 #define NUMSENS 64
43 #define NUMACTS 64
44 #define FIRST_ID_SEN 0
45 #define FIRST_ID_ACT 0
46 #define BYTES_ADDRESS_DEVICE 1
47 #define ADDR_ANY 0
48 #define BYTES_UNSIGNED_INT 4
49 #define BYTES_MESSAGE 8
50 //#define BIG_ENDIAN
51 #define LITTLE_ENDIAN
52 //====================================================================//
53 
56 //--------------------------------------------------
57 // Check ENDIAN
58 #if defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
59 #error "Please define: BIG_ENDIAN or LITTLE_ENDIAN, not both"
60 #endif
61 
62 #if !defined(BIG_ENDIAN) && !defined(LITTLE_ENDIAN)
63 #error "Please define: BIG_ENDIAN or LITTLE_ENDIAN"
64 #endif
65 
66 // Macro to send in big endian
67 #ifdef LITTLE_ENDIAN
68 #define SEND(array,size,converter) _reverseArray(array, size, converter); send(converter, size)
69 #define RECV(array,size,converter) receive(converter, size); _reverseArray(converter, size, array)
70 #else
71 #define SEND(array,size,converter) send(array,size)
72 #define RECV(array,size,converter) receive(array,size)
73 #endif
74 
75 //--------------------------------------------------
76 
77 typedef unsigned char byte_t;
78 
83 typedef union converter_t {
84  unsigned int integer;
85  unsigned char byte[BYTES_MESSAGE];
86 } converter_t;
87 
88 //------------------------------------------------------------------//
89 
90 
91 /*** Device ***/
92 
98 typedef union deviceAddress_t {
99  unsigned int integer;
100  unsigned char byte[BYTES_ADDRESS_DEVICE];
102 
109 typedef void (*messageHandlerFunc)(unsigned char *);
110 
118 typedef void (*messageAndAnswerHandlerFunc)(unsigned char *request, unsigned char*reply);
119 
128 void createDevice(unsigned int address,unsigned char sizeIOmsg,messageHandlerFunc callback1,messageAndAnswerHandlerFunc callback2);
129 
135 typedef struct device_t{
136  deviceAddress_t address;
137  unsigned char sizeIOMsg; // 1 byte
138  unsigned char sizeIDSen; // 1 byte
139  unsigned char sizeIDAct; // 1 byte
140  messageHandlerFunc messageHandler;
141  messageAndAnswerHandlerFunc messageAndAnswerHandler;
142 } device_t;
143 
144 
145 //--------------------------------------------------------------------//
146 
147 /*** Sensor ***/
148 
154 typedef void (*getSensorValueFunc)(unsigned char *sensor_value);
155 
159 typedef union sensorType_t {
160  unsigned int integer;
161  unsigned char byte[SIZE_TYPE_SENSOR];
162 } sensorType_t;
163 
169 typedef struct sensor_t{
170  converter_t ID;
171  sensorType_t typeSensor;
172  unsigned char sizeOutput; // 1 byte
173  unsigned char typeOutput; // 1 byte
174  getSensorValueFunc getValue;
175 } sensor_t;
176 
185 void addSensor(unsigned int typeSensor, unsigned char sizeOutput, unsigned char typeOutput, getSensorValueFunc getValue);
186 
187 //--------------------------------------------------------------------//
188 
189 /*** Actuator ***/
190 
191 // Actuator struct, addActuator, functionCallBack
192 
198 typedef void (*setActuatorValueFunc)(unsigned char* act_value);
199 
203 typedef union actuatorType_t {
204  unsigned int integer;
205  unsigned char byte[SIZE_TYPE_ACTUATOR];
207 
213 typedef struct actuator_t {
214  converter_t ID;
215  actuatorType_t typeActuator;
216  unsigned char sizeInput; // 1 byte
217  unsigned char typeInput; // 1 byte
218  setActuatorValueFunc setValue;
219 } actuator_t;
220 
221 
230 void addActuator(unsigned int typeActuator,unsigned char sizeInput, unsigned char typeInput, setActuatorValueFunc setValue) ;
231 
232 
233 //-------------------------------------------------------------------//
234 
235 
236 /* Communication Handler */
237 
245 typedef void(*receiveUnisasa)(unsigned char* message,unsigned int size);
246 
254 typedef void (*sendUnisasa)(unsigned char* message,unsigned int size);
255 
264 void communication(receiveUnisasa recvFunc, sendUnisasa sendFunc );
265 
266 
267 #endif
void addSensor(unsigned int typeSensor, unsigned char sizeOutput, unsigned char typeOutput, getSensorValueFunc getValue)
Definition: unisasa.c:64
void createDevice(unsigned int address, unsigned char sizeIOmsg, messageHandlerFunc callback1, messageAndAnswerHandlerFunc callback2)
Definition: unisasa.c:54
union sensorType_t sensorType_t
void(* messageHandlerFunc)(unsigned char *)
Definition: unisasa.h:109
void communication(receiveUnisasa recvFunc, sendUnisasa sendFunc)
Definition: unisasa.c:87
struct device_t device_t
void(* setActuatorValueFunc)(unsigned char *act_value)
Definition: unisasa.h:198
#define BYTES_ADDRESS_DEVICE
Definition: unisasa.h:46
void(* getSensorValueFunc)(unsigned char *sensor_value)
Definition: unisasa.h:154
union actuatorType_t actuatorType_t
struct actuator_t actuator_t
void(* receiveUnisasa)(unsigned char *message, unsigned int size)
Definition: unisasa.h:245
void addActuator(unsigned int typeActuator, unsigned char sizeInput, unsigned char typeInput, setActuatorValueFunc setValue)
Definition: unisasa.c:75
union converter_t converter_t
void(* messageAndAnswerHandlerFunc)(unsigned char *request, unsigned char *reply)
Definition: unisasa.h:118
union deviceAddress_t deviceAddress_t
void(* sendUnisasa)(unsigned char *message, unsigned int size)
Definition: unisasa.h:254
struct sensor_t sensor_t