Example #1
0
    def order_up(self):
        '''
        Deliver completed orders to the relevant Customers.
        '''
        self.send_cmd(self.CMD_ORDER_UP)
        if DEBUG:
            print "cmd: order up -----------"

        orders_taken = self.state['e'].get_ready_orders(count=0)  # 0 means all
        order_count = len(orders_taken)

        # send number of orders
        write_buf = ''
        write_buf += sp.pack_single_uint8(order_count)

        # send orders
        if 0 < order_count:
            packed = self.state['e'].pack_orders(orders_taken)
            write_buf += packed

        self.write(write_buf)
        recv_buf = recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #2
0
    def get_orders(self):
        '''
        Get orders from tables with Customers that are ready to order.
        '''
        self.send_cmd(self.CMD_GET_ORDERS)
        if DEBUG:
            print "cmd: get orders -----------"

        orders = self.state['e'].get_orders(self.magic_page)

        # recv order count
        recv_buf = ''
        recv_buf += sp.pack_single_uint8(len(orders))

        if DEBUG:
            print " {0} orders: {1}".format(len(orders), orders)

        if 0 < len(orders):
            packed = self.state['e'].pack_orders(orders)
            # recv orders
            recv_buf += packed

        recv_buf += recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #3
0
    def order_up(self):
        '''
        Deliver completed orders to the relevant Customers.
        '''
        self.send_cmd(self.CMD_ORDER_UP)
        if DEBUG:
            print "cmd: order up -----------"

        orders_taken = self.state['e'].get_ready_orders(count=0) # 0 means all
        order_count = len(orders_taken)

        # send number of orders
        write_buf = ''
        write_buf += sp.pack_single_uint8(order_count)

        # send orders
        if 0 < order_count:
            packed = self.state['e'].pack_orders(orders_taken)
            write_buf += packed

        self.write(write_buf)
        recv_buf = recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #4
0
    def get_orders(self):
        '''
        Get orders from tables with Customers that are ready to order.
        '''
        self.send_cmd(self.CMD_GET_ORDERS)
        if DEBUG:
            print "cmd: get orders -----------"

        orders = self.state['e'].get_orders(self.magic_page)

        # recv order count
        self.read(length=1, expect=sp.pack_single_uint8(len(orders)))

        if DEBUG:
            print " {0} orders: {1}".format(len(orders), orders)

        for o in orders:
            [(p_tid, p_cid, p_ft, p_fi)] = self.state['e'].pack_orders_tuples([o])
            # recv orders
            f = Variable('food{0}'.format(o.cid))
            f.set_slice(0)
            i = Variable('id{0}'.format(o.cid))
            i.set_slice(0)
            self.read(length=len(p_tid), expect=p_tid)
            self.read(length=len(p_cid), assign=i)
            self.read(length=len(p_ft), expect=p_ft)
            self.read(length=len(p_fi), assign=f)
            self.state['food_item'][o.cid] = f
            self.state['c_ids'][o.cid] = i

        self.recv_status(self.STATUS_OK)

        return 0
Example #5
0
    def get_orders(self):
        '''
        Get orders from tables with Customers that are ready to order.
        '''
        self.send_cmd(self.CMD_GET_ORDERS)
        if DEBUG:
            print "cmd: get orders -----------"

        orders = self.state['e'].get_orders(self.magic_page)

        # recv order count
        self.read(length=1, expect=sp.pack_single_uint8(len(orders)))

        if DEBUG:
            print " {0} orders: {1}".format(len(orders), orders)

        for o in orders:
            [(p_tid, p_cid, p_ft, p_fi)
             ] = self.state['e'].pack_orders_tuples([o])
            # recv orders
            f = Variable('food{0}'.format(o.cid))
            f.set_slice(0)
            i = Variable('id{0}'.format(o.cid))
            i.set_slice(0)
            self.read(length=len(p_tid), expect=p_tid)
            self.read(length=len(p_cid), assign=i)
            self.read(length=len(p_ft), expect=p_ft)
            self.read(length=len(p_fi), assign=f)
            self.state['food_item'][o.cid] = f
            self.state['c_ids'][o.cid] = i

        self.recv_status(self.STATUS_OK)

        return 0
Example #6
0
    def get_orders(self):
        '''
        Get orders from tables with Customers that are ready to order.
        '''
        self.send_cmd(self.CMD_GET_ORDERS)
        if DEBUG:
            print "cmd: get orders -----------"

        orders = self.state['e'].get_orders(self.magic_page)

        # recv order count
        recv_buf = ''
        recv_buf += sp.pack_single_uint8(len(orders))

        if DEBUG:
            print " {0} orders: {1}".format(len(orders), orders)

        if 0 < len(orders):
            packed = self.state['e'].pack_orders(orders)
            # recv orders
            recv_buf += packed

        recv_buf += recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #7
