Beispiel #1
0
void initSettings(int argc, char **argv)
{
    char tmpDir[256];
    char mediaDir[256];

	settings.binDirectory = strdup(dirname(argv[0]));
	settings.fppMode = PLAYER_MODE;
    
    strcpy(tmpDir, settings.binDirectory);

    // trim off src/ or bin/
    char *offset = NULL;
    int size = strlen(tmpDir);

    if ((size > 4) && (!strcmp(&tmpDir[size - 4], "/src")))
        offset = &tmpDir[size - 4];
    else if ((size > 4) && (!strcmp(&tmpDir[size - 4], "/bin")))
        offset = &tmpDir[size - 4];
    else if ((size > 8) && (!strcmp(&tmpDir[size - 8], "/scripts")))
        offset = &tmpDir[size - 8];

    if (offset != NULL)
        *offset = 0;

    settings.fppDirectory = strdup(tmpDir);

	if (DirectoryExists("/home/fpp"))
		strcpy(mediaDir, "/home/fpp");
	else
		strcpy(mediaDir, "/home/pi");

	strcat(mediaDir, "/media");
	settings.mediaDirectory = strdup(mediaDir);

	strcpy(tmpDir, mediaDir);
	settings.musicDirectory = strdup(strcat(tmpDir, "/music"));
	strcpy(tmpDir, mediaDir);
	settings.sequenceDirectory = strdup(strcat(tmpDir, "/sequences"));
	strcpy(tmpDir, mediaDir);
	settings.playlistDirectory = strdup(strcat(tmpDir, "/playlists"));
	strcpy(tmpDir, mediaDir);
	settings.eventDirectory = strdup(strcat(tmpDir, "/events"));
	strcpy(tmpDir, mediaDir);
	settings.videoDirectory = strdup(strcat(tmpDir, "/videos"));
	strcpy(tmpDir, mediaDir);
	settings.effectDirectory = strdup(strcat(tmpDir, "/effects"));
	strcpy(tmpDir, mediaDir);
	settings.scriptDirectory = strdup(strcat(tmpDir, "/scripts"));
	strcpy(tmpDir, mediaDir);
	settings.pluginDirectory = strdup(strcat(tmpDir, "/plugins"));
	strcpy(tmpDir, mediaDir);
	settings.universeFile = strdup(strcat(tmpDir, "/universes"));
	strcpy(tmpDir, mediaDir);
	settings.pixelnetFile = strdup(strcat(tmpDir, "/config/Falcon.FPDV1"));
	strcpy(tmpDir, mediaDir);
	settings.scheduleFile = strdup(strcat(tmpDir, "/schedule"));
	strcpy(tmpDir, mediaDir);
	settings.logFile = strdup(strcat(tmpDir, "/logs/fppd.log"));
	strcpy(tmpDir, mediaDir);
	settings.silenceMusic = strdup(strcat(tmpDir, "/silence.ogg"));
	strcpy(tmpDir, mediaDir);
	settings.bytesFile = strdup(strcat(tmpDir, "/bytesReceived"));
	strcpy(tmpDir, mediaDir);
	settings.settingsFile = strdup(strcat(tmpDir, "/settings"));
	settings.daemonize = 1;
	settings.E131interface = strdup("eth0");
	settings.controlMajor = 0;
	settings.controlMinor = 0;

	SetLogLevel("info");
	SetLogMask("most");
}
Beispiel #2
0
int parseSetting(char *key, char *value)
{
    if (settings.keyVal[key]) {
        free(settings.keyVal[key]);
        settings.keyVal[key] = strdup(value);
    }

	if ( strcmp(key, "daemonize") == 0 )
	{
		settings.daemonize = atoi(value);
	}
	else if ( strcmp(key, "fppMode") == 0 )
	{
		if ( strcmp(value, "player") == 0 )
			settings.fppMode = PLAYER_MODE;
		else if ( strcmp(value, "bridge") == 0 )
			settings.fppMode = BRIDGE_MODE;
		else if ( strcmp(value, "master") == 0 )
			settings.fppMode = MASTER_MODE;
		else if ( strcmp(value, "remote") == 0 )
			settings.fppMode = REMOTE_MODE;
		else
		{
			fprintf(stderr, "Error parsing mode\n");
			exit(EXIT_FAILURE);
		}
	}
	else if ( strcmp(key, "alwaysTransmit") == 0 )
	{
		if ( strlen(value) )
			settings.alwaysTransmit = atoi(value);
		else
			fprintf(stderr, "Failed to apply alwaysTransmit setting\n");
	}
	else if ( strcmp(key, "mediaDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.mediaDirectory);
			settings.mediaDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply mediaDirectory\n");
	}
	else if ( strcmp(key, "musicDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.musicDirectory);
			settings.musicDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply musicDirectory\n");
	}
	else if ( strcmp(key, "sequenceDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.sequenceDirectory);
			settings.sequenceDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply sequenceDirectory\n");
	}
	else if ( strcmp(key, "eventDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.eventDirectory);
			settings.eventDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply eventDirectory\n");
	}
	else if ( strcmp(key, "videoDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.videoDirectory);
			settings.videoDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply videoDirectory\n");
	}
	else if ( strcmp(key, "effectDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.effectDirectory);
			settings.effectDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply effectDirectory\n");
	}
	else if ( strcmp(key, "scriptDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.scriptDirectory);
			settings.scriptDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply scriptDirectory\n");
	}
	else if ( strcmp(key, "pluginDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.pluginDirectory);
			settings.pluginDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply pluginDirectory\n");
	}
	else if ( strcmp(key, "playlistDirectory") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.playlistDirectory);
			settings.playlistDirectory = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply playlistDirectory\n");
	}
	else if ( strcmp(key, "universeFile") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.universeFile);
			settings.universeFile = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply universeFile\n");
	}
	else if ( strcmp(key, "pixelnetFile") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.pixelnetFile);
			settings.pixelnetFile = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply pixelnetFile\n");
	}
	else if ( strcmp(key, "scheduleFile") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.scheduleFile);
			settings.scheduleFile = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply scheduleFile\n");
	}
	else if ( strcmp(key, "LogLevel") == 0 )
	{
		if (strlen(value))
			SetLogLevel(value);
		else
			SetLogLevel("warn");
	}
	else if ( strcmp(key, "LogMask") == 0 )
	{
		if (strlen(value))
			SetLogMask(value);
		else
			SetLogMask("");
	}
	else if ( strcmp(key, "logFile") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.logFile);
			settings.logFile = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply logFile\n");
	}
	else if ( strcmp(key, "silenceMusic") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.silenceMusic);
			settings.silenceMusic = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply silenceMusic\n");
	}
	else if ( strcmp(key, "bytesFile") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.bytesFile);
			settings.bytesFile = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply bytesFile\n");
	}
	else if ( strcmp(key, "E131interface") == 0 )
	{
		if ( strlen(value) )
		{
			free(settings.E131interface);
			settings.E131interface = strdup(value);
		}
		else
			fprintf(stderr, "Failed to apply E131interface\n");
	}
	else if ( strcmp(key, "controlMajor") == 0 )
	{
		if ( strlen(value) )
		{
			int ivalue = atoi(value);
			if (ivalue >= 0)
				settings.controlMajor = (unsigned int)ivalue;
			else
				fprintf(stderr, "Error, controlMajor value negative\n");
		}
		else
			fprintf(stderr, "Failed to apply controlMajor setting\n");
	}
	else if ( strcmp(key, "controlMinor") == 0 )
	{
		if ( strlen(value) )
		{
			int ivalue = atoi(value);
			if (ivalue >= 0)
				settings.controlMinor = (unsigned int)ivalue;
			else
				fprintf(stderr, "Error, controlMinor value negative\n");
		}
		else
			fprintf(stderr, "Failed to apply controlMinor setting\n");
	}

	return 1;
}
Beispiel #3
0
int main (int argc, char *argv[])
{
	char *inFilename = 0;
	char *outFilename = 0;
	int info = 0;

	SetLogLevel("debug");
	SetLogMask("sequence");

	if(argc>1)
	{
		for (int c = 1; c < argc; c++)
		{
			if(!strncmp(argv[c],"-h",2))
			{
				Usage(argv[0]);
			}
			// Info - example "fpp -i <FILENAME>"
			else if(!strncmp(argv[c],"-i",2))
			{
				info = 1;
			}
			else if(!strncmp(argv[c],"-o",2) && ((c+1) < argc))
			{
				outFilename = argv[c+1];
				c++;
			}
			else if(!strncmp(argv[c],"-b",2) && ((c+1) < argc))
			{
				brightness = atoi(argv[c+1]);
				c++;
			}
			else if (c == (argc - 1))
			{
				inFilename = argv[c];
			}
			else
			{
				// Unknown option, print usage
				printf( "Unknown option: '%s'\n\n", argv[c]);

				Usage(argv[0]);
			}
		}
	}
	else
	{
		Usage(argv[0]);
	}

	if (!inFilename)
	{
		Usage(argv[0]);
	}

	if (info)
	{
		fseqInfo(inFilename);
	}
	else if (outFilename)
	{
		fseqCopy(inFilename, outFilename);
	}
	else
	{
		// No other valid args so display info on the file by default
		fseqInfo(inFilename);
	}

	return 0;
}
Beispiel #4
0
  void ProcessCommand(char *command)
  {
    char *s;
    char *s2;
    char *s3;
    char *s4;
    char *response2 = NULL;
    int i;
		char NextPlaylist[128] = "No playlist scheduled.";
		char NextScheduleStartText[64] = "";
		char CommandStr[64];
		LogExcess(VB_COMMAND, "CMD: %s\n", command);
		s = strtok(command,",");
		strcpy(CommandStr, s);
		if (!strcmp(CommandStr, "s"))
		{
				Json::Value info = player->GetCurrentPlaylistInfo();
				char currentEntryType = 'u'; // Unknown
				const char *currentSequenceName = NULL;
				const char *currentMediaName = NULL;

				if (info["currentEntry"].isMember("sequenceName"))
					currentSequenceName = info["currentEntry"]["sequenceName"].asString().c_str();

				if (info["currentEntry"].isMember("mediaFilename"))
					currentMediaName = info["currentEntry"]["mediaFilename"].asString().c_str();

				if (info["currentEntry"].isMember("type"))
				{
					std::string type = info["currentEntry"]["type"].asString();
					if (type == "both")
						currentEntryType = 'b';
					else if (type == "event")
						currentEntryType = 'e';
					else if (type == "media")
						currentEntryType = 'm';
					else if (type == "pause")
						currentEntryType = 'p';
					else if (type == "plugin")
						currentEntryType = 'P';
					else if (type == "sequence")
						currentEntryType = 's';
				}

				player->GetNextScheduleStartText(NextScheduleStartText);
				player->GetNextPlaylistText(NextPlaylist);
				if(FPPstatus==FPP_STATUS_IDLE)
				{
					if (getFPPmode() == REMOTE_MODE)
					{
						sprintf(response,"%d,%d,%d,%s,%s,%d,%d\n",
							getFPPmode(), 0, getVolume(),
							currentSequenceName,
							currentMediaName,
							player->GetPlaybackSecondsElapsed(),
							player->GetPlaybackSecondsRemaining());
					}
					else
					{
						sprintf(response,"%d,%d,%d,%s,%s\n",
							getFPPmode(),0,getVolume(),
							NextPlaylist,NextScheduleStartText);
					}
				}
				else
				{
					sprintf(response,"%d,%d,%d,%s,%c,%s,%s,%d,%d,%d,%d,%s,%s,%d\n",
							getFPPmode(),FPPstatus,getVolume(),
							info["name"].asString().c_str(),
							currentEntryType,
							currentSequenceName,
							currentMediaName,
							info["currentPosition"].asInt() + 1,
							info["size"].asInt(),
							info["currentEntry"]["secondsElapsed"].asInt(),
							info["currentEntry"]["secondsRemaining"].asInt(),
							NextPlaylist,NextScheduleStartText,
							info["repeat"].asInt());
				}
		}
		else if ((!strcmp(CommandStr, "p")) ||
				 (!strcmp(CommandStr, "P")))
		{
				if(FPPstatus==FPP_STATUS_PLAYLIST_PLAYING || FPPstatus==FPP_STATUS_STOPPING_GRACEFULLY)
				{
					player->PlaylistStopNow();
					sleep(1);
				}
	
				s = strtok(NULL,",");
				if (s)
				{
					std::string playlistName(s);
					int repeat = !strcmp(CommandStr, "p") ? 1 : 0;
					int position = 0;

					s = strtok(NULL,",");
					if (s)
						position = atoi(s);

					if (player->PlaylistStart(playlistName, position, repeat))
					{
						sprintf(response,"%d,%d,Playlist Started,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
					}
					else
					{
						sprintf(response,"%d,%d,Playlist Start Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
					}
				}
				else
				{
					sprintf(response,"%d,%d,Unknown Playlist,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
				}
		}
		else if (!strcmp(CommandStr, "S"))
		{
				if(FPPstatus==FPP_STATUS_PLAYLIST_PLAYING)
				{
					player->PlaylistStopGracefully();
					player->ReLoadCurrentScheduleInfo();
					sprintf(response,"%d,%d,Playlist Stopping Gracefully,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
				}
				else
				{
					sprintf(response,"%d,Not playing,,,,,,,,,,,\n",COMMAND_FAILED);
				}
		}
		else if (!strcmp(CommandStr, "d"))
		{
				if(FPPstatus==FPP_STATUS_PLAYLIST_PLAYING || FPPstatus==FPP_STATUS_STOPPING_GRACEFULLY)
				{
					player->PlaylistStopNow();
					player->ReLoadCurrentScheduleInfo();
					sprintf(response,"%d,%d,Playlist Stopping Now,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
				}
				else
				{
					sprintf(response,"%d,%d,Not playing,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
				}
		}
		else if (!strcmp(CommandStr, "R"))
		{
				if(FPPstatus==FPP_STATUS_IDLE)
				{
					player->ReLoadCurrentScheduleInfo();
				}
				player->ReLoadNextScheduleInfo();
				
				
				sprintf(response,"%d,%d,Reloading Schedule,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
		}
		else if (!strcmp(CommandStr, "v"))
		{
				s = strtok(NULL,",");
				if (s)
				{
					setVolume(atoi(s));
					sprintf(response,"%d,%d,Setting Volume,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
				}
				else
				{
					sprintf(response,"%d,%d,Invalid Volume,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
				}
		}
		else if (!strcmp(CommandStr, "w"))
		{
				LogInfo(VB_SETTING, "Sending Falcon hardware config\n");
				if (!DetectFalconHardware(1))
					SendFPDConfig();
		}
		else if (!strcmp(CommandStr, "r"))
		{
				WriteBytesReceivedFile();
				sprintf(response,"true\n");
		}
		else if (!strcmp(CommandStr, "q"))
		{
			// Quit/Shutdown fppd
			ShutdownFPPD();
		}
		else if (!strcmp(CommandStr, "e"))
		{
			// Start an Effect
			s = strtok(NULL,",");
			s2 = strtok(NULL,",");
			s3 = strtok(NULL,",");
			if (s && s2)
			{
				i = StartEffect(s, atoi(s2), atoi(s3));
				if (i >= 0)
					sprintf(response,"%d,%d,Starting Effect,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
				else
					sprintf(response,"%d,%d,Invalid Effect,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
			}
			else
				sprintf(response,"%d,%d,Invalid Effect,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
		}
		else if (!strcmp(CommandStr, "t"))
		{
			// Trigger an event
			s = strtok(NULL,",");
			pluginCallbackManager.eventCallback(s, "command");
			i = TriggerEventByID(s);
			if (i >= 0)
				sprintf(response,"%d,%d,Event Triggered,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
			else
				sprintf(response,"%d,%d,Event Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
		}
		else if (!strcmp(CommandStr, "GetTestMode"))
		{
			strcpy(response, channelTester->GetConfig().c_str());
			strcat(response, "\n");
		}
		else if (!strcmp(CommandStr, "SetTestMode"))
		{
			if (channelTester->SetupTest(std::string(s + strlen(s) + 1)))
			{
				sprintf(response, "0,%d,Test Mode Activated,,,,,,,,,\n",
					COMMAND_SUCCESS);
			}
			else
			{
				sprintf(response, "0,%d,Test Mode Deactivated,,,,,,,,,\n",
					COMMAND_SUCCESS);
			}
		}
		else if (!strcmp(CommandStr, "LogLevel"))
		{
			s = strtok(NULL,",");

			if (SetLogLevel(s)) {
				sprintf(response,"%d,%d,Log Level Updated,%d,%d,,,,,,,,,\n",
					getFPPmode(),COMMAND_SUCCESS,logLevel,logMask);
			} else {
				sprintf(response,"%d,%d,Error Updating Log Level,%d,%d,,,,,,,,,\n",
					getFPPmode(),COMMAND_FAILED,logLevel,logMask);
			}
		}
		else if (!strcmp(CommandStr, "LogMask"))
		{
			s = strtok(NULL,",");

			if ((s && SetLogMask(s)) || SetLogMask("")) {
				sprintf(response,"%d,%d,Log Mask Updated,%d,%d,,,,,,,,,\n",
					getFPPmode(),COMMAND_SUCCESS,logLevel,logMask);
			} else {
				sprintf(response,"%d,%d,Error Updating Log Mask,%d,%d,,,,,,,,,\n",
					getFPPmode(),COMMAND_FAILED,logLevel,logMask);
			}
		}
		else if (!strcmp(CommandStr, "SetSetting"))
		{
			char name[128];

			s = strtok(NULL,",");
			if (s)
			{
				strcpy(name, s);
				s = strtok(NULL,",");
				if (s)
					parseSetting(name, s);
			}
		}
		else if (!strcmp(CommandStr, "StopAllEffects"))
		{
			StopAllEffects();
			sprintf(response,"%d,%d,All Effects Stopped,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
		}
		else if (!strcmp(CommandStr, "StopEffectByName"))
		{
			s = strtok(NULL,",");
			if (strlen(s))
			{
				if (StopEffect(s))
						sprintf(response,"%d,%d,Stopping Effect,%s,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,s);
				else
						sprintf(response,"%d,%d,Stop Effect Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
			}
		}
		else if (!strcmp(CommandStr, "StopEffect"))
		{
			s = strtok(NULL,",");
			i = atoi(s);
			if (StopEffect(i))
					sprintf(response,"%d,%d,Stopping Effect,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
			else
					sprintf(response,"%d,%d,Stop Effect Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
		}
		else if (!strcmp(CommandStr, "GetRunningEffects"))
		{
			sprintf(response,"%d,%d,Running Effects",getFPPmode(),COMMAND_SUCCESS);
			GetRunningEffects(response, &response2);
		}
		else if (!strcmp(CommandStr, "ReloadChannelRemapData"))
		{
			if ((FPPstatus==FPP_STATUS_IDLE) &&
				(LoadChannelRemapData())) {
				sprintf(response,"%d,%d,Channel Remap Data Reloaded,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
			} else {
				sprintf(response,"%d,%d,Failed to reload Channel Remap Data,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
			}
		}
		else if (!strcmp(CommandStr, "GetFPPDUptime"))
		{
			sprintf(response,"%d,%d,FPPD Uptime,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS, time(NULL) - fppdStartTime);
		}
		else if (!strcmp(CommandStr, "StartSequence"))
		{
			s = strtok(NULL,",");
			s2 = strtok(NULL,",");
			if (s && s2)
			{
				i = atoi(s2);
				player->StartSequence(s, 0, i);
				sprintf(response,"%d,%d,Sequence Started,,,,,,,,,,,,\n",
					getFPPmode(), COMMAND_SUCCESS);
			}
			else
			{
				LogErr(VB_COMMAND, "Tried to start a sequence when a playlist or "
						"sequence is already running\n");
				sprintf(response,"%d,%d,Sequence Failed,,,,,,,,,,,,\n",
					getFPPmode(), COMMAND_FAILED);
			}
		}
		else if (!strcmp(CommandStr, "StopSequence"))
		{
			s = strtok(NULL,",");
			if (s)
			{
				player->StopSequence(s);
				sprintf(response,"%d,%d,Sequence Stopped,,,,,,,,,,,,\n",
					getFPPmode(), COMMAND_SUCCESS);
			}
			else
			{
				LogDebug(VB_COMMAND, "Invalid command: %s\n", command);
				sprintf(response,"%d,%d,Sequence Name Missing,,,,,,,,,,,,\n",
					getFPPmode(), COMMAND_FAILED);
			}
		}
		else if (!strcmp(CommandStr, "ToggleSequencePause"))
		{
			if ((player->SequencesRunning()) &&
				((FPPstatus == FPP_STATUS_IDLE) ||
				 (FPPstatus != FPP_STATUS_IDLE)))
			{
				player->ToggleSequencePause();
			}
		}
		else if (!strcmp(CommandStr, "SingleStepSequence"))
		{
			if ((player->SequencesRunning()) &&
				(player->SequencesArePaused()) &&
				((FPPstatus == FPP_STATUS_IDLE) ||
				 ((FPPstatus != FPP_STATUS_IDLE))))
			{
				player->SingleStepSequences();
			}
		}
		else if (!strcmp(CommandStr, "SingleStepSequenceBack"))
		{
			if ((player->SequencesRunning()) &&
				(player->SequencesArePaused()) &&
				((FPPstatus == FPP_STATUS_IDLE) ||
				 ((FPPstatus != FPP_STATUS_IDLE))))
			{
				player->SingleStepSequencesBack();
			}
		}
		else if (!strcmp(CommandStr, "NextPlaylistItem"))
		{
			switch (FPPstatus)
			{
				case FPP_STATUS_IDLE:
					sprintf(response,"%d,%d,No playlist running\n",getFPPmode(),COMMAND_FAILED);
					break;
				case FPP_STATUS_PLAYLIST_PLAYING:
					sprintf(response,"%d,%d,Skipping to next playlist item\n",getFPPmode(),COMMAND_SUCCESS);
					player->NextPlaylistItem();
					break;
				case FPP_STATUS_STOPPING_GRACEFULLY:
					sprintf(response,"%d,%d,Playlist is stopping gracefully\n",getFPPmode(),COMMAND_FAILED);
					break;
			}
		}
		else if (!strcmp(CommandStr, "PrevPlaylistItem"))
		{
			switch (FPPstatus)
			{
				case FPP_STATUS_IDLE:
					sprintf(response,"%d,%d,No playlist running\n",getFPPmode(),COMMAND_FAILED);
					break;
				case FPP_STATUS_PLAYLIST_PLAYING:
					sprintf(response,"%d,%d,Skipping to previous playlist item\n",getFPPmode(),COMMAND_SUCCESS);
					player->PrevPlaylistItem();
					break;
				case FPP_STATUS_STOPPING_GRACEFULLY:
					sprintf(response,"%d,%d,Playlist is stopping gracefully\n",getFPPmode(),COMMAND_FAILED);
					break;
			}
		}
		else if (!strcmp(CommandStr, "SetupExtGPIO"))
		{
			// Configure the given GPIO to the given mode
			s = strtok(NULL,",");
			s2 = strtok(NULL,",");
			if (s && s2)
			{
				
				if (!SetupExtGPIO(atoi(s), s2))
				{
					sprintf(response, "%d,%d,Configuring GPIO,%d,%s,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,atoi(s),s2);
				}
				else
				{
					sprintf(response, "%d,%d,Configuring GPIO,%d,%s,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED,atoi(s),s2);
				}
			}
		}
		else if (!strcmp(CommandStr, "ExtGPIO"))
		{
			s = strtok(NULL,",");
			s2 = strtok(NULL,",");
			s3 = strtok(NULL,",");
			if (s && s2 && s3)
			{
				i = ExtGPIO(atoi(s), s2, atoi(s3));
				if (i >= 0) 
				{
					sprintf(response, "%d,%d,Setting GPIO,%d,%s,%d,%d,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,atoi(s),s2,atoi(s3),i);
				}
				else
				{
					sprintf(response, "%d,%d,Setting GPIO,%d,%s,%d,,,,,,,,\n",getFPPmode(),COMMAND_FAILED,atoi(s),s2,atoi(s3));
				}
			}
		}
		else
		{
			sprintf(response,"Invalid command: '%s'\n", CommandStr);
		}

		if (response2)
		{
			bytes_sent = sendto(socket_fd, response2, strlen(response2), 0,
                          (struct sockaddr *) &(client_address), sizeof(struct sockaddr_un));
			LogDebug(VB_COMMAND, "%s %s", CommandStr, response2);
			free(response2);
			response2 = NULL;
		}
		else
		{
			bytes_sent = sendto(socket_fd, response, strlen(response), 0,
                          (struct sockaddr *) &(client_address), sizeof(struct sockaddr_un));
			LogDebug(VB_COMMAND, "%s %s", CommandStr, response);
		}
  }
Beispiel #5
0
char *ProcessCommand(char *command, char *response)
{
    char *s;
    char *s2;
    char *s3;
    char *s4;
    char *response2 = NULL;
    int i;
    char NextPlaylist[128] = "No playlist scheduled.";
    char NextScheduleStartText[64] = "";
    char CommandStr[64];
    LogExcess(VB_COMMAND, "CMD: %s\n", command);
    s = strtok(command,",");
    strcpy(CommandStr, s);
    if (!strcmp(CommandStr, "s")) {
        scheduler->GetNextScheduleStartText(NextScheduleStartText);
        scheduler->GetNextPlaylistText(NextPlaylist);
        if(FPPstatus==FPP_STATUS_IDLE) {
            if (getFPPmode() == REMOTE_MODE) {
                int secsElapsed = 0;
                int secsRemaining = 0;
                char seqFilename[1024];
                char mediaFilename[1024];

                if (sequence->IsSequenceRunning()) {
                    strcpy(seqFilename, sequence->m_seqFilename);
                    secsElapsed = sequence->m_seqSecondsElapsed;
                    secsRemaining = sequence->m_seqSecondsRemaining;
                } else {
                    strcpy(seqFilename, "");
                }

                if (mediaOutput) {
                    strcpy(mediaFilename, mediaOutput->m_mediaFilename.c_str());
                    secsElapsed = mediaOutputStatus.secondsElapsed;
                    secsRemaining = mediaOutputStatus.secondsRemaining;
                } else {
                    strcpy(mediaFilename, "");
                }

                sprintf(response,"%d,%d,%d,%s,%s,%d,%d\n",
                        getFPPmode(), 0, getVolume(), seqFilename,
                        mediaFilename, secsElapsed, secsRemaining);
            } else if (sequence->IsSequenceRunning()) {
                sprintf(response,"%d,%d,%d,,,%s,,0,0,%d,%d,%s,%s,0\n",
                        getFPPmode(),
                        1,
                        getVolume(),
                        sequence->m_seqFilename,
                        sequence->m_seqSecondsElapsed,
                        sequence->m_seqSecondsRemaining,
                        NextPlaylist,
                        NextScheduleStartText);
            } else {
                sprintf(response,"%d,%d,%d,%s,%s\n",getFPPmode(),0,getVolume(),NextPlaylist,NextScheduleStartText);
            }
        } else {
            Json::Value pl = playlist->GetInfo();
            if (pl["currentEntry"].isMember("dynamic"))
                pl["currentEntry"] = pl["currentEntry"]["dynamic"];

            if ((pl["currentEntry"]["type"] == "both") ||
                (pl["currentEntry"]["type"] == "media")) {
                //printf(" %s\n", pl.toStyledString().c_str());
                sprintf(response,"%d,%d,%d,%s,%s,%s,%s,%d,%d,%d,%d,%s,%s,%d\n",
                    getFPPmode(),
                    FPPstatus,
                    getVolume(),
                    pl["name"].asString().c_str(),
                    pl["currentEntry"]["type"].asString().c_str(),
                    pl["currentEntry"]["type"].asString() == "both" ? pl["currentEntry"]["sequence"]["sequenceName"].asString().c_str() : "",
                    pl["currentEntry"]["type"].asString() == "both"
                        ? pl["currentEntry"]["media"]["mediaFilename"].asString().c_str()
                        : pl["currentEntry"]["mediaFilename"].asString().c_str() ,
//							pl["currentEntry"]["entryID"].asInt() + 1,
                    playlist->GetPosition(),
                    pl["size"].asInt(),
                    pl["currentEntry"]["type"].asString() == "both"
                        ? pl["currentEntry"]["media"]["secondsElapsed"].asInt()
                        : pl["currentEntry"]["secondsElapsed"].asInt(),
                    pl["currentEntry"]["type"].asString() == "both"
                        ? pl["currentEntry"]["media"]["secondsRemaining"].asInt()
                        : pl["currentEntry"]["secondsRemaining"].asInt(),
                    NextPlaylist,
                    NextScheduleStartText,
                    pl["repeat"].asInt());
            } else if (pl["currentEntry"]["type"] == "sequence") {
                sprintf(response,"%d,%d,%d,%s,%s,%s,%s,%d,%d,%d,%d,%s,%s,%d\n",
                    getFPPmode(),
                    FPPstatus,
                    getVolume(),
                    pl["name"].asString().c_str(),
                    pl["currentEntry"]["type"].asString().c_str(),
                    pl["currentEntry"]["sequenceName"].asString().c_str(),
                    "",
//							pl["currentEntry"]["entryID"].asInt() + 1,
                    playlist->GetPosition(),
                    pl["size"].asInt(),
                    sequence->m_seqSecondsElapsed,
                    sequence->m_seqSecondsRemaining,
                    NextPlaylist,
                    NextScheduleStartText,
                    pl["repeat"].asInt());
            } else {
                sprintf(response,"%d,%d,%d,%s,%s,%s,%s,%d,%d,%d,%d,%s,%s,%d\n",
                    getFPPmode(),
                    FPPstatus,
                    getVolume(),
                    pl["name"].asString().c_str(),
                    pl["currentEntry"]["type"].asString().c_str(),
                    "",
                    "",
//							pl["currentEntry"]["entryID"].asInt() + 1,
                    playlist->GetPosition(),
                    pl["size"].asInt(),
                    pl["currentEntry"]["type"].asString() == "pause" ? pl["currentEntry"]["duration"].asInt() - pl["currentEntry"]["remaining"].asInt() : 0,
                    pl["currentEntry"]["type"].asString() == "pause" ? pl["currentEntry"]["remaining"].asInt() : 0,
                    NextPlaylist,
                    NextScheduleStartText,
                    pl["repeat"].asInt());
            }
        }
    } else if ((!strcmp(CommandStr, "P")) || (!strcmp(CommandStr, "p"))) {
        s = strtok(NULL,",");
        s2 = strtok(NULL,",");

        int entry = 0;
        if (s2 && s2[0])
            entry = atoi(s2);

        if (s)
        {
            int repeat = strcmp(CommandStr, "p") ? 0 : 1;
            int scheduledRepeat = 0;
            std::string playlistName = scheduler->GetPlaylistThatShouldBePlaying(scheduledRepeat);

            if ((playlistName == s) && (repeat == scheduledRepeat)) {
                // Use CheckIfShouldBePlayingNow() so the scheduler knows when
                // to stop the playlist
                scheduler->CheckIfShouldBePlayingNow(1);
                sprintf(response,"%d,%d,Playlist Started,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
            } else if (playlist->Play(s, entry, repeat, 0)) {
                FPPstatus = FPP_STATUS_PLAYLIST_PLAYING;
                sprintf(response,"%d,%d,Playlist Started,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
		    } else {
                sprintf(response,"%d,%d,Error Starting Playlist,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
            }
        } else {
            sprintf(response,"%d,%d,Unknown Playlist,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
        }
    } else if ((!strcmp(CommandStr, "S")) ||
               (!strcmp(CommandStr, "StopGracefully"))) {
        if (FPPstatus==FPP_STATUS_PLAYLIST_PLAYING) {
            playlist->StopGracefully(1);
            scheduler->ReLoadCurrentScheduleInfo();
            sprintf(response,"%d,%d,Playlist Stopping Gracefully,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
        } else {
            sprintf(response,"%d,Not playing,,,,,,,,,,,\n",COMMAND_FAILED);
        }
    } else if ((!strcmp(CommandStr, "d")) ||
               (!strcmp(CommandStr, "StopNow"))) {
        if (FPPstatus==FPP_STATUS_PLAYLIST_PLAYING || FPPstatus==FPP_STATUS_STOPPING_GRACEFULLY) {
            playlist->StopNow(1);
            scheduler->ReLoadCurrentScheduleInfo();
            sprintf(response,"%d,%d,Playlist Stopping Now,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
        } else if ((FPPstatus == FPP_STATUS_IDLE) &&
                   (sequence->IsSequenceRunning())) {
            sequence->CloseSequenceFile();
            sprintf(response,"%d,%d,Sequence Stopping Now,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
        } else {
            sprintf(response,"%d,%d,Not playing,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
        }
    } else if (!strcmp(CommandStr, "R")) {
        scheduler->ReLoadNextScheduleInfo();
        if (FPPstatus==FPP_STATUS_IDLE) {
            scheduler->ReLoadCurrentScheduleInfo();
            scheduler->CheckIfShouldBePlayingNow();
        }
        sprintf(response,"%d,%d,Reloading Schedule,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
    } else if (!strcmp(CommandStr, "v")) {
        s = strtok(NULL,",");
        if (s) {
            setVolume(atoi(s));
            sprintf(response,"%d,%d,Setting Volume,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
        } else {
            sprintf(response,"%d,%d,Invalid Volume,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
        }
    } else if (!strcmp(CommandStr, "q")) {
        // Quit/Shutdown fppd
        if ((FPPstatus == FPP_STATUS_PLAYLIST_PLAYING) ||
            (FPPstatus == FPP_STATUS_STOPPING_GRACEFULLY)) {
            playlist->StopNow(1);
            sleep(2);
        }

        ShutdownFPPD();

        sleep(1);
    } else if (!strcmp(CommandStr, "e")) {
        // Start an Effect
        s = strtok(NULL,",");
        s2 = strtok(NULL,",");
        s3 = strtok(NULL,",");
        if (s && s2) {
            i = StartEffect(s, atoi(s2), atoi(s3));
            if (i >= 0)
                sprintf(response,"%d,%d,Starting Effect,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
            else
                sprintf(response,"%d,%d,Invalid Effect,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
        } else
            sprintf(response,"%d,%d,Invalid Effect,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
    } else if (!strcmp(CommandStr, "t")) {
        // Trigger an event
        s = strtok(NULL,",");
        pluginCallbackManager.eventCallback(s, "command");
        i = TriggerEventByID(s);
        if (i >= 0)
            sprintf(response,"%d,%d,Event Triggered,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
        else
            sprintf(response,"%d,%d,Event Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
    } else if (!strcmp(CommandStr, "GetTestMode")) {
        strcpy(response, channelTester->GetConfig().c_str());
        strcat(response, "\n");
    } else if (!strcmp(CommandStr, "SetTestMode")) {
        if (channelTester->SetupTest(std::string(s + strlen(s) + 1)))
        {
            sprintf(response, "0,%d,Test Mode Activated,,,,,,,,,\n",
                COMMAND_SUCCESS);
        } else {
            sprintf(response, "0,%d,Test Mode Deactivated,,,,,,,,,\n",
                COMMAND_SUCCESS);
        }
    } else if (!strcmp(CommandStr, "LogLevel")) {
        s = strtok(NULL,",");

        if (SetLogLevel(s)) {
            sprintf(response,"%d,%d,Log Level Updated,%d,%d,,,,,,,,,\n",
                getFPPmode(),COMMAND_SUCCESS,logLevel,logMask);
        } else {
            sprintf(response,"%d,%d,Error Updating Log Level,%d,%d,,,,,,,,,\n",
                getFPPmode(),COMMAND_FAILED,logLevel,logMask);
        }
    } else if (!strcmp(CommandStr, "LogMask")) {
        s = strtok(NULL,",");

        if ((s && SetLogMask(s)) || SetLogMask("")) {
            sprintf(response,"%d,%d,Log Mask Updated,%d,%d,,,,,,,,,\n",
                getFPPmode(),COMMAND_SUCCESS,logLevel,logMask);
        } else {
            sprintf(response,"%d,%d,Error Updating Log Mask,%d,%d,,,,,,,,,\n",
                getFPPmode(),COMMAND_FAILED,logLevel,logMask);
        }
    } else if (!strcmp(CommandStr, "SetSetting")) {
        char name[128];

        s = strtok(NULL,",");
        if (s) {
            strcpy(name, s);
            s = strtok(NULL,",");
            if (s)
                parseSetting(name, s);
        }
    } else if (!strcmp(CommandStr, "StopAllEffects")) {
        StopAllEffects();
        sprintf(response,"%d,%d,All Effects Stopped,,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS);
    } else if (!strcmp(CommandStr, "StopEffectByName")) {
        s = strtok(NULL,",");
        if (strlen(s)) {
            if (StopEffect(s))
                sprintf(response,"%d,%d,Stopping Effect,%s,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,s);
            else
                sprintf(response,"%d,%d,Stop Effect Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
        }
    } else if (!strcmp(CommandStr, "StopEffect")) {
        s = strtok(NULL,",");
        i = atoi(s);
        if (StopEffect(i))
            sprintf(response,"%d,%d,Stopping Effect,%d,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,i);
        else
            sprintf(response,"%d,%d,Stop Effect Failed,,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED);
    } else if (!strcmp(CommandStr, "GetRunningEffects")) {
        sprintf(response,"%d,%d,Running Effects",getFPPmode(),COMMAND_SUCCESS);
        GetRunningEffects(response, &response2);
    } else if (!strcmp(CommandStr, "GetFPPDUptime")) {
        sprintf(response,"%d,%d,FPPD Uptime,%ld,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS, time(NULL) - fppdStartTime);
    } else if (!strcmp(CommandStr, "StartSequence")) {
        if ((FPPstatus == FPP_STATUS_IDLE) &&
            (!sequence->IsSequenceRunning())) {
            s = strtok(NULL,",");
            s2 = strtok(NULL,",");
            if (s && s2) {
                i = atoi(s2);
                sequence->OpenSequenceFile(s, 0, i);
            } else {
                LogDebug(VB_COMMAND, "Invalid command: %s\n", command);
            }
        } else {
            LogErr(VB_COMMAND, "Tried to start a sequence when a playlist or "
                    "sequence is already running\n");
        }
    } else if (!strcmp(CommandStr, "StopSequence")) {
        if ((FPPstatus == FPP_STATUS_IDLE) &&
            (sequence->IsSequenceRunning())) {
            sequence->CloseSequenceFile();
        } else {
            LogDebug(VB_COMMAND,
                "Tried to stop a sequence when no sequence is running\n");
        }
    } else if (!strcmp(CommandStr, "ToggleSequencePause")) {
        if ((sequence->IsSequenceRunning()) &&
            ((FPPstatus == FPP_STATUS_IDLE) ||
             ((FPPstatus != FPP_STATUS_IDLE) &&
              (playlist->GetInfo()["currentEntry"]["type"] == "sequence")))) {
            sequence->ToggleSequencePause();
        }
    } else if (!strcmp(CommandStr, "SingleStepSequence")) {
        if ((sequence->IsSequenceRunning()) &&
            (sequence->SequenceIsPaused()) &&
            ((FPPstatus == FPP_STATUS_IDLE) ||
             ((FPPstatus != FPP_STATUS_IDLE) &&
              (playlist->GetInfo()["currentEntry"]["type"] == "sequence")))) {
            sequence->SingleStepSequence();
        }
    } else if (!strcmp(CommandStr, "SingleStepSequenceBack")) {
        if ((sequence->IsSequenceRunning()) &&
            (sequence->SequenceIsPaused()) &&
            ((FPPstatus == FPP_STATUS_IDLE) ||
             ((FPPstatus != FPP_STATUS_IDLE) &&
              (playlist->GetInfo()["currentEntry"]["type"] == "sequence")))) {
            sequence->SingleStepSequenceBack();
        }
    } else if (!strcmp(CommandStr, "NextPlaylistItem")) {
        switch (FPPstatus)
        {
            case FPP_STATUS_IDLE:
                sprintf(response,"%d,%d,No playlist running\n",getFPPmode(),COMMAND_FAILED);
                break;
            case FPP_STATUS_PLAYLIST_PLAYING:
                sprintf(response,"%d,%d,Skipping to next playlist item\n",getFPPmode(),COMMAND_SUCCESS);
                playlist->NextItem();
                break;
            case FPP_STATUS_STOPPING_GRACEFULLY:
                sprintf(response,"%d,%d,Playlist is stopping gracefully\n",getFPPmode(),COMMAND_FAILED);
                break;
        }
    } else if (!strcmp(CommandStr, "PrevPlaylistItem")) {
        switch (FPPstatus) {
            case FPP_STATUS_IDLE:
                sprintf(response,"%d,%d,No playlist running\n",getFPPmode(),COMMAND_FAILED);
                break;
            case FPP_STATUS_PLAYLIST_PLAYING:
                sprintf(response,"%d,%d,Skipping to previous playlist item\n",getFPPmode(),COMMAND_SUCCESS);
                playlist->PrevItem();
                break;
            case FPP_STATUS_STOPPING_GRACEFULLY:
                sprintf(response,"%d,%d,Playlist is stopping gracefully\n",getFPPmode(),COMMAND_FAILED);
                break;
        }
    } else if (!strcmp(CommandStr, "SetupExtGPIO")) {
        // Configure the given GPIO to the given mode
        s = strtok(NULL,",");
        s2 = strtok(NULL,",");
        if (s && s2)
        {
            
            if (!SetupExtGPIO(atoi(s), s2))
            {
                sprintf(response, "%d,%d,Configuring GPIO,%d,%s,,,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,atoi(s),s2);
            } else {
                sprintf(response, "%d,%d,Configuring GPIO,%d,%s,,,,,,,,,\n",getFPPmode(),COMMAND_FAILED,atoi(s),s2);
            }
        }
    } else if (!strcmp(CommandStr, "ExtGPIO")) {
        s = strtok(NULL,",");
        s2 = strtok(NULL,",");
        s3 = strtok(NULL,",");
        if (s && s2 && s3)
        {
            i = ExtGPIO(atoi(s), s2, atoi(s3));
            if (i >= 0)
            {
                sprintf(response, "%d,%d,Setting GPIO,%d,%s,%d,%d,,,,,,,\n",getFPPmode(),COMMAND_SUCCESS,atoi(s),s2,atoi(s3),i);
            } else {
                sprintf(response, "%d,%d,Setting GPIO,%d,%s,%d,,,,,,,,\n",getFPPmode(),COMMAND_FAILED,atoi(s),s2,atoi(s3));
            }
        }
    } else {
        sprintf(response,"Invalid command: '%s'\n", CommandStr);
    }

    return response2;
}