1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2015/05/27
|
---|
6 | // filename: Controller.cpp
|
---|
7 | //
|
---|
8 | // author: Gildas Bayard
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: Utility classes for controllers
|
---|
14 | //
|
---|
15 | //
|
---|
16 | /*********************************************************************/
|
---|
17 | #include "Controller.h"
|
---|
18 |
|
---|
19 | using namespace flair::core;
|
---|
20 |
|
---|
21 | namespace flair {
|
---|
22 | namespace sensor {
|
---|
23 |
|
---|
24 | RumbleMessage::RumbleMessage(unsigned int leftForce, unsigned int leftTimeout,
|
---|
25 | unsigned int rightForce, unsigned int rightTimeout)
|
---|
26 | : Message(sizeof(ControllerAction) + sizeof(leftForce) +
|
---|
27 | sizeof(leftTimeout) + sizeof(rightForce) + sizeof(rightTimeout)) {
|
---|
28 | SetLeftForce(leftForce);
|
---|
29 | SetLeftTimeout(leftTimeout);
|
---|
30 | SetRightForce(rightForce);
|
---|
31 | SetRightTimeout(rightTimeout);
|
---|
32 | buffer[0] = (char)ControllerAction::Rumble;
|
---|
33 | }
|
---|
34 |
|
---|
35 | unsigned int RumbleMessage::GetLeftForce() const {
|
---|
36 | unsigned int leftForce;
|
---|
37 | memcpy(&leftForce, buffer + leftForceOffset, sizeof(leftForce));
|
---|
38 | return leftForce;
|
---|
39 | }
|
---|
40 |
|
---|
41 | unsigned int RumbleMessage::GetLeftTimeout() const {
|
---|
42 | unsigned int leftTimeout;
|
---|
43 | memcpy(&leftTimeout, buffer + leftTimeoutOffset, sizeof(leftTimeout));
|
---|
44 | return leftTimeout;
|
---|
45 | }
|
---|
46 |
|
---|
47 | unsigned int RumbleMessage::GetRightForce() const {
|
---|
48 | unsigned int rightForce;
|
---|
49 | memcpy(&rightForce, buffer + rightForceOffset, sizeof(rightForce));
|
---|
50 | return rightForce;
|
---|
51 | }
|
---|
52 |
|
---|
53 | unsigned int RumbleMessage::GetRightTimeout() const {
|
---|
54 | unsigned int rightTimeout;
|
---|
55 | memcpy(&rightTimeout, buffer + rightTimeoutOffset, sizeof(rightTimeout));
|
---|
56 | return rightTimeout;
|
---|
57 | }
|
---|
58 |
|
---|
59 | void RumbleMessage::SetLeftForce(unsigned int leftForce) {
|
---|
60 | memcpy(buffer + leftForceOffset, &leftForce, sizeof(leftForce));
|
---|
61 | }
|
---|
62 |
|
---|
63 | void RumbleMessage::SetLeftTimeout(unsigned int leftTimeout) {
|
---|
64 | memcpy(buffer + leftTimeoutOffset, &leftTimeout, sizeof(leftTimeout));
|
---|
65 | }
|
---|
66 |
|
---|
67 | void RumbleMessage::SetRightForce(unsigned int rightForce) {
|
---|
68 | memcpy(buffer + rightForceOffset, &rightForce, sizeof(rightForce));
|
---|
69 | }
|
---|
70 |
|
---|
71 | void RumbleMessage::SetRightTimeout(unsigned int rightTimeout) {
|
---|
72 | memcpy(buffer + rightTimeoutOffset, &rightTimeout, sizeof(rightTimeout));
|
---|
73 | }
|
---|
74 |
|
---|
75 | SwitchLedMessage::SwitchLedMessage(bool isOn, unsigned int ledId)
|
---|
76 | : Message(sizeof(ControllerAction) + sizeof(isOn) + sizeof(ledId)) {
|
---|
77 | if (isOn)
|
---|
78 | SetOn();
|
---|
79 | else
|
---|
80 | SetOff();
|
---|
81 | SetLedId(ledId);
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool SwitchLedMessage::IsOn() const {
|
---|
85 | bool isOn;
|
---|
86 | memcpy(&isOn, buffer + isOnOffset, sizeof(isOn));
|
---|
87 | return isOn;
|
---|
88 | }
|
---|
89 |
|
---|
90 | unsigned int SwitchLedMessage::GetLedId() const {
|
---|
91 | unsigned int ledId;
|
---|
92 | memcpy(&ledId, buffer + ledIdOffset, sizeof(ledId));
|
---|
93 | return ledId;
|
---|
94 | }
|
---|
95 |
|
---|
96 | void SwitchLedMessage::SetOn() {
|
---|
97 | bool isOn = true;
|
---|
98 | memcpy(buffer + isOnOffset, &isOn, sizeof(isOn));
|
---|
99 | }
|
---|
100 |
|
---|
101 | void SwitchLedMessage::SetOff() {
|
---|
102 | bool isOn = false;
|
---|
103 | memcpy(buffer + isOnOffset, &isOn, sizeof(isOn));
|
---|
104 | }
|
---|
105 |
|
---|
106 | void SwitchLedMessage::SetLedId(unsigned int ledId) {
|
---|
107 | memcpy(buffer + ledIdOffset, &ledId, sizeof(ledId));
|
---|
108 | }
|
---|
109 |
|
---|
110 | FlashLedMessage::FlashLedMessage(unsigned int ledId, unsigned int onTime,
|
---|
111 | unsigned int offTime)
|
---|
112 | : Message(sizeof(ControllerAction) + sizeof(ledId) + sizeof(onTime) +
|
---|
113 | sizeof(offTime)) {
|
---|
114 | SetLedId(ledId);
|
---|
115 | SetOnTime(onTime);
|
---|
116 | SetOffTime(offTime);
|
---|
117 | }
|
---|
118 |
|
---|
119 | unsigned int FlashLedMessage::GetLedId() const {
|
---|
120 | unsigned int ledId;
|
---|
121 | memcpy(&ledId, buffer + ledIdOffset, sizeof(ledId));
|
---|
122 | return ledId;
|
---|
123 | }
|
---|
124 |
|
---|
125 | unsigned int FlashLedMessage::GetOnTime() const {
|
---|
126 | unsigned int onTime;
|
---|
127 | memcpy(&onTime, buffer + onTimeOffset, sizeof(onTime));
|
---|
128 | return onTime;
|
---|
129 | }
|
---|
130 |
|
---|
131 | unsigned int FlashLedMessage::GetOffTime() const {
|
---|
132 | unsigned int offTime;
|
---|
133 | memcpy(&offTime, buffer + offTimeOffset, sizeof(offTime));
|
---|
134 | return offTime;
|
---|
135 | }
|
---|
136 |
|
---|
137 | void FlashLedMessage::SetLedId(unsigned int ledId) {
|
---|
138 | memcpy(buffer + ledIdOffset, &ledId, sizeof(ledId));
|
---|
139 | }
|
---|
140 |
|
---|
141 | void FlashLedMessage::SetOnTime(unsigned int onTime) {
|
---|
142 | memcpy(buffer + onTimeOffset, &onTime, sizeof(onTime));
|
---|
143 | }
|
---|
144 |
|
---|
145 | void FlashLedMessage::SetOffTime(unsigned int offTime) {
|
---|
146 | memcpy(buffer + offTimeOffset, &offTime, sizeof(offTime));
|
---|
147 | }
|
---|
148 |
|
---|
149 | } // end namespace sensor
|
---|
150 | } // end namespace flair
|
---|