def main_loop(): time.sleep(1) if emuReactor.protocolActive is None: print("can't connect server") return emuReactor.protocolActive.role = BaseCommand.PV_ROLE_RELAYER counting = 0 while True: request = None if counting <= 0: command = "Authorize" else: time.sleep(60) command = "HeartBeat" # command = input('Enter Command: ') counting += 1 if command == "quit": break try: request = eval(command + ".C" + command + "()") request.protocol = emuReactor.protocolActive except Exception as e: print("unknown command :", command, e) continue if isinstance(request, Authorize.CAuthorize): request.body[BaseCommand.PN_SB_CODE] = "test_relayer" request.body[ BaseCommand.PN_TERMINALTYPE] = BaseCommand.PV_ROLE_RELAYER emuReactor.SendAndVerify(request)
def main_loop(): time.sleep(1) if emuReactor.protocolActive is None: print "can't connect server" return while True: request = None try: command = raw_input('Enter Command: ') if command == "quit": break request = eval(command + ".C" + command + "()") request.protocol = emuReactor.protocolActive except Exception, e: print "unknown command :", command, e continue if isinstance(request, Authorize.CAuthorize): request.body[BaseCommand.PN_SB_CODE] = "test_relayer" request.body[ BaseCommand.PN_TERMINALTYPE] = BaseCommand.PV_ROLE_RELAYER # elif isinstance(request, EventDev.CEventDev): # request.body[BaseCommand.PN_DEVCODE]="1234" # request.body[BaseCommand.PN_DEVSEQ]=0 # request.body[BaseCommand.PN_DEVVALUE]=199 emuReactor.SendAndVerify(request)
def main_loop(): time.sleep(1) if emuReactor.protocolActive is None: print "can't connect server" return global run_mode,run_role if len(sys.argv)>1: run_mode=sys.argv[1] if len(sys.argv)>2: run_role=sys.argv[2] user_name='pp'+str(random.randint(0, 99999999)) sb_code='test_relayer' dev_code='12345678'+str(random.randint(0, 99999999)) apartment_id=4 account=apartment=relayer=device=scene=contactor=None CommandList=["AddAccount","Authorize","AddApartment","AddRelayer","AddDevice",\ "QueryApartment", "ControlDevice",\ "QueryAccount","RemoveDevice","ModifyRelayer","RemoveRelayer",\ "ModifyApartment","RemoveApartment"] nCommandIndex=0 while True: #for str_command in CommandList: request=None commands=[] try: command="" if run_mode=="command": command = raw_input('Enter Command: ') elif run_mode=="press_control": if nCommandIndex==0: command="Authorize" nCommandIndex=nCommandIndex+1 else: command="ControlDevice" else: if nCommandIndex>=len(CommandList):break command=CommandList[nCommandIndex] nCommandIndex=nCommandIndex+1 if command=="quit": break; commands=command.split() request=eval(commands[0]+".C"+commands[0]+"()") request.protocol=emuReactor.protocolActive except Exception, e: print "unknown command :", command,e continue if isinstance(request, Authorize.CAuthorize): request.body[BaseCommand.PN_USERNAME]=user_name request.body[BaseCommand.PN_PASSWORD]="123" request.body[BaseCommand.PN_TERMINALTYPE]=BaseCommand.PV_ROLE_HUMAN elif isinstance(request,AddAccount.CAddAccount): #user_name="user"+str(random.uniform(0,4000)) request.body[BaseCommand.PN_USERNAME]=user_name request.body[BaseCommand.PN_PASSWORD]="123" request.body[BaseCommand.PN_EMAIL]=user_name+"@163.com" account=request elif isinstance(request, AddApartment.CAddApartment): request.body[BaseCommand.PN_APARTMENTNAME]="apartment"+str(random.randint(0,100)) apartment=request elif isinstance(request, AddRelayer.CAddRelayer): sb_code="sb_"+str(random.uniform(0,4000)) request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] #request.body[BaseCommand.PN_SB_CODE]="sb_code"+str(random.randint(0,100)) request.body[BaseCommand.PN_SB_CODE]="test_relayer" request.body[BaseCommand.PN_NAME]="sb_name"+str(random.randint(0,100)) relayer=request elif isinstance(request, ModifyApartment.CModifyApartment): request.body[BaseCommand.PN_APARTMENTNAME]="apartment"+str(random.randint(0,100)) request.body[BaseCommand.PN_ID]=apartment.respond.body[BaseCommand.PN_ID] elif isinstance(request, ModifyRelayer.CModifyRelayer): request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] request.body[BaseCommand.PN_SB_CODE]="sb_code"+str(random.randint(0,100)) request.body[BaseCommand.PN_RELAYERID]=relayer.respond.body[BaseCommand.PN_ID] request.body[BaseCommand.PN_NAME]="sb_name"+str(random.randint(0,100)) elif isinstance(request, RemoveApartment.CRemoveApartment): request.body[BaseCommand.PN_ID]=apartment.respond.body[BaseCommand.PN_ID] elif isinstance(request, RemoveRelayer.CRemoveRelayer): request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] request.body[BaseCommand.PN_RELAYERID]=relayer.respond.body[BaseCommand.PN_ID] elif isinstance(request, AddDevice.CAddDevice): if run_mode=="auto": request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] else: request.body[BaseCommand.PN_APARTMENTID]=apartment_id request.body[BaseCommand.PN_DEVMODEL]="2111S" request.body[BaseCommand.PN_DEVCODE]=dev_code #str(random.randint(0,10000)) request.body[BaseCommand.PN_RELAYERID]=1 device=request elif isinstance(request, RemoveDevice.CRemoveDevice): request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] request.body[BaseCommand.PN_DEVICEID]=device.respond.body[BaseCommand.PN_DEVICEID] request.body[BaseCommand.PN_DEVKEYS] = [{"dev_key_seq":0}] elif isinstance(request, ControlDevice.CControlDevice): request.body[BaseCommand.PN_DEVMODEL]="2111S" if len(commands)>1: request.body[BaseCommand.PN_DEVCODE]=commands[1] else: request.body[BaseCommand.PN_DEVCODE]=dev_code if len(commands)>2: request.body[BaseCommand.PN_DEVSEQ]=int(commands[2]) else: request.body[BaseCommand.PN_DEVSEQ]=0 if len(commands)>3: request.body[BaseCommand.PN_DEVVALUE]=int(commands[3]) else: request.body[BaseCommand.PN_DEVVALUE]=1 if len(commands)>4: request.body[BaseCommand.PN_DEVMODEL]=commands[4] else: request.body[BaseCommand.PN_DEVMODEL]="2111S" elif isinstance(request, QueryApartment.CQueryApartment): request.body[BaseCommand.PN_APARTMENTID]=apartment.respond.body[BaseCommand.PN_ID] request.body[BaseCommand.PN_VERSION]=0 elif isinstance(request, QueryDevice.CQueryDevice): request.body[BaseCommand.PN_DEVMODEL]="2113D" if len(commands)>1: request.body[BaseCommand.PN_DEVCODE]=commands[1] else: request.body[BaseCommand.PN_DEVCODE]=dev_code if len(commands)>2: request.body[BaseCommand.PN_DEVSEQ]=int(commands[2]) else: request.body[BaseCommand.PN_DEVSEQ]=0 if not emuReactor.SendAndVerify(request): if run_mode=="auto": break