NerfUS mobile node that manages a target for the Nerf gun firing range
Dependencies: LedController mbed-rtos mbed NerfUSXbee Servomotor TargetManager
Fork of NerfUS by
Diff: source/Target.cpp
- Revision:
- 40:1f0a5e5f24f6
- Parent:
- 36:f55ce07292c9
- Child:
- 41:d60c9ced57ab
--- a/source/Target.cpp Sun Apr 09 19:49:07 2017 +0000 +++ b/source/Target.cpp Sun Apr 09 21:22:08 2017 +0000 @@ -40,28 +40,27 @@ enemy_leds.turn_on(); } -std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms) const +void Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms, uint8_t* message) const { const uint8_t time_taken_msb = time_taken_ms >> 8; const uint8_t time_taken_lsb = (time_taken_ms << 8) >> 8; - std::vector<uint8_t> message; - message.push_back(target_number); - message.push_back(result); - message.push_back(time_taken_msb); - message.push_back(time_taken_lsb); - - return message; + message[0] = target_number; + message[1] = result; + message[2] = time_taken_msb; + message[3] = time_taken_lsb; } void Target::timeout(const int time_taken_ms) { - const std::vector<uint8_t> message = generate_message(target_number, Target::RESULT_MISSED, time_taken_ms); + uint8_t message[4]; + generate_message(target_number, Target::RESULT_MISSED, time_taken_ms, message); xbee_transmitter.transmit(message, coordinator_address); } void Target::hit(const int time_taken_ms) { - const std::vector<uint8_t> message = generate_message(target_number, Target::RESULT_HIT, time_taken_ms); + uint8_t message[4]; + generate_message(target_number, Target::RESULT_HIT, time_taken_ms, message); xbee_transmitter.transmit(message, coordinator_address); }