Yuki Suga / RTnoV4

Dependencies:   EthernetInterface mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OutPort.h Source File

OutPort.h

00001 #ifndef OUTPORT_HEADER_INCLUDED
00002 #define OUTPORT_HEADER_INCLUDED
00003 
00004 /*******************************************
00005  * OutPort.h
00006  * @author Yuki Suga
00007  * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010.
00008  * @license LGPLv3
00009  *****************************************/
00010 
00011 #include <stdint.h>
00012 #include "PortBase.h"
00013 #include "PortBuffer.h"
00014 #include "NullBuffer.h"
00015 #include "TypeCode.h"
00016 #include <string.h>
00017 #include <stdlib.h>
00018 
00019 class OutPortBase : public PortBase {
00020  private:
00021 
00022  public:
00023   OutPortBase(const char* name, char tCode) {
00024     PortBase_init(this, name, tCode, NullBuffer_create());
00025   }
00026 
00027  public:
00028 
00029 };
00030 
00031 template<typename T>
00032 class OutPort : public OutPortBase {
00033  private:
00034   T* m_pData;
00035   
00036  public:
00037  OutPort(const char* name, T& data) : OutPortBase(name, data.typeCode) {
00038     m_pData = &data;
00039   }
00040   ~OutPort() {}
00041 
00042  public:
00043   uint8_t write() {
00044     uint8_t size = TypeCode_getElementSize(m_pData->typeCode);
00045     if(TypeCode_isSequence(m_pData->typeCode)) {
00046       size *= ((SequenceBase*)&(m_pData->data))->length();
00047       pPortBuffer->push(pPortBuffer,
00048             (int8_t*)((SequenceBase*)&(m_pData->data))->getData(),
00049             size);
00050     } else {
00051       pPortBuffer->push(pPortBuffer, (const int8_t*)&(m_pData->data), size);
00052     }
00053     return size;
00054   }
00055 };
00056 
00057 
00058 #endif