![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
RTno/OutPort.cpp@0:b14546a3cfab, 2011-07-29 (annotated)
- Committer:
- nucho
- Date:
- Fri Jul 29 11:23:06 2011 +0000
- Revision:
- 0:b14546a3cfab
- Child:
- 1:b96a6ff9bb6f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:b14546a3cfab | 1 | /******************************************* |
nucho | 0:b14546a3cfab | 2 | * OutPort.cpp |
nucho | 0:b14546a3cfab | 3 | * @author Yuki Suga |
nucho | 0:b14546a3cfab | 4 | * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010. |
nucho | 0:b14546a3cfab | 5 | * @license LGPLv3 |
nucho | 0:b14546a3cfab | 6 | *****************************************/ |
nucho | 0:b14546a3cfab | 7 | |
nucho | 0:b14546a3cfab | 8 | #include <string.h> |
nucho | 0:b14546a3cfab | 9 | #include "BasicDataType.h" |
nucho | 0:b14546a3cfab | 10 | #include "OutPort.h" |
nucho | 0:b14546a3cfab | 11 | #include "SendPacket.h" |
nucho | 0:b14546a3cfab | 12 | #include "ReceivePacket.h" |
nucho | 0:b14546a3cfab | 13 | |
nucho | 0:b14546a3cfab | 14 | |
nucho | 0:b14546a3cfab | 15 | OutPort::OutPort(char* name, TimedBoolean& Data) : |
nucho | 0:b14546a3cfab | 16 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 17 | { |
nucho | 0:b14546a3cfab | 18 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 19 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 20 | m_TypeCode = 'b'; |
nucho | 0:b14546a3cfab | 21 | } |
nucho | 0:b14546a3cfab | 22 | |
nucho | 0:b14546a3cfab | 23 | OutPort::OutPort(char* name, TimedChar& Data) : |
nucho | 0:b14546a3cfab | 24 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 25 | { |
nucho | 0:b14546a3cfab | 26 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 27 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 28 | m_TypeCode = 'c'; |
nucho | 0:b14546a3cfab | 29 | } |
nucho | 0:b14546a3cfab | 30 | |
nucho | 0:b14546a3cfab | 31 | OutPort::OutPort(char* name, TimedOctet& Data) : |
nucho | 0:b14546a3cfab | 32 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 33 | { |
nucho | 0:b14546a3cfab | 34 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 35 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 36 | m_TypeCode = 'o'; |
nucho | 0:b14546a3cfab | 37 | } |
nucho | 0:b14546a3cfab | 38 | |
nucho | 0:b14546a3cfab | 39 | OutPort::OutPort(char* name, TimedLong& Data) : |
nucho | 0:b14546a3cfab | 40 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 41 | { |
nucho | 0:b14546a3cfab | 42 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 43 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 44 | m_TypeCode = 'l'; |
nucho | 0:b14546a3cfab | 45 | } |
nucho | 0:b14546a3cfab | 46 | |
nucho | 0:b14546a3cfab | 47 | OutPort::OutPort(char* name, TimedFloat& Data) : |
nucho | 0:b14546a3cfab | 48 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 49 | { |
nucho | 0:b14546a3cfab | 50 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 51 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 52 | m_TypeCode = 'f'; |
nucho | 0:b14546a3cfab | 53 | } |
nucho | 0:b14546a3cfab | 54 | |
nucho | 0:b14546a3cfab | 55 | OutPort::OutPort(char* name, TimedDouble& Data) : |
nucho | 0:b14546a3cfab | 56 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 57 | { |
nucho | 0:b14546a3cfab | 58 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 59 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 60 | m_TypeCode = 'd'; |
nucho | 0:b14546a3cfab | 61 | } |
nucho | 0:b14546a3cfab | 62 | |
nucho | 0:b14546a3cfab | 63 | OutPort::OutPort(char* name, TimedBooleanSeq& Data) : |
nucho | 0:b14546a3cfab | 64 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 65 | { |
nucho | 0:b14546a3cfab | 66 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 67 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 68 | m_TypeCode = 'B'; |
nucho | 0:b14546a3cfab | 69 | } |
nucho | 0:b14546a3cfab | 70 | |
nucho | 0:b14546a3cfab | 71 | OutPort::OutPort(char* name, TimedCharSeq& Data) : |
nucho | 0:b14546a3cfab | 72 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 73 | { |
nucho | 0:b14546a3cfab | 74 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 75 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 76 | m_TypeCode = 'C'; |
nucho | 0:b14546a3cfab | 77 | } |
nucho | 0:b14546a3cfab | 78 | |
nucho | 0:b14546a3cfab | 79 | OutPort::OutPort(char* name, TimedOctetSeq& Data) : |
nucho | 0:b14546a3cfab | 80 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 81 | { |
nucho | 0:b14546a3cfab | 82 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 83 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 84 | m_TypeCode = 'O'; |
nucho | 0:b14546a3cfab | 85 | } |
nucho | 0:b14546a3cfab | 86 | |
nucho | 0:b14546a3cfab | 87 | |
nucho | 0:b14546a3cfab | 88 | OutPort::OutPort(char* name, TimedLongSeq& Data) : |
nucho | 0:b14546a3cfab | 89 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 90 | { |
nucho | 0:b14546a3cfab | 91 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 92 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 93 | m_TypeCode = 'L'; |
nucho | 0:b14546a3cfab | 94 | } |
nucho | 0:b14546a3cfab | 95 | |
nucho | 0:b14546a3cfab | 96 | OutPort::OutPort(char* name, TimedFloatSeq& Data) : |
nucho | 0:b14546a3cfab | 97 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 98 | { |
nucho | 0:b14546a3cfab | 99 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 100 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 101 | m_TypeCode = 'F'; |
nucho | 0:b14546a3cfab | 102 | } |
nucho | 0:b14546a3cfab | 103 | |
nucho | 0:b14546a3cfab | 104 | OutPort::OutPort(char* name, TimedDoubleSeq& Data) : |
nucho | 0:b14546a3cfab | 105 | OutPortBase(name) |
nucho | 0:b14546a3cfab | 106 | { |
nucho | 0:b14546a3cfab | 107 | // m_pData = pData; |
nucho | 0:b14546a3cfab | 108 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 109 | m_TypeCode = 'D'; |
nucho | 0:b14546a3cfab | 110 | } |
nucho | 0:b14546a3cfab | 111 | |
nucho | 0:b14546a3cfab | 112 | OutPort::~OutPort() |
nucho | 0:b14546a3cfab | 113 | { |
nucho | 0:b14546a3cfab | 114 | |
nucho | 0:b14546a3cfab | 115 | } |
nucho | 0:b14546a3cfab | 116 | |
nucho | 0:b14546a3cfab | 117 | int OutPort::SizeofData() { |
nucho | 0:b14546a3cfab | 118 | switch(m_TypeCode) { |
nucho | 0:b14546a3cfab | 119 | case 'b': |
nucho | 0:b14546a3cfab | 120 | case 'B': |
nucho | 0:b14546a3cfab | 121 | case 'o': |
nucho | 0:b14546a3cfab | 122 | case 'O': |
nucho | 0:b14546a3cfab | 123 | case 'c': |
nucho | 0:b14546a3cfab | 124 | case 'C': |
nucho | 0:b14546a3cfab | 125 | return 1; |
nucho | 0:b14546a3cfab | 126 | default: |
nucho | 0:b14546a3cfab | 127 | return 4; |
nucho | 0:b14546a3cfab | 128 | } |
nucho | 0:b14546a3cfab | 129 | } |
nucho | 0:b14546a3cfab | 130 | |
nucho | 0:b14546a3cfab | 131 | int OutPort::write() |
nucho | 0:b14546a3cfab | 132 | { |
nucho | 0:b14546a3cfab | 133 | int datalen = GetLength() * SizeofData(); |
nucho | 0:b14546a3cfab | 134 | int namelen = strlen(GetName()); |
nucho | 0:b14546a3cfab | 135 | char packet_buffer[MAX_PACKET_SIZE]; |
nucho | 0:b14546a3cfab | 136 | packet_buffer[0] = namelen; |
nucho | 0:b14546a3cfab | 137 | packet_buffer[1] = datalen; |
nucho | 0:b14546a3cfab | 138 | memcpy(&(packet_buffer[2]), GetName(), namelen); |
nucho | 0:b14546a3cfab | 139 | memcpy(&(packet_buffer[2 + namelen]), GetBuffer(), datalen); |
nucho | 0:b14546a3cfab | 140 | SendPacket(OUTPORT_WRITE, 2+namelen+datalen, packet_buffer); |
nucho | 0:b14546a3cfab | 141 | ReceivePacket(packet_buffer); |
nucho | 0:b14546a3cfab | 142 | return PACKET_HEADER_SIZE+2+namelen+datalen; |
nucho | 0:b14546a3cfab | 143 | } |