X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Factuator.c;h=2caa03c513560f5b5b2b3819562e789a973870bf;hb=9e7cfbbc6137056bba8ed8644fc6ecfe398553fe;hp=ff51732bb38861b227b05d1f3f284c5931a82d88;hpb=7284f69ded90441c34efb8f86a515ef399d3ccf3;p=matches%2FMCTX3420.git diff --git a/server/actuator.c b/server/actuator.c index ff51732..2caa03c 100644 --- a/server/actuator.c +++ b/server/actuator.c @@ -4,6 +4,7 @@ */ #include "actuator.h" +#include "control.h" #include "options.h" /** Array of Actuators (global to this file) initialised by Actuator_Init **/ @@ -53,6 +54,25 @@ void Actuator_Start(Actuator * a, const char * experiment_name) pthread_create(&(a->thread), NULL, Actuator_Loop, (void*)(a)); } +void Actuator_Pause(Actuator *a) +{ + if (a->activated) + { + a->activated = false; + Actuator_SetControl(a, NULL); + pthread_join(a->thread, NULL); // Wait for thread to exit + } +} + +void Actuator_Resume(Actuator *a) +{ + if (!a->activated) + { + a->activated = true; + pthread_create(&(a->thread), NULL, Actuator_Loop, (void*)(a)); + } +} + /** * Stop an Actuator * @param s - The Actuator to stop @@ -60,13 +80,23 @@ void Actuator_Start(Actuator * a, const char * experiment_name) void Actuator_Stop(Actuator * a) { // Stop - a->activated = false; - Actuator_SetControl(a, NULL); - pthread_join(a->thread, NULL); // Wait for thread to exit + Actuator_Pause(a); Data_Close(&(a->data_file)); // Close DataFile } +void Actuator_PauseAll() +{ + for (int i = 0; i < NUMACTUATORS; ++i) + Actuator_Pause(g_actuators+i); +} + +void Actuator_ResumeAll() +{ + for (int i = 0; i < NUMACTUATORS; ++i) + Actuator_Resume(g_actuators+i); +} + /** * Stop all Actuators */ @@ -143,7 +173,7 @@ void Actuator_SetValue(Actuator * a, double value) struct timeval t; gettimeofday(&t, NULL); - DataPoint d = {TIMEVAL_DIFF(t, g_options.start_time), value}; + DataPoint d = {TIMEVAL_DIFF(t, *Control_GetStartTime()), value}; //TODO: Set actuator switch (a->id) { @@ -211,7 +241,7 @@ void Actuator_Handler(FCGIContext * context, char * params) { struct timeval now; gettimeofday(&now, NULL); - double current_time = TIMEVAL_DIFF(now, g_options.start_time); + double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime()); int id = 0; double set = 0; double start_time = 0;