def testMovPosA2P():
	print("Test1: ")
	c_msg = (0x80, 0x1+1, 0x4, 0x2)
	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = MovPosA2P()
	data.decode(msgContent)

	data_encode = data.encode()

	print(c_msg)
	print(data_encode)
	print("movMode: " + str(data.movMode))
	print("\n")

	print("Test2: ")
	c_msg2 = (0x80, 0x1+1, 0x4, 0x3)
	parser = MessageParser()
	for msgByte in c_msg2:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = MovPosA2P()
	try:
		data.decode(msgContent)
	except CorruptData as details:
		print(details)

	print("===================================================")
	print("Testing MovPosA2P----------------------complete\n\n\n")
def testReusingCoroutine():
	c_msg = (0x80, 0x4+1, 0x4, 0x0, 0x1, 0x2, 0x3)

	parser = MessageParser()

	for msgByte in c_msg:
		parser.parseMsg(msgByte)
	print(parser.getRetVal())

	c_msg2 = (0x80, 0x4+1, 0x4, 0x0, 0x1, 0x2, 0x3)
	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)
	print(parser.getRetVal())

	print("===================================================")
	print("Testing reusingCoroutine----------------------complete\n\n\n")
def testCorrectMsgWithEscape():
	c_msg = (0x80, 0x6+1, 0x0, 0x81, 0xA1, 0x81, 0xA0, 0x1, 0x2, 0x3, 0x4)

	parser = MessageParser()
	for msgByte in c_msg:
		print( hex(parser.parseMsg(msgByte)[1]) )

	print(parser.getRetVal())

	print("===================================================")
	print("Testing correctMsgWithEscape----------------------complete\n\n\n")
def testHomeRobotP2A():
	c_msg = (0x80, 0x0+1, 0x3)
	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	print(parser.getRetVal())

	msgContent = parser.getRetVal()[2]

	data = HomeRobotP2A()
	data.decode(msgContent)

	data_encode = data.encode()

	print("Test1: ")
	print(c_msg)
	print(data_encode)

	print("===================================================")
	print("Testing HomeRobotP2A----------------------complete\n\n\n")
def testMovPosP2A():
	c_msg = (0x80, 0x4+1, 0x4, 0x11, 0x11, 0x22, 0x22)
	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = MovPosP2A()
	data.decode(msgContent)

	data_encode = data.encode()

	print("Test1: ")
	print(c_msg)
	print(data_encode)

	print("x_enc: " + str(data.x_enc))
	print("y_enc: " + str(data.y_enc))

	print("===================================================")
	print("Testing MovPosP2A----------------------complete\n\n\n")
def testDepoInvA2P():
	c_msg = (0x80, 0x3+1, 0x2, 0x1, 0x11, 0x11)
	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = DepoInvA2P()
	data.decode(msgContent)

	data_encode = data.encode()

	print("Test1: ")
	print(c_msg)
	print(data_encode)

	print("barcode: " + str(data.barcode))
	print("y_enc: " + str(data.y_enc))

	print("===================================================")
	print("Testing DepoInvA2P----------------------complete\n\n\n")
def testRetInvA2P():
	
	c_msg = (0x80, 0x2+1, 0x1, 0x1, 0x2)

	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = RetInvA2P()
	data.decode(msgContent)

	data_encode = data.encode()

	print("Test1: ")
	print(c_msg)
	print(data_encode)

	print("invInfoRowId: " + str(data.invInfoRowId) )
	print("virtCartId: " + str(data.virtCartId))

	print("===================================================")
	print("Testing RetInvA2P----------------------complete\n\n\n")
Beispiel #8
0
	def run(self):
		print("ArduinoComm::Starting")


		# wait for initialization
		time.sleep(5)

		while True:

			## sending a message to Arduino
			while self.msgQueue.empty():
				time.sleep(1)	# poll the queue every 1 second
				
			# [ MessageFormat.retInv
			# (True, 
			#  [inventoryDetailsId, barcodeDetailsFk, X_index, Y_index, X_encoder, Y_encoder, checkoutFlag],
			#  newVirtualCartRowId)
			# ]

			# [ MessageFormat.depInv, barcode ]

			msgQueue = self.msgQueue.get()
			msgType = msgQueue[0]
			txMsg = None
			encodedMsg = None

			if msgType == MessageFormat.retInv:
				reservedInventoryLoc = msgQueue[1][1]
				virtCartRowId = msgQueue[1][2]

				txMsg = RetInvP2A()
				txMsg.invInfoRowId = reservedInventoryLoc[0]
				txMsg.virtCartId = virtCartRowId
				txMsg.x_idx = reservedInventoryLoc[1]
				txMsg.y_idx = reservedInventoryLoc[2]
				txMsg.x_enc = reservedInventoryLoc[3]
				txMsg.y_enc = reservedInventoryLoc[4]
				txMsg.x_encAbove = reservedInventoryLoc[5]
				txMsg.y_encAbove = reservedInventoryLoc[6]

				self.msgInProcess = [MessageFormat.retInv, txMsg]

			elif msgType == MessageFormat.depInv:
				barcode = msgQueue[1]

				robotService = ArduinoService()
				[x_idx, y_idx, x_enc, y_enc] = robotService.getDepositLocation()

				txMsg = DepoInvP2A()
				txMsg.barcode = barcode
				txMsg.x_enc = x_enc
				txMsg.y_enc = y_enc

				self.msgInProcess = [MessageFormat.depInv, (barcode, x_idx, y_idx, x_enc, y_enc)]


			try:
				encodedMsg = txMsg.encode()
			except CorruptData as details:
				print(details)

			for byte in encodedMsg:
				print("writing: " + str(hex(byte)))
				self.__ser.write(bytes([byte]))


			## receiving message from arduino
			print("start receiving messages")


			msgParser = MessageParser()

			isCompleteMsg = False
			while not isCompleteMsg:
				msgByte = self.__ser.read(1)		# blocking i/o with infinite timeout
				parseResult = msgParser.parseMsg((int.from_bytes(msgByte, byteorder='big', signed=False)))
				isCompleteMsg = parseResult[0]

				print("parsing Msgs: " + str(hex(int.from_bytes(msgByte, byteorder='big', signed=False) ) ) )

			parseResult = msgParser.getRetVal()		# [True, msgType, msgContent]

			msgType = parseResult[1]
			msgContent = parseResult[2]

			try:
				robotService = ArduinoService()

				if msgType == MessageFormat.retInv:
					msg = RetInvA2P()
					msg.decode(msgContent)
					robotService.processRetrievedInventory(msg.invInfoRowId, msg.virtCartId)

				elif msgType == MessageFormat.depInv:
					msg = DepoInvA2P()
					msg.decode(msgContent)
					#(barcode, x_index, y_index, x_encoder, y_encoder):
					txMsgContent = self.msgInProcess[1]
					robotService.depositInventory(txMsgContent[0],
											      txMsgContent[1],
											      txMsgContent[2],
											      txMsgContent[3],
											      txMsgContent[4])

				elif msgType == MessageFormat.homeRobot:
					msg = HomeRobotA2P()
					msg.decode(msgContent)

				elif msgType == MessageFormat.movRobot:
					msg = MovPosA2P()
					msg.decode(msgContent)

			except CorruptData as details:
				print(details)
def testRetInvP2A():

	print("Test1: ")
	c_msg = (0x80, 0x0D, 0x01, 0x01, 0x02, 0x02, 0x05, 0x33, 0x33,
		     0x44, 0x44, 0x55, 0x55, 0x66, 0x66)

	parser = MessageParser()
	for msgByte in c_msg:
		parser.parseMsg(msgByte)

	msgContent = parser.getRetVal()[2]

	data = RetInvP2A()
	data.decode(msgContent)
	data_encode = data.encode()

	print(c_msg)
	print(data_encode)

	# TODO: output the msg content so we can see the data integrity
	print("invInfoRowId: " + str(data.invInfoRowId) )
	print("virtCartId: " + str(data.virtCartId) )
	print("x_idx: " + str(data.x_idx) )
	print("y_idx: " + str(data.y_idx) )
	print("x_enc: " + str(data.x_enc) )
	print("y_enc: " + str(data.y_enc) )
	print("x_encAbove: " + str(data.x_encAbove) )
	print("y_encAbove: " + str(data.y_encAbove) )
	print("\n")


	print("Test2: ")
	c_msg2 = (0x80, 0x0D, 0x01, 0x01, 0x02, 0x03, 0x05, 0x33, 0x33,
		      0x44, 0x44, 0x55, 0x55, 0x66, 0x66)

	parser = MessageParser()
	for msgByte in c_msg2:
		parser.parseMsg(msgByte)

	msgContent2 = parser.getRetVal()[2]
	try:
		data.decode(msgContent2)
	except CorruptData as detail:
		print(detail)


	print("Test3: ")
	c_msg3 = (0x80, 0x0D, 0x01, 0x01, 0x02, 0x02, 0x06, 0x33, 0x33,
		      0x44, 0x44, 0x55, 0x55, 0x66, 0x66)

	parser = MessageParser()
	for msgByte in c_msg3:
		parser.parseMsg(msgByte)

	msgContent3 = parser.getRetVal()[2]

	try:
		data.decode(msgContent3)
	except CorruptData as detail:
		print(detail)
	print("\n")

	print("===================================================")
	print("Testing testRetInvP2A----------------------complete\n\n\n")