0
    def bus_tables(self):
        '''
        For all tables where customers are finished, clear and reset the table.
        '''
        self.send_cmd(self.CMD_BUS_TABLES)
        if DEBUG:
            print "cmd: bus tables -----------"

        bus_cnt = self.state['e'].bus_finished_tables()
        packed = sp.pack_single_uint8(bus_cnt)
        if DEBUG:
            print " bus count {0}".format(bus_cnt)

        self.read(length=len(packed), expect=packed)

        self.recv_status(self.STATUS_OK)

        return 0
Example #8
0
    def bus_tables(self):
        '''
        For all tables where customers are finished, clear and reset the table.
        '''
        self.send_cmd(self.CMD_BUS_TABLES)
        if DEBUG:
            print "cmd: bus tables -----------"

        bus_cnt = self.state['e'].bus_finished_tables()
        packed = sp.pack_single_uint8(bus_cnt)
        if DEBUG:
            print " bus count {0}".format(bus_cnt)

        self.read(length=len(packed), expect=packed)

        self.recv_status(self.STATUS_OK)

        return 0
Example #9
0
    def order_up(self, pov=False):
        '''
        Deliver completed orders to the relevant Customers.
        '''
        self.send_cmd(self.CMD_ORDER_UP)
        if DEBUG:
            print "cmd: order up -----------"

        orders_taken = []
        orders_taken = self.state['e'].get_ready_orders(count=0)  # 0 means all
        if True == pov:
            orders = self.state['e'].get_orders(self.magic_page,
                                                pov)  # make new orders
            orders_taken = self.state['e'].get_ready_orders(
                count=0)  # 0 means all
            # set the Meal.main value to be something that would preresent the crashing EIP
            for o in orders_taken:
                # o.fitem.name = 'N'*CONFIG['MEAL_NAME_SZ']
                o.fitem.main = o.fitem.main[:4] + 'M' * 4 + o.fitem.main
                o.fitem.main = o.fitem.main[:CONFIG['MEAL_MAIN_SZ']]
                # o.fitem.veggie = 'V'*CONFIG['MEAL_VEG_SZ']
                # o.fitem.side = 'S'*CONFIG['MEAL_SIDE_SZ']
            # orders_taken.reverse()

        order_count = len(orders_taken)

        # send number of orders
        self.write(sp.pack_single_uint8(order_count))

        # send orders
        for o in orders_taken:
            [(p_tid, p_cid, p_ft, p_fi)
             ] = self.state['e'].pack_orders_tuples([o])
            self.write(p_tid)
            self.write(self.state['c_ids'][o.cid])
            self.write(p_ft)
            if True == pov:
                self.state['food_item'][o.cid] = p_fi
            self.write(self.state['food_item'][o.cid])

        self.recv_status(self.STATUS_OK)

        return 0
Example #10
0
    def add_customers(self):
        '''
        A new group of customers arrives at the restaurant.
        '''
        self.send_cmd(self.CMD_ADD_CUST)
        if DEBUG:
            print "cmd: add customer -----------"

        # new_customers = self.state['e'].get_next_arriving_customers()
        c_id_init = 0x41414141
        new_customers = []
        for _ in range(2):
            new_customers.append(Customer(cid=c_id_init))
            c_id_init += 1

        if DEBUG:
            print " {0} customers to be added.".format(len(new_customers))

        # send customer count
        self.write(sp.pack_single_uint8(len(new_customers)))

        # send all customers on new_customers list
        for c in new_customers:
            if DEBUG:
                print " packing customer {0}".format(c.id)
            self.write(sp.pack_single_uint32(c.id))

        # self.write(write_data)

        # add all customers on new_customers list to waiting_list
        # try to seat all customers on waiting_list at empty tables
        seated_cnt = self.state['e'].seat_customers(new_customers)

        # recv number of customers seated
        if DEBUG:
            print " {0} seated".format(seated_cnt)

        self.recv_uint8(seated_cnt)

        self.recv_status(self.STATUS_OK)

        return 0
Example #11
0
    def add_customers(self):
        '''
        A new group of customers arrives at the restaurant.
        '''
        self.send_cmd(self.CMD_ADD_CUST)
        if DEBUG:
            print "cmd: add customer -----------"

        # new_customers = self.state['e'].get_next_arriving_customers()
        c_id_init = 0x41414141
        new_customers = []
        for _ in range(2):
            new_customers.append(Customer(cid=c_id_init))
            c_id_init += 1

        if DEBUG:
            print " {0} customers to be added.".format(len(new_customers))

        # send customer count
        self.write(sp.pack_single_uint8(len(new_customers)))

        # send all customers on new_customers list
        for c in new_customers:
            if DEBUG:
                print " packing customer {0}".format(c.id)
            self.write(sp.pack_single_uint32(c.id))

        # self.write(write_data)

        # add all customers on new_customers list to waiting_list
        # try to seat all customers on waiting_list at empty tables
        seated_cnt = self.state['e'].seat_customers(new_customers)

        # recv number of customers seated
        if DEBUG:
            print " {0} seated".format(seated_cnt)

        self.recv_uint8(seated_cnt)

        self.recv_status(self.STATUS_OK)

        return 0
Example #12
0
    def order_up(self, pov=False):
        '''
        Deliver completed orders to the relevant Customers.
        '''
        self.send_cmd(self.CMD_ORDER_UP)
        if DEBUG:
            print "cmd: order up -----------"

        orders_taken = []
        orders_taken = self.state['e'].get_ready_orders(count=0) # 0 means all
        if True == pov:
            orders = self.state['e'].get_orders(self.magic_page, pov) # make new orders
            orders_taken = self.state['e'].get_ready_orders(count=0) # 0 means all
            # set the Meal.main value to be something that would preresent the crashing EIP
            for o in orders_taken:
                # o.fitem.name = 'N'*CONFIG['MEAL_NAME_SZ']
                o.fitem.main = o.fitem.main[:4] + 'M'*4 + o.fitem.main
                o.fitem.main = o.fitem.main[:CONFIG['MEAL_MAIN_SZ']]
                # o.fitem.veggie = 'V'*CONFIG['MEAL_VEG_SZ']
                # o.fitem.side = 'S'*CONFIG['MEAL_SIDE_SZ']
            # orders_taken.reverse()

        order_count = len(orders_taken)

        # send number of orders
        self.write(sp.pack_single_uint8(order_count))

        # send orders
        for o in orders_taken:
            [(p_tid, p_cid, p_ft, p_fi)] = self.state['e'].pack_orders_tuples([o])
            self.write(p_tid)
            self.write(self.state['c_ids'][o.cid])
            self.write(p_ft)
            if True == pov:
                self.state['food_item'][o.cid] = p_fi
            self.write(self.state['food_item'][o.cid])

        self.recv_status(self.STATUS_OK)

        return 0
Example #13
0
    def add_customers(self):
        '''
        A new group of customers arrives at the restaurant.
        '''
        self.send_cmd(self.CMD_ADD_CUST)
        if DEBUG:
            print "cmd: add customer -----------"

        new_customers = self.state['e'].get_next_arriving_customers()

        if DEBUG:
            print " {0} customers to be added.".format(len(new_customers))

        # send customer count
        write_data = sp.pack_single_uint8(len(new_customers))

        # send all customers on new_customers list
        for c in new_customers:
            if DEBUG:
                print " packing customer {0}".format(c.id)
            write_data += sp.pack_single_uint32(c.id)

        self.write(write_data)

        # add all customers on new_customers list to waiting_list
        # try to seat all customers on waiting_list at empty tables
        seated_cnt = self.state['e'].seat_customers(new_customers)

        # recv number of customers seated
        if DEBUG:
            print " {0} seated".format(seated_cnt)

        recv_buf = recv_uint8(seated_cnt)

        recv_buf += recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #14
0
    def add_customers(self):
        '''
        A new group of customers arrives at the restaurant.
        '''
        self.send_cmd(self.CMD_ADD_CUST)
        if DEBUG:
            print "cmd: add customer -----------"

        new_customers = self.state['e'].get_next_arriving_customers()

        if DEBUG:
            print " {0} customers to be added.".format(len(new_customers))

        # send customer count
        write_data = sp.pack_single_uint8(len(new_customers))

        # send all customers on new_customers list
        for c in new_customers:
            if DEBUG:
                print " packing customer {0}".format(c.id)
            write_data += sp.pack_single_uint32(c.id)

        self.write(write_data)

        # add all customers on new_customers list to waiting_list
        # try to seat all customers on waiting_list at empty tables
        seated_cnt = self.state['e'].seat_customers(new_customers)

        # recv number of customers seated
        if DEBUG:
            print " {0} seated".format(seated_cnt)

        recv_buf = recv_uint8(seated_cnt)

        recv_buf += recv_status(self.STATUS_OK)
        self.read(length=len(recv_buf), expect=recv_buf)

        return 0
Example #15
0
 def get_plain_content(self):
     pc = ''
     pc += sp.pack_single_uint32(self.serialVersionUID)
     pc += sp.pack_single_uint8(self.subTypeID)
     return pc
Example #16
0
 def recv_uint8(self, val, match=True):
     if True == match:
         self.read(length=1, expect=sp.pack_single_uint8(val))
     else:
         self.read(length=1)
Example #17
0
def recv_uint8(val):
    return sp.pack_single_uint8(val)
Example #18
0
 def recv_uint8(self, val, match=True):
     if True == match:
         self.read(length=1, expect=sp.pack_single_uint8(val))
     else:
         self.read(length=1)
Example #19
0
 def get_plain_content(self):
     pc = ""
     pc += sp.pack_single_uint32(self.serialVersionUID)
     pc += sp.pack_single_uint8(self.subTypeID)
     return pc
Example #20
0
def recv_uint8(val):
    return sp.pack_single_uint8(val)