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

Last change on this file since 3 was 3, checked in by Sanahuja Guillaume, 5 years ago

sensoractuator

File size: 4.0 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 { namespace sensor {
22
23RumbleMessage::RumbleMessage(unsigned int leftForce,unsigned int leftTimeout,unsigned int rightForce,unsigned int rightTimeout):Message(sizeof(ControllerAction)+sizeof(leftForce)+sizeof(leftTimeout)+sizeof(rightForce)+sizeof(rightTimeout)) {
24    SetLeftForce(leftForce);
25    SetLeftTimeout(leftTimeout);
26    SetRightForce(rightForce);
27    SetRightTimeout(rightTimeout);
28    buffer[0]=(char)ControllerAction::Rumble;
29}
30
31unsigned int RumbleMessage::GetLeftForce() const {
32    unsigned int leftForce;
33    memcpy(&leftForce,buffer+leftForceOffset,sizeof(leftForce));
34    return leftForce;
35}
36
37unsigned int RumbleMessage::GetLeftTimeout() const {
38    unsigned int leftTimeout;
39    memcpy(&leftTimeout,buffer+leftTimeoutOffset,sizeof(leftTimeout));
40    return leftTimeout;
41}
42
43unsigned int RumbleMessage::GetRightForce() const {
44    unsigned int rightForce;
45    memcpy(&rightForce,buffer+rightForceOffset,sizeof(rightForce));
46    return rightForce;
47}
48
49unsigned int RumbleMessage::GetRightTimeout() const {
50    unsigned int rightTimeout;
51    memcpy(&rightTimeout,buffer+rightTimeoutOffset,sizeof(rightTimeout));
52    return rightTimeout;
53}
54
55void RumbleMessage::SetLeftForce(unsigned int leftForce) {
56    memcpy(buffer+leftForceOffset,&leftForce,sizeof(leftForce));
57}
58
59void RumbleMessage::SetLeftTimeout(unsigned int leftTimeout) {
60    memcpy(buffer+leftTimeoutOffset,&leftTimeout,sizeof(leftTimeout));
61}
62
63void RumbleMessage::SetRightForce(unsigned int rightForce) {
64    memcpy(buffer+rightForceOffset,&rightForce,sizeof(rightForce));
65}
66
67void RumbleMessage::SetRightTimeout(unsigned int rightTimeout){
68    memcpy(buffer+rightTimeoutOffset,&rightTimeout,sizeof(rightTimeout));
69}
70
71SwitchLedMessage::SwitchLedMessage(bool isOn, unsigned int ledId):Message(sizeof(ControllerAction)+sizeof(isOn)+sizeof(ledId)) {
72    if (isOn) SetOn(); else SetOff();
73    SetLedId(ledId);
74}
75
76bool SwitchLedMessage::IsOn() const {
77    bool isOn;
78    memcpy(&isOn,buffer+isOnOffset,sizeof(isOn));
79    return isOn;
80}
81
82unsigned int SwitchLedMessage::GetLedId() const {
83    unsigned int ledId;
84    memcpy(&ledId,buffer+ledIdOffset,sizeof(ledId));
85    return ledId;
86}
87
88void SwitchLedMessage::SetOn() {
89    bool isOn=true;
90    memcpy(buffer+isOnOffset,&isOn,sizeof(isOn));
91}
92
93void SwitchLedMessage::SetOff() {
94    bool isOn=false;
95    memcpy(buffer+isOnOffset,&isOn,sizeof(isOn));
96}
97
98void SwitchLedMessage::SetLedId(unsigned int ledId) {
99    memcpy(buffer+ledIdOffset,&ledId,sizeof(ledId));
100}
101
102FlashLedMessage::FlashLedMessage(unsigned int ledId,unsigned int onTime,unsigned int offTime):Message(sizeof(ControllerAction)+sizeof(ledId)+sizeof(onTime)+sizeof(offTime)) {
103    SetLedId(ledId);
104    SetOnTime(onTime);
105    SetOffTime(offTime);
106}
107
108unsigned int FlashLedMessage::GetLedId() const {
109    unsigned int ledId;
110    memcpy(&ledId,buffer+ledIdOffset,sizeof(ledId));
111    return ledId;
112}
113
114unsigned int FlashLedMessage::GetOnTime() const {
115    unsigned int onTime;
116    memcpy(&onTime,buffer+onTimeOffset,sizeof(onTime));
117    return onTime;
118}
119
120unsigned int FlashLedMessage::GetOffTime() const {
121    unsigned int offTime;
122    memcpy(&offTime,buffer+offTimeOffset,sizeof(offTime));
123    return offTime;
124}
125
126void FlashLedMessage::SetLedId(unsigned int ledId) {
127    memcpy(buffer+ledIdOffset,&ledId,sizeof(ledId));
128}
129
130void FlashLedMessage::SetOnTime(unsigned int onTime) {
131    memcpy(buffer+onTimeOffset,&onTime,sizeof(onTime));
132}
133
134void FlashLedMessage::SetOffTime(unsigned int offTime) {
135    memcpy(buffer+offTimeOffset,&offTime,sizeof(offTime));
136}
137
138} // end namespace sensor
139} // end namespace flair
Note: See TracBrowser for help on using the repository browser.