00001
00002
00003
00004
00005 import sys
00006 import time
00007
00008 import RTC
00009 import OpenRTM_aist
00010
00011 seqin_spec = ["implementation_id", "SeqIn",
00012 "type_name", "SequenceInComponent",
00013 "description", "Sequence InPort component",
00014 "version", "1.0",
00015 "vendor", "Shinji Kurihara",
00016 "category", "example",
00017 "activity_type", "DataFlowComponent",
00018 "max_instance", "10",
00019 "language", "Python",
00020 "lang_type", "script",
00021 ""]
00022
00023
00024 class SeqIn(OpenRTM_aist.DataFlowComponentBase):
00025 def __init__(self, manager):
00026 OpenRTM_aist.DataFlowComponentBase.__init__(self, manager)
00027 return
00028
00029
00030 def onInitialize(self):
00031 self._octet = RTC.TimedOctet(RTC.Time(0,0),0)
00032 self._short = RTC.TimedShort(RTC.Time(0,0),0)
00033 self._long = RTC.TimedLong(RTC.Time(0,0),0)
00034 self._float = RTC.TimedFloat(RTC.Time(0,0),0)
00035 self._double = RTC.TimedDouble(RTC.Time(0,0),0)
00036 self._octetSeq = RTC.TimedOctetSeq(RTC.Time(0,0),[])
00037 self._shortSeq = RTC.TimedShortSeq(RTC.Time(0,0),[])
00038 self._longSeq = RTC.TimedLongSeq(RTC.Time(0,0),[])
00039 self._floatSeq = RTC.TimedFloatSeq(RTC.Time(0,0),[])
00040 self._doubleSeq = RTC.TimedDoubleSeq(RTC.Time(0,0),[])
00041
00042 self._octetIn = OpenRTM_aist.InPort("Octet", self._octet)
00043 self._shortIn = OpenRTM_aist.InPort("Short", self._short)
00044 self._longIn = OpenRTM_aist.InPort("Long", self._long)
00045 self._floatIn = OpenRTM_aist.InPort("Float", self._float)
00046 self._doubleIn = OpenRTM_aist.InPort("Double", self._double)
00047 self._octetSeqIn = OpenRTM_aist.InPort("OctetSeq", self._octetSeq)
00048 self._shortSeqIn = OpenRTM_aist.InPort("ShortSeq", self._shortSeq)
00049 self._longSeqIn = OpenRTM_aist.InPort("LongSeq", self._longSeq)
00050 self._floatSeqIn = OpenRTM_aist.InPort("FloatSeq", self._floatSeq)
00051 self._doubleSeqIn = OpenRTM_aist.InPort("DoubleSeq", self._doubleSeq)
00052
00053
00054
00055 self.addInPort("Octet", self._octetIn)
00056 self.addInPort("Short", self._shortIn)
00057 self.addInPort("Long", self._longIn)
00058 self.addInPort("Float", self._floatIn)
00059 self.addInPort("Double", self._doubleIn)
00060
00061 self.addInPort("OctetSeq", self._octetSeqIn)
00062 self.addInPort("ShortSeq", self._shortSeqIn)
00063 self.addInPort("LongSeq", self._longSeqIn)
00064 self.addInPort("FloatSeq", self._floatSeqIn)
00065 self.addInPort("DoubleSeq", self._doubleSeqIn)
00066 return RTC.RTC_OK
00067
00068
00069 def onExecute(self, ec_id):
00070 octet_ = self._octetIn.read()
00071 short_ = self._shortIn.read()
00072 long_ = self._longIn.read()
00073 float_ = self._floatIn.read()
00074 double_ = self._doubleIn.read()
00075
00076 octetSeq_ = self._octetSeqIn.read()
00077 shortSeq_ = self._shortSeqIn.read()
00078 longSeq_ = self._longSeqIn.read()
00079 floatSeq_ = self._floatSeqIn.read()
00080 doubleSeq_ = self._doubleSeqIn.read()
00081
00082 octetSize_ = len(octetSeq_.data)
00083 shortSize_ = len(shortSeq_.data)
00084 longSize_ = len(longSeq_.data)
00085 floatSize_ = len(floatSeq_.data)
00086 doubleSize_ = len(doubleSeq_.data)
00087
00088 octetSeqDisp_ = []
00089 for i in range(octetSize_):
00090 octetSeqDisp_.append(ord(octetSeq_.data[i]))
00091
00092 maxsize = max(octetSize_, shortSize_, longSize_, floatSize_, doubleSize_)
00093 octetSeqDisp_ = octetSeqDisp_ + ['-'] * (maxsize - octetSize_)
00094 shortSeq_.data = shortSeq_.data + ['-'] * (maxsize - shortSize_)
00095 longSeq_.data = longSeq_.data + ['-'] * (maxsize - longSize_)
00096 floatSeq_.data = floatSeq_.data + ['-'] * (maxsize - floatSize_)
00097 doubleSeq_.data = doubleSeq_.data + ['-'] * (maxsize - doubleSize_)
00098
00099 if 0x20 <= octet_.data < 0x7e :
00100 octetDisp_ = chr(octet_.data)
00101 else:
00102 octetDisp_ = " "
00103 print '%3.2s %10.8s %10.8s %10.8s %10.8s %10.8s' \
00104 % (' ', 'octet', 'short', 'long', 'float', 'double')
00105 print '%3.2s %7s[%s] %10.8s %10.8s %10.8s %10.8s' \
00106 % (' ', octet_.data, octetDisp_, short_.data, long_.data, float_.data, double_.data)
00107 print "-----------------------------------------------------------"
00108 print " Sequence Data "
00109 print "-----------------------------------------------------------"
00110 for i in range(maxsize):
00111 if 0x20 <= octetSeqDisp_[i] < 0x7e :
00112 octetDisp_ = chr(octetSeqDisp_[i])
00113 else:
00114 octetDisp_ = " "
00115 print '%3.2s %7s[%s] %10.8s %10.8s %10.8s %10.8s' \
00116 % (i, octetSeqDisp_[i], octetDisp_, shortSeq_.data[i], longSeq_.data[i], floatSeq_.data[i], doubleSeq_.data[i])
00117
00118
00119 print "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r"
00120
00121 time.sleep(0.5)
00122 return RTC.RTC_OK
00123
00124
00125 def SeqInInit(manager):
00126 profile = OpenRTM_aist.Properties(defaults_str=seqin_spec)
00127 manager.registerFactory(profile,
00128 SeqIn,
00129 OpenRTM_aist.Delete)
00130
00131
00132 def MyModuleInit(manager):
00133 SeqInInit(manager)
00134
00135
00136 comp = manager.createComponent("SeqIn")
00137
00138
00139 def main():
00140
00141 mgr = OpenRTM_aist.Manager.init(sys.argv)
00142
00143
00144
00145 mgr.setModuleInitProc(MyModuleInit)
00146
00147
00148 mgr.activateManager()
00149
00150
00151
00152 mgr.runManager()
00153
00154
00155
00156
00157 if __name__ == "__main__":
00158 main()
00159