Add usleep to strain.c just in case...
[matches/MCTX3420.git] / server / actuator.h
1 /**
2  * @file actuator.h
3  * @brief Declarations for actuator control
4  */
5
6 #ifndef _ACTUATOR_H
7 #define _ACTUATOR_H
8
9 #include "common.h"
10 #include "data.h"
11 #include "device.h"
12
13
14 /** 
15  * Maximum number of actuators program can be compiled with
16  * (If you get an error "Increase ACTUATORS_MAX from %d" this is what it refers to)
17  */
18 #define ACTUATORS_MAX 5
19 extern int g_num_actuators; // in actuator.c
20
21
22
23 /** Control structure for Actuator setting **/
24 typedef struct
25 {
26         //TODO: Add functionality as needed
27         // Currently implements a simple piecewise step increase
28         // Would be cool to have a function specified as a string... eg: "1.0 + 0.5*s^2" with "s" the step number, and then give "stepwait" and "steps"
29         //      ... But that, like so many things, is probably overkill
30         /** Current value of Actuator **/
31         double start;
32         /** Time to maintain Actuator at each value **/
33         double stepwait;
34         /**     Amount to increase/decrease Actuator on each step **/
35         double stepsize;
36         /** Number of steps still to perform **/
37         int steps; // Note that after it is first set, this will be decremented until it is zero
38
39 } ActuatorControl;
40
41 typedef struct
42 {
43         /** ID number of the actuator **/
44         int id;
45         /** User ID number **/
46         int user_id;
47         /** Name **/
48         const char * name;
49         /** Control parameters for the Actuator **/
50         ActuatorControl control;
51         /** Flag indicates if ActuatorControl has been changed **/
52         bool control_changed;
53         /** DataFile to store actuator settings **/
54         DataFile data_file;
55         /** Thread the Actuator is controlled by **/
56         pthread_t thread;
57         /** Mutex around ActuatorControl **/
58         pthread_mutex_t mutex;
59         /** Used to wake up Actuator control thread **/
60         pthread_cond_t cond;
61         /** Indicates whether the Actuator is running **/
62         bool activated;
63         /** Initialisation function **/
64         InitFn init;
65         /** Set function **/
66         SetFn set;
67         /** Sanity check function **/
68         SanityFn sanity;
69         /** Cleanup function **/
70         CleanFn cleanup;
71         /** Last setting **/
72         DataPoint last_setting;
73         
74 } Actuator;
75
76 extern void Actuator_Init(); // One off initialisation of *all* Actuators
77 extern void Actuator_Cleanup();
78
79 extern void Actuator_SetModeAll(ControlModes mode, void *arg);
80 extern void Actuator_SetMode(Actuator * a, ControlModes mode, void *arg);
81
82 extern void * Actuator_Loop(void * args); // Main loop for a thread that handles an Actuator
83 extern void Actuator_SetValue(Actuator * a, double value, bool record); // Set an actuator by value
84 extern void Actuator_SetControl(Actuator * a, ActuatorControl * c); // Set the control for an Actuator
85 extern Actuator * Actuator_Identify(const char * str); // Identify a Sensor from a string Id
86
87 extern void Actuator_Handler(FCGIContext *context, char * params); // Handle a FCGI request for Actuator control
88 extern const char * Actuator_GetName(int id);
89 extern DataPoint Actuator_LastData(int id);
90
91 #endif //_ACTUATOR_H
92
93 //EOF

UCC git Repository :: git.ucc.asn.au