This library is designed to create and run state graphs. It supports hierarchical states and parallel states execution.

Committer:
martin13
Date:
Tue Feb 02 20:47:45 2021 +0000
Revision:
4:22b4462fcb26
Parent:
0:f4fdca2c4c67
Added unittests

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martin13 0:f4fdca2c4c67 1 ////////////////////////////////////////////////////////////////////////////////
martin13 0:f4fdca2c4c67 2 // Copyright Rottor SAS 2017
martin13 0:f4fdca2c4c67 3 // All rigths reserved.
martin13 0:f4fdca2c4c67 4 //
martin13 0:f4fdca2c4c67 5 // File Name : MetaData.h
martin13 0:f4fdca2c4c67 6 // Authors : Martin Matignon
martin13 0:f4fdca2c4c67 7 //
martin13 0:f4fdca2c4c67 8 // If you find any bug or if you have any question please contact
martin13 0:f4fdca2c4c67 9 // Martin Matignon <martin.matignon@rottor.fr>
martin13 0:f4fdca2c4c67 10 // Nicolas Forestier <nicolas.forestier@rottor.fr>
martin13 0:f4fdca2c4c67 11 //
martin13 0:f4fdca2c4c67 12 ////////////////////////////////////////////////////////////////////////////////
martin13 0:f4fdca2c4c67 13
martin13 0:f4fdca2c4c67 14 #ifndef __SM_META_DATA_H__
martin13 0:f4fdca2c4c67 15 #define __SM_META_DATA_H__
martin13 0:f4fdca2c4c67 16
martin13 0:f4fdca2c4c67 17 #include "mbed.h"
martin13 0:f4fdca2c4c67 18
martin13 0:f4fdca2c4c67 19 template<typename T>
martin13 0:f4fdca2c4c67 20 class MetaData{
martin13 0:f4fdca2c4c67 21
martin13 0:f4fdca2c4c67 22 public:
martin13 0:f4fdca2c4c67 23
martin13 0:f4fdca2c4c67 24 MetaData()
martin13 0:f4fdca2c4c67 25 {
martin13 0:f4fdca2c4c67 26 /* Empty */
martin13 0:f4fdca2c4c67 27 }
martin13 0:f4fdca2c4c67 28
martin13 0:f4fdca2c4c67 29 MetaData(T data):
martin13 0:f4fdca2c4c67 30 m_data(data)
martin13 0:f4fdca2c4c67 31 {
martin13 0:f4fdca2c4c67 32 /* Empty */
martin13 0:f4fdca2c4c67 33 }
martin13 0:f4fdca2c4c67 34
martin13 0:f4fdca2c4c67 35 void setData(T data){
martin13 0:f4fdca2c4c67 36 m_mutex.lock();
martin13 0:f4fdca2c4c67 37 m_data = data;
martin13 0:f4fdca2c4c67 38 m_mutex.unlock();
martin13 0:f4fdca2c4c67 39 }
martin13 0:f4fdca2c4c67 40
martin13 0:f4fdca2c4c67 41 T getData(){
martin13 0:f4fdca2c4c67 42 m_mutex.lock();
martin13 0:f4fdca2c4c67 43 T data = m_data;
martin13 0:f4fdca2c4c67 44 m_mutex.unlock();
martin13 0:f4fdca2c4c67 45 return data;
martin13 0:f4fdca2c4c67 46 }
martin13 0:f4fdca2c4c67 47
martin13 0:f4fdca2c4c67 48 T& operator=(T& other){
martin13 0:f4fdca2c4c67 49 if (sizeof(m_data) == sizeof(other.getData())){
martin13 0:f4fdca2c4c67 50 setData(other.getData());
martin13 0:f4fdca2c4c67 51 }
martin13 0:f4fdca2c4c67 52 return *this;
martin13 0:f4fdca2c4c67 53 }
martin13 0:f4fdca2c4c67 54
martin13 0:f4fdca2c4c67 55 private:
martin13 0:f4fdca2c4c67 56 T m_data;
martin13 0:f4fdca2c4c67 57 Mutex m_mutex;
martin13 0:f4fdca2c4c67 58 };
martin13 0:f4fdca2c4c67 59
martin13 0:f4fdca2c4c67 60 /** Standard data decalration
martin13 0:f4fdca2c4c67 61 */
martin13 0:f4fdca2c4c67 62 typedef MetaData<uint8_t> DataUInt8;
martin13 0:f4fdca2c4c67 63 typedef MetaData<int8_t> DataInt8;
martin13 0:f4fdca2c4c67 64 typedef MetaData<uint16_t> DataUInt16;
martin13 0:f4fdca2c4c67 65 typedef MetaData<int16_t> DataInt16;
martin13 0:f4fdca2c4c67 66 typedef MetaData<uint32_t> DataUInt32;
martin13 0:f4fdca2c4c67 67 typedef MetaData<int32_t> DataInt32;
martin13 0:f4fdca2c4c67 68 typedef MetaData<float> DataFloat;
martin13 0:f4fdca2c4c67 69 typedef MetaData<double> DataDouble;
martin13 0:f4fdca2c4c67 70
martin13 0:f4fdca2c4c67 71 #endif /* #ifndef __SM_META_DATA_H__*/