Coordinator v2
Dependencies: NerfUSXbee PinDetect EthernetInterface JSON MFRC522 WebSocketClient mbed-rtos mbed
src/Target.cpp@2:019d8848cf7e, 2017-04-11 (annotated)
- Committer:
- Ismael Balafrej
- Date:
- Tue Apr 11 12:40:05 2017 -0400
- Revision:
- 2:019d8848cf7e
- Parent:
- 1:e1c5259b7d9a
Final version without allies/enemies
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ismael Balafrej |
1:e1c5259b7d9a | 1 | #include "Target.hpp" |
Ismael Balafrej |
1:e1c5259b7d9a | 2 | |
Ismael Balafrej |
1:e1c5259b7d9a | 3 | RealXbeeTransmitter xbee_transmitter; |
Ismael Balafrej |
1:e1c5259b7d9a | 4 | |
Ismael Balafrej |
1:e1c5259b7d9a | 5 | Target::Target(int address_msb, int address_lsb, int target_number) |
Ismael Balafrej |
1:e1c5259b7d9a | 6 | { |
Ismael Balafrej |
1:e1c5259b7d9a | 7 | get_address_for_xbee(address_msb, address_lsb); |
Ismael Balafrej |
1:e1c5259b7d9a | 8 | this->target_number = target_number; |
Ismael Balafrej |
1:e1c5259b7d9a | 9 | } |
Ismael Balafrej |
1:e1c5259b7d9a | 10 | |
Ismael Balafrej |
1:e1c5259b7d9a | 11 | void Target::rise(int mode, int timeout) |
Ismael Balafrej |
1:e1c5259b7d9a | 12 | { |
Ismael Balafrej |
2:019d8848cf7e | 13 | is_risen = true; |
Ismael Balafrej |
1:e1c5259b7d9a | 14 | toPc("Rising target %i!", target_number); |
Ismael Balafrej |
1:e1c5259b7d9a | 15 | vector<uint8_t> message; |
Ismael Balafrej |
1:e1c5259b7d9a | 16 | message.push_back(target_number); |
Ismael Balafrej |
1:e1c5259b7d9a | 17 | message.push_back(mode); |
Ismael Balafrej |
1:e1c5259b7d9a | 18 | message.push_back((timeout >> 8) & 0xFF); |
Ismael Balafrej |
1:e1c5259b7d9a | 19 | message.push_back(timeout && 0xFF); |
Ismael Balafrej |
1:e1c5259b7d9a | 20 | xbee_transmitter.transmit(message, addr_table); |
Ismael Balafrej |
1:e1c5259b7d9a | 21 | } |
Ismael Balafrej |
1:e1c5259b7d9a | 22 | |
Ismael Balafrej |
1:e1c5259b7d9a | 23 | void Target::get_address_for_xbee(int address_msb, int address_lsb) |
Ismael Balafrej |
1:e1c5259b7d9a | 24 | { |
Ismael Balafrej |
1:e1c5259b7d9a | 25 | addr_table[0] = address_msb >> 24; |
Ismael Balafrej |
1:e1c5259b7d9a | 26 | addr_table[1] = (address_msb >> 16) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 27 | addr_table[2] = (address_msb >> 8) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 28 | addr_table[3] = (address_msb) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 29 | addr_table[4] = address_lsb >> 24; |
Ismael Balafrej |
1:e1c5259b7d9a | 30 | addr_table[5] = (address_lsb >> 16) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 31 | addr_table[6] = (address_lsb >> 8) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 32 | addr_table[7] = (address_lsb) & 0xFF; |
Ismael Balafrej |
1:e1c5259b7d9a | 33 | } |