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 NerfUS

Revision:
23:fb47bceb61da
Parent:
22:d9df16225df3
Child:
24:801271795da0
diff -r d9df16225df3 -r fb47bceb61da source/Target.cpp
--- a/source/Target.cpp	Sat Mar 11 12:59:26 2017 -0500
+++ b/source/Target.cpp	Sat Mar 11 13:25:00 2017 -0500
@@ -4,11 +4,13 @@
 Target::Target(ServomotorInterface& servomotor,
         LedControllerInterface& ally_leds,
         LedControllerInterface& enemy_leds,
-        XbeeTransmitterInterface& xbee_transmitter):
+        XbeeTransmitterInterface& xbee_transmitter,
+        const int target_number):
     servomotor(servomotor),
     ally_leds(ally_leds),
     enemy_leds(enemy_leds),
-    xbee_transmitter(xbee_transmitter)
+    xbee_transmitter(xbee_transmitter),
+    target_number(target_number)
 {
 }
 
@@ -39,15 +41,20 @@
 
 std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t time_taken_ms) const
 {
-    const uint8_t target_number_and_result = (target_number << 3) + result;
     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_and_result);
+    message.push_back(target_number);
+    message.push_back(result);
     message.push_back(time_taken_msb);
     message.push_back(time_taken_lsb);
 
     return message;
 }
+
+void Target::timeout(const int time_taken_ms)
+{
+    const std::vector<uint8_t> message = generate_message(target_number, Target::RESULT_MISSED, time_taken_ms);
+    xbee_transmitter.transmit(message);
+}