Example #1
0
 def __init__(self, nr):
     CommandFactory.__init__(self)
     
     self.command.append(0x04)
     self.command.append(0x01)
     self.command.append(self.ZERO_BYTE)
     self.command.append(nr)
     self.command.append(self.ZERO_BYTE)
Example #2
0
    def __init__(self, nr):
        CommandFactory.__init__(self)

        self.command.append(0x04)
        self.command.append(0x01)
        self.command.append(self.ZERO_BYTE)
        self.command.append(nr)
        self.command.append(self.ZERO_BYTE)
Example #3
0
    def __init__(self, ASDU, IOA, CONTROL_ACTION):
        """
        Builds the telegram as a list of bytes. CONTROL_ACTION specifies whether the target
        object given by the IOA should be switched \"ON\" or \"OFF\".
        """
        CommandFactory.__init__(self)
        # 1) length of APDU
        self.command.append(10 + 4)

        # 2-5) Control Fields
        # leave them all zero for the moment
        # we need to care about them later, when trying to check whether
        # telegrams arrived and were processed or not
        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)

        # 6) Type Identification
        self.command.append(self.TYPE_C_DC_NA_1)

        # 7) SQ / Number of Objects
        self.command.append(1)

        # 8) T / P/N / Cause of Transmission
        self.command.append(self.COT_ACTIVATION)
        # COT is always "activation", even if switching off!!!

        # 9) Originator Address
        # this is always zero in our case
        self.command.append(self.ZERO_BYTE)

        # 10-11) ASDU address
        asdu_bytes = int_to_hex_bytes(ASDU)
        # - low octet
        self.command.append(asdu_bytes[1])
        # - high octet
        self.command.append(asdu_bytes[0])

        # 12-n) IOAs + respective Object informations
        ioa_bytes = int_to_hex_bytes(IOA)
        # IOA - low octet
        self.command.append(ioa_bytes[1])
        # IOA - high octet
        self.command.append(ioa_bytes[0])
        # IOA - special - always 0 in our case
        self.command.append(self.ZERO_BYTE)
        # Object Information - always one byte in our case
        if CONTROL_ACTION == "ON":
            self.command.append(self.EXECUTE_UNSPECIFIED_ON)
        else:
            self.command.append(self.EXECUTE_UNSPECIFIED_OFF)
 def __init__(self, ASDU, IOA, CONTROL_ACTION):
     """
     Builds the telegram as a list of bytes. CONTROL_ACTION specifies whether the target
     object given by the IOA should be switched \"ON\" or \"OFF\".
     """
     CommandFactory.__init__(self)
     # 1) length of APDU
     self.command.append(10 + 4)
     
     # 2-5) Control Fields
     # leave them all zero for the moment
     # we need to care about them later, when trying to check whether 
     # telegrams arrived and were processed or not
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     
     # 6) Type Identification
     self.command.append(self.TYPE_C_DC_NA_1)
     
     # 7) SQ / Number of Objects  
     self.command.append(1)
     
     # 8) T / P/N / Cause of Transmission
     self.command.append(self.COT_ACTIVATION)
     # COT is always "activation", even if switching off!!!
         
     # 9) Originator Address
     # this is always zero in our case        
     self.command.append(self.ZERO_BYTE)
     
     # 10-11) ASDU address
     asdu_bytes = int_to_hex_bytes(ASDU)
     # - low octet
     self.command.append(asdu_bytes[1])
     # - high octet
     self.command.append(asdu_bytes[0])
     
     # 12-n) IOAs + respective Object informations
     ioa_bytes = int_to_hex_bytes(IOA)
     # IOA - low octet
     self.command.append(ioa_bytes[1])
     # IOA - high octet
     self.command.append(ioa_bytes[0])
     # IOA - special - always 0 in our case
     self.command.append(self.ZERO_BYTE)
     # Object Information - always one byte in our case
     if CONTROL_ACTION == "ON":
         self.command.append(self.EXECUTE_UNSPECIFIED_ON)
     else:
         self.command.append(self.EXECUTE_UNSPECIFIED_OFF)
Example #5
0
 def __init__(self, ASDU):
     """
     Builds the general interrogation command as a list of bytes.
     """
     CommandFactory.__init__(self)
     # 1) length of APDU
     self.command.append(14)
     
     # 2-5) Control Fields
     # leave them all zero for the moment
     # we need to care about them later, when trying to check whether 
     # telegrams arrived and were processed or not
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     self.command.append(self.ZERO_BYTE)
     
     # 6) Type Identification
     self.command.append(self.TYPE_C_IC_NA_1)
     
     # 7) SQ / Number of Objects  
     self.command.append(1)
     
     # 8) T / P/N / Cause of Transmission
     self.command.append(self.COT_ACTIVATION)
     # COT is always "activation", even if switching off!!!
         
     # 9) Originator Address
     # this is always zero in our case        
     self.command.append(self.ZERO_BYTE)
     
     # 10-11) ASDU address
     asdu_bytes = int_to_hex_bytes(ASDU)
     # - low octet
     self.command.append(asdu_bytes[1])
     # - high octet
     self.command.append(asdu_bytes[0])
     
     # 12-n) IOA is always zero for general interrogation command
     # IOA - low octet
     self.command.append(self.ZERO_BYTE)
     # IOA - high octet
     self.command.append(self.ZERO_BYTE)
     # IOA - special - always 0 in our case
     self.command.append(self.ZERO_BYTE)
     # Object Information - always one byte in our case
     self.command.append(self.GENERAL_INTERROGATION)
    def __init__(self, DT_ACTION):
        """
        Builds the telegram as a list of bytes. DT_ACTION is used to specify whether
        data transfer should be started (\"START\") or terminated (\"STOP\").
        """
        CommandFactory.__init__(self)
        # 1) Apdu length
        self.command.append(self.SHORT_APDU_LENGTH)

        # 2-4) Control Fields
        if DT_ACTION == "START":
            self.command.append(self.STARTDT_BYTE)
        elif DT_ACTION == "STOP":
            self.command.append(self.STOPDT_BYTE)

        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
Example #7
0
    def __init__(self, DT_ACTION):
        """
        Builds the telegram as a list of bytes. DT_ACTION is used to specify whether
        data transfer should be started (\"START\") or terminated (\"STOP\").
        """
        CommandFactory.__init__(self)
        # 1) Apdu length
        self.command.append(self.SHORT_APDU_LENGTH)

        # 2-4) Control Fields
        if DT_ACTION == "START":
            self.command.append(self.STARTDT_BYTE)
        elif DT_ACTION == "STOP":
            self.command.append(self.STOPDT_BYTE)

        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
        self.command.append(self.ZERO_BYTE)
Example #8
0
 def on_pubmsg(self, connection, event):
     source = event.source.split('!')[0]
     chan = None
     if source in self.ignore_list:
         return
     for ch in self.channel_list:
         if event.target == ch.name:
             chan = ch
     chan.last_speaker = source
     # --- DEBUG ONLY ---#
     # connection.privmsg(event.target, '%s: %s' % (source, ' '.join(event.arguments)))
     #------------------#
     args = event.arguments[0].split()
     # Check for any urls in the arguments
     url_args = [arg for arg in args if arg.startswith('http')]
     if len(args) < 1:
         return
     #Look for triggered commands
     if args[0].startswith("!"):
         cmd_class = CommandFactory.factory(args[0], connection, event, chan, self.start_time)
         if cmd_class:
             cmd_class.resolve()
     #Last-Ten Quote Voting handler
     elif chan.is_valid_vote(args, source):
         choice = int(args[1])
         choice_idx = choice - 1
         if 0 < choice <= len(chan.quote_bets):  # PYTHON WOOH
             # Check if someone else already picked it
             if not chan.quote_bets[choice_idx]['who']:
                 chan.quote_bets[choice_idx]['who'] = source
                 vote_response = '\x02{}\x0f chose \x02{}\x0f'.format(source, chan.quote_bets[choice_idx]['src'])
             else:
                 vote_response = '\x02{}\x0f was already chosen by \x02{}\x0f'.format(
                     chan.quote_bets[choice_idx]['who'], source)
             connection.privmsg(event.target, vote_response)
     # Grab/display <title> text for URLs
     elif len(url_args) > 0:
         for arg in url_args:
             soup = make_soup(arg, event.target, self.cfg)
             if soup and soup.title and soup.title.string:
                 title = re.sub(r'\s+', r' ', soup.title.string).strip()
                 good_title = ""
                 for char in title:
                     try:
                         good_title += char.decode('utf-8')
                     except UnicodeEncodeError:
                         continue
                 connection.privmsg(event.target, '[title] {}'.format(good_title))
     # He should only look for things like 'botsnack' if there's nothing else to do!
     else:
         self.match_keyword_list(connection, event, args)
    def parseMsg(self, response):
        AgentLog.debug("receive msg: {0}".format(response.body))
        try:
            try:
                command = CommandFactory.getCommand(response.getDBType(), response.getAction())(self.context, response)
            except AttributeError:
                request = self.createErrorRequest(response, 'command is not exist')
                self.sender.send(request.getRequest())
                return

            # 异步消息,需要返回一个响应,表示已经在处理
            self.sender.send(command.responseACK().getRequest())

            data = [((), {'command': command, 'asyncSender': self.asyncSender})]
            reqs = threadpool.makeRequests(doWork, data)
            [AsyncCMDReceiver.pool.putRequest(req) for req in reqs]

        except Exception, e:
            AgentLog.error('AsyncCMDReceiver.parseMsg error %s' % e)
Example #10
0
    > If no commands are entered, you will be prompted for a file name.
    
    '''
    arg_parser = argparse.ArgumentParser(
        description="Extract filename if present")
    arg_parser.add_argument("-f",
                            "--file",
                            help="Name of the file",
                            default=None)
    args = arg_parser.parse_args()
    the_exception_handler = TigrExceptionHandler(
        "TIGr encountered an error and had to exit")

    if args.file:
        # file name provided - read input from file
        TigrReader(RegexParser(CommandFactory(TurtleDrawer()),
                               the_exception_handler),
                   the_exception_handler,
                   optional_file_name=args.file).go()
    else:
        # read from stdin
        # TODO examine if this section of the code can be incorporated within the class structure
        source = None
        if sys.stdin.isatty():
            # read from input at prompt
            print("Enter your commands. Ctrl + Z to exit or finish.")
            # only on windows, if this was portable we should add the linux interrupt command x3
            print(
                "If no commands are entered, you will be prompted for a file name."
            )
            source = sys.stdin.readlines()
Example #11
0
	# # read config file
	# config_file_name=sys.argv[1]		
	# try:
	# 	config_file = open(config_file_name)
	# 	config = ConfigParser()	
	# 	config.readfp(config_file)
	# 	conf_dir = os.path.dirname(os.path.abspath(config_file.name))
	# except Exception:
	# 	exit("Cannot read config file: " + config_file_name)

	# # get app config values
	# try:
	# 	wget_path = config.get(APP_NAME,'wget.path')
	# 	mirrors = [x.strip() for x in
	# 		   config.get(APP_NAME,'mirrors.active.list').split(',')]

	# 	plugins = [x.strip() for x in
	# 		   config.get(APP_NAME,'plugins.active.list').split(',')]
	# except Exception:
	# 	exit("Bad configuration option in: " + APP_NAME)


	json = '{ "command": "date" }'

	cf = CommandFactory()
	cmd = cf.createCommand(json)
	output = cmd.__exec__()
	print output