Esempio n. 1
0
def readConfigUpdate(data):
	print "Current config: ", configtool.config
	print "Processing config update message..."
	key, data = readString(data)
	value, data = readConfigValue(data, key)
	print "New Key/Value Pair:"
	print "KEY: ", key
	print "VALUE: ", value
	configtool.setConfigValue(key, value)
	return data
Esempio n. 2
0
def readConfigUpdate(data):
    #print "Current config: ", configtool.config
    #print "Processing config update message..."
    key, data = readString(data)
    value, data = readConfigValue(data, key)
    print "New Key/Value Pair:"
    print "KEY: ", key
    print "VALUE: ", value
    configtool.setConfigValue(key, value)
    return data
Esempio n. 3
0
def CopyMediaFiles():
    print "Copying files from USB to RaspMedia Player"
    clear = True
    # search for update indicator file
    for file in os.listdir(USB_MEDIA_PATH):
        if not file.endswith((SUPPORTED_IMAGE_EXTENSIONS)) and not file.endswith((SUPPORTED_VIDEO_EXTENSIONS)) and file.startswith('update'):
            # file indicating a file update found, load config and set flag
            print "File to indicate a media file update found."
            print "Current files on the player will not be deleted."
            print "Existing files with the same name as a new media file will be overwritten."
            clear = False
            config = configtool.readConfig()
            try:
                configDict = ast.literal_eval(config)
                config = configDict
            except:
                pass
            imgEnabled = config["image_enabled"]
            vidEnabled = config["video_enabled"]
    if clear:
        # delete previous files from player
        shutil.rmtree(MEDIA_PATH)
        if not os.path.isdir(MEDIA_PATH):
            os.mkdir(MEDIA_PATH)
        imgEnabled = 0
        vidEnabled = 0
    for file in os.listdir(USB_MEDIA_PATH):
        if not file.startswith('.'):
            if file.endswith((SUPPORTED_IMAGE_EXTENSIONS)):
                imgEnabled = 1
                ResizeFitAndCopyImage(file, USB_MEDIA_PATH, MEDIA_PATH)
                # OptimizeAndCopyImage(file, USB_MEDIA_PATH, MEDIA_PATH)
            elif file.endswith((SUPPORTED_VIDEO_EXTENSIONS)):
                vidEnabled = 1
                print "Copy video file: ", file
                size = (os.stat(USB_MEDIA_PATH + '/' + file).st_size)
                size /= 1024
                size /= 1024
                fileSize = str(size) + 'MB'
                print "Size: ", fileSize
                print "Please wait..."
                srcFile = USB_MEDIA_PATH + '/' + file
                dstFile = MEDIA_PATH + '/' + file
                shutil.copyfile(srcFile, dstFile)

    print "Media files copied to player successfully!"
    print "Configuring playback settings for your new media files..."
    configtool.readConfig()
    configtool.setConfigValue("image_enabled", imgEnabled)
    configtool.setConfigValue("video_enabled", vidEnabled)
    print "Done!"
Esempio n. 4
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
Esempio n. 5
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