コード例 #1
0
ファイル: falcon.c プロジェクト: FalconChristmas/fpp
/*
 * Write out the given buffer to the specified filename
 */
int FalconWriteConfig(char *filename, char *buf, int size)
{
	LogDebug(VB_SETTING, "FalconWriteConfig(%s, %p, %d)\n", filename, buf, size);
	char  fullFilename[1024];
	FILE *fp = NULL;

	sprintf(fullFilename, "%s/config/%s", getMediaDirectory(), filename);

	fp = fopen(fullFilename, "w");
	if (!fp)
	{
		LogErr(VB_SETTING, "Error opening Falcon hardware config file %s",
			fullFilename);
		return -1;
	}

	if (size > FALCON_CFG_FILE_MAX_SIZE)
	{
		LogWarn(VB_SETTING, "Tried to write out %d bytes when max is %d\n",
			size, FALCON_CFG_FILE_MAX_SIZE);
		size = FALCON_CFG_FILE_MAX_SIZE;
	}

	int bytesWritten = fwrite(buf, 1, size, fp);

	fclose(fp);

	return bytesWritten;
}
コード例 #2
0
ファイル: falcon.c プロジェクト: FalconChristmas/fpp
/*
 * Read the specified file into the given buffer
 */
int FalconReadConfig(char *filename, char *buf)
{
	LogDebug(VB_SETTING, "FalconReadConfig(%s, %p)\n", filename, buf);
	char  fullFilename[1024];
	FILE *fp = NULL;

	sprintf(fullFilename, "%s/config/%s", getMediaDirectory(), filename);

	fp = fopen(fullFilename, "r");
	if (!fp)
	{
		LogErr(VB_SETTING, "Error opening Falcon hardware config file %s\n",
			fullFilename);
		return -1;
	}

	int bytesRead = fread(buf, 1, FALCON_CFG_FILE_MAX_SIZE, fp);

	fclose(fp);

	return bytesRead;
}
コード例 #3
0
ファイル: settings.c プロジェクト: ihbar/fpp
void CheckExistanceOfDirectoriesAndFiles(void)
{
	if(!DirectoryExists(getMediaDirectory()))
	{
		LogWarn(VB_SETTING, "FPP directory does not exist, creating it.\n");

		if ( mkdir(getMediaDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create media directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getMusicDirectory()))
	{
		LogWarn(VB_SETTING, "Music directory does not exist, creating it.\n");

		if ( mkdir(getMusicDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create music directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getSequenceDirectory()))
	{
		LogWarn(VB_SETTING, "Sequence directory does not exist, creating it.\n");

		if ( mkdir(getSequenceDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create sequence directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getEventDirectory()))
	{
		LogWarn(VB_SETTING, "Event directory does not exist, creating it.\n");

		if ( mkdir(getEventDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create event directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getVideoDirectory()))
	{
		LogWarn(VB_SETTING, "Video directory does not exist, creating it.\n");

		if ( mkdir(getVideoDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create video directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getEffectDirectory()))
	{
		LogWarn(VB_SETTING, "Effect directory does not exist, creating it.\n");

		if ( mkdir(getEffectDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create effect directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getScriptDirectory()))
	{
		LogWarn(VB_SETTING, "Script directory does not exist, creating it.\n");

		if ( mkdir(getScriptDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create script directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getPlaylistDirectory()))
	{
		LogWarn(VB_SETTING, "Playlist directory does not exist, creating it.\n");

		if ( mkdir(getPlaylistDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create playlist directory.\n");
			exit(EXIT_FAILURE);
		}
	}

	if(!FileExists(getUniverseFile()))
	{
		LogWarn(VB_SETTING, "Universe file does not exist, creating it.\n");

		char *cmd, *file = getUniverseFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create universe file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}

	if(!FileExists(getScheduleFile()))
	{
		LogWarn(VB_SETTING, "Schedule file does not exist, creating it.\n");

		char *cmd, *file = getScheduleFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create schedule file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}
	if(!FileExists(getBytesFile()))
	{
		LogWarn(VB_SETTING, "Bytes file does not exist, creating it.\n");

		char *cmd, *file = getBytesFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create bytes file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}

	if(!FileExists(getSettingsFile()))
	{
		LogWarn(VB_SETTING, "Settings file does not exist, creating it.\n");

		char *cmd, *file = getSettingsFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create settings file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}
  


  
}
コード例 #4
0
ファイル: e131bridge.cpp プロジェクト: FalconChristmas/fpp
void LoadInputUniversesFromFile(void)
{
	FILE *fp;
	char buf[512];
	char *s;
	InputUniverseCount=0;
	char active =0;
	char filename[1024];

	strcpy(filename, getMediaDirectory());
	strcat(filename, "/config/ci-universes.json");

	LogDebug(VB_E131BRIDGE, "Opening File Now %s\n", filename);

	if (!FileExists(filename)) {
		LogErr(VB_E131BRIDGE, "Universe file %s does not exist\n",
			filename);
		return;
	}

	Json::Value root;
    Json::Reader reader;
	std::ifstream t(filename);
	std::stringstream buffer;

	buffer << t.rdbuf();

	std::string config = buffer.str();

	bool success = reader.parse(buffer.str(), root);
    if (!success) {
		LogErr(VB_E131BRIDGE, "Error parsing %s\n", filename);
		return;
	}

	Json::Value outputs = root["channelInputs"];

	std::string type;
	int start = 0;
	int count = 0;

	for (int c = 0; c < outputs.size(); c++) {
		if (outputs[c]["type"].asString() != "universes")
			continue;

		if (outputs[c]["enabled"].asInt() == 0)
			continue;

		Json::Value univs = outputs[c]["universes"];

		for (int i = 0; i < univs.size(); i++) {
			Json::Value u = univs[i];

			if(u["active"].asInt()) {
                int universe = u["id"].asInt();
                int count = u.get("universeCount", Json::Value(1)).asInt();
                int startChannel = u["startChannel"].asInt();
                int channelCount = u["channelCount"].asInt();
                for (int x = 0; x < count; ++x) {
                    InputUniverses[InputUniverseCount].active = u["active"].asInt();
                    InputUniverses[InputUniverseCount].universe = universe + x;
                    InputUniverses[InputUniverseCount].startAddress = startChannel;
                    InputUniverses[InputUniverseCount].size = channelCount;
                    InputUniverses[InputUniverseCount].type = u["type"].asInt();
                    
                    switch (InputUniverses[InputUniverseCount].type) {
                        case 0: // Multicast
                            strcpy(InputUniverses[InputUniverseCount].unicastAddress,"\0");
                            break;
                        case 1: //UnicastAddress
                            strcpy(InputUniverses[InputUniverseCount].unicastAddress,
                                   u["address"].asString().c_str());
                            break;
                        default: // ArtNet
                            continue;
                    }
                    
                    InputUniverses[InputUniverseCount].priority = u["priority"].asInt();
                    startChannel += channelCount;
                    InputUniverseCount++;
                }
			}
		}
	}

	InputUniversesPrint();
}
コード例 #5
0
ファイル: channeloutput.c プロジェクト: elfchief/fpp
/*
 *
 * NOTE: We subtract 1 from all source and destination channel numbers
 *       because our array is 0-based and the channel numbers start at 1.
 */
int LoadChannelRemapData(void) {
	FILE *fp;
	char filename[1024];
	char buf[32];
	char *s;
	int src;
	int dest;
	int count;

	strcpy(filename, getMediaDirectory());
	strcat(filename, "/channelremap");

	if (!FileExists(filename))
		return 0;

	channelRemaps = 0;

	LogDebug(VB_CHANNELOUT, "Loading Channel Remap data.\n");
	fp = fopen(filename, "r");
	if (fp == NULL) 
	{
		LogErr(VB_CHANNELOUT, "Could not open Channel Remap file %s\n", filename);
		return 0;
	}

	while(fgets(buf, 32, fp) != NULL)
	{
		if (buf[0] == '#') // Allow # comments for testing
			continue;

		// Source
		s = strtok(buf, ",");
		src = strtol(s, NULL, 10);
		if (src <= 0)
			continue;

		remappedChannels[channelRemaps].src = src - 1;

		// Destination
		s = strtok(NULL, ",");
		dest = strtol(s, NULL, 10);
		if (dest <= 0)
			continue;

		remappedChannels[channelRemaps].dest = dest - 1;

		// Count
		s=strtok(NULL,",");
		count = strtol(s, NULL, 10);
		if (count <= 0)
			continue;

		remappedChannels[channelRemaps].count = count;

		if ((src + count - 1) > FPPD_MAX_CHANNELS) {
			LogErr(VB_CHANNELOUT, "ERROR: Source + Count exceeds max channel count in: %s\n", buf );
		} else if ((dest + count - 1) > FPPD_MAX_CHANNELS) {
			LogErr(VB_CHANNELOUT, "ERROR: Destination + Count exceeds max channel count in: %s\n", buf );
		} else {
		    channelRemaps++;
		}
	}
	fclose(fp);

	PrintRemappedChannels();

	return 1;
}
コード例 #6
0
ファイル: channeloutput.c プロジェクト: elfchief/fpp
int InitializeChannelOutputs(void) {
	Json::Value root;
	Json::Reader reader;
	int i = 0;

	channelOutputFrame = 0;

	for (i = 0; i < FPPD_MAX_CHANNEL_OUTPUTS; i++) {
		bzero(&channelOutputs[i], sizeof(channelOutputs[i]));
	}

	// Reset index so we can start populating the outputs array
	i = 0;

	if (FPDOutput.isConfigured())
	{
		channelOutputs[i].startChannel = getSettingInt("FPDStartChannelOffset");
		channelOutputs[i].outputOld = &FPDOutput;

		if (FPDOutput.open("", &channelOutputs[i].privData)) {
			channelOutputs[i].channelCount = channelOutputs[i].outputOld->maxChannels(channelOutputs[i].privData);

			i++;
		} else {
			LogErr(VB_CHANNELOUT, "ERROR Opening FPD Channel Output\n");
		}
	}

	if (((getFPPmode() != BRIDGE_MODE) ||
		 (getSettingInt("E131Bridging"))) &&
		(E131Output.isConfigured()))
	{
		channelOutputs[i].startChannel = 0;
		channelOutputs[i].outputOld  = &E131Output;

		if (E131Output.open("", &channelOutputs[i].privData)) {
			channelOutputs[i].channelCount = channelOutputs[i].outputOld->maxChannels(channelOutputs[i].privData);

			i++;
		} else {
			LogErr(VB_CHANNELOUT, "ERROR Opening E1.31 Channel Output\n");
		}
	}

	FILE *fp;
	char filename[1024];
	char buf[2048];

	// Parse the channeloutputs.json config file
	strcpy(filename, getMediaDirectory());
	strcat(filename, "/config/channeloutputs.json");

	LogDebug(VB_CHANNELOUT, "Loading %s\n", filename);

	if (FileExists(filename))
	{
		std::ifstream t(filename);
		std::stringstream buffer;

		buffer << t.rdbuf();

		std::string config = buffer.str();

		bool success = reader.parse(buffer.str(), root);
		if (!success)
		{
			LogErr(VB_CHANNELOUT, "Error parsing %s\n", filename);
			return 0;
		}

		const Json::Value outputs = root["channelOutputs"];
		std::string type;
		int start = 0;
		int count = 0;

		for (int c = 0; c < outputs.size(); c++)
		{
			type = outputs[c]["type"].asString();

			if (!outputs[c]["enabled"].asInt())
			{
				LogDebug(VB_CHANNELOUT, "Skipping Disabled Channel Output: %s\n", type.c_str());
				continue;
			}

			start = outputs[c]["startChannel"].asInt();
			count = outputs[c]["channelCount"].asInt();

			// internally we start channel counts at zero
			start -= 1;

			channelOutputs[i].startChannel = start;
			channelOutputs[i].channelCount = count;

			if (type == "LEDPanelMatrix") {
#if defined(PLATFORM_PI) || defined(PLATFORM_ODROID)
				if (outputs[c]["subType"] == "RGBMatrix")
					channelOutputs[i].output = new RGBMatrixOutput(start, count);
				else
				{
					LogErr(VB_CHANNELOUT, "%s subType not valid on Pi\n", outputs[c]["subType"].asString().c_str());
					continue;
				}
#endif
#ifdef PLATFORM_BBB
				if (outputs[c]["subType"] == "LEDscapeMatrix")
					channelOutputs[i].output = new LEDscapeMatrixOutput(start, count);
				else
				{
					LogErr(VB_CHANNELOUT, "%s subType not valid on BBB\n", outputs[c]["subType"].asString().c_str());
					continue;
				}
			} else if (type == "BBB48String") {
				channelOutputs[i].output = new BBB48StringOutput(start, count);
			} else if (type == "BBBSerial") {
				channelOutputs[i].output = new BBBSerialOutput(start, count);
#endif
#ifdef USEOLA
			} else if (type == "OLA") {
				channelOutputs[i].output = new OLAOutput(start, count);
#endif
			} else if (type == "USBRelay") {
				channelOutputs[i].output = new USBRelayOutput(start, count);
#if defined(PLATFORM_PI)
			} else if (type == "Hill320") {
				channelOutputs[i].output = new Hill320Output(start, count);
#endif
#ifdef USE_X11Matrix
			} else if (type == "X11Matrix") {
				channelOutputs[i].output = new X11MatrixOutput(start, count);
#endif
			} else {
				LogErr(VB_CHANNELOUT, "Unknown Channel Output type: %s\n", type.c_str());
				continue;
			}

			if (channelOutputs[i].output->Init(outputs[c])) {
				i++;
			} else {
				LogErr(VB_CHANNELOUT, "ERROR Opening %s Channel Output\n", type.c_str());
			}
		}
	}

	// Parse the channeloutputs config file
	strcpy(filename, getMediaDirectory());
	strcat(filename, "/channeloutputs");

	if (FileExists(filename))
	{
		LogDebug(VB_CHANNELOUT, "Loading %s\n", filename);

		fp = fopen(filename, "r");

		if (fp == NULL)
		{
			LogErr(VB_CHANNELOUT,
				"Could not open Channel Outputs config file %s: %s\n",
				filename, strerror(errno));
			channelOutputCount = 0;

			return 0;
		}

		while(fgets(buf, 2048, fp) != NULL)
		{
			int  enabled = 0;
			char type[32];
			int  start = 0;
			int  count = 0;
			char deviceConfig[160];

			if (buf[0] == '#') // Allow # comments for testing
				continue;

			int fields = sscanf(buf, "%d,%[^,],%d,%d,%s",
				&enabled, type, &start, &count, deviceConfig);

			if (fields != 5) {
				LogErr(VB_CHANNELOUT,
					"Invalid line in channeloutputs config file: %s\n", buf);
				continue;
			}

			if (!enabled) {
				LogDebug(VB_CHANNELOUT, "Skipping disabled channel output: %s", buf);
				continue;
			}

			if (count > (FPPD_MAX_CHANNELS - start)) {
				LogWarn(VB_CHANNELOUT,
					"Channel Output config, start (%d) + count (%d) exceeds max (%d) channel\n",
					start, count, FPPD_MAX_CHANNELS);

				count = FPPD_MAX_CHANNELS - start;

				LogWarn(VB_CHANNELOUT,
					"Count suppressed to %d for config line: %s\n", count, buf);
			}

			if (strlen(deviceConfig))
				strcat(deviceConfig, ";");

			strcat(deviceConfig, "type=");
			strcat(deviceConfig, type);

			LogDebug(VB_CHANNELOUT, "ChannelOutput: %d %s %d %d %s\n", enabled, type, start, count, deviceConfig);

			// internally we start channel counts at zero
			start -= 1;

			channelOutputs[i].startChannel = start;
			channelOutputs[i].channelCount = count;


			if ((!strcmp(type, "Pixelnet-Lynx")) ||
				(!strcmp(type, "Pixelnet-Open")))
			{
				channelOutputs[i].output = new USBPixelnetOutput(start, count);
			} else if ((!strcmp(type, "DMX-Pro")) ||
					   (!strcmp(type, "DMX-Open"))) {
				channelOutputs[i].output = new USBDMXOutput(start, count);
			} else if ((!strcmp(type, "VirtualMatrix")) ||
						(!strcmp(type, "FBMatrix"))) {
				channelOutputs[i].output = new FBMatrixOutput(start, count);
			} else if (!strcmp(type, "GPIO")) {
				channelOutputs[i].output = new GPIOOutput(start, count);
			} else if (!strcmp(type, "GenericSerial")) {
				channelOutputs[i].output = new GenericSerialOutput(start, count);
			} else if (!strcmp(type, "LOR")) {
				channelOutputs[i].outputOld = &LOROutput;
			} else if (!strcmp(type, "Renard")) {
				channelOutputs[i].outputOld = &USBRenardOutput;
#ifdef PLATFORM_PI
			} else if (!strcmp(type, "RPIWS281X")) {
				channelOutputs[i].output = new RPIWS281xOutput(start, count);
#endif
			} else if (!strcmp(type, "SPI-WS2801")) {
				channelOutputs[i].output = new SPIws2801Output(start, count);
			} else if (!strcmp(type, "SPI-nRF24L01")) {
				channelOutputs[i].outputOld = &SPInRF24L01Output;
			} else if (!strcmp(type, "Triks-C")) {
				channelOutputs[i].outputOld = &TriksCOutput;
			} else if (!strcmp(type, "GPIO-595")) {
				channelOutputs[i].output = new GPIO595Output(start, count);
			} else if (!strcmp(type, "Debug")) {
				channelOutputs[i].output = new DebugOutput(start, count);
			} else {
				LogErr(VB_CHANNELOUT, "Unknown Channel Output type: %s\n", type);
				continue;
			}

			if ((channelOutputs[i].outputOld) &&
				(channelOutputs[i].outputOld->open(deviceConfig, &channelOutputs[i].privData)))
			{
				if (channelOutputs[i].channelCount > channelOutputs[i].outputOld->maxChannels(channelOutputs[i].privData)) {
					LogWarn(VB_CHANNELOUT,
						"Channel Output config, count (%d) exceeds max (%d) channel for configured output\n",
						channelOutputs[i].channelCount, channelOutputs[i].outputOld->maxChannels(channelOutputs[i].privData));

					channelOutputs[i].channelCount = channelOutputs[i].outputOld->maxChannels(channelOutputs[i].privData);

					LogWarn(VB_CHANNELOUT,
						"Count suppressed to %d for config: %s\n", channelOutputs[i].channelCount, buf);
				}
				i++;
			} else if ((channelOutputs[i].output) &&
					   (channelOutputs[i].output->Init(deviceConfig))) {
				i++;
			} else {
				LogErr(VB_CHANNELOUT, "ERROR Opening %s Channel Output\n", type);
			}
		}
	}

	channelOutputCount = i;

	LogDebug(VB_CHANNELOUT, "%d Channel Outputs configured\n", channelOutputCount);

	LoadChannelRemapData();

	return 1;
}
コード例 #7
0
ファイル: PixelOverlay.cpp プロジェクト: jcochran/fpp
/*
 * Load memory mapped channel blocks configuration file
 */
int LoadChannelMemoryMapData(void) {
	LogDebug(VB_CHANNELOUT, "LoadChannelMemoryMapData()\n");

	FPPChannelMemoryMapControlBlock *cb = NULL;

	FILE *fp;
	char filename[1024];
	char buf[64];
	char *s;
	int startChannel;
	int channelCount;

	if (!ctrlMap) {
		LogErr(VB_CHANNELOUT, "Error, trying to load memory map data when "
			"memory map is not configured.");
		return -1;
	}

	ctrlHeader->majorVersion = FPPCHANNELMEMORYMAPMAJORVER;
	ctrlHeader->minorVersion = FPPCHANNELMEMORYMAPMINORVER;
	ctrlHeader->totalBlocks  = 0;
	ctrlHeader->testMode     = 0;

	strcpy(filename, getMediaDirectory());
	strcat(filename, "/channelmemorymaps");

	if (!FileExists(filename))
		return 0;

	LogDebug(VB_CHANNELOUT, "Loading Channel Memory Map data.\n");
	fp = fopen(filename, "r");
	if (fp == NULL) 
	{
		LogErr(VB_CHANNELOUT, "Could not open Channel Memory Map config file %s\n", filename);
		return 0;
	}

	cb = (FPPChannelMemoryMapControlBlock*)(ctrlMap +
			sizeof(FPPChannelMemoryMapControlHeader));
	while(fgets(buf, 64, fp) != NULL)
	{
		if (buf[0] == '#') // Allow # comments for testing
			continue;

		// Name
		s = strtok(buf, ",");
		if (s) {
			strncpy(cb->blockName, s, 32);
		} else {
			continue;
		}

		// Start Channel
		s = strtok(NULL, ",");
		if (!s)
			continue;
		startChannel = strtol(s, NULL, 10);
		if ((startChannel <= 0) ||
			(startChannel > FPPD_MAX_CHANNELS))
			continue;
		cb->startChannel = startChannel;

		// Channel Count
		s=strtok(NULL,",");
		if (!s)
			continue;
		channelCount = strtol(s, NULL, 10);
		if ((channelCount <= 0) ||
			((startChannel + channelCount) > FPPD_MAX_CHANNELS))
			continue;
		cb->channelCount = channelCount;

		// Orientation
		s=strtok(NULL,",");
		if (!s)
			continue;
		if (!strcmp(s, "vertical"))
			cb->orientation = 'V';
		else
			cb->orientation = 'H';

		// Start Corner
		s=strtok(NULL,",");
		if (!s)
			continue;
		strncpy(cb->startCorner, s, 2);

		// String Count
		s=strtok(NULL,",");
		if (!s)
			continue;
		cb->stringCount = strtol(s, NULL, 10);

		// Strands Per String
		s=strtok(NULL,",");
		if (!s)
			continue;
		cb->strandsPerString = strtol(s, NULL, 10);

		// Sanity check our string count
		if (cb->stringCount > (cb->channelCount / 3))
			cb->stringCount = cb->channelCount / 3;

		SetupPixelMapForBlock(cb);

		cb++;

		ctrlHeader->totalBlocks++;
	}
	fclose(fp);

	if ((logLevel >= LOG_INFO) &&
		(logMask & VB_CHANNELOUT))
		PrintChannelMapBlocks();

	return 1;
}