Subversion Repositories heating

Rev

Rev 5 | Rev 9 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 8
Line 42... Line 42...
42
{
42
{
43
struct termios options;
43
struct termios options;
44
 
44
 
45
	initialized = false;
45
	initialized = false;
46
	fd_serial = -1;
46
	fd_serial = -1;
-
 
47
	outPos = 0;
-
 
48
	outside = 0.0;
-
 
49
	stop = false;
-
 
50
 
-
 
51
	for (int i = 0; i < MAX_TEMPS; i++)
-
 
52
		allTemps[i] = 100.0;
47
 
53
 
48
	// Test if serial port is available.
54
	// Test if serial port is available.
49
	if (access(Configure.serial, R_OK | W_OK))
55
	if (access(Configure.serial, R_OK | W_OK))
50
	{
56
	{
51
		syslog(LOG_DAEMON, "Serial device <%s> is not accessible!", Configure.serial);
57
		syslog(LOG_DAEMON, "Serial device <%s> is not accessible!", Configure.serial);
Line 62... Line 68...
62
	tcgetattr(fd_serial, &options);
68
	tcgetattr(fd_serial, &options);
63
	cfsetispeed(&options, B9600);
69
	cfsetispeed(&options, B9600);
64
	cfsetospeed(&options, B9600);
70
	cfsetospeed(&options, B9600);
65
	tcsetattr(fd_serial, TCSANOW, &options);
71
	tcsetattr(fd_serial, TCSANOW, &options);
66
	fcntl(fd_serial, F_SETFL, 0);
72
	fcntl(fd_serial, F_SETFL, 0);
67
	// TODO: Detecting the menu of the temperature controller and set it to
-
 
68
	//       meassure mode.
-
 
69
 
-
 
70
	initialized = true;
73
	initialized = true;
71
}
74
}
72
 
75
 
73
temperature::~temperature()
76
temperature::~temperature()
74
{
77
{
75
	if (fd_serial != -1)
78
	if (fd_serial != -1)
76
		close(fd_serial);
79
		close(fd_serial);
77
 
80
 
-
 
81
	stop = true;
-
 
82
	sleep(1);
78
	fd_serial = -1;
83
	fd_serial = -1;
79
	initialized = false;
84
	initialized = false;
80
}
85
}
81
 
86
 
82
double temperature::getTemp (int pos)
87
void temperature::trun()
83
{
88
{
84
char hv0[1024];
89
char buf[512], ch;
85
int r;
90
int r, pos;
86
 
91
 
87
	if (!pos || fd_serial == -1 || !initialized)
92
	if (!initialized)
88
		return 100.0;
93
		return;
89
 
94
 
90
	if ((r = read(fd_serial, &hv0[0], sizeof(hv0))) <= 0)
-
 
91
	{
-
 
92
		if (r < 0)
95
	pos = 0;
93
			syslog(LOG_DAEMON, "Error reading serial device <%s>: %s", Configure.serial, strerror(errno));
-
 
94
 
96
 
-
 
97
	while (!stop)
-
 
98
	{
-
 
99
		if ((r = read(fd_serial, &ch, 1)) <= 0)
-
 
100
		{
-
 
101
			if (r < 0)
-
 
102
				syslog(LOG_DAEMON, "Error reading serial device <%s>: %s", Configure.serial, strerror(errno));
-
 
103
 
-
 
104
			sleep(1);
-
 
105
			continue;
-
 
106
		}
-
 
107
 
-
 
108
		if (pos < (sizeof(buf) - 1))
-
 
109
		{
-
 
110
			buf[pos] = ch;
-
 
111
			buf[pos+1] = 0;
-
 
112
			pos++;
-
 
113
 
-
 
114
			if (ch == 0x0d)
-
 
115
			{
-
 
116
				if (strstr(buf, "Templog 2.5") != NULL)
-
 
117
				{
-
 
118
					ch = '1';
-
 
119
					write (fd_serial, &ch, 1);
-
 
120
				}
-
 
121
				else if (isdigit(buf[0]))
-
 
122
				{
-
 
123
					string temps = buf;
-
 
124
					vector<string> s = split(temps, ' ');
-
 
125
 
-
 
126
					if (outPos != 0 && outPos <= s.size())
-
 
127
						outside = strtod(s.at(outPos - 1).c_str(), NULL);
-
 
128
					// save all temperatures
-
 
129
					for (int i = 0; i < s.size(); i++)
-
 
130
						allTemps[i] = strtod(s.at(i).c_str(), NULL);
-
 
131
				}
-
 
132
 
95
		return 100.0;
133
				pos = 0;
-
 
134
			}
-
 
135
		}
96
	}
136
	}
97
 
137
 
98
	buffer.append(hv0);
138
	stop = false;
-
 
139
}
99
 
140
 
100
	if (buffer.find('\x0d') != string::npos)
141
double temperature::getTemp (int pos)
101
	{
142
{
102
		string temps = buffer.substr(buffer.find('\x0d') - 1);
-
 
103
		buffer.erase(0, buffer.find('\x0d'));
-
 
104
		vector<string> s = split(temps, ' ');
143
	if (pos <= MAX_TEMPS)
105
		return strtod(s.at(pos - 1).c_str(), NULL);
144
		return allTemps[pos-1];
106
	}
-
 
107
 
145
 
108
	return 100.0;
146
	return 100.0;
109
}
147
}
110
 
148