def stdinHnd(fd, clientData): global done input = sys.stdin.readline() if (input[0] == 'q' or input[0] == 'Q'): IPC.IPC_disconnect() done = True elif (input[0] == 'm' or input[0] == 'M'): i1 = 42 print "\n IPC_publishData(%s, %d)" % (MSG1, i1) IPC.IPC_publishData(MSG1, i1) elif (input[0] == 'r' or input[0] == 'R'): t1 = T1() t1.i1 = 666 t1.status = SendVal t1.matrix = ((0.0, 1.0, 2.0), (1.0, 2.0, 3.0)) t1.d1 = 3.14159 print "\n IPC_queryResponseData(%s, %s, IPC_WAIT_FOREVER, %s)" % \ (QUERY1, t1, T1.__name__) (r1, ret) = IPC.IPC_queryResponseData(QUERY1, t1, IPC.IPC_WAIT_FOREVER, T1) print "\n Received response" IPC.IPC_printData(IPC.IPC_msgFormatter(RESPONSE1), sys.stdout, r1) else: print "stdinHnd [%s]: Received %s" % (clientData, input),
def disconnect1Hnd (moduleName, clientData) : global first print "DISCONNECT:", moduleName if (first) : IPC.IPC_unsubscribeConnect(connect1Hnd) else : IPC.IPC_unsubscribeConnect(connect2Hnd) if (first) : IPC.IPC_unsubscribeHandlerChange(MSG1, handlerChangeHnd2) else : IPC.IPC_unsubscribeHandlerChange(MSG1, handlerChangeHnd) first = False
def main(): global done done = False # Connect to the central server print "\nIPC.IPC_connect(%s)" % MODULE2_NAME IPC.IPC_connect(MODULE2_NAME) # Define the messages that this module publishes print "\nIPC.IPC_defineMsg(%s, IPC_VARIABLE_LENGTH, %s)" % \ (MSG2, MSG2_FORMAT) IPC.IPC_defineMsg(MSG2, IPC.IPC_VARIABLE_LENGTH, MSG2_FORMAT) print "\nIPC.IPC_defineMsg(%s, IPC_VARIABLE_LENGTH, %s)" % \ (RESPONSE1, RESPONSE1_FORMAT) IPC.IPC_defineMsg(RESPONSE1, IPC.IPC_VARIABLE_LENGTH, RESPONSE1_FORMAT) # Subscribe to the messages that this module listens to print "\nIPC.IPC_subscribeData(%s,%s, %s)" % \ (MSG1, msg1Handler.__name__, MODULE2_NAME) IPC.IPC_subscribeData(MSG1, msg1Handler, MODULE2_NAME) print "\nIPC.IPC_subscribeData(%s, %s, %s, %s)" % \ (QUERY1 , queryHandler.__name__, MODULE2_NAME, T1.__name__) IPC.IPC_subscribeData(QUERY1, queryHandler, MODULE2_NAME, T1) # Subscribe a handler for tty input. Typing "q" will quit the program. print "\nIPC_subscribeFD(%d, stdinHnd, %s)" % \ (sys.stdin.fileno(), MODULE2_NAME) IPC.IPC_subscribeFD(sys.stdin.fileno(), stdinHnd, MODULE2_NAME) print "\nType 'q' to quit" while (not done): IPC.IPC_listen(250) IPC.IPC_disconnect()
def connEvent(self, nErrCode): if nErrCode == 0: print('로그인 성공') mode = input("읽기모드(1), 쓰기모드(다른거)") if mode == 1: IPC.ReadPath = "pipe\\name" IPC.StartReceiving(getData) else: while True: self.code = input("종목코드 입력하세요 숫자로 된거 아무것도 입력안하면 삼성꺼로함") self.saveType = input("w: csv 가져오기, e: pipe 보내기 시작") # csv 가져옴 if self.saveType == 'w': print("csv 저장 수행") self.loadCount = int(input("몇분치 불러올거? (int)")) self.reqTR() if self.saveType == 'e': print("pipe 보내기 기능 수행") self.loadCount = 30 # 첫시작을 비우고 새로 불러오는거로 시작 open(ReadPath, 'r+b').truncate(0) self.reqTR() else: print('로그인 실패')
def stdinHnd(fd, clientData): global done input = sys.stdin.readline() if (input[0] == 'q' or input[0] == 'Q'): IPC.IPC_disconnect() done = True else: print "stdinHnd [%s]: Received %s" % (clientData, input)
def queryHandler(msgRef, t1, clientData): print "queryHandler: Receiving %s [%s]", \ (IPC.IPC_msgInstanceName(msgRef), clientData) IPC.IPC_printData(IPC.IPC_msgInstanceFormatter(msgRef), sys.stdout, t1) # Publish this message -- all subscribers get it str1 = "Hello, world" print '\n IPC.IPC_publishData(%s, "%s")' % (MSG2, str1) IPC.IPC_publishData(MSG2, str1) t2 = T2() t2.str1 = str1 # Variable length array of one element t2.t1 = [T1()] t2.t1[0] = t1 t2.count = 1 t2.status = ReceiveVal # Respond with this message -- only the query handler gets it print "\n IPC.IPC_respondData(%s, %s, %s)" % (msgRef, RESPONSE1, t2) IPC.IPC_respondData(msgRef, RESPONSE1, t2)
def main(): global done done = False # Connect to the central server print "\nIPC.IPC_connect(%s)" % MODULE3_NAME IPC.IPC_connect(MODULE3_NAME) # Subscribe to the messages that this module listens to. print "\nIPC_subscribe(%s, %s, %s)" % \ (MSG1, msg1Handler_3.__name__, MODULE3_NAME) IPC.IPC_subscribe(MSG1, msg1Handler_3, MODULE3_NAME) # Subscribe to the messages that this module listens to. print "\nIPC_subscribe(%s, %s, %s)" % \ (MSG2, msg2Handler_3.__name__, MODULE3_NAME) IPC.IPC_subscribe(MSG2, msg2Handler_3, MODULE3_NAME) # Subscribe a handler for tty input. Typing "q" will quit the program. print "\nIPC_subscribeFD(%d, stdinHnd_3, %s)" % \ (sys.stdin.fileno(), MODULE3_NAME) IPC.IPC_subscribeFD(sys.stdin.fileno(), stdinHnd_3, MODULE3_NAME) print "\nType 'q' to quit" while (not done): IPC.IPC_listen(250) IPC.IPC_disconnect()
def marshall(formatter, object, varcontent): if (not checkMarshallStatus(formatter)): return _IPC.IPC_Error else: varcontent.length = bufferSize(formatter, object, True) varcontent.content = None if (varcontent.length > 0): varcontent.content = createByteArray(varcontent.length) buffer = createBuffer(varcontent.content) encodeData(formatter, object, buffer) if (bufferLength(buffer) != varcontent.length): IPC.Raise("Mismatch between buffer size (%d) and encoded data (%d)" % \ (varcontent.length, bufferLength(buffer))) freeBuffer(buffer) return _IPC.IPC_OK
def unmarshall(formatter, byteArray, object=None, oclass=None): if (not checkMarshallStatus(formatter)): return _IPC.IPC_Error elif (validFormatter(formatter)): buffer = createBuffer(byteArray) needEnclosingObject = not _IPC.formatType(formatter) in \ (StructFMT, FixedArrayFMT, VarArrayFMT) if (needEnclosingObject or object is None): needEnclosingObject = (_IPC.formatType(formatter) != StructFMT) if (oclass is None or needEnclosingObject): theObject = IPCdata() else: theObject = oclass() else: if (not oclass is None and not isinstance(object, oclass)): IPC.Raise("unmarshall: Object %s and class %s do not match" % \ (object, oclass)) theObject = object decodeData(formatter, buffer, theObject, oclass) if (needEnclosingObject): theObject = theObject._f0 _IPC.freeBuffer(buffer) return (theObject, _IPC.IPC_OK) else: return (None, _IPC.IPC_OK)
def main () : global done, first done = False; first = True # Connect to the central server print "\nIPC.IPC_connect(%s)" % MODULE1_NAME print IPC.IPC_connect, sys.stdin, sys.stdin.fileno() IPC.IPC_connect(MODULE1_NAME) print "HERE1" IPC.IPC_subscribeConnect(connect1Hnd, None) IPC.IPC_subscribeConnect(connect2Hnd, None) IPC.IPC_subscribeDisconnect(disconnect1Hnd, None) # Define the named formats that the modules need print "\nIPC.IPC_defineFormat(%s, %s)" % (T1_NAME, T1_FORMAT) IPC.IPC_defineFormat(T1_NAME, T1_FORMAT) print "\nIPC.IPC_defineFormat(%s, %s)" % (T2_NAME, T2_FORMAT) IPC.IPC_defineFormat(T2_NAME, T2_FORMAT) # Define the messages that this module publishes print "\nIPC.IPC_defineMsg(%s, IPC_VARIABLE_LENGTH, %s)" %(MSG1, MSG1_FORMAT) IPC.IPC_defineMsg(MSG1, IPC.IPC_VARIABLE_LENGTH, MSG1_FORMAT) IPC.IPC_subscribeHandlerChange(MSG1, handlerChangeHnd, None) IPC.IPC_subscribeHandlerChange(MSG1, handlerChangeHnd2, None) print "\nIPC.IPC_defineMsg(%s, IPC_VARIABLE_LENGTH, %s)" % \ (QUERY1, QUERY1_FORMAT) IPC.IPC_defineMsg(QUERY1, IPC.IPC_VARIABLE_LENGTH, QUERY1_FORMAT) IPC.IPC_msgClass(QUERY1, T1) IPC.IPC_msgClass(RESPONSE1, T2) IPC.IPC_subscribeHandlerChange(QUERY1, handlerChangeHnd, None) # Subscribe to the messages that this module listens to. # NOTE: No need to subscribe to the RESPONSE1 message, since it is a # response to a query, not a regular subscription! print "\nIPC.IPC_subscribeData(%s, msg2Handler, %s)" % (MSG2, MODULE1_NAME) IPC.IPC_subscribe(MSG2, msg2Handler, MODULE1_NAME) # Subscribe a handler for tty input. # Typing "q" will quit the program; Typing "m" will send MSG1; # Typing "r" will send QUERY1 ("r" for response) print "\nIPC.IPC_subscribeFD(%d, stdinHnd, %s)" % \ (sys.stdin.fileno(), MODULE1_NAME) IPC.IPC_subscribeFD(sys.stdin.fileno(), stdinHnd, MODULE1_NAME) print "\nType 'm' to send %s; Type 'r' to send %s; Type 'q' to quit" % \ (MSG1, QUERY1) while (not done) : IPC.IPC_listen(250) IPC.IPC_disconnect()
global readyTT global lastMoveTime print "Turn around received" readyTT = False if not r.isbumped(): km.write("sleep\n") sp.write("turnAround\n") r.rotate(np.pi/1.1) #rotate 180 degrees r.setvel(0,0) km.write("wake\n") lastMoveTime = time.time() # How to search for a gesture #open communication to the kinect monitor km = IPC.process(False, 'KinectMonitor.py') #when input from the kinect monitor is received, # add the input to the queue km.setOnReadLine(KinectQueue) # Lily's voice control #open communication to phrasesToSay sp = IPC.process(False, 'phrasesToSay.py') #when input is received from phrasesToSay, #check if the TTS program is ready to receive input sp.setOnReadLine(checkReady) # Open Speech Recognition Control vm = IPC.process(False, 'VoiceMonitor.py') vm.setOnReadLine(VocalQueue)
def connect2Hnd (moduleName, clientData) : print "CONNECT2: Connection from %s" % moduleName print " Number of handlers: %d" % IPC.IPC_numHandlers(MSG1)
def connect1Hnd (moduleName, clientData) : print "CONNECT1: Connection from %s" % moduleName print " Confirming connection (%d)" % \ IPC.IPC_isModuleConnected(moduleName)
def trEvent(self, sScrNo, sRQName, sTrCode, sRecordName, sPreNext, nDataLength, sErrorCode, sMessage, sSplmMsg): # sScrNo(화면번호), sRQName(사용자구분), sTrCode(Tran명), sRecordName(레코드명), sPreNext(연속조회 유무) print("trEvent", sRQName) if sRQName == 'AT_opt10001': # 이름 출력 print('레코드이름', sRecordName) name = self.OCXconn.dynamicCall( "GetCommData(QString, QString, int, QString)", sTrCode, sRQName, 0, "종목명").strip() print(name) if sRQName == '주식분봉차트조회요청': self.sPreNext = sPreNext dataCnt = self.OCXconn.dynamicCall( "GetRepeatCnt(QString, QString)", sTrCode, sRQName) print('데이터 계속여부 : ', sPreNext, ', 가져온 갯수 : ', dataCnt) averageList = [] average = 0 sendData = [] if self.loadCount < self.totalDataCnt + dataCnt: dataCnt = self.loadCount - self.totalDataCnt self.totalDataCnt += dataCnt for i in range(dataCnt): date = self.OCXconn.dynamicCall( "GetCommData(QString, QString, int, QString)", sTrCode, sRQName, i, "체결시간").strip() start = int( self.OCXconn.dynamicCall( "GetCommData(QString, QString, int, QString)", sTrCode, sRQName, i, "시가").strip()) mount = self.OCXconn.dynamicCall( "GetCommData(QString, QString, int, QString)", sTrCode, sRQName, i, "거래량").strip() start = abs(start) averageList.append(start) if len(averageList) > 20: averageList.pop(0) for v in averageList: average += v average /= len(averageList) average = int(average) if self.saveType == 'e': sendData.append([start, int(mount), average]) if self.saveType == 'w': self.spamwriter.writerow([start, mount, average]) if self.saveType == 'e': print("ipc가 보내고 있는 데이터: ", sendData) IPC.Send(sendData) try: self.tr_event_loop.exit() except AttributeError: pass
phrases["unrecognized"] = "I am sorry. I do not know you" phrases["turnAround"] = "I am turning" #set of initial delays delay = {"right": 3} delay["left"] = 3 delay["hello"] = 3 delay["query"] = 3 delay["bye"] = 2 delay["follow"] = 3 delay["stopFollow"] = 3.3 delay["lost"] = 2.5 delay["unrecognized"] = 4 delay["turnAround"] = 3 #set of initial names names = ["Daniel", "Chris", "Cassie"] #initial setup for interprocess communication p = IPC.process(True, "phrasesToSay") p.setOnReadLine(onLineRead) IPC.InitSync() #tell master controller that it is ready to speak p.write('ready\n') #main loop to run and communicate with master controller while True: p.tryReadLine() IPC.Sync()
import interpreter.interpreter as interp from subprocess import call import sys import IPC from time import sleep is_windows = True if is_windows: # Path for Windows vlc_path = '"C:\Program Files (x86)\VideoLAN\VLC\VLC.exe"' else: # Path for Mac vlc_path = "/Applications/VLC.app/Contents/MacOS/VLC" vm = IPC.process(True, ".\lili-interpreter\LILIExecutor.py") started = False # Changes once it gets start command from master controller r = sr.Recognizer() def runRecognizer(): # Comment out this with block to use standard input instead of speech recognition with sr.Microphone() as source: audio = r.adjust_for_ambient_noise(source, duration=1) r.energy_threshold = 2146 sys.stderr.write("Speak now\n") audio = r.listen(source) sent = "" + r.recognize(audio) # Uncomment this to use standard input instead of speech recognition
def sendGmail(): # 메일 s = smtplib.SMTP('smtp.gmail.com', 587) s.starttls() s.login('*****@*****.**', 'cxthezwhgvlzxzgh') msg = MIMEText(str("마지막 가격은 " + str(price[-1]) + "원 입니다.")) msg['Subject'] = '제목 : 주식예측봇이 전해드립니다.' # 메일 보내기 s.sendmail("*****@*****.**", "*****@*****.**", msg.as_string()) # 세션 종료 s.quit() if __name__ == '__main__': global model import sys getHanRiverTemp() model = load_model('model.h5') # IPC 받기 IPC.StartReceiving(getData) app = QtWidgets.QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec_())
def msg2Handler_3(msgRef, callData, clientData): (str1, ret) = IPC.IPC_unmarshallData(IPC.IPC_msgInstanceFormatter(msgRef), callData) print "msg2Handler: Receiving %s (%s) [%s]" % \ (IPC.IPC_msgInstanceName(msgRef), str1, clientData) IPC.IPC_freeByteArray(callData)
sys.path.append("C:\Users\chuah\Desktop\Jacob's\LSSRobotWin32") clr.AddReference('LiliVoiceCommand') import SpeechRecognitionApp as sra commands = [ 'Lily', 'rightWave', 'leftWave', 'follow', 'stop', 'turnAround', 'quit', 'storyMode' ] #gesture commands recoged = [ 'Lily', 'Move right', 'Move left', 'Follow me', 'Stop', 'Turn around', 'Goodbye', 'Story mode' ] #recognized phrases vm = IPC.process(True, 'VoiceMonitor.py') started = False #changes once it gets start command from master controller Lily = False #user must say Lily before giving a command lilytime = time.time() timeout = time.time() re = sra.Program() engine = re.buildRecognizer() #create Speech Recognition Engine #for now, only used to receive start command def onLineRead(): global started message = vm.line.strip() if message == "start":
def msg1Handler(msgRef, callData, clientData): print "msg1Handler: Receiving %s (%d) [%s] " % \ (IPC.IPC_msgInstanceName(msgRef), callData, clientData)
def transferToDataStructure(format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct, oclass=None): ftype = _IPC.formatType(format) if (ftype == LengthFMT): IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT): try: dataStruct.__dict__ # Is this a settable object except AttributeError: IPC.Raise( invalidStructFormat( type(dataStruct), primFmttrs.PrimType(_IPC.formatPrimitiveProc(format)))) primFmttrs.Decode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT): theChar = _IPC.formatGetChar(buffer) if (theChar == '\0'): primFmttrs.setObjectField(dataStruct, dStart, None) else: transferToDataStructure( _IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct, oclass) elif (ftype == StructFMT): formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct): struct = dataStruct else: struct1 = primFmttrs.getObjectField(dataStruct, dStart) struct = validateObject(struct1, dataStruct, dStart) if (not struct == struct1): primFmttrs.setObjectField(dataStruct, dStart, struct) for i in range(1, n): transferToDataStructure( _IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) size = _IPC.formatFormatArrayItemInt(formatArray, 2) if (isTopLevelStruct and isinstance(dataStruct, (tuple, list))): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure( arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, False, oclass) elif (ftype == VarArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) # The total size of the array is the stored first size = _IPC.formatGetInt(buffer) numDims = _IPC.formatFormatArrayMax(formatArray) - 2 if (numDims > 1): size = varArrayDimSize(2, formatArray, dataStruct) if (not feasibleToDecodeVarArray(size, formatArray, dStart)): IPC.Raise("Python version of IPC cannot decode " + \ "multi-dimensional variable length arrays unless " + \ "the size variables appear BEFORE the array " + \ "in the enclosing structure") elif (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) arrayObject = validateArrayObject(arrayObject, size, dataStruct, dStart) primFmttrs.setObjectField(dataStruct, dStart, arrayObject) arrayTransferToDataStructure(arrayObject, buffer, 2, numDims + 1, size, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, dStart, True, oclass) elif (ftype == NamedFMT): transferToDataStructure(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT): primFmttrs.Decode(primFmttrs.INT_FMT, dataStruct, dStart, buffer) else: IPC.Raise("Unhandled format: %s" % ftype)
def validateArrayObject(arrayObject, dim, object, index): if (not (arrayObject is None or isinstance(arrayObject, (list, tuple)))): IPC.Raise(invalidArrayFormat(object, index)) elif (arrayObject is None or len(arrayObject) != dim): arrayObject = [None] * dim return arrayObject
def sendName(self, text): IPC.WritePath = "pipe\\name" IPC.Send( stockDB.dfstockcode.loc[self.stockName.text()][0]) # 종목코드로 보내기
def bufferSize1(format, dataStruct, dStart, parentFormat, isTopLevelStruct): bufSize = 0 ftype = _IPC.formatType(format) if (ftype == LengthFMT): IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT): primType = _IPC.formatPrimitiveProc(format) bufSize = bufSize + primFmttrs.ELength(primType, dataStruct, dStart) elif (ftype == PointerFMT): bufSize = bufSize + 1 if (not primFmttrs.getObjectField(dataStruct, dStart) is None): bufSize = bufSize + \ bufferSize1(_IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, 0, isTopLevelStruct) elif (ftype == StructFMT): formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct): struct = dataStruct else: struct = primFmttrs.getObjectField(dataStruct, dStart) for i in range(1, n): bufSize = bufSize + \ bufferSize1(_IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) elif (isSimpleType(nextFormat)): bufSize = bufSize + ( bufferSize1(nextFormat, arrayObject, 0, 0, False) * fixedArrayNumElements(formatArray)) else: bufSize = bufSize + \ arrayBufferSize(arrayObject, 2, _IPC.formatFormatArrayMax(formatArray)-1, formatArray, nextFormat, None) elif (ftype == VarArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) # For the size of the array bufSize = bufSize + primFmttrs.ELength(primFmttrs.INT_FMT, None, 0) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) elif (isSimpleType(nextFormat)): bufSize = bufSize + ( bufferSize1(nextFormat, arrayObject, 0, 0, False) * varArrayNumElements(formatArray, dataStruct)) else: bufSize = bufSize + \ arrayBufferSize(arrayObject, 2, _IPC.formatFormatArrayMax(formatArray)-1, formatArray, nextFormat, dataStruct) elif (ftype == NamedFMT): bufSize = bufSize + \ bufferSize1(_IPC.findNamedFormat(format), dataStruct, dStart, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT): bufSize = bufSize + primFmttrs.ELength(primFmttrs.INT_FMT, None, 0) else: IPC.Raise("Unhandled format: %s" % ftype) return bufSize
def transferToBuffer(format, dataStruct, dStart, buffer, parentFormat, isTopLevelStruct): ftype = _IPC.formatType(format) if (ftype == LengthFMT): IPC.Raise("Python version of IPC can only use explicit formats") elif (ftype == PrimitiveFMT): if (isTopLevelStruct): object = IPCdata() object._f0 = dataStruct dataStruct = object primFmttrs.Encode(_IPC.formatPrimitiveProc(format), dataStruct, dStart, buffer) elif (ftype == PointerFMT): object = primFmttrs.getObjectField(dataStruct, dStart) # 'Z' means data, 0 means NIL if (object is None): theChar = '\0' else: theChar = 'Z' _IPC.formatPutChar(buffer, theChar) if (not object is None): transferToBuffer(_IPC.formatChoosePtrFormat(format, parentFormat), dataStruct, dStart, buffer, 0, isTopLevelStruct) elif (ftype == StructFMT): formatArray = _IPC.formatFormatArray(format) structStart = 0 n = _IPC.formatFormatArrayMax(formatArray) if (isTopLevelStruct): struct = dataStruct else: struct = primFmttrs.getObjectField(dataStruct, dStart) for i in range(1, n): transferToBuffer(_IPC.formatFormatArrayItemPtr(formatArray, i), struct, structStart, buffer, format, False) structStart = structStart + 1 elif (ftype == FixedArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else: arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, False) elif (ftype == VarArrayFMT): formatArray = _IPC.formatFormatArray(format) nextFormat = _IPC.formatFormatArrayItemPtr(formatArray, 1) if (isTopLevelStruct): arrayObject = dataStruct else: arrayObject = primFmttrs.getObjectField(dataStruct, dStart) # For the size of the array _IPC.formatPutInt(buffer, varArrayNumElements(formatArray, dataStruct)) if (not isinstance(arrayObject, (tuple, list))): IPC.Raise(invalidArrayFormat(dataStruct, dStart)) else: arrayTransferToBuffer(arrayObject, buffer, 2, _IPC.formatFormatArrayMax(formatArray) - 1, isSimpleType(nextFormat), formatArray, nextFormat, dataStruct, True) elif (ftype == NamedFMT): transferToBuffer(_IPC.findNamedFormat(format), dataStruct, dStart, buffer, parentFormat, isTopLevelStruct) elif (ftype == EnumFMT): primFmttrs.Encode(primFmttrs.INT_FMT, dataStruct, dStart, buffer) else: IPC.Raise("Unhandled format: %s" % ftype)
import IPC import sys import clr import time sys.path.append("C:\Users\vader\Documents\lssrobotwin32") clr.AddReference('LiliVoiceCommand') import SpeechRecognitionApp as sra commands = ['Lily', 'rightWave', 'leftWave', 'follow', 'stop', 'turnAround', 'quit'] #gesture commands recoged = ['Lily', 'Move right', 'Move left', 'Follow me', 'Stop', 'Turn around', 'Goodbye'] #recognized phrases vm = IPC.process(True, 'VoiceMonitor.py') started = False #changes once it gets start command from master controller Lily = False #user must say Lily before giving a command lilytime = time.time() timeout = time.time() re = sra.Program() engine = re.buildRecognizer() #create Speech Recognition Engine #for now, only used to receive start command def onLineRead(): global started message = vm.line.strip() if message == "start": re.runRecognizer(engine) #start listening started = True #changes to exit first while loop
global readyTT global lastMoveTime print "Turn around received" readyTT = False if not r.isbumped(): km.write("sleep\n") sp.write("turnAround\n") r.rotate(np.pi/1.1) #rotate 180 degrees r.setvel(0,0) km.write("wake\n") lastMoveTime = time.time() ''' # How to search for a gesture #open communication to the kinect monitor km = IPC.process(False, 'KinectMonitor.py') #when input from the kinect monitor is received, # add the input to the queue km.setOnReadLine(KinectQueue) # Lily's voice control #open communication to phrasesToSay sp = IPC.process(False, 'phrasesToSay.py') #when input is received from phrasesToSay, #check if the TTS program is ready to receive input sp.setOnReadLine(checkReady) # Open Speech Recognition Control vm = IPC.process(False, 'VoiceMonitor.py') vm.setOnReadLine(VocalQueue)