Added external measure command
This commit is contained in:
+39
-7
@@ -8,19 +8,36 @@
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/io.h>
|
||||
#include <errno.h>
|
||||
#include <cmath>
|
||||
#include <stdio.h>
|
||||
|
||||
const int BASE_DEFAULT = 0x3BC;
|
||||
|
||||
void temperature_update()
|
||||
string Read(FILE *f)
|
||||
{
|
||||
char buffer[256];
|
||||
string result = "";
|
||||
while (fgets(buffer, sizeof(buffer), f) != nullptr)
|
||||
{
|
||||
result += buffer;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void temperature_update(const string &cmd)
|
||||
{
|
||||
// other helper variables
|
||||
float temperature = 1.5;
|
||||
auto output = popen(cmd.c_str(), "r");
|
||||
if (output == nullptr) return;
|
||||
string value = Read(output);
|
||||
pclose(output);
|
||||
temperature = atof(value.c_str());
|
||||
|
||||
registers[REGISTER_CUR_TEMP] = (int)(temperature * 100);
|
||||
float additional_temperature = 2.5;
|
||||
registers[REGISTER_SECONDARY_TEMP] = (int)(additional_temperature * 100);
|
||||
|
||||
registers[REGISTER_SECONDARY_TEMP] = (int)(temperature * 100);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -40,10 +57,25 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
// load config
|
||||
ConfigParser cfg;
|
||||
cfg.Load(argv[1] );
|
||||
cfg.Load(argv[1]);
|
||||
mainlog.InitLogging(cfg.GetParam("LogPath"), LIBLOGSINGLEFILE, "defrost", true);
|
||||
mainlog.LogString("Defrost service started");
|
||||
|
||||
int port_base = BASE_DEFAULT;
|
||||
auto port_address = cfg.GetParamSilent("PortAddress");
|
||||
if (port_address != "")
|
||||
{
|
||||
port_base = atoi(port_address.c_str());
|
||||
}
|
||||
|
||||
if (ioperm(port_base, 1, 1))
|
||||
{
|
||||
mainlog.LogString("Access to port denied");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
string measure_command = cfg.GetParam("MeasureCommand");
|
||||
|
||||
if (pthread_mutex_init(®ister_mutex, NULL) != 0)
|
||||
{
|
||||
mainlog.LogString("Unable to create registers_mutex");
|
||||
@@ -62,7 +94,7 @@ int main(int argc, char *argv[])
|
||||
while (true)
|
||||
{
|
||||
LockMutex(register_mutex);
|
||||
temperature_update();
|
||||
temperature_update(measure_command);
|
||||
int mode = registers[REGISTER_MODE];
|
||||
if (mode == 0)
|
||||
{
|
||||
@@ -74,7 +106,7 @@ int main(int argc, char *argv[])
|
||||
io_value = registers[REGISTER_CUR_STATE];
|
||||
}
|
||||
registers[REGISTER_CUR_STATE] = io_value;
|
||||
//gpio.write(io_value);
|
||||
outb(io_value, port_base);
|
||||
ReleaseMutex(register_mutex);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user