Esempio n. 1
0
 def procLine(self, parent):
     name = parent.tokens[parent.currToken]
     ProcLedCards.name.append(name)
     if ProcChains.checkNameExists(parent.procChains, name):
         parent.consoleObj.updateConsole("!!! Error !!! LED bit name already exists, read %s, at line num %d." %
            (name, parent.lineNumList[parent.currToken]))
         return (410)           
     ProcChains.addName(parent.procChains, name, ProcChains.LED_BIT)
     
     # Verify card num
     if not parent.helpFuncs.isInt(parent.tokens[parent.currToken + 1]):
         parent.consoleObj.updateConsole("!!! Error !!! LED card num, read %s, at line num %d." %
            (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
         return (411)
     # Convert from 1 base to 0 based card num
     cardNum = parent.helpFuncs.out - 1
     # Card number is base 1
     if (cardNum < 0) or (cardNum >= ProcLedCards.numLedCards):
         parent.consoleObj.updateConsole("!!! Error !!! Illegal LED card num, read %s, at line num %d." %
            (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
         return (412)
     ProcLedCards.cardNum.append(cardNum)
     
     # Verify pin num
     if not parent.helpFuncs.isInt(parent.tokens[parent.currToken + 2]):
         parent.consoleObj.updateConsole("!!! Error !!! LED pin num, read %s, at line num %d." %
            (parent.tokens[parent.currToken + 2], parent.lineNumList[parent.currToken + 2]))
         return (413)
     # Convert from 1 base to 0 based pin num, bit 0 = 0x80, bit 7 = 0x01
     pinNum = 7 - (parent.helpFuncs.out - 1)
     # Pin number is base 1
     if (pinNum < 0) or (pinNum >= ProcLedCards.NUM_LED_BITS):
         parent.consoleObj.updateConsole("!!! Error !!! Illegal LED pin num, read %s, at line num %d." %
            (parent.tokens[parent.currToken + 2], parent.lineNumList[parent.currToken + 2]))
         return (414)
     if (ProcLedCards.ledCfgBits[cardNum] & (1 << pinNum)) != 0: 
         parent.consoleObj.updateConsole("!!! Error !!! LED pin configured multiple times, at line num %d." %
            (parent.lineNumList[parent.currToken + 2]))
         return (415)
     ProcLedCards.ledCfgBits[cardNum] |= (1 << pinNum)
     ProcLedCards.pinNum.append(pinNum)
     
     # Grab description
     desc = parent.tokens[parent.currToken + 3]
     ProcLedCards.desc.append(desc)
     
     # increment currToken
     parent.currToken += 4
     return (0)
    def procAllChains(self, parent):
        # Copy name
        name = parent.tokens[parent.currToken]
        if (name in ProcVidChains.nameSet):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Name found twice, read %s, at line num %d." %
                (parent.tokens[parent.currToken],
                 parent.lineNumList[parent.currToken]))
            return (1410)
        ProcVidChains.nameSet.add(name)
        ProcChains.addName(parent.procChains, name,
                           ProcChains.VIDEO_CHAIN_NAME)
        ProcVidChains.outHndl.write("    ## Video Chain {0}\n".format(name))
        ProcVidChains.outHndl.write(
            "    #    - Groups have video name then WAIT command\n")
        ProcVidChains.outHndl.write(
            "    #    - Chain ends with REPEAT if desired\n")
        ProcVidChains.outHndl.write("    {0} = [\n".format(name))

        # Verify opening symbol
        parent.currToken += 1
        if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Expected opening symbol, read %s, at line num %d."
                % (parent.tokens[parent.currToken],
                   parent.lineNumList[parent.currToken]))
            return (1411)
        closeSymb = parent.helpFuncs.findMatch(parent)
        parent.currToken += 1
        typeProc = ProcVidChains.PROC_VIDEO
        while parent.currToken < closeSymb:
            if parent.tokens[parent.currToken] in ProcVidChains.tokenLookup:
                tokenType = ProcVidChains.tokenLookup[parent.tokens[
                    parent.currToken]]
            else:
                tokenType = ProcVidChains.UNKNOWN
            if tokenType == ProcVidChains.WAIT_COMMAND:
                if typeProc != ProcVidChains.PROC_COMMAND:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! WAIT command in video chain in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1412)
                # Next token should be wait timeout (ms)
                if not parent.helpFuncs.isInt(
                        parent.tokens[parent.currToken + 1]):
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! WAIT parameter should be integer, read %s, at line num %d."
                        % (parent.tokens[parent.currToken + 1],
                           parent.lineNumList[parent.currToken + 1]))
                    return (1413)
                ProcVidChains.outHndl.write(" WAIT, " +
                                            parent.tokens[parent.currToken +
                                                          1] + "],\n")
                parent.currToken += 2
                # Next token must be a comma
                if (ProcVidChains.tokenLookup[parent.tokens[parent.currToken]]
                        != ProcVidChains.COMMA):
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Comma missing after wait command, found %s, at line num %d."
                        % (parent.tokens[parent.currToken],
                           parent.lineNumList[parent.currToken]))
                    return (1414)
                parent.currToken += 1
                typeProc = ProcVidChains.PROC_VIDEO
            elif tokenType == ProcVidChains.REPEAT_COMMAND:
                if (typeProc == ProcVidChains.PROC_VIDEO):
                    ProcVidChains.outHndl.write("        [0, ")
                elif (typeProc == ProcVidChains.PROC_COMMAND):
                    pass
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! REPEAT command in video chain in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1415)
                ProcVidChains.outHndl.write("REPEAT, 0] ]\n\n")
                typeProc = ProcVidChains.PROC_DONE_CHAIN
                parent.currToken += 1
            elif tokenType == ProcVidChains.COMMA:
                if (typeProc == ProcVidChains.PROC_VIDEO) or (
                        typeProc == ProcVidChains.PROC_COMMAND):
                    # No processing necessary, next sound will start the line
                    parent.currToken += 1
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Unexpected comma at line num %d." %
                        (parent.lineNumList[parent.currToken]))
                    return (1416)
            else:
                #This must be a video name
                if (ProcChains.checkNameExists(
                        parent.procChains, parent.tokens[parent.currToken])):
                    if (ProcChains.getNameType(parent.procChains,
                                               parent.tokens[parent.currToken])
                            != ProcChains.VIDEO_NAME):
                        parent.consoleObj.updateConsole(
                            "!!! Error !!! Symbol %s should only be a video name, at line num %d."
                            % (parent.tokens[parent.currToken],
                               parent.lineNumList[parent.currToken]))
                        return (1417)
                    else:
                        if typeProc == ProcVidChains.PROC_VIDEO:
                            ProcVidChains.outHndl.write(
                                "        [Videos.{0}, ".format(
                                    parent.tokens[parent.currToken]))
                            typeProc = ProcVidChains.PROC_COMMAND
                            parent.currToken += 1
                        elif typeProc == ProcVidChains.PROC_COMMAND:
                            # Two or more sounds back to back, put a wait of 0 between them
                            ProcVidChains.outHndl.write(
                                "WAIT, 0],\n        [Videos.{0}, ".format(
                                    parent.tokens[parent.currToken]))
                            parent.currToken += 1
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Can't understand symbol, read %s, at line num %d."
                        % (parent.tokens[parent.currToken],
                           parent.lineNumList[parent.currToken]))
                    return (1418)
        if (typeProc != ProcVidChains.PROC_DONE_CHAIN):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Video chain did not end properly, at line num %d."
                % (parent.lineNumList[parent.currToken]))
            return (1419)
        parent.currToken += 1
        return (0)
    def procAllChains(self, parent):
        # Create the lists to support multiple LED cards
        ledCard = [[] for _ in range(ProcLedCards.numLedCards)]

        # Copy name
        name = parent.tokens[parent.currToken]
        if (name in ProcLedChains.nameSet):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Name found twice, read %s, at line num %d." %
                (parent.tokens[parent.currToken],
                 parent.lineNumList[parent.currToken]))
            return (1210)
        ProcLedChains.nameSet.add(name)
        ProcChains.addName(parent.procChains, name, ProcChains.LED_CHAIN_NAME)
        ProcLedChains.outHndl.write("    ## LED Chain {0}\n".format(name))
        ProcLedChains.outHndl.write("    #    - First entry is LED mask\n")
        ProcLedChains.outHndl.write(
            "    #    - Next groups have a bitfield of LEDs to change and command\n"
        )
        ProcLedChains.outHndl.write("    {0} = [".format(name))

        # Verify opening symbol
        parent.currToken += 1
        if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Expected opening symbol, read %s, at line num %d."
                % (parent.tokens[parent.currToken],
                   parent.lineNumList[parent.currToken]))
            return (1211)
        closeSymb = parent.helpFuncs.findMatch(parent)
        parent.currToken += 1
        typeProc = ProcLedChains.PROC_MASK
        firstBit = True
        while parent.currToken < closeSymb:
            if parent.tokens[parent.currToken] in ProcLedChains.tokenLookup:
                tokenType = ProcLedChains.tokenLookup[parent.tokens[
                    parent.currToken]]
            else:
                tokenType = ProcLedChains.UNKNOWN
            if (tokenType == ProcLedChains.OPEN_PAREN) or (
                    tokenType == ProcLedChains.CLOSE_PAREN):
                # Opening and closing parenthesis are dropped since they aren't necessary
                # Move to next symbol
                parent.currToken += 1
            elif tokenType == ProcLedChains.WAIT_COMMAND:
                if typeProc != ProcLedChains.PROC_COMMAND:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! WAIT command in LED chain in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1212)
                # Next token should be wait timeout (ms)
                if not parent.helpFuncs.isInt(
                        parent.tokens[parent.currToken + 1]):
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! WAIT parameter should be integer, read %s, at line num %d."
                        % (parent.tokens[parent.currToken + 1],
                           parent.lineNumList[parent.currToken + 1]))
                    return (1213)
                ProcLedChains.outHndl.write(" WAIT, " +
                                            parent.tokens[parent.currToken +
                                                          1] +
                                            "],\n          [ ")
                # If any close parenthesis exist eat them
                parent.currToken += 2
                while (ProcLedChains.tokenLookup[parent.tokens[
                        parent.currToken]] == ProcLedChains.CLOSE_PAREN):
                    parent.currToken += 1
                # Next token must be a comma
                if (ProcLedChains.tokenLookup[parent.tokens[parent.currToken]]
                        != ProcLedChains.COMMA):
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Comma missing after wait command, found %s, at line num %d."
                        % (parent.tokens[parent.currToken],
                           parent.lineNumList[parent.currToken]))
                    return (1214)
                parent.currToken += 1
                typeProc = ProcLedChains.PROC_LED_BIT
                firstBit = True
            elif tokenType == ProcLedChains.END_CHAIN_COMMAND:
                if typeProc != ProcLedChains.PROC_COMMAND:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! END_CHAIN command in LED chain in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1215)
                ProcLedChains.outHndl.write("END_CHAIN, 0] ] ]\n\n")
                parent.currToken += 1
                typeProc = ProcLedChains.PROC_DONE_CHAIN
            elif tokenType == ProcLedChains.REPEAT_COMMAND:
                if typeProc != ProcLedChains.PROC_COMMAND:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! REPEAT command in LED chain in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1216)
                ProcLedChains.outHndl.write("REPEAT, 0] ] ]\n\n")
                parent.currToken += 1
                typeProc = ProcLedChains.PROC_DONE_CHAIN
            elif tokenType == ProcLedChains.COMMA:
                if typeProc == ProcLedChains.PROC_MASK:
                    ProcLedChains.outHndl.write("\n        [ ")
                    for card in xrange(ProcLedCards.numLedCards):
                        if (card != 0):
                            ProcLedChains.outHndl.write(", ")
                        if len(ledCard[card]) == 0:
                            ProcLedChains.outHndl.write("0")
                        else:
                            for bit in xrange(len(ledCard[card])):
                                if (bit != 0):
                                    ProcLedChains.outHndl.write(" | ")
                                ProcLedChains.outHndl.write(ledCard[card][bit])
                    ProcLedChains.outHndl.write(" ],\n        [ [ ")
                    parent.currToken += 1
                    typeProc = ProcLedChains.PROC_LED_BIT
                    firstBit = True
                    ledCard = [[] for _ in range(ProcLedCards.numLedCards)]
                elif typeProc == ProcLedChains.PROC_LED_BIT:
                    ProcLedChains.outHndl.write("[ ")
                    for card in xrange(ProcLedCards.numLedCards):
                        if (card != 0):
                            ProcLedChains.outHndl.write(", ")
                        if len(ledCard[card]) == 0:
                            ProcLedChains.outHndl.write("0")
                        else:
                            for bit in xrange(len(ledCard[card])):
                                if (bit != 0):
                                    ProcLedChains.outHndl.write(" | ")
                                ProcLedChains.outHndl.write(ledCard[card][bit])
                    ProcLedChains.outHndl.write(" ], ")
                    parent.currToken += 1
                    typeProc = ProcLedChains.PROC_COMMAND
                    ledCard = [[] for _ in range(ProcLedCards.numLedCards)]
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Unexpected comma at line num %d." %
                        (parent.lineNumList[parent.currToken]))
                    return (1217)
            elif tokenType == ProcLedChains.LOGIC_OR:
                if ((typeProc != ProcLedChains.PROC_LED_BIT) and
                    (typeProc != ProcLedChains.PROC_MASK)) or firstBit:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Unexpected | at line num %d." %
                        (parent.lineNumList[parent.currToken]))
                    return (1218)
                parent.currToken += 1
            elif tokenType == ProcLedChains.ZERO:
                if not firstBit:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! 0 not first bit in mask at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1219)
                if (typeProc == ProcLedChains.PROC_MASK):
                    ProcLedChains.outHndl.write(",\n        [ [ ")
                    parent.currToken += 1
                    typeProc = ProcLedChains.PROC_LED_BIT
                    firstBit = True
                elif (typeProc == ProcLedChains.PROC_LED_BIT):
                    parent.currToken += 1
                    typeProc = ProcLedChains.PROC_LED_BIT
                    firstBit = True
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Unexpected 0 at line num %d." %
                        (parent.lineNumList[parent.currToken]))
                    return (1220)
            else:
                #This must be a bit name symbol
                if (ProcChains.checkNameExists(
                        parent.procChains, parent.tokens[parent.currToken])):
                    if (ProcChains.getNameType(parent.procChains,
                                               parent.tokens[parent.currToken])
                            != ProcChains.LED_BIT):
                        parent.consoleObj.updateConsole(
                            "!!! Error !!! Symbol %s should only be an LED bit, at line num %d."
                            % (parent.tokens[parent.currToken],
                               parent.lineNumList[parent.currToken]))
                        return (1221)
                    else:
                        # HRS:  This could be improved to verify any set bits are in the mask
                        card = parent.procChains.findBit(
                            parent.tokens[parent.currToken].upper()) >> 16
                        ledCard[card].append("LedBitNames.{0}".format(
                            parent.tokens[parent.currToken].upper()))
                        firstBit = False
                        parent.currToken += 1
                else:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Can't understand symbol, read %s, at line num %d."
                        % (parent.tokens[parent.currToken],
                           parent.lineNumList[parent.currToken]))
                    return (1222)
        if (typeProc != ProcLedChains.PROC_DONE_CHAIN):
            parent.consoleObj.updateConsole(
                "!!! Error !!! LED chain did not end properly, at line num %d."
                % (parent.lineNumList[parent.currToken]))
            return (1223)
        parent.currToken += 1
        return (0)
Esempio n. 4
0
    def procAllModes(self, parent):
        # Copy name
        name = parent.tokens[parent.currToken]
        if (name in ProcModes.nameSet):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Mode name found twice, read %s, at line num %d."
                % (parent.tokens[parent.currToken],
                   parent.lineNumList[parent.currToken]))
            return (1510)
        ProcModes.nameSet.add(name)
        ProcModes.name.append(name)
        ProcChains.addName(parent.procChains, name, ProcChains.MODE_NAME)
        ProcModes.outHndl.write("        [State.{0}, ".format(name.upper()))
        parent.currToken += 1

        # Next symbol should be the description in quotes.
        # HRS:  This should probably support spaces inside the quotes but that will break the current
        #  tokenizer function.
        desc = parent.tokens[parent.currToken]
        if (not desc.startswith('"')) or (not desc.endswith('"')):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Descriptions strings should start and end with quotes, read %s, at line num %d."
                % (desc, parent.lineNumList[parent.currToken]))
            return (1511)
        ProcModes.desc.append(desc)
        parent.currToken += 1

        # Verify opening symbol
        if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Expected opening symbol, read %s, at line num %d."
                % (parent.tokens[parent.currToken],
                   parent.lineNumList[parent.currToken]))
            return (1512)
        closeSymb = parent.helpFuncs.findMatch(parent)
        parent.currToken += 1
        typeProc = ProcModes.PROC_INIT_CHAIN
        subState = ProcModes.FIND_OPEN_PAREN
        while parent.currToken < closeSymb:
            if parent.tokens[parent.currToken] in ProcModes.tokenLookup:
                tokenType = ProcModes.tokenLookup[parent.tokens[
                    parent.currToken]]
            else:
                tokenType = ProcModes.UNKNOWN
            if (tokenType == ProcModes.OPEN_PAREN):
                # Opening is the beginning of a chain group
                if (subState != ProcModes.FIND_OPEN_PAREN):
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Expected opening paren, read %s, at line num %d."
                        % (parent.tokens[parent.currToken],
                           parent.lineNumList[parent.currToken]))
                    return (1513)
                # Find the matching close parenthesis
                if (typeProc == ProcModes.PROC_INIT_CHAIN) or (
                        typeProc == ProcModes.PROC_PROCESS_CHAIN):
                    ProcModes.outHndl.write("[")
                closeChainList = parent.helpFuncs.findMatch(parent)
                parent.currToken += 1
                subState = ProcModes.FIND_CHAIN
                hasEntries = False
            elif (tokenType == ProcModes.CLOSE_PAREN):
                if not hasEntries:
                    # If this is an audio, LED, scoring, or video chain, need to add starting bracket
                    # to create an empty list
                    if (typeProc == ProcModes.PROC_AUDIO_CHAIN) or (typeProc == ProcModes.PROC_LED_CHAIN) or \
                        (typeProc == ProcModes.PROC_SCORING) or (typeProc == ProcModes.PROC_VIDEO_CHAIN):
                        ProcModes.outHndl.write("[")
                    # If there are no entries, a close parenthesis is valid
                    ProcModes.outHndl.write("]")
                else:
                    if (subState != ProcModes.FIND_COMMA) and (
                            subState != ProcModes.FIND_END):
                        parent.consoleObj.updateConsole(
                            "!!! Error !!! Found close parenthesis at incorrect location at line num %d."
                            % (parent.lineNumList[parent.currToken]))
                        return (1514)
                    else:
                        if (typeProc == ProcModes.PROC_INIT_CHAIN) or (
                                typeProc == ProcModes.PROC_PROCESS_CHAIN):
                            ProcModes.outHndl.write("]")
                subState = ProcModes.FIND_OPEN_PAREN
                if (typeProc == ProcModes.PROC_SCORING):
                    ProcModes.outHndl.write(" ],\n")
                    typeProc = ProcModes.PROC_END_MODE
                else:
                    ProcModes.outHndl.write(", ")
                    typeProc += 1
                parent.currToken += 1
            elif (tokenType == ProcModes.COMMA):
                if subState != ProcModes.FIND_COMMA:
                    parent.consoleObj.updateConsole(
                        "!!! Error !!! Comma in incorrect location at line num %d."
                        % (parent.lineNumList[parent.currToken]))
                    return (1515)
                ProcModes.outHndl.write(", ")
                parent.currToken += 1
                subState = ProcModes.FIND_CHAIN
            else:
                #This must be a name symbol
                if (ProcChains.checkNameExists(
                        parent.procChains, parent.tokens[parent.currToken])):
                    nameType = ProcChains.getNameType(
                        parent.procChains, parent.tokens[parent.currToken])
                    if (typeProc == ProcModes.PROC_INIT_CHAIN):
                        if (nameType != ProcChains.CHAIN_NAME):
                            parent.consoleObj.updateConsole(
                                "!!! Error !!! Expected a chain name in init chain, read %s, at line num %d."
                                % (parent.tokens[parent.currToken],
                                   parent.lineNumList[parent.currToken]))
                            return (1516)
                        ProcModes.outHndl.write(
                            "RulesFunc." + parent.tokens[parent.currToken])
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_PROCESS_CHAIN):
                        if (nameType != ProcChains.CHAIN_NAME):
                            parent.consoleObj.updateConsole(
                                "!!! Error !!! Expected a chain name in process chain, read %s, at line num %d."
                                % (parent.tokens[parent.currToken],
                                   parent.lineNumList[parent.currToken]))
                            return (1517)
                        ProcModes.outHndl.write(
                            "RulesFunc." + parent.tokens[parent.currToken])
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_VIDEO_CHAIN):
                        if (nameType == ProcChains.VIDEO_NAME):
                            ProcModes.outHndl.write(
                                "Videos." +
                                parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.VIDEO_CHAIN_NAME):
                            # HRS:  Warning, in the original code, chains were not contained within another list,
                            #   but were simply part of the procChains table.  This will need to be fixed by removing
                            #   the extra list (which would make multiple chains not work), or combining the chains
                            #   into one.
                            ProcModes.outHndl.write(
                                "VideoChains." +
                                parent.tokens[parent.currToken])
                        elif (nameType == ProcChains.IMAGE_NAME):
                            ProcModes.outHndl.write(
                                "Images." +
                                parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.IMAGE_CHAIN_NAME):
                            # HRS:  Warning, in the original code, chains were not contained within another list,
                            #   but were simply part of the procChains table.  This will need to be fixed by removing
                            #   the extra list (which would make multiple chains not work), or combining the chains
                            #   into one.
                            ProcModes.outHndl.write(
                                "ImageChains." +
                                parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole(
                                "!!! Error !!! Expected a video/image or video/image chain, read %s, at line num %d."
                                % (parent.tokens[parent.currToken],
                                   parent.lineNumList[parent.currToken]))
                            return (1518)
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_AUDIO_CHAIN):
                        if (nameType == ProcChains.SOUND_NAME):
                            ProcModes.outHndl.write(
                                "Sounds." +
                                parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.SOUND_CHAIN_NAME):
                            ProcModes.outHndl.write(
                                "SoundChains." +
                                parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole(
                                "!!! Error !!! Expected a sound or sound chain name, read %s, at line num %d."
                                % (parent.tokens[parent.currToken],
                                   parent.lineNumList[parent.currToken]))
                            return (1519)
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_LED_CHAIN):
                        if (nameType == ProcChains.LED_CHAIN_NAME):
                            ProcModes.outHndl.write(
                                "LedChains." + parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole(
                                "!!! Error !!! Expected an LED chain name, read %s, at line num %d."
                                % (parent.tokens[parent.currToken],
                                   parent.lineNumList[parent.currToken]))
                            return (1520)
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_SCORING):
                        print "Not implemented"
                        parent.currToken += 1
                    else:
                        parent.consoleObj.updateConsole(
                            "!!! Error !!! Parsing error, invalid typeProc = %d, at line num %d."
                            % (typeProc, parent.lineNumList[parent.currToken]))
                        return (1521)
                else:
                    # Assume this is the name of a chain
                    ProcChains.possChainDict[parent.tokens[
                        parent.currToken]] = parent.lineNumList[
                            parent.currToken]
                    ProcModes.outHndl.write("RulesFunc." +
                                            parent.tokens[parent.currToken])
                    subState = ProcModes.FIND_COMMA
                    hasEntries = True
                    parent.currToken += 1
        if (typeProc != ProcModes.PROC_END_MODE):
            parent.consoleObj.updateConsole(
                "!!! Error !!! Mode did not end properly, at line num %d." %
                (parent.lineNumList[parent.currToken]))
            return (1523)
        parent.currToken += 1
        return (0)
Esempio n. 5
0
 def procSection(self, parent):
     parent.consoleObj.updateConsole("Processing %s section" % parent.tokens[parent.currToken])
     if (parent.tokens[parent.currToken] == "FIRST_MODE"):
         #Check if section found before
         if (ProcSimple.foundInit):
             parent.consoleObj.updateConsole("!!! Error !!! Found multiple FIRST_MODE commands, at line num %d." %
                (parent.lineNumList[parent.currToken]))
             return (900)
         ProcSimple.foundInit = True
         #Verify parent.tokens[parent.currToken + 1] is a valid mode
         if (ProcChains.checkNameExists(parent.procChains, parent.tokens[parent.currToken + 1])):
             nameType = ProcChains.getNameType(parent.procChains, parent.tokens[parent.currToken + 1])
             if (nameType != ProcChains.MODE_NAME):
                 parent.consoleObj.updateConsole("!!! Error !!! FIRST_MODE symbole should be a mode, read %s, at line num %d." %
                    (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
                 return (901)
             else:
                 ProcSimple.initMode = parent.tokens[parent.currToken + 1]
         else:
             parent.consoleObj.updateConsole("!!! Error !!! Can't understand symbol, read %s, at line num %d." %
                (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
             return (902)
         parent.consoleObj.updateConsole("Done processing FIRST_MODE")
         parent.currToken += 2
     elif (parent.tokens[parent.currToken] == "TICK_TIME"):
         if not parent.helpFuncs.isInt(parent.tokens[parent.currToken + 1]):
             parent.consoleObj.updateConsole("!!! Error !!! Indexed variable numEntries, read %s, at line num %d." %
                (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
             return (910)
         ProcSimple.tickTime = parent.helpFuncs.out
         parent.currToken += 2
     elif (parent.tokens[parent.currToken] == "CARD_ORDER"):
         parent.currToken += 1
         if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
             parent.consoleObj.updateConsole("!!! Error !!! Expected opening symbol, read %s, at line num %d." %
                (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
             return (920)
         closeSymb = parent.helpFuncs.findMatch(parent)
         parent.currToken += 1
         while parent.currToken < closeSymb:
             # Ignore all commas
             if (parent.tokens[parent.currToken] == ","):
                 pass
             elif (parent.tokens[parent.currToken] == "INPUT_CARD"):
                 ProcSimple.cardInv.append((ord)(rs232Intf.CARD_ID_INP_CARD) + ProcSimple.currInp)
                 ProcSimple.currInp += 1
             elif (parent.tokens[parent.currToken] == "SOLENOID_CARD"):
                 ProcSimple.cardInv.append((ord)(rs232Intf.CARD_ID_SOL_CARD) + ProcSimple.currSol)
                 ProcSimple.currSol += 1
             else:
                 parent.consoleObj.updateConsole("!!! Error !!! Expected INPUT_CARD or SOLENOID_CARD, read %s, at line num %d." %
                    (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                 return (921)
             parent.currToken += 1
         parent.currToken += 1
     else:
         print parent.tokens[parent.currToken]
         parent.consoleObj.updateConsole("!!! SW Error !!! Expected FIRST_MODE or TICK_TIME, read %s, at line num %d." %
            (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
         return (920)
     return (0)
     
Esempio n. 6
0
    def procAllModes(self, parent):
        # Copy name
        name = parent.tokens[parent.currToken]
        if (name in ProcModes.nameSet):
            parent.consoleObj.updateConsole("!!! Error !!! Mode name found twice, read %s, at line num %d." %
               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
            return (1510)
        ProcModes.nameSet.add(name)
        ProcModes.name.append(name)
        ProcChains.addName(parent.procChains, name, ProcChains.MODE_NAME)
        ProcModes.outHndl.write("        [State.{0}, ".format(name.upper()))
        parent.currToken += 1
        
        # Next symbol should be the description in quotes.
        # HRS:  This should probably support spaces inside the quotes but that will break the current
        #  tokenizer function.
        desc = parent.tokens[parent.currToken]
        if (not desc.startswith('"')) or (not desc.endswith('"')):
            parent.consoleObj.updateConsole("!!! Error !!! Descriptions strings should start and end with quotes, read %s, at line num %d." %
               (desc, parent.lineNumList[parent.currToken]))
            return (1511)
        ProcModes.desc.append(desc)
        parent.currToken += 1

        # Verify opening symbol
        if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
            parent.consoleObj.updateConsole("!!! Error !!! Expected opening symbol, read %s, at line num %d." %
               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
            return (1512)
        closeSymb = parent.helpFuncs.findMatch(parent)
        parent.currToken += 1
        typeProc = ProcModes.PROC_INIT_CHAIN
        subState = ProcModes.FIND_OPEN_PAREN
        while parent.currToken < closeSymb:
            if parent.tokens[parent.currToken] in ProcModes.tokenLookup:
                tokenType = ProcModes.tokenLookup[parent.tokens[parent.currToken]]
            else:
                tokenType = ProcModes.UNKNOWN
            if (tokenType == ProcModes.OPEN_PAREN):
                # Opening is the beginning of a chain group
                if (subState != ProcModes.FIND_OPEN_PAREN):
                    parent.consoleObj.updateConsole("!!! Error !!! Expected opening paren, read %s, at line num %d." %
                       (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                    return (1513)
                # Find the matching close parenthesis
                if (typeProc == ProcModes.PROC_INIT_CHAIN) or (typeProc == ProcModes.PROC_PROCESS_CHAIN):
                    ProcModes.outHndl.write("[")
                closeChainList = parent.helpFuncs.findMatch(parent)
                parent.currToken += 1
                subState = ProcModes.FIND_CHAIN
                hasEntries = False
            elif (tokenType == ProcModes.CLOSE_PAREN):
                if not hasEntries:
                    # If this is an audio, LED, scoring, or video chain, need to add starting bracket
                    # to create an empty list
                    if (typeProc == ProcModes.PROC_AUDIO_CHAIN) or (typeProc == ProcModes.PROC_LED_CHAIN) or \
                        (typeProc == ProcModes.PROC_SCORING) or (typeProc == ProcModes.PROC_VIDEO_CHAIN):
                        ProcModes.outHndl.write("[")
                    # If there are no entries, a close parenthesis is valid
                    ProcModes.outHndl.write("]")
                else:
                    if (subState != ProcModes.FIND_COMMA) and (subState != ProcModes.FIND_END): 
                        parent.consoleObj.updateConsole("!!! Error !!! Found close parenthesis at incorrect location at line num %d." %
                           (parent.lineNumList[parent.currToken]))
                        return (1514)
                    else:
                        if (typeProc == ProcModes.PROC_INIT_CHAIN) or (typeProc == ProcModes.PROC_PROCESS_CHAIN):
                            ProcModes.outHndl.write("]")
                subState = ProcModes.FIND_OPEN_PAREN
                if (typeProc == ProcModes.PROC_SCORING):
                    ProcModes.outHndl.write(" ],\n")
                    typeProc = ProcModes.PROC_END_MODE
                else:
                    ProcModes.outHndl.write(", ")
                    typeProc += 1
                parent.currToken += 1
            elif (tokenType == ProcModes.COMMA):
                if subState != ProcModes.FIND_COMMA: 
                    parent.consoleObj.updateConsole("!!! Error !!! Comma in incorrect location at line num %d." %
                       (parent.lineNumList[parent.currToken]))
                    return (1515)
                ProcModes.outHndl.write(", ")
                parent.currToken += 1
                subState = ProcModes.FIND_CHAIN
            else:
                #This must be a name symbol
                if (ProcChains.checkNameExists(parent.procChains, parent.tokens[parent.currToken])):
                    nameType = ProcChains.getNameType(parent.procChains, parent.tokens[parent.currToken])
                    if (typeProc == ProcModes.PROC_INIT_CHAIN):
                        if (nameType != ProcChains.CHAIN_NAME):
                            parent.consoleObj.updateConsole("!!! Error !!! Expected a chain name in init chain, read %s, at line num %d." %
                               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                            return (1516)
                        ProcModes.outHndl.write("RulesFunc." + parent.tokens[parent.currToken])
                        subState = ProcModes.FIND_COMMA
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_PROCESS_CHAIN):
                        if (nameType != ProcChains.CHAIN_NAME):
                            parent.consoleObj.updateConsole("!!! Error !!! Expected a chain name in process chain, read %s, at line num %d." %
                               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                            return (1517)
                        ProcModes.outHndl.write("RulesFunc." + parent.tokens[parent.currToken])
                        subState = ProcModes.FIND_COMMA 
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_VIDEO_CHAIN):
                        if (nameType == ProcChains.VIDEO_NAME):
                            ProcModes.outHndl.write("Videos." + parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.VIDEO_CHAIN_NAME):
                            # HRS:  Warning, in the original code, chains were not contained within another list,
                            #   but were simply part of the procChains table.  This will need to be fixed by removing
                            #   the extra list (which would make multiple chains not work), or combining the chains
                            #   into one.
                            ProcModes.outHndl.write("VideoChains." + parent.tokens[parent.currToken])
                        elif (nameType == ProcChains.IMAGE_NAME):
                            ProcModes.outHndl.write("Images." + parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.IMAGE_CHAIN_NAME):
                            # HRS:  Warning, in the original code, chains were not contained within another list,
                            #   but were simply part of the procChains table.  This will need to be fixed by removing
                            #   the extra list (which would make multiple chains not work), or combining the chains
                            #   into one.
                            ProcModes.outHndl.write("ImageChains." + parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole("!!! Error !!! Expected a video/image or video/image chain, read %s, at line num %d." %
                               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                            return (1518)
                        subState = ProcModes.FIND_COMMA 
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_AUDIO_CHAIN):
                        if (nameType == ProcChains.SOUND_NAME):
                            ProcModes.outHndl.write("Sounds." + parent.tokens[parent.currToken].upper())
                        elif (nameType == ProcChains.SOUND_CHAIN_NAME):
                            ProcModes.outHndl.write("SoundChains." + parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole("!!! Error !!! Expected a sound or sound chain name, read %s, at line num %d." %
                               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                            return (1519)
                        subState = ProcModes.FIND_COMMA 
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_LED_CHAIN):
                        if (nameType == ProcChains.LED_CHAIN_NAME):
                            ProcModes.outHndl.write("LedChains." + parent.tokens[parent.currToken])
                        else:
                            parent.consoleObj.updateConsole("!!! Error !!! Expected an LED chain name, read %s, at line num %d." %
                               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                            return (1520)
                        subState = ProcModes.FIND_COMMA 
                        hasEntries = True
                        parent.currToken += 1
                    elif (typeProc == ProcModes.PROC_SCORING):
                        print "Not implemented"
                        parent.currToken += 1
                    else:
                        parent.consoleObj.updateConsole("!!! Error !!! Parsing error, invalid typeProc = %d, at line num %d." %
                           (typeProc, parent.lineNumList[parent.currToken]))
                        return (1521)
                else:
                    # Assume this is the name of a chain
                    ProcChains.possChainDict[parent.tokens[parent.currToken]] = parent.lineNumList[parent.currToken]
                    ProcModes.outHndl.write("RulesFunc." + parent.tokens[parent.currToken])
                    subState = ProcModes.FIND_COMMA
                    hasEntries = True
                    parent.currToken += 1
        if (typeProc != ProcModes.PROC_END_MODE):
            parent.consoleObj.updateConsole("!!! Error !!! Mode did not end properly, at line num %d." %
               (parent.lineNumList[parent.currToken]))
            return (1523)
        parent.currToken += 1
        return (0)
    def procAllChains(self, parent):
        # Copy name
        name = parent.tokens[parent.currToken]
        if (name in ProcVidChains.nameSet):
            parent.consoleObj.updateConsole("!!! Error !!! Name found twice, read %s, at line num %d." %
               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
            return (1410)
        ProcVidChains.nameSet.add(name)
        ProcChains.addName(parent.procChains, name, ProcChains.VIDEO_CHAIN_NAME)
        ProcVidChains.outHndl.write("    ## Video Chain {0}\n".format(name))
        ProcVidChains.outHndl.write("    #    - Groups have video name then WAIT command\n")
        ProcVidChains.outHndl.write("    #    - Chain ends with REPEAT if desired\n")
        ProcVidChains.outHndl.write("    {0} = [\n".format(name))

        # Verify opening symbol
        parent.currToken += 1
        if not parent.helpFuncs.isOpenSym(parent.tokens[parent.currToken]):
            parent.consoleObj.updateConsole("!!! Error !!! Expected opening symbol, read %s, at line num %d." %
               (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
            return (1411)
        closeSymb = parent.helpFuncs.findMatch(parent)
        parent.currToken += 1
        typeProc = ProcVidChains.PROC_VIDEO
        while parent.currToken < closeSymb:
            if parent.tokens[parent.currToken] in ProcVidChains.tokenLookup:
                tokenType = ProcVidChains.tokenLookup[parent.tokens[parent.currToken]]
            else:
                tokenType = ProcVidChains.UNKNOWN
            if tokenType == ProcVidChains.WAIT_COMMAND:
                if typeProc != ProcVidChains.PROC_COMMAND: 
                    parent.consoleObj.updateConsole("!!! Error !!! WAIT command in video chain in incorrect location at line num %d." %
                       (parent.lineNumList[parent.currToken]))
                    return (1412)
                # Next token should be wait timeout (ms) 
                if not parent.helpFuncs.isInt(parent.tokens[parent.currToken + 1]):
                    parent.consoleObj.updateConsole("!!! Error !!! WAIT parameter should be integer, read %s, at line num %d." %
                       (parent.tokens[parent.currToken + 1], parent.lineNumList[parent.currToken + 1]))
                    return (1413)
                ProcVidChains.outHndl.write(" WAIT, " + parent.tokens[parent.currToken + 1] + "],\n")
                parent.currToken += 2
                # Next token must be a comma
                if (ProcVidChains.tokenLookup[parent.tokens[parent.currToken]] != ProcVidChains.COMMA):
                    parent.consoleObj.updateConsole("!!! Error !!! Comma missing after wait command, found %s, at line num %d." %
                       (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                    return (1414)
                parent.currToken += 1
                typeProc = ProcVidChains.PROC_VIDEO
            elif tokenType == ProcVidChains.REPEAT_COMMAND:
                if (typeProc == ProcVidChains.PROC_VIDEO):
                    ProcVidChains.outHndl.write("        [0, ")
                elif (typeProc == ProcVidChains.PROC_COMMAND):
                    pass
                else:  
                    parent.consoleObj.updateConsole("!!! Error !!! REPEAT command in video chain in incorrect location at line num %d." %
                       (parent.lineNumList[parent.currToken]))
                    return (1415)
                ProcVidChains.outHndl.write("REPEAT, 0] ]\n\n")
                typeProc = ProcVidChains.PROC_DONE_CHAIN
                parent.currToken += 1
            elif tokenType == ProcVidChains.COMMA:
                if (typeProc == ProcVidChains.PROC_VIDEO) or (typeProc == ProcVidChains.PROC_COMMAND):
                    # No processing necessary, next sound will start the line
                    parent.currToken += 1
                else:
                    parent.consoleObj.updateConsole("!!! Error !!! Unexpected comma at line num %d." %
                       (parent.lineNumList[parent.currToken]))
                    return (1416)
            else:
                #This must be a video name
                if (ProcChains.checkNameExists(parent.procChains, parent.tokens[parent.currToken])):
                    if (ProcChains.getNameType(parent.procChains, parent.tokens[parent.currToken]) != ProcChains.VIDEO_NAME):
                        parent.consoleObj.updateConsole("!!! Error !!! Symbol %s should only be a video name, at line num %d." %
                           (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                        return (1417)
                    else:
                        if typeProc == ProcVidChains.PROC_VIDEO:
                            ProcVidChains.outHndl.write("        [Videos.{0}, ".format(parent.tokens[parent.currToken]))
                            typeProc = ProcVidChains.PROC_COMMAND
                            parent.currToken += 1
                        elif typeProc == ProcVidChains.PROC_COMMAND:
                            # Two or more sounds back to back, put a wait of 0 between them
                            ProcVidChains.outHndl.write("WAIT, 0],\n        [Videos.{0}, ".format(parent.tokens[parent.currToken]))
                            parent.currToken += 1
                else:
                    parent.consoleObj.updateConsole("!!! Error !!! Can't understand symbol, read %s, at line num %d." %
                       (parent.tokens[parent.currToken], parent.lineNumList[parent.currToken]))
                    return (1418)
        if (typeProc != ProcVidChains.PROC_DONE_CHAIN):
            parent.consoleObj.updateConsole("!!! Error !!! Video chain did not end properly, at line num %d." %
               (parent.lineNumList[parent.currToken]))
            return (1419)
        parent.currToken += 1
        return (0)