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

Committer:
Maxime Dupuis
Date:
Wed Mar 08 13:56:18 2017 -0500
Revision:
19:377887760869
Parent:
18:353fb432c03c
Child:
20:05e2c4941285
Generate message for a target hit or miss

See: https://trello.com/c/VuH8fxTH/34-xbee-message-protocol-between-gameccoordinator-and-target-s

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Maxime Dupuis 18:353fb432c03c 1 #include "Target.hpp"
Maxime Dupuis 18:353fb432c03c 2
Maxime Dupuis 18:353fb432c03c 3
Maxime Dupuis 19:377887760869 4 Target::Target(ServomotorInterface& servomotor, LedControllerInterface& led_controller, XbeeTransmitterInterface& xbee_transmitter):
Maxime Dupuis 18:353fb432c03c 5 servomotor(servomotor),
Maxime Dupuis 19:377887760869 6 led_controller(led_controller),
Maxime Dupuis 19:377887760869 7 xbee_transmitter(xbee_transmitter)
Maxime Dupuis 18:353fb432c03c 8 {
Maxime Dupuis 18:353fb432c03c 9 }
Maxime Dupuis 18:353fb432c03c 10
Maxime Dupuis 18:353fb432c03c 11 void Target::execute_command(Mode mode, int timeout_ms)
Maxime Dupuis 18:353fb432c03c 12 {
Maxime Dupuis 18:353fb432c03c 13 if(mode == Ally)
Maxime Dupuis 18:353fb432c03c 14 {
Maxime Dupuis 18:353fb432c03c 15 ally_command();
Maxime Dupuis 18:353fb432c03c 16 }
Maxime Dupuis 18:353fb432c03c 17 else
Maxime Dupuis 18:353fb432c03c 18 {
Maxime Dupuis 18:353fb432c03c 19 enemy_command();
Maxime Dupuis 18:353fb432c03c 20 }
Maxime Dupuis 18:353fb432c03c 21 }
Maxime Dupuis 18:353fb432c03c 22
Maxime Dupuis 18:353fb432c03c 23
Maxime Dupuis 18:353fb432c03c 24 void Target::ally_command()
Maxime Dupuis 18:353fb432c03c 25 {
Maxime Dupuis 18:353fb432c03c 26 servomotor.set_position_up();
Maxime Dupuis 18:353fb432c03c 27 }
Maxime Dupuis 18:353fb432c03c 28
Maxime Dupuis 18:353fb432c03c 29 void Target::enemy_command()
Maxime Dupuis 18:353fb432c03c 30 {
Maxime Dupuis 18:353fb432c03c 31 led_controller.turn_on();
Maxime Dupuis 18:353fb432c03c 32 servomotor.set_position_up();
Maxime Dupuis 18:353fb432c03c 33 }
Maxime Dupuis 18:353fb432c03c 34
Maxime Dupuis 19:377887760869 35 std::vector<uint8_t> Target::generate_message(uint8_t target_number, Result result, uint16_t timeout_ms) const
Maxime Dupuis 19:377887760869 36 {
Maxime Dupuis 19:377887760869 37 const uint8_t target_number_and_result = (target_number << 3) + result;
Maxime Dupuis 19:377887760869 38 const uint8_t timeout_ms_msb = timeout_ms >> 8;
Maxime Dupuis 19:377887760869 39 const uint8_t timeout_ms_lsb = (timeout_ms << 8) >> 8;
Maxime Dupuis 19:377887760869 40
Maxime Dupuis 19:377887760869 41 std::vector<uint8_t> message;
Maxime Dupuis 19:377887760869 42
Maxime Dupuis 19:377887760869 43 message.push_back(target_number_and_result);
Maxime Dupuis 19:377887760869 44 message.push_back(timeout_ms_msb);
Maxime Dupuis 19:377887760869 45 message.push_back(timeout_ms_lsb);
Maxime Dupuis 19:377887760869 46
Maxime Dupuis 19:377887760869 47 return message;
Maxime Dupuis 19:377887760869 48 }