Exemple #1
0
void CSBFSpot::Init()
{
	m_SBFDataPath="";
	m_SBFPlantName="";
	m_SBFDateFormat="";
	m_SBFTimeFormat="";
	m_LastDateTime="";

	std::string tmpString;
	std::ifstream infile;
	std::string sLine;
	infile.open(m_SBFConfigFile.c_str());
	if (!infile.is_open())
	{
		_log.Log(LOG_ERROR,"SBFSpot: Could not open configuration file!");
		return;
	}
	while (!infile.eof())
	{
		getline(infile, sLine);
		sLine.erase(std::remove(sLine.begin(), sLine.end(), '\r'), sLine.end());
		sLine = stdstring_trim(sLine);
		if (sLine.size()!=0)
		{
			if (sLine.find("OutputPath=")==0)
			{
				tmpString=sLine.substr(strlen("OutputPath="));
				if (tmpString!="")
				{
					unsigned char lastchar=tmpString[tmpString.size()-1];
#ifdef WIN32
					if (lastchar!='\\')
						tmpString+='\\';
#else
					if (lastchar!='/')
						tmpString+='/';
#endif
					m_SBFDataPath=tmpString;
				}
			}
			else if (sLine.find("Plantname=")==0)
			{
				m_SBFPlantName=sLine.substr(strlen("Plantname="));
			}
			else if (sLine.find("DateFormat=")==0)
			{
				m_SBFDateFormat=sLine.substr(strlen("DateFormat="));
			}
			else if (sLine.find("TimeFormat=")==0)
			{
				m_SBFTimeFormat=sLine.substr(strlen("TimeFormat="));
			}
		}
	}
	infile.close();
	if ((m_SBFDataPath.size()==0)||(m_SBFDateFormat.size()==0)||(m_SBFTimeFormat.size()==0))
	{
		_log.Log(LOG_ERROR,"SBFSpot: Could not find OutputPath in configuration file!");
	}
}
Exemple #2
0
CThermosmart::CThermosmart(const int ID, const std::string &Username, const std::string &Password)
{
	m_UserName = "";
	if ((Password == "secret")|| (Password.empty()))
	{
		_log.Log(LOG_ERROR, "Thermosmart: Please update your username/password!...");
	}
	else
	{
		m_UserName = Username;
		m_Password = Password;
		stdstring_trim(m_UserName);
		stdstring_trim(m_Password);
	}
	m_HwdID=ID;
	Init();
}
Exemple #3
0
void CYouLess::GetMeterDetails()
{
	std::string sResult;

	char szURL[200];

	if(m_Password.size() == 0)
	{
		sprintf(szURL,"http://%s:%d/a",m_szIPAddress.c_str(), m_usIPPort);
	}
	else
	{
		sprintf(szURL,"http://%s:%d/a&w=%s",m_szIPAddress.c_str(), m_usIPPort, m_Password.c_str());
	}

	if (!HTTPClient::GET(szURL,sResult))
	{
		_log.Log(LOG_ERROR,"YouLess: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}

	std::vector<std::string> results;
	StringSplit(sResult, "\n", results);
	if (results.size()<2)
	{
		_log.Log(LOG_ERROR,"YouLess: Error connecting to: %s", m_szIPAddress.c_str());
		return;
	}
	int fpos;
	std::string pusage=stdstring_trim(results[0]);
	fpos=pusage.find_first_of(" ");
	if (fpos!=std::string::npos)
		pusage=pusage.substr(0,fpos);
	stdreplace(pusage,",","");

	std::string pcurrent=stdstring_trim(results[1]);
	fpos=pcurrent.find_first_of(" ");
	if (fpos!=std::string::npos)
		pcurrent=pcurrent.substr(0,fpos);
	stdreplace(pcurrent,",","");

	m_meter.powerusage=atol(pusage.c_str());
	m_meter.usagecurrent=atol(pcurrent.c_str());
	sDecodeRXMessage(this, (const unsigned char *)&m_meter);//decode message
}
Exemple #4
0
CThermosmart::CThermosmart(const int ID, const std::string &Username, const std::string &Password, const int Mode1, const int Mode2, const int Mode3, const int Mode4, const int Mode5, const int Mode6)
{
	if ((Password == "secret")|| (Password.empty()))
	{
		_log.Log(LOG_ERROR, "Thermosmart: Please update your username/password!...");
	}
	else
	{
		m_UserName = Username;
		m_Password = Password;
		stdstring_trim(m_UserName);
		stdstring_trim(m_Password);
	}
	m_HwdID=ID;
	m_OutsideTemperatureIdx = 0; //use build in
	m_LastMinute = -1;
	SetModes(Mode1, Mode2, Mode3, Mode4, Mode5, Mode6);
	Init();
}
Exemple #5
0
/*
 * static
 * One-shot method to initialize pins
 *
 */
bool CGpio::InitPins()
{
	char buf[256];
	bool exports[MAX_GPIO+1] = { false };
	int gpioNumber;
	FILE *cmd = NULL;
	
	// 1. List exports and parse the result
#ifndef WIN32
	cmd = popen("gpio exports", "r");
#else
	cmd = fopen("E:\\exports.txt", "r");
#endif
	while (fgets(buf, sizeof(buf), cmd) != 0) {
		// Decode GPIO pin number from the output formatted as follows:
		//
		// GPIO Pins exported:
		//   17: out  0  none
		//   18: in   1  none
		//
		// 00000000001111111111
		// 01234567890123456789

		std::string exportLine(buf);
		//std::cout << "Processing line: " << exportLine;
		std::vector<std::string> sresults;
		StringSplit(exportLine, " :", sresults);
		if (sresults.empty())
			continue;
		if (sresults[0] == "GPIO")
			continue;
		if (sresults.size() >= 4)
		{
			gpioNumber = atoi(sresults[0].c_str());
			if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) {
				exports[gpioNumber] = true;
			}
			else {
				_log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", buf);
			}
		}
	}
#ifndef WIN32
	pclose(cmd);
#else
	fclose(cmd);
#endif

	// 2. List the full pin set and parse the result
#ifndef WIN32
	cmd = popen("gpio readall", "r");
#else
	cmd = fopen("E:\\readall.txt", "r");
#endif
	while (fgets(buf, sizeof(buf), cmd) != 0) {
		// Decode IN and OUT lines from the output formatted as follows:
		//
		// Old style (wiringPi<=2.16):
		// +----------+-Rev1-+------+--------+------+-------+
		// | wiringPi | GPIO | Phys | Name   | Mode | Value |
		// +----------+------+------+--------+------+-------+
		// |      0   |  17  |  11  | GPIO 0 | IN   | Low   |
		// |      1   |  18  |  12  | GPIO 1 | IN   | Low   |
		// |      2   |  21  |  13  | GPIO 2 | IN   | Low   |
		// |      3   |  22  |  15  | GPIO 3 | IN   | Low   |
		// ...
		//
		// New style:
		//  +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+
		//  | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
		//  +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
		//  |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
		//  |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
		//  |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
		//  |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
		// ...
		//
		// 0000000000111111111122222222223333333333444444444455555555556666666666777777777
		// 0123456789012345678901234567890123456789012345678901234567890123456789012345678

		std::string line(buf);
		std::vector<std::string> fields;
		
		//std::cout << "Processing line: " << line;
		StringSplit(line, "|", fields);
		if (fields.size()<7)
			continue;

		//std::cout << "# fields: " << fields.size() << std::endl;
		
		// trim each field
		for (size_t i = 0; i < fields.size(); i++) {
			fields[i]=stdstring_trim(fields[i]);
			//std::cout << "fields[" << i << "] = '" << fields[i] << "'" << std::endl;
		}

		if (fields.size() == 7) {
			// Old style
			if (fields[0] != "wiringPi") {
				gpioNumber = atoi(fields[1].c_str());
				if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) {
					pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[1] + " (" + fields[3] + ") on pin " + fields[2],
							fields[4] == "IN", fields[4] == "OUT", exports[gpioNumber]));
				} else {
					_log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[1].c_str());
				}
			}
		} else if (fields.size() == 14) {
			// New style
			if (fields[1].length() > 0) {
				gpioNumber = atoi(fields[1].c_str());
				if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) {
					pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[1] + " (" + fields[3] + ") on pin " + fields[6],
							(fields[4] == "IN"), (fields[4] == "OUT"), exports[gpioNumber]));
				} else {
					_log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[1].c_str());
				}
			}

			if (fields[12].length() > 0) {
				gpioNumber = atoi(fields[12].c_str());
				if ((gpioNumber >= 0) && (gpioNumber <= MAX_GPIO)) {
					pins.push_back(CGpioPin(gpioNumber, "gpio" + fields[12] + " (" + fields[10] + ") on pin " + fields[7],
							fields[9] == "IN", fields[9] == "OUT", exports[gpioNumber]));
				} else {
					_log.Log(LOG_NORM, "GPIO: Ignoring unsupported pin '%s'", fields[12].c_str());
				}
			}
		}
	}
#ifndef WIN32
	pclose(cmd);
#else
	fclose(cmd);
#endif
	if (pins.size() > 0) {
		std::sort(pins.begin(), pins.end());
		// debug
		//for(std::vector<CGpioPin>::iterator it = pins.begin(); it != pins.end(); ++it) {
		//	CGpioPin pin=*it;
		//	std::cout << "Pin " << pin.GetId() << " : " << pin.GetLabel() << ", " << pin.GetIsInput() << ", " << pin.GetIsOutput() << ", " << pin.GetIsExported() << std::endl;
		//}
	} else {
		_log.Log(LOG_ERROR, "GPIO: Failed to detect any pins, make sure you exported them!");
		return false;
	}
	return true;
}