git.ucc.asn.au
/
matches
/
MCTX3420.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of github:szmoore/MCTX3420
[matches/MCTX3420.git]
/
server
/
actuator.c
diff --git
a/server/actuator.c
b/server/actuator.c
index
9b9a1a8
..
1c105db
100644
(file)
--- a/
server/actuator.c
+++ b/
server/actuator.c
@@
-8,9
+8,6
@@
// Files containing GPIO and PWM definitions
#include "bbb_pin.h"
// Files containing GPIO and PWM definitions
#include "bbb_pin.h"
-
-
-
/** Number of actuators **/
int g_num_actuators = 0;
/** Number of actuators **/
int g_num_actuators = 0;
@@
-79,12
+76,17
@@
void Actuator_SetMode(Actuator * a, ControlModes mode, void *arg)
{
case CONTROL_START:
{
{
case CONTROL_START:
{
+ // Set filename
char filename[BUFSIZ];
char filename[BUFSIZ];
- const char *experiment_name = (const char*) arg;
+ const char *experiment_path = (const char*) arg;
+ int ret;
+
+ ret = snprintf(filename, BUFSIZ, "%s/actuator_%d", experiment_path, a->id);
- if (
snprintf(filename, BUFSIZ, "%s_a%d", experiment_name, a->id) >= BUFSIZ)
+ if (
ret >= BUFSIZ)
{
{
- Fatal("Experiment name \"%s\" too long (>%d)", experiment_name, BUFSIZ);
+ Fatal("Experiment path \"%s\" too long (%d, limit %d)",
+ experiment_path, ret, BUFSIZ);
}
Log(LOGDEBUG, "Actuator %d with DataFile \"%s\"", a->id, filename);
}
Log(LOGDEBUG, "Actuator %d with DataFile \"%s\"", a->id, filename);
@@
-141,7
+143,7
@@
void Actuator_SetMode(Actuator * a, ControlModes mode, void *arg)
*/
void Actuator_SetModeAll(ControlModes mode, void * arg)
{
*/
void Actuator_SetModeAll(ControlModes mode, void * arg)
{
- for (int i = 0; i <
ACTUATORS_MAX
; i++)
+ for (int i = 0; i <
g_num_actuators
; i++)
Actuator_SetMode(&g_actuators[i], mode, arg);
}
Actuator_SetMode(&g_actuators[i], mode, arg);
}
@@
-169,9
+171,12
@@
void * Actuator_Loop(void * arg)
Actuator_SetValue(a, a->control.start, true);
// Currently does discrete steps after specified time intervals
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)
{
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);
a->control.start += a->control.stepsize;
Actuator_SetValue(a, a->control.start, true);
@@
-179,7
+184,7
@@
void * Actuator_Loop(void * arg)
}
if (a->control_changed)
continue;
}
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,
//TODO:
// Note that although this loop has a sleep in it which would seem to make it hard to enforce urgent shutdowns,
@@
-229,8
+234,8
@@
void Actuator_SetValue(Actuator * a, double value, bool record)
}
// Set time stamp
}
// Set time stamp
- struct time
val
t;
-
gettimeofday(&t, NULL
);
+ struct time
spec
t;
+
clock_gettime(CLOCK_MONOTONIC, &t
);
DataPoint d = {TIMEVAL_DIFF(t, *Control_GetStartTime()), a->last_setting.value};
// Record value change
if (record)
DataPoint d = {TIMEVAL_DIFF(t, *Control_GetStartTime()), a->last_setting.value};
// Record value change
if (record)
@@
-294,8
+299,8
@@
void Actuator_EndResponse(FCGIContext * context, Actuator * a, DataFormat format
*/
void Actuator_Handler(FCGIContext * context, char * params)
{
*/
void Actuator_Handler(FCGIContext * context, char * params)
{
- struct time
val
now;
-
gettimeofday(&now, NULL
);
+ struct time
spec
now;
+
clock_gettime(CLOCK_MONOTONIC, &now
);
double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime());
int id = 0;
char * name = "";
double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime());
int id = 0;
char * name = "";
UCC
git Repository :: git.ucc.asn.au