source: flair-src/trunk/lib/FlairSensorActuator/src/Controller.cpp@ 16

Last change on this file since 16 was 15, checked in by Bayard Gildas, 7 years ago

sources reformatted with flair-format-dir script

File size: 4.1 KB
Line 
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
19using namespace flair::core;
20
21namespace flair {
22namespace sensor {
23
24RumbleMessage::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
35unsigned int RumbleMessage::GetLeftForce() const {
36 unsigned int leftForce;
37 memcpy(&leftForce, buffer + leftForceOffset, sizeof(leftForce));
38 return leftForce;
39}
40
41unsigned int RumbleMessage::GetLeftTimeout() const {
42 unsigned int leftTimeout;
43 memcpy(&leftTimeout, buffer + leftTimeoutOffset, sizeof(leftTimeout));
44 return leftTimeout;
45}
46
47unsigned int RumbleMessage::GetRightForce() const {
48 unsigned int rightForce;
49 memcpy(&rightForce, buffer + rightForceOffset, sizeof(rightForce));
50 return rightForce;
51}
52
53unsigned int RumbleMessage::GetRightTimeout() const {
54 unsigned int rightTimeout;
55 memcpy(&rightTimeout, buffer + rightTimeoutOffset, sizeof(rightTimeout));
56 return rightTimeout;
57}
58
59void RumbleMessage::SetLeftForce(unsigned int leftForce) {
60 memcpy(buffer + leftForceOffset, &leftForce, sizeof(leftForce));
61}
62
63void RumbleMessage::SetLeftTimeout(unsigned int leftTimeout) {
64 memcpy(buffer + leftTimeoutOffset, &leftTimeout, sizeof(leftTimeout));
65}
66
67void RumbleMessage::SetRightForce(unsigned int rightForce) {
68 memcpy(buffer + rightForceOffset, &rightForce, sizeof(rightForce));
69}
70
71void RumbleMessage::SetRightTimeout(unsigned int rightTimeout) {
72 memcpy(buffer + rightTimeoutOffset, &rightTimeout, sizeof(rightTimeout));
73}
74
75SwitchLedMessage::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
84bool SwitchLedMessage::IsOn() const {
85 bool isOn;
86 memcpy(&isOn, buffer + isOnOffset, sizeof(isOn));
87 return isOn;
88}
89
90unsigned int SwitchLedMessage::GetLedId() const {
91 unsigned int ledId;
92 memcpy(&ledId, buffer + ledIdOffset, sizeof(ledId));
93 return ledId;
94}
95
96void SwitchLedMessage::SetOn() {
97 bool isOn = true;
98 memcpy(buffer + isOnOffset, &isOn, sizeof(isOn));
99}
100
101void SwitchLedMessage::SetOff() {
102 bool isOn = false;
103 memcpy(buffer + isOnOffset, &isOn, sizeof(isOn));
104}
105
106void SwitchLedMessage::SetLedId(unsigned int ledId) {
107 memcpy(buffer + ledIdOffset, &ledId, sizeof(ledId));
108}
109
110FlashLedMessage::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
119unsigned int FlashLedMessage::GetLedId() const {
120 unsigned int ledId;
121 memcpy(&ledId, buffer + ledIdOffset, sizeof(ledId));
122 return ledId;
123}
124
125unsigned int FlashLedMessage::GetOnTime() const {
126 unsigned int onTime;
127 memcpy(&onTime, buffer + onTimeOffset, sizeof(onTime));
128 return onTime;
129}
130
131unsigned int FlashLedMessage::GetOffTime() const {
132 unsigned int offTime;
133 memcpy(&offTime, buffer + offTimeOffset, sizeof(offTime));
134 return offTime;
135}
136
137void FlashLedMessage::SetLedId(unsigned int ledId) {
138 memcpy(buffer + ledIdOffset, &ledId, sizeof(ledId));
139}
140
141void FlashLedMessage::SetOnTime(unsigned int onTime) {
142 memcpy(buffer + onTimeOffset, &onTime, sizeof(onTime));
143}
144
145void FlashLedMessage::SetOffTime(unsigned int offTime) {
146 memcpy(buffer + offTimeOffset, &offTime, sizeof(offTime));
147}
148
149} // end namespace sensor
150} // end namespace flair
Note: See TracBrowser for help on using the repository browser.