Exemple #1
0
def handle_inst_fifo(bs_code):
        '''
        handles the BS command that comes in one by one. 
	maintains state in case of SCRIPT
        '''
	global script
        bs_code = bs_code.strip() #only single BS inst
	print "bs_code : ", bs_code
	
	if bs_code == "ENDSCRIPT":
		if not script: #endscript without a startscript?
			return 0 #some problem
		script = False

	elif bs_code == "SCRIPT":
		if  script: #startscript in a script
			return 0
		script = True
	
	elif script:
		pru_speak.SCRIPT_CODE += '\n' + bs_code

	elif bs_code == "RUN":
		if pru_speak.SCRIPT_CODE :
			print "running script :"
			print pru_speak.SCRIPT_CODE
			pru_speak.load(pru_speak.SCRIPT_CODE, trigger = True)
		else : 
			return 0

	else :#normal single inst execution
		pru_speak.single_instruction(bs_code)

        return 1
Exemple #2
0
def handle_data(bs_code):
    '''
        handles the BS commands which are part of the incoming packet
        seperately takes care of single instructions and scripts
        bs_code (str) : TCP packet data. The code block with BS instructions seperated by new lines.
        '''
    #print "bs_code.strip() " , bs_code.strip()
    bs_code = bs_code.strip().split("\n")
    bs_code = map(str.strip, bs_code)
    print "bs_code \n", bs_code
    # change logic either here or in compiler.py to make
    # all this more clean and efficient. but this is ok for now.

    if "SCRIPT" in bs_code:
        #download and keep the script
        start = bs_code.index("SCRIPT")
        try:
            end = bs_code.index("ENDSCRIPT")
            #get the script postion
            script_list = bs_code[start + 1:end]
            #remove it out of the original list of inst.
            bs_code = bs_code[:start] + bs_code[end + 1:]

            pru_speak.SCRIPT_CODE = '\n'.join(script_list)
            print "SCRIPT loaded\n", pru_speak.SCRIPT_CODE + "\n ENDSCRIPT \n"
        except Exception as e:
            print "ENDSCRIPT NOT FOUND"
            return -1  #ENDSCRIPT not found - syntax error

    for inst in bs_code:
        if inst == "RUN":  #have to move run to PRU, why simply put it here?
            if pru_speak.SCRIPT_CODE:
                #maybe abort the previous script before this?
                pru_speak.load(pru_speak.SCRIPT_CODE, trigger=True)
            else:
                return -1
        else:
            pru_speak.single_instruction(inst)

    return 1
Exemple #3
0
def handle_data(bs_code):
        '''
        handles the BS commands which are part of the incoming packet
        seperately takes care of single instructions and scripts
        bs_code (str) : TCP packet data. The code block with BS instructions seperated by new lines.
        '''
        #print "bs_code.strip() " , bs_code.strip()
        bs_code = bs_code.strip().split("\n")
        bs_code = map(str.strip, bs_code)
        print "bs_code \n", bs_code
        # change logic either here or in compiler.py to make 
        # all this more clean and efficient. but this is ok for now.

        if "SCRIPT" in bs_code:
                #download and keep the script
                start = bs_code.index("SCRIPT")
                try:
                        end = bs_code.index("ENDSCRIPT")
                        #get the script postion
                        script_list = bs_code[start+1 : end]
                        #remove it out of the original list of inst.
                        bs_code = bs_code[:start] + bs_code[end+1 :]

                        pru_speak.SCRIPT_CODE = '\n'.join(script_list)
                        print "SCRIPT loaded\n",  pru_speak.SCRIPT_CODE + "\n ENDSCRIPT \n"
                except Exception as e:
			print "ENDSCRIPT NOT FOUND"
                        return -1 #ENDSCRIPT not found - syntax error

        for inst in bs_code :
                if inst == "RUN": #have to move run to PRU, why simply put it here?
                        if pru_speak.SCRIPT_CODE :
                                #maybe abort the previous script before this?
                                pru_speak.load(pru_speak.SCRIPT_CODE, trigger = True)
                        else :
                                return -1
                else :
                        pru_speak.single_instruction(inst)

        return 1
Exemple #4
0
import pru_speak
#import compiler

botspeak_code = \
'''	SET DIO[4], 1
	WAIT 1000
	SET DIO[4], 0
	WAIT 1000
	GOTO 0'''

#print map(lambda x : hex(x), compiler.compile(botspeak_code))
pru_speak.load(botspeak_code)
pru_speak.execute()
pru_speak.single_instruction("SET DIO[0], 1")