TwirreLink
 All Classes Functions Pages
SerialValue.h
1 /*
2  * Twirre: architecture for autonomous UAVs using interchangeable commodity components
3  *
4  * Copyright© 2017 Centre of expertise in Computer Vision & Data Science, NHL Stenden University of applied sciences
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7  *
8  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11  */
12 
13 #ifndef SERIALVALUE_H_
14 #define SERIALVALUE_H_
15 
16 #include <string>
17 #include <cstdint>
18 #include <vector>
19 
20 #include "../TwirreSerial/SerialDevice.h"
21 #include "../Serial/SerialRW.h"
22 
23 #include "../Core/Value.h"
24 #include "../Core/owned_mutex.h"
25 
26 
27 namespace twirre
28 {
30  {
31  friend class SerialActuator;
32  friend class SerialSensor;
33  public:
34  SerialValue(uint8_t ID, SerialRW & srw);
35  virtual ~SerialValue() {};
36  uint8_t getID() const;
37  protected:
38  virtual void updateFromSerial() = 0;
39  virtual void addToMessage(std::vector<unsigned char> & data) const = 0;
40  const uint8_t _id;
41  SerialRW & _serial;
42  };
43 
44  template<typename T>
45  class SerialValueImpl: public ValueImpl<T>, public SerialValue
46  {
47  public:
48  SerialValueImpl(const uint8_t ID, const std::string name, T val, SerialRW & srw, owned_mutex * actuateMutex = nullptr);
49  virtual ~SerialValueImpl() {};
50  protected:
51  virtual void updateFromSerial() override;
52  virtual void addToMessage(std::vector<unsigned char> & data) const override;
53  };
54 
55  template<typename T>
56  class SerialArrayValue: public ArrayValue<T>, public SerialValue
57  {
58  public:
59  SerialArrayValue(const uint8_t ID, const std::string name, SerialRW & srw, owned_mutex * actuateMutex = nullptr);
60  virtual ~SerialArrayValue() {};
61  protected:
62  virtual void updateFromSerial() override;
63  virtual void addToMessage(std::vector<unsigned char> & data) const override;
64  };
65 
66  /* explicit template instantiations of ValueImpl */
67  extern template class SerialValueImpl<uint8_t> ;
68  extern template class SerialValueImpl<int8_t> ;
69  extern template class SerialValueImpl<uint16_t> ;
70  extern template class SerialValueImpl<int16_t> ;
71  extern template class SerialValueImpl<uint32_t> ;
72  extern template class SerialValueImpl<int32_t> ;
73  extern template class SerialValueImpl<uint64_t> ;
74  extern template class SerialValueImpl<int64_t> ;
75  extern template class SerialValueImpl<float> ;
76  extern template class SerialValueImpl<double> ;
77 
78  /* explicit template instantiations of ArrayValue */
79  extern template class SerialArrayValue<uint8_t> ;
80  extern template class SerialArrayValue<int8_t> ;
81  extern template class SerialArrayValue<uint16_t> ;
82  extern template class SerialArrayValue<int16_t> ;
83  extern template class SerialArrayValue<uint32_t> ;
84  extern template class SerialArrayValue<int32_t> ;
85  extern template class SerialArrayValue<uint64_t> ;
86  extern template class SerialArrayValue<int64_t> ;
87  extern template class SerialArrayValue<float> ;
88  extern template class SerialArrayValue<double> ;
89 } /* namespace twirre */
90 
91 #endif /* VALUE_H_ */
Definition: SerialActuator.h:20
Definition: ValueImpl.h:21
Definition: SerialValue.h:56
Definition: SerialValue.h:29
Definition: ArrayValue.h:21
Definition: SerialSensor.h:23
Definition: SerialRW.h:26
A mutex with the concept of 'ownership'.
Definition: owned_mutex.h:27
Definition: SerialValue.h:45