tobicore  7.0.0
 All Classes Functions Variables Typedefs Enumerator Friends Groups Pages
IDMessage.cpp
1 /*
2  Copyright (C) 2009-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
3  Michele Tavella <michele.tavella@epfl.ch>
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "IDMessage.hpp"
20 #include <tobicore/TCException.hpp>
21 #include <string.h>
22 #include <stdio.h>
23 
24 #ifdef __BORLANDC__
25 using namespace std;
26 #endif
27 
28 std::string IDMessage::TxtFamilyUndef("FamilyUndef");
29 std::string IDMessage::TxtFamilyBiosig("FamilyBiosig");
30 std::string IDMessage::TxtFamilyCustom("FamilyCustom");
31 
32 IDMessage::IDMessage(void) {
33  this->Init();
34 }
35 
36 IDMessage::~IDMessage(void) {
37 }
38 
39 IDMessage::IDMessage(IDMessage* const other) {
40  this->Init();
41  this->Copy(other);
42 }
43 
44 IDMessage::IDMessage(IDFtype familyType, IDevent event) {
45  this->Init();
46  this->_familyType = familyType;
47  this->_event = event;
48  this->_description = "unset";
49 }
50 
51 void IDMessage::Copy(IDMessage* const other) {
53  this->_event = other->GetEvent();
54  this->_familyType = other->GetFamilyType();
55  this->_description = other->GetDescription();
56 }
57 
58 void IDMessage::Init(void) {
60  this->_familyType = IDMessage::FamilyUndef;
61  this->_event = IDMessage::EventNull;
62 }
63 
64 std::string IDMessage::GetDescription(void) const {
65  return this->_description;
66 }
67 
68 void IDMessage::SetDescription(const std::string& description) {
69  this->_description = description;
70 }
71 
72 std::string IDMessage::GetSource(void) const {
73  return this->_description;
74 }
75 
76 void IDMessage::SetSource(const std::string& description) {
77  this->_description = description;
78 }
79 
80 IDFvalue IDMessage::GetFamily(void) const {
81  IDFvalue fvalue;
82  switch(this->_familyType) {
83  case IDMessage::FamilyBiosig:
84  fvalue.assign(IDTYPES_FAMILY_BIOSIG);
85  break;
86  case IDMessage::FamilyCustom:
87  fvalue.assign(IDTYPES_FAMILY_CUSTOM);
88  break;
89  case IDMessage::FamilyUndef:
90  default:
91  fvalue.assign(IDTYPES_FAMILY_UNDEF);
92  break;
93  }
94  return fvalue;
95 }
96 
97 bool IDMessage::SetFamilyType(const IDFtype type) {
98  if(type < IDMessage::FamilyUndef || type > IDMessage::FamilyCustom)
99  return false;
100  this->_familyType = type;
101  return true;
102 }
103 
104 bool IDMessage::SetFamilyType(const std::string& type) {
105  if(type.compare(IDMessage::TxtFamilyUndef) == 0)
106  this->_familyType = IDMessage::FamilyUndef;
107  else if(type.compare(IDMessage::TxtFamilyBiosig) == 0)
108  this->_familyType = IDMessage::FamilyBiosig;
109  else if(type.compare(IDMessage::TxtFamilyCustom) == 0)
110  this->_familyType = IDMessage::FamilyCustom;
111  else
112  return false;
113  return true;
114 }
115 
116 IDFtype IDMessage::GetFamilyType(void) const {
117  return this->_familyType;
118 }
119 
120 void IDMessage::SetEvent(const IDevent event) {
121  this->_event = event;
122 }
123 
124 IDevent IDMessage::GetEvent(void) const {
125  return this->_event;
126 }
127 
128 void IDMessage::Dump(void) const {
129  printf("[IDMessage::Dump] TOBI iD message for frame %d [%s]\n",
130  TCBlock::GetBlockIdx(), this->GetDescription().c_str());
131  IDFvalue fvalue = this->GetFamily();
132  printf(" + Event family %d/%s\n", this->GetFamilyType(), fvalue.c_str());
133  printf(" + Event value %d\n", this->GetEvent());
134 
135 }
136 
137 const IDFtype IDMessage::FamilyType(IDFvalue family) {
138  if(family.compare(IDTYPES_FAMILY_BIOSIG) == 0)
139  return IDMessage::FamilyBiosig;
140  else
141  return IDMessage::FamilyUndef;
142 }