7 unsigned int nextIDSen = FIRST_ID_SEN;
8 unsigned int nextIDAct = FIRST_ID_ACT;
10 unsigned char numSens=0;
11 unsigned char numActs=0;
18 void _reverseArray(
unsigned char* src,
unsigned int size,
unsigned char* dest)
32 unsigned char _getSizeBytes(
unsigned int i)
38 tmp.integer=con.integer;
39 _reverseArray(tmp.byte, BYTES_UNSIGNED_INT, con.byte);
41 unsigned char size = 0;
42 for(i=0; i<BYTES_UNSIGNED_INT; i++)
50 unsigned char byte[BYTES_MESSAGE];
56 thisDevice.address.integer = address;
57 thisDevice.sizeIOMsg = sizeIOmsg;
58 thisDevice.sizeIDSen = _getSizeBytes(
NUMSENS);
59 thisDevice.sizeIDAct = _getSizeBytes(
NUMACTS);
60 thisDevice.messageHandler = msgHandler;
61 thisDevice.messageAndAnswerHandler = msgAnsHandler;
66 sensors[nextIDSen].ID.integer = nextIDSen;
67 sensors[nextIDSen].typeSensor.integer = typeSensor;
68 sensors[nextIDSen].sizeOutput = sizeOutput;
69 sensors[nextIDSen].typeOutput = typeOutput;
70 sensors[nextIDSen].getValue = getValue;
77 actuators[nextIDAct].ID.integer = nextIDAct;
78 actuators[nextIDAct].typeActuator.integer = typeActuator;
79 actuators[nextIDAct].sizeInput = sizeInput;
80 actuators[nextIDAct].typeInput = typeInput;
81 actuators[nextIDAct].setValue = setValue;
93 receive(message.byte,1);
94 switch (message.byte[0])
109 send(message.byte,1);
111 send(&(thisDevice.sizeIOMsg),1);
113 send(&thisDevice.sizeIDSen,1);
114 SEND(&numSens,thisDevice.sizeIDSen,converter.byte);
115 for(s=0;s< numSens; s++)
117 SEND(sensors[s].ID.byte,thisDevice.sizeIDSen,converter.byte);
118 SEND(sensors[s].typeSensor.byte,SIZE_TYPE_SENSOR,converter.byte);
119 send(&(sensors[s].sizeOutput),1);
120 send(&(sensors[s].typeOutput),1);
122 send(&(thisDevice.sizeIDAct),1);
123 SEND(&numActs,thisDevice.sizeIDAct,converter.byte);
124 for(a=0;a< numActs; a++)
126 SEND(actuators[a].ID.byte,thisDevice.sizeIDAct,converter.byte);
127 SEND(actuators[a].typeActuator.byte,SIZE_TYPE_ACTUATOR,converter.byte);
128 send(&(actuators[a].sizeInput),1);
129 send(&(actuators[a].typeInput),1);
133 message.byte[0] = ACTIVE_DEVICE_ACK;
139 RECV(message.byte,thisDevice.sizeIOMsg,converter.byte);
140 thisDevice.messageHandler(message.byte);
142 case MSG_AND_ANSWER_TO_DEVICE:
143 RECV(message.byte,thisDevice.sizeIOMsg,converter.byte);
144 thisDevice.messageAndAnswerHandler(message.byte,answer.byte);
145 SEND(answer.byte,thisDevice.sizeIOMsg,converter.byte);
147 case GET_SENSOR_VALUE:
150 RECV(message.byte,thisDevice.sizeIDSen,converter.byte);
152 sensors[id].getValue(answer.byte);
153 SEND(answer.byte,sensors[
id].sizeOutput,converter.byte);
155 case SET_ACTUATOR_VALUE:
157 RECV(message.byte,thisDevice.sizeIDAct,converter.byte);
158 id = message.integer;
159 RECV(message.byte,actuators[
id].sizeInput,converter.byte);
160 actuators[id].setValue(message.byte);
void addSensor(unsigned int typeSensor, unsigned char sizeOutput, unsigned char typeOutput, getSensorValueFunc getValue)
void createDevice(unsigned int address, unsigned char sizeIOmsg, messageHandlerFunc callback1, messageAndAnswerHandlerFunc callback2)
void(* messageHandlerFunc)(unsigned char *)
void communication(receiveUnisasa recvFunc, sendUnisasa sendFunc)
void(* setActuatorValueFunc)(unsigned char *act_value)
#define BYTES_ADDRESS_DEVICE
void(* getSensorValueFunc)(unsigned char *sensor_value)
void(* receiveUnisasa)(unsigned char *message, unsigned int size)
void addActuator(unsigned int typeActuator, unsigned char sizeInput, unsigned char typeInput, setActuatorValueFunc setValue)
void(* messageAndAnswerHandlerFunc)(unsigned char *request, unsigned char *reply)
void(* sendUnisasa)(unsigned char *message, unsigned int size)