31 boolean trustpack =
false;
32 uint32_t lostpack = 0;
40 this->_stmRef=stmObject;
48 this->_stmRef->print(
"Lost packets: ");
49 this->_stmRef->println(this->lostpack);
57 while (this->_stmRef->available()) this->_stmRef->read();
73 this->_stmRef->write(
"WRoS");
74 this->_stmRef->write(CRC_ck_a);
75 this->_stmRef->write(CRC_ck_b);
80 DATA_buffer[ck] = me->
NGS;
85 DATA_buffer[ck] = byte(me->
age >> 24 & 0xFF);
86 DATA_buffer[ck+1] = byte(me->
age >> 16 & 0xFF);
87 DATA_buffer[ck+2] = byte(me->
age >> 8 & 0xFF);
88 DATA_buffer[ck+3] = byte(me->
age & 0xFF);
92 DATA_buffer[ck] = byte(me->
ASBM >> 24 & 0xFF);
93 DATA_buffer[ck+1] = byte(me->
ASBM >> 16 & 0xFF);
94 DATA_buffer[ck+2] = byte(me->
ASBM >> 8 & 0xFF);
95 DATA_buffer[ck+3] = byte(me->
ASBM & 0xFF);
102 DATA_buffer[ck] = byte(me->
sensors.coord.x >> 8 & 0xFF);
103 DATA_buffer[ck+1] = byte(me->
sensors.coord.x & 0xFF);
104 DATA_buffer[ck+2] = byte(me->
sensors.coord.y >> 8 & 0xFF);
105 DATA_buffer[ck+3] = byte(me->
sensors.coord.y & 0xFF);
106 DATA_buffer[ck+4] = byte(me->
sensors.coord.z >> 8 & 0xFF);
107 DATA_buffer[ck+5] = byte(me->
sensors.coord.z & 0xFF);
113 DATA_buffer[ck] = byte(me->
sensors.angle.pitch >> 8 & 0xFF);
114 DATA_buffer[ck+1] = byte(me->
sensors.angle.pitch & 0xFF);
115 DATA_buffer[ck+2] = byte(me->
sensors.angle.roll >> 8 & 0xFF);
116 DATA_buffer[ck+3] = byte(me->
sensors.angle.roll & 0xFF);
117 DATA_buffer[ck+4] = byte(me->
sensors.angle.yaw >> 8 & 0xFF);
118 DATA_buffer[ck+5] = byte(me->
sensors.angle.yaw & 0xFF);
124 DATA_buffer[ck] = byte(me->
sensors.accel.x >> 8 & 0xFF);
125 DATA_buffer[ck+1] = byte(me->
sensors.accel.x & 0xFF);
126 DATA_buffer[ck+2] = byte(me->
sensors.accel.y >> 8 & 0xFF);
127 DATA_buffer[ck+3] = byte(me->
sensors.accel.y & 0xFF);
128 DATA_buffer[ck+4] = byte(me->
sensors.accel.z >> 8 & 0xFF);
129 DATA_buffer[ck+5] = byte(me->
sensors.accel.z & 0xFF);
135 DATA_buffer[ck] = byte(me->
sensors.ang_rate.x >> 8 & 0xFF);
136 DATA_buffer[ck+1] = byte(me->
sensors.ang_rate.x & 0xFF);
137 DATA_buffer[ck+2] = byte(me->
sensors.ang_rate.y >> 8 & 0xFF);
138 DATA_buffer[ck+3] = byte(me->
sensors.ang_rate.y & 0xFF);
139 DATA_buffer[ck+4] = byte(me->
sensors.ang_rate.z >> 8 & 0xFF);
140 DATA_buffer[ck+5] = byte(me->
sensors.ang_rate.z & 0xFF);
146 DATA_buffer[ck] = byte(me->
sensors.gps_pos.lat >> 24 & 0xFF);
147 DATA_buffer[ck+1] = byte(me->
sensors.gps_pos.lat >> 16 & 0xFF);
148 DATA_buffer[ck+2] = byte(me->
sensors.gps_pos.lat >> 8 & 0xFF);
149 DATA_buffer[ck+3] = byte(me->
sensors.gps_pos.lat & 0xFF);
150 DATA_buffer[ck+4] = byte(me->
sensors.gps_pos.lon >> 24 & 0xFF);
151 DATA_buffer[ck+5] = byte(me->
sensors.gps_pos.lon >> 16 & 0xFF);
152 DATA_buffer[ck+6] = byte(me->
sensors.gps_pos.lon >> 8 & 0xFF);
153 DATA_buffer[ck+7] = byte(me->
sensors.gps_pos.lon & 0xFF);
154 DATA_buffer[ck+8] = byte(me->
sensors.gps_pos.alt >> 24 & 0xFF);
155 DATA_buffer[ck+9] = byte(me->
sensors.gps_pos.alt >> 16 & 0xFF);
156 DATA_buffer[ck+10] = byte(me->
sensors.gps_pos.alt >> 8 & 0xFF);
157 DATA_buffer[ck+11] = byte(me->
sensors.gps_pos.alt & 0xFF);
158 DATA_buffer[ck+12] = byte(me->
sensors.gps_pos.gspeed >> 24 & 0xFF);
159 DATA_buffer[ck+13] = byte(me->
sensors.gps_pos.gspeed >> 16 & 0xFF);
160 DATA_buffer[ck+14] = byte(me->
sensors.gps_pos.gspeed >> 8 & 0xFF);
161 DATA_buffer[ck+15] = byte(me->
sensors.gps_pos.gspeed & 0xFF);
167 DATA_buffer[ck] = byte(me->
sensors.wind.speed >> 8 & 0xFF);
168 DATA_buffer[ck+1] = byte(me->
sensors.wind.speed & 0xFF);
169 DATA_buffer[ck+2] = byte(me->
sensors.wind.dir >> 8 & 0xFF);
170 DATA_buffer[ck+3] = byte(me->
sensors.wind.dir & 0xFF);
176 DATA_buffer[ck] = byte(me->
sensors.light.lux >> 24 & 0xFF);
177 DATA_buffer[ck+1] = byte(me->
sensors.light.lux >> 16 & 0xFF);
178 DATA_buffer[ck+2] = byte(me->
sensors.light.lux >> 8 & 0xFF);
179 DATA_buffer[ck+3] = byte(me->
sensors.light.lux & 0xFF);
180 DATA_buffer[ck+4] = byte(me->
sensors.light.temp >> 8 & 0xFF);
181 DATA_buffer[ck+5] = byte(me->
sensors.light.temp & 0xFF);
188 for (
int i=0;i<ck;i++) this->_stmRef->write(DATA_buffer[i]);
192 for (
int i=0;i<ck;i++)
194 CRC_ck_a += DATA_buffer[i];
195 CRC_ck_b += CRC_ck_a;
197 this->_stmRef->write(CRC_ck_a);
198 this->_stmRef->write(CRC_ck_b);
208 this->ck_b += this->ck_a;
216 byte _data = this->_stmRef->read();
228 boolean keepgoing =
true;
232 uint8_t DT_ck_a, DT_ck_b = 0;
236 _stmRef->println(
"Entered getData");
239 this->trustpack =
false;
241 if (this->_stmRef->available() > 0){
243 _stmRef->println(
"Ther is something to read");
246 while(this->_stmRef->available() && keepgoing)
249 _stmRef->println(
"Entered the read loop");
251 data = this->_stmRef->read();
278 _stmRef->println(
"Header OK");
301 nb->
age |= uint32_t(data) << 24;
303 nb->
age |= uint32_t(data) << 16;
305 nb->
age |= uint32_t(data) << 8;
307 nb->
age |= uint32_t(data);
311 nb->
ASBM |= uint32_t(data)<<24;
313 nb->
ASBM |= uint32_t(data)<<16;
315 nb->
ASBM |= uint32_t(data)<<8;
321 for(
int i=0;i<32;i++){
322 if(nb->
ASBM & (1<<i)){
326 sensdata.coord.x = 0;
327 sensdata.coord.y = 0;
328 sensdata.coord.z = 0;
331 sensdata.coord.x |= int16_t(data) << 8;
333 sensdata.coord.x |= data;
335 sensdata.coord.y |= int16_t(data) << 8;
337 sensdata.coord.y |= data;
339 sensdata.coord.z |= int16_t(data) << 8;
341 sensdata.coord.z |= data;
345 sensdata.angle.pitch = 0;
346 sensdata.angle.roll = 0;
347 sensdata.angle.yaw = 0;
350 sensdata.angle.pitch |= int16_t(data) << 8;
352 sensdata.angle.pitch |= data;
354 sensdata.angle.roll |= int16_t(data) << 8;
356 sensdata.angle.roll |= data;
358 sensdata.angle.yaw |= int16_t(data) << 8;
360 sensdata.angle.yaw |= data;
364 sensdata.accel.x = 0;
365 sensdata.accel.y = 0;
366 sensdata.accel.z = 0;
369 sensdata.accel.x |= int16_t(data) << 8;
371 sensdata.accel.x |= data;
373 sensdata.accel.y |= int16_t(data) << 8;
375 sensdata.accel.y |= data;
377 sensdata.accel.z |= int16_t(data) << 8;
379 sensdata.accel.z |= data;
383 sensdata.ang_rate.x = 0;
384 sensdata.ang_rate.y = 0;
385 sensdata.ang_rate.z = 0;
388 sensdata.ang_rate.x |= int16_t(data) << 8;
390 sensdata.ang_rate.x |= data;
392 sensdata.ang_rate.y |= int16_t(data) << 8;
394 sensdata.ang_rate.y |= data;
396 sensdata.ang_rate.z |= int16_t(data) << 8;
398 sensdata.ang_rate.z |= data;
402 sensdata.gps_pos.lat = 0;
403 sensdata.gps_pos.lon = 0;
404 sensdata.gps_pos.alt = 0;
405 sensdata.gps_pos.gspeed = 0;
408 sensdata.gps_pos.lat |= int32_t(data) << 24;
410 sensdata.gps_pos.lat |= int32_t(data) << 16;
412 sensdata.gps_pos.lat |= int32_t(data) << 8;
414 sensdata.gps_pos.lat |= data;
416 sensdata.gps_pos.lon |= int32_t(data) << 24;
418 sensdata.gps_pos.lon |= int32_t(data) << 16;
420 sensdata.gps_pos.lon |= int32_t(data) << 8;
422 sensdata.gps_pos.lon |= data;
424 sensdata.gps_pos.alt |= int32_t(data) << 24;
426 sensdata.gps_pos.alt |= int32_t(data) << 16;
428 sensdata.gps_pos.alt |= int32_t(data) << 8;
430 sensdata.gps_pos.alt |= data;
432 sensdata.gps_pos.gspeed |= int32_t(data) << 24;
434 sensdata.gps_pos.gspeed |= int32_t(data) << 16;
436 sensdata.gps_pos.gspeed |= int32_t(data) << 8;
438 sensdata.gps_pos.gspeed |= data;
442 sensdata.wind.speed = 0;
443 sensdata.wind.dir = 0;
446 sensdata.wind.speed |= int16_t(data) << 8;
448 sensdata.wind.speed |= data;
450 sensdata.wind.dir |= int16_t(data) << 8;
452 sensdata.wind.dir |= data;
456 sensdata.light.lux = 0;
457 sensdata.light.temp = 0;
460 sensdata.light.lux |= int32_t(data) << 24;
462 sensdata.light.lux |= int32_t(data) << 16;
464 sensdata.light.lux |= int32_t(data) << 8;
466 sensdata.light.lux |= data;
468 sensdata.light.temp |= int16_t(data) << 8;
470 sensdata.light.temp |= data;
489 if((this->ck_a==DT_ck_a) && (this->ck_b==DT_ck_b)){
492 this->trustpack =
true;
500 if(chances-- == 0) keepgoing =
false;
This file defines the WindRose's Being class.
This file is for keeping any general configuration parameters.
This file contains the Sensing types, the sensors enumeration, and defines the sensing holder Sensing...
#define MAX_SENSING_BYTES_PER_PACKET
Definition of all sensor bytes summed up in a single packet.
Definition: Sensing.h:15
This file defines the WindRose's Multiplexer Control class WRMux.
The base class (the soul) for all the beings in the simulation.
Definition: Being.h:23
uint32_t age
The age of the being, since the board is up.
Definition: Being.h:30
boolean isactive(uint8_t bit_pos)
Checks if a sensor is active in the 32bit Active Sensor Bit Map (ASBM)
Definition: Being.h:70
boolean alive
The state of the being (dead = 0, alive = 1)
Definition: Being.h:28
SensingData sensors
Sensor dada holder It has all the sensor types defined in the Sensing.h file. Think of it as a holde...
Definition: Being.h:35
byte NGS
The neighborhood state mapping (NGS)
Definition: Being.h:37
long ASBM
The active sensor mapping (ASBM)
Definition: Being.h:39
The class to control the Serial State Machine.
Definition: SSMachine.h:24
byte readsum()
This function reads the data from the input stream, calculates the CRC checksum and returns the data.
Definition: SSMachine.h:215
void getData(Being *nb)
This function grabs the data from the input stream and feeds the local neigbour sensing data holder.
Definition: SSMachine.h:225
void clearBuffer()
Clears the Serial Buffer.
Definition: SSMachine.h:55
void setSerial(Stream *stmObject)
Initializes the Serial State Machine by setting its internal Stream object to a pointer to the Serial...
Definition: SSMachine.h:38
void printLostPack()
Prints the Lost Packets counter to the Serial port.
Definition: SSMachine.h:46
void checksum(byte dt)
This function is used to calculate the CRC checksum for the data.
Definition: SSMachine.h:205
void sendData(Being *me)
Sends the data of the itself Sensing data to the Serial port.
Definition: SSMachine.h:64
The class for the WindRose Multiplexer Control.
Definition: WRMux.h:21
void disable()
Sets the inhibit pin and disable the mux.
Definition: WRMux.h:52
Sensing holder structure with all the sensor types, ordered by the ASBM bits from its least significa...
Definition: Sensing.h:130