![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
RTno/InPort.cpp@1:b96a6ff9bb6f, 2011-08-01 (annotated)
- Committer:
- nucho
- Date:
- Mon Aug 01 14:45:58 2011 +0000
- Revision:
- 1:b96a6ff9bb6f
- Parent:
- 0:b14546a3cfab
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:b14546a3cfab | 1 | /******************************************* |
nucho | 0:b14546a3cfab | 2 | * InPort.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 | |
nucho | 0:b14546a3cfab | 9 | #include <string.h> |
nucho | 0:b14546a3cfab | 10 | #include "Packet.h" |
nucho | 0:b14546a3cfab | 11 | #include "ReceivePacket.h" |
nucho | 0:b14546a3cfab | 12 | #include "SendPacket.h" |
nucho | 0:b14546a3cfab | 13 | #include "BasicDataType.h" |
nucho | 0:b14546a3cfab | 14 | #include "InPort.h" |
nucho | 0:b14546a3cfab | 15 | |
nucho | 0:b14546a3cfab | 16 | InPort::InPort(char* name, TimedOctet& Data): |
nucho | 0:b14546a3cfab | 17 | InPortBase(name) |
nucho | 0:b14546a3cfab | 18 | { |
nucho | 0:b14546a3cfab | 19 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 20 | m_TypeCode = 'o'; |
nucho | 0:b14546a3cfab | 21 | } |
nucho | 0:b14546a3cfab | 22 | |
nucho | 0:b14546a3cfab | 23 | InPort::InPort(char* name, TimedChar& Data): |
nucho | 0:b14546a3cfab | 24 | InPortBase(name) |
nucho | 0:b14546a3cfab | 25 | { |
nucho | 0:b14546a3cfab | 26 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 27 | m_TypeCode = 'c'; |
nucho | 0:b14546a3cfab | 28 | } |
nucho | 0:b14546a3cfab | 29 | |
nucho | 0:b14546a3cfab | 30 | InPort::InPort(char* name, TimedBoolean& Data): |
nucho | 0:b14546a3cfab | 31 | InPortBase(name) |
nucho | 0:b14546a3cfab | 32 | { |
nucho | 0:b14546a3cfab | 33 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 34 | m_TypeCode = 'b'; |
nucho | 0:b14546a3cfab | 35 | } |
nucho | 0:b14546a3cfab | 36 | |
nucho | 0:b14546a3cfab | 37 | |
nucho | 0:b14546a3cfab | 38 | InPort::InPort(char* name, TimedDouble& Data): |
nucho | 0:b14546a3cfab | 39 | InPortBase(name) |
nucho | 0:b14546a3cfab | 40 | { |
nucho | 0:b14546a3cfab | 41 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 42 | m_TypeCode = 'd'; |
nucho | 0:b14546a3cfab | 43 | } |
nucho | 0:b14546a3cfab | 44 | |
nucho | 0:b14546a3cfab | 45 | InPort::InPort(char* name, TimedFloat& Data): |
nucho | 0:b14546a3cfab | 46 | InPortBase(name) |
nucho | 0:b14546a3cfab | 47 | { |
nucho | 0:b14546a3cfab | 48 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 49 | m_TypeCode = 'f'; |
nucho | 0:b14546a3cfab | 50 | } |
nucho | 0:b14546a3cfab | 51 | |
nucho | 0:b14546a3cfab | 52 | InPort::InPort(char* name, TimedLong& Data): |
nucho | 0:b14546a3cfab | 53 | InPortBase(name) |
nucho | 0:b14546a3cfab | 54 | { |
nucho | 0:b14546a3cfab | 55 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 56 | m_TypeCode = 'l'; |
nucho | 0:b14546a3cfab | 57 | } |
nucho | 0:b14546a3cfab | 58 | |
nucho | 0:b14546a3cfab | 59 | InPort::InPort(char* name, TimedOctetSeq& Data): |
nucho | 0:b14546a3cfab | 60 | InPortBase(name) |
nucho | 0:b14546a3cfab | 61 | { |
nucho | 0:b14546a3cfab | 62 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 63 | m_TypeCode = 'O'; |
nucho | 0:b14546a3cfab | 64 | } |
nucho | 0:b14546a3cfab | 65 | |
nucho | 0:b14546a3cfab | 66 | InPort::InPort(char* name, TimedCharSeq& Data): |
nucho | 0:b14546a3cfab | 67 | InPortBase(name) |
nucho | 0:b14546a3cfab | 68 | { |
nucho | 0:b14546a3cfab | 69 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 70 | m_TypeCode = 'C'; |
nucho | 0:b14546a3cfab | 71 | } |
nucho | 0:b14546a3cfab | 72 | |
nucho | 0:b14546a3cfab | 73 | InPort::InPort(char* name, TimedBooleanSeq& Data): |
nucho | 0:b14546a3cfab | 74 | InPortBase(name) |
nucho | 0:b14546a3cfab | 75 | { |
nucho | 0:b14546a3cfab | 76 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 77 | m_TypeCode = 'B'; |
nucho | 0:b14546a3cfab | 78 | } |
nucho | 0:b14546a3cfab | 79 | |
nucho | 0:b14546a3cfab | 80 | |
nucho | 0:b14546a3cfab | 81 | |
nucho | 0:b14546a3cfab | 82 | InPort::InPort(char* name, TimedDoubleSeq& Data): |
nucho | 0:b14546a3cfab | 83 | InPortBase(name) |
nucho | 0:b14546a3cfab | 84 | { |
nucho | 0:b14546a3cfab | 85 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 86 | m_TypeCode = 'D'; |
nucho | 0:b14546a3cfab | 87 | } |
nucho | 0:b14546a3cfab | 88 | |
nucho | 0:b14546a3cfab | 89 | |
nucho | 0:b14546a3cfab | 90 | InPort::InPort(char* name, TimedFloatSeq& Data): |
nucho | 0:b14546a3cfab | 91 | InPortBase(name) |
nucho | 0:b14546a3cfab | 92 | { |
nucho | 0:b14546a3cfab | 93 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 94 | m_TypeCode = 'F'; |
nucho | 0:b14546a3cfab | 95 | } |
nucho | 0:b14546a3cfab | 96 | |
nucho | 0:b14546a3cfab | 97 | InPort::InPort(char* name, TimedLongSeq&Data): |
nucho | 0:b14546a3cfab | 98 | InPortBase(name) |
nucho | 0:b14546a3cfab | 99 | { |
nucho | 0:b14546a3cfab | 100 | m_pData = &Data; |
nucho | 0:b14546a3cfab | 101 | m_TypeCode = 'L'; |
nucho | 0:b14546a3cfab | 102 | } |
nucho | 0:b14546a3cfab | 103 | |
nucho | 0:b14546a3cfab | 104 | InPort::~InPort() |
nucho | 0:b14546a3cfab | 105 | { |
nucho | 0:b14546a3cfab | 106 | } |
nucho | 0:b14546a3cfab | 107 | |
nucho | 0:b14546a3cfab | 108 | |
nucho | 0:b14546a3cfab | 109 | int InPort::isNew() |
nucho | 0:b14546a3cfab | 110 | { |
nucho | 0:b14546a3cfab | 111 | char packet_buffer[MAX_PACKET_SIZE]; |
nucho | 0:b14546a3cfab | 112 | SendPacket(INPORT_ISNEW, strlen(GetName()), GetName()); |
nucho | 0:b14546a3cfab | 113 | ReceivePacket(packet_buffer); |
nucho | 0:b14546a3cfab | 114 | if(packet_buffer[INTERFACE] != INPORT_ISNEW) { |
nucho | 0:b14546a3cfab | 115 | return 0;//-INVALID_PACKET_INTERFACE; |
nucho | 0:b14546a3cfab | 116 | } |
nucho | 0:b14546a3cfab | 117 | return packet_buffer[DATA_START_ADDR]; |
nucho | 0:b14546a3cfab | 118 | } |
nucho | 0:b14546a3cfab | 119 | |
nucho | 0:b14546a3cfab | 120 | |
nucho | 0:b14546a3cfab | 121 | int InPort::read() { |
nucho | 0:b14546a3cfab | 122 | char packet_buffer[MAX_PACKET_SIZE]; |
nucho | 0:b14546a3cfab | 123 | SendPacket(INPORT_READ, strlen(GetName()), GetName()); |
nucho | 0:b14546a3cfab | 124 | ReceivePacket(packet_buffer); |
nucho | 0:b14546a3cfab | 125 | if(packet_buffer[INTERFACE] != INPORT_READ) { |
nucho | 0:b14546a3cfab | 126 | return -INVALID_PACKET_INTERFACE; |
nucho | 0:b14546a3cfab | 127 | } |
nucho | 0:b14546a3cfab | 128 | int len = packet_buffer[DATA_LENGTH] / SizeofData(); |
nucho | 0:b14546a3cfab | 129 | int isSequence = isSequenceType(); |
nucho | 0:b14546a3cfab | 130 | SetLength(len); |
nucho | 0:b14546a3cfab | 131 | void *pBuffer = GetBuffer(); |
nucho | 0:b14546a3cfab | 132 | memcpy(pBuffer, &(packet_buffer[DATA_START_ADDR]), len*SizeofData()); |
nucho | 0:b14546a3cfab | 133 | |
nucho | 0:b14546a3cfab | 134 | return len; |
nucho | 0:b14546a3cfab | 135 | } |
nucho | 0:b14546a3cfab | 136 | |
nucho | 0:b14546a3cfab | 137 | |
nucho | 0:b14546a3cfab | 138 | int InPort::SizeofData() { |
nucho | 0:b14546a3cfab | 139 | switch(m_TypeCode) { |
nucho | 0:b14546a3cfab | 140 | case 'b': |
nucho | 0:b14546a3cfab | 141 | case 'B': |
nucho | 0:b14546a3cfab | 142 | case 'o': |
nucho | 0:b14546a3cfab | 143 | case 'O': |
nucho | 0:b14546a3cfab | 144 | case 'c': |
nucho | 0:b14546a3cfab | 145 | case 'C': |
nucho | 0:b14546a3cfab | 146 | return 1; |
nucho | 0:b14546a3cfab | 147 | default: |
nucho | 0:b14546a3cfab | 148 | return 4; |
nucho | 0:b14546a3cfab | 149 | } |
nucho | 0:b14546a3cfab | 150 | } |
nucho | 0:b14546a3cfab | 151 |