コード例 #1
0
class RobotStationServer:
    def __init__(self):
        self.processController = ProcessController()

    @cherrypy.expose
    def index(self):
        return 'welcome to virtuoso robot drink station'

    @cherrypy.expose
    @cherrypy.tools.json_in()
    @cherrypy.tools.json_out()
    def order(self):
        # print 'get somthing'
        orderList = []
        order_id = randint(0, 9999)
        orderdata = cherrypy.request.json
        print orderdata
        for drinkinfo in orderdata['orderList']:
            drink = Drink(**drinkinfo)
            drink.order_id = order_id
            orderList.append(drink)
            print drink.__dict__

        self.processController.getorder(orderList)
        self.processController.lockerManager.addProcessingOrder(order_id)
        print orderList
        return {'response': 'Order recivied!! Your order id is %d' % order_id}

    @cherrypy.expose
    def getProcess(self):
        info = 'processing list = '
        for drink in self.processController.getProcessingList():
            info += str(drink.__dict__)

        return info

    @cherrypy.expose
    def close(self):
        self.processController.lockerManager.disConnectMega()
        return 'serial closed'
コード例 #2
0
from processController import ProcessController
import json
from RobotStations.Drinks import Drink

pc = ProcessController()
drink1 = Drink()
drink2 = Drink()

drink1.black_tea = 10
drink1.wm_tea = 0
drink1.ingredients = 5
drink1.ice = 5
drink1.sugar = 3

drink2.black_tea = 1
drink2.wm_tea = 10
drink2.ingredients = 3
drink2.ice = 7
drink2.sugar = 0

drinkList = [drink1, drink2]

if __name__ == '__main__':
    pc.getorder(drinkList)