X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Factuator.c;h=f2ab4fec0f6771a3f78e2cf3f0be1aac5b68afab;hb=5a9a05166c4b22e7b7a522063d3dd6f75d1fa589;hp=e650cf88c5a877a4a08608dabe03e378617ca80a;hpb=450583abb79d5fedb0debabed073d9b191dac80c;p=matches%2FMCTX3420.git diff --git a/server/actuator.c b/server/actuator.c index e650cf8..f2ab4fe 100644 --- a/server/actuator.c +++ b/server/actuator.c @@ -36,12 +36,17 @@ int Actuator_Add(const char * name, int user_id, SetFn set, InitFn init, CleanFn a->name = name; a->set = set; // Set read function a->init = init; // Set init function - if (init != NULL) - init(name, user_id); // Call it + a->sanity = sanity; pthread_mutex_init(&(a->mutex), NULL); + if (init != NULL) + { + if (!init(name, user_id)) + Fatal("Couldn't initialise actuator %s", name); + } + Actuator_SetValue(a, initial_value, false); return g_num_actuators; @@ -164,9 +169,12 @@ void * Actuator_Loop(void * arg) Actuator_SetValue(a, a->control.start, true); // Currently does discrete steps after specified time intervals + + struct timespec wait; + DOUBLE_TO_TIMEVAL(a->control.stepsize, &wait); while (!a->control_changed && a->control.steps > 0 && a->activated) { - usleep(1e6*(a->control.stepwait)); + clock_nanosleep(CLOCK_MONOTONIC, 0, &wait, NULL); a->control.start += a->control.stepsize; Actuator_SetValue(a, a->control.start, true); @@ -174,7 +182,7 @@ void * Actuator_Loop(void * arg) } if (a->control_changed) continue; - usleep(1e6*(a->control.stepwait)); + clock_nanosleep(CLOCK_MONOTONIC, 0, &wait, NULL); //TODO: // Note that although this loop has a sleep in it which would seem to make it hard to enforce urgent shutdowns, @@ -224,8 +232,8 @@ void Actuator_SetValue(Actuator * a, double value, bool record) } // Set time stamp - struct timeval t; - gettimeofday(&t, NULL); + struct timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); DataPoint d = {TIMEVAL_DIFF(t, *Control_GetStartTime()), a->last_setting.value}; // Record value change if (record) @@ -289,8 +297,8 @@ void Actuator_EndResponse(FCGIContext * context, Actuator * a, DataFormat format */ void Actuator_Handler(FCGIContext * context, char * params) { - struct timeval now; - gettimeofday(&now, NULL); + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime()); int id = 0; char * name = "";