Example #1
0
def interpret(msg_data, sender_ip=None):
    #print "Interpreting incoming data..."
    if str(msg_data).startswith("rm"):
        # string interpretation
        result = INTERPRETER_SUCCESS
        msg = None
        values = str(msg_data).split(":")
        cmd = values[1]
        if cmd == "state":
            val = values[2]
            # switch state
            mediaplayer.setState(int(val))
        elif cmd == "number":
            val = values[2]
            mediaplayer.setMediaFileNumber(int(val))
        elif cmd == "next":
            mediaplayer.nextFile()
        elif cmd == "prev":
            mediaplayer.prevFile()
        elif cmd == "config":
            # config must be sent as key/value pair
            if len(values) == 4:
                key = values[2]
                value = values[3]
                print "New Key/Value Pair:"
                print "KEY: ", key
                print "VALUE: ", value
                configtool.setConfigValue(key, value)
        elif cmd == "hdmi":
            val = values[2]
            os.system(os.getcwd() + "/scripts/rpi-hdmi.sh " + val)
        else:
            result = INTERPRETER_ERROR
            msg = "Unknown UDP string command"
    else:
        data = bytearray(msg_data)
        size, data = readInt(data)
        #print "Size: " + str(size)

        flag, data = readShort(data)
        result = flag
        msg = None
        #print "Flag: " + str(flag)
        if flag == CONFIG_UPDATE:
            data = readConfigUpdate(data)
        elif flag == PLAYER_START:
            print 'UDP COMMAND Mediaplayer start...'
            mediaplayer.setState(1)
        elif flag == PLAYER_STOP:
            print 'UDP COMMAND Mediaplayer stop...'
            mediaplayer.setState(0)
        elif flag == PLAYER_PAUSE:
            mediaplayer.setState(3)
        elif flag == PLAYER_RESTART:
            print 'UDP COMMAND Mediaplayer restart...'
            mediaplayer.playerState = PLAYER_STOPPED
            mediaplayer.stop()
            time.sleep(2)
            mediaplayer.playerState = PLAYER_STARTED
            mediaplayer.play()
        elif flag == SERVER_REQUEST:
            data = None
            result = SERVER_REQUEST
        elif flag == FILELIST_REQUEST:
            result = FILELIST_REQUEST
        elif flag == FILELIST_RESPONSE:
            readFileList(data)
            result = FILELIST_REQUEST
        elif flag == CONFIG_REQUEST:
            result = CONFIG_REQUEST
        elif flag == DELETE_FILE:
            numFiles, data = readInt(data)
            files = []
            for i in range(numFiles):
                msg, data = readString(data)
                if msg:
                    files.append(msg)
            mediaplayer.deleteFiles(files)
        elif flag == DELETE_ALL_IMAGES:
            files = mediaplayer.getImageFilelist()
            mediaplayer.deleteFiles(files)
        elif flag == PLAYER_IDENTIFY:
            print 'Showing identify image...'
            mediaplayer.identifySelf()
        elif flag == PLAYER_IDENTIFY_DONE:
            print 'Identifying done...'
            mediaplayer.identifyDone()
        elif flag == PLAYER_REBOOT:
            os.system("sudo reboot")
        elif flag == PLAYER_UPDATE:
            if is_connected():
                os.system("/home/pi/raspmedia/Raspberry/scripts/update.sh")
            else:
                result = PLAYER_UPDATE_ERROR
                msg = "Player is not connected to the internet."
        elif flag == WIFI_CONFIG:
            setupWifi(data)
        ### GROUP AND ACTION MESSAGE FLAGS ###
        elif flag == GROUP_CONFIG_REQUEST:
            result = flag
        elif flag == GROUP_MEMBER_REQUEST:
            group, data = readString(data)
            GroupManager.MemberRequest(group, sender_ip)
        elif flag == GROUP_MEMBER_ACKNOWLEDGE:
            group, data = readString(data)
            byRequest, data = readInt(data)
            GroupManager.MemberAcknowledge(group, sender_ip, byRequest)
        elif flag == GROUP_CONFIG:
            result = flag
            readGroupConfig(data)
        elif flag == GROUP_DELETE:
            result = flag
            groupName, data = readString(data)
            if configtool.readGroupConfig()['group'] == groupName:
                configtool.resetGroupConfig()
                gConf = configtool.readGroupConfig()
                GroupManager.ReInitGroupManager(gConf)
        elif flag == GROUP_CONFIG_ADD_ACTION:
            result = flag
            msg, data = readString(data)
        elif flag == GROUP_CONFIG_ACTION_DELETE:
            result = flag
            msg, data = readString(data)
        elif flag == FILE_DATA_REQUEST:
            result = flag
        elif flag == PLAYER_START_FILENUMBER:
            print "UDP COMMAND Start Filenumber..."
            number, data = readInt(data)
            mediaplayer.startFileNumber(number)
        elif flag == DISK_INFO_REQUEST:
            result = flag
        else:
            result = INTERPRETER_ERROR
            msg = "Unknown command flag"

        #print "Remaining data: " + data.decode("utf-8")

    return result, msg
Example #2
0
def interpret(msg_data):
	print "Interpreting incoming data..."

	# initialize with error state
	result = INTERPRETER_ERROR

	data = bytearray(msg_data)
	size, data = readInt(data)
	print "Size: " + str(size)

	flag, data = readShort(data)
	msg = None
	print "Flag: " + str(flag)
	if flag == CONFIG_UPDATE:
		data = readConfigUpdate(data)
		result = INTERPRETER_SUCCESS
	elif flag == PLAYER_START:
		print 'UDP COMMAND Mediaplayer start...'
		mediaplayer.playerState = PLAYER_STARTED
		mediaplayer.play()
		result = INTERPRETER_SUCCESS
	elif flag == PLAYER_STOP:
		print 'UDP COMMAND Mediaplayer stop...'
		mediaplayer.playerState = PLAYER_STOPPED
		mediaplayer.stop()
		result = INTERPRETER_SUCCESS
	elif flag == PLAYER_RESTART:
		print 'UDP COMMAND Mediaplayer restart...'
		mediaplayer.playerState = PLAYER_STOPPED
		mediaplayer.stop()
		time.sleep(2)
		mediaplayer.playerState = PLAYER_STARTED
		mediaplayer.play()
	elif flag == SERVER_REQUEST:
		data = None
		result = SERVER_REQUEST
	elif flag == FILELIST_REQUEST:
		result = FILELIST_REQUEST
	elif flag == FILELIST_RESPONSE:
		readFileList(data)
		result = FILELIST_REQUEST
	elif flag == CONFIG_REQUEST:
		result = CONFIG_REQUEST
	elif flag == DELETE_FILE:
		numFiles, data = readInt(data)
		files = []
		for i in range(numFiles):
			msg, data = readString(data)
			if msg:
				files.append(msg)
		mediaplayer.deleteFiles(files)
	elif flag == DELETE_ALL_IMAGES:
		files = mediaplayer.getImageFilelist()
		mediaplayer.deleteFiles(files)
	elif flag == PLAYER_IDENTIFY:
		print 'Showing identify image...'
		mediaplayer.identifySelf()
	elif flag == PLAYER_IDENTIFY_DONE:
		print 'Identifying done...'
		mediaplayer.identifyDone()
	elif flag == PLAYER_REBOOT:
		os.system("sudo reboot")
	elif flag == PLAYER_UPDATE:
		if is_connected():
			os.system("/home/pi/raspmedia/Raspberry/scripts/update.sh")
		else:
			result = PLAYER_UPDATE_ERROR
			msg = "Player is not connected to the internet."
	elif flag == WIFI_CONFIG:
		setupWifi(data)

	#print "Remaining data: " + data.decode("utf-8")

	return result, msg
Example #3
0
def interpret(msg_data, sender_ip=None):
    #print "Interpreting incoming data..."
    if str(msg_data).startswith("rm"):
        # string interpretation
        result = INTERPRETER_SUCCESS
        msg = None
        values = str(msg_data).split(":")
        cmd = values[1]
        if cmd == "state":
            val = values[2]
            # switch state
            mediaplayer.setState(int(val))
        elif cmd == "number":
            val = values[2]
            mediaplayer.setMediaFileNumber(int(val))
        elif cmd == "next":
            mediaplayer.nextFile()
        elif cmd == "prev":
            mediaplayer.prevFile()
        elif cmd == "config":
            # config must be sent as key/value pair
            if len(values) == 4:
                key = values[2]
                value = values[3]
                print "New Key/Value Pair:"
                print "KEY: ", key
                print "VALUE: ", value
                configtool.setConfigValue(key, value)
        elif cmd == "hdmi":
            val = values[2]
            os.system(os.getcwd()+"/scripts/rpi-hdmi.sh "+val)
        else:
            result = INTERPRETER_ERROR
            msg = "Unknown UDP string command"
    else:
        data = bytearray(msg_data)
        size, data = readInt(data)
        #print "Size: " + str(size)

        flag, data = readShort(data)
        result = flag;
        msg = None
        #print "Flag: " + str(flag)
        if flag == CONFIG_UPDATE:
            data = readConfigUpdate(data)
        elif flag == PLAYER_START:
            print 'UDP COMMAND Mediaplayer start...'
            mediaplayer.setState(1)
        elif flag == PLAYER_STOP:
            print 'UDP COMMAND Mediaplayer stop...'
            mediaplayer.setState(0)
        elif flag == PLAYER_PAUSE:
            mediaplayer.setState(3)
        elif flag == PLAYER_RESTART:
            print 'UDP COMMAND Mediaplayer restart...'
            mediaplayer.playerState = PLAYER_STOPPED
            mediaplayer.stop()
            time.sleep(2)
            mediaplayer.playerState = PLAYER_STARTED
            mediaplayer.play()
        elif flag == SERVER_REQUEST:
            data = None
            result = SERVER_REQUEST
        elif flag == FILELIST_REQUEST:
            result = FILELIST_REQUEST
        elif flag == FILELIST_RESPONSE:
            readFileList(data)
            result = FILELIST_REQUEST
        elif flag == CONFIG_REQUEST:
            result = CONFIG_REQUEST
        elif flag == DELETE_FILE:
            numFiles, data = readInt(data)
            files = []
            for i in range(numFiles):
                msg, data = readString(data)
                if msg:
                    files.append(msg)
            mediaplayer.deleteFiles(files)
        elif flag == DELETE_ALL_IMAGES:
            files = mediaplayer.getImageFilelist()
            mediaplayer.deleteFiles(files)
        elif flag == PLAYER_IDENTIFY:
            print 'Showing identify image...'
            mediaplayer.identifySelf()
        elif flag == PLAYER_IDENTIFY_DONE:
            print 'Identifying done...'
            mediaplayer.identifyDone()
        elif flag == PLAYER_REBOOT:
            os.system("sudo reboot")
        elif flag == PLAYER_UPDATE:
            if is_connected():
                os.system("/home/pi/raspmedia/Raspberry/scripts/update.sh")
            else:
                result = PLAYER_UPDATE_ERROR
                msg = "Player is not connected to the internet."
        elif flag == WIFI_CONFIG:
            setupWifi(data)
        ### GROUP AND ACTION MESSAGE FLAGS ###
        elif flag == GROUP_CONFIG_REQUEST:
            result = flag
        elif flag == GROUP_MEMBER_REQUEST:
            group, data = readString(data)
            GroupManager.MemberRequest(group, sender_ip)
        elif flag == GROUP_MEMBER_ACKNOWLEDGE:
            group, data = readString(data)
            byRequest , data = readInt(data)
            GroupManager.MemberAcknowledge(group, sender_ip, byRequest)
        elif flag == GROUP_CONFIG:
            result = flag
            readGroupConfig(data)
        elif flag == GROUP_DELETE:
            result = flag
            groupName, data = readString(data)
            if configtool.readGroupConfig()['group'] == groupName:
                configtool.resetGroupConfig()
                gConf = configtool.readGroupConfig()
                GroupManager.ReInitGroupManager(gConf)
        elif flag == GROUP_CONFIG_ADD_ACTION:
            result = flag
            msg, data = readString(data)
        elif flag == GROUP_CONFIG_ACTION_DELETE:
            result = flag
            msg, data = readString(data)
        elif flag == FILE_DATA_REQUEST:
            result = flag
        elif flag == PLAYER_START_FILENUMBER:
            print "UDP COMMAND Start Filenumber..."
            number, data = readInt(data)
            mediaplayer.startFileNumber(number)
        elif flag == DISK_INFO_REQUEST:
            result = flag
        else:
            result = INTERPRETER_ERROR
            msg = "Unknown command flag"

        #print "Remaining data: " + data.decode("utf-8")

    return result, msg