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