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

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

sources reformatted with flair-format-dir script

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