try to make things work on 64 bit systems
Annotate for file test/demo/demo.st
2010-02-26 benjamin.fra 1 /* demo.st,v 1.1.1.2 2000/04/25 19:15:14 wlupton Exp
2000-04-04 William 2 *
03:23:15 ' 3 * Demo EPICS sequence
' 4 */
' 5
' 6 #define PRINTF seqLog
' 7
' 8 /* message system choice */
' 9 #ifdef KTL
' 10
' 11 #define PVSYS "pvsys=ktl"
' 12
2000-04-25 William 13 #define LIGHT "demo.light"
19:15:14 ' 14 #define LIGHTON "demo.lighton"
' 15 #define LIGHTOFF "demo.lightoff"
' 16 #define VOLTAGE "demo.voltage"
' 17 #define LOLIMIT "demo.lolimit"
' 18 #define HILIMIT "demo.hilimit"
2000-04-04 William 19
03:23:15 ' 20 #else
' 21
' 22 #define PVSYS "pvsys=ca"
' 23
' 24 #define LIGHT "demo:light"
' 25 #define LIGHTON "demo:lightOn"
' 26 #define LIGHTOFF "demo:lightOff"
' 27 #define VOLTAGE "demo:voltage"
' 28 #define LOLIMIT "demo:loLimit"
' 29 #define HILIMIT "demo:hiLimit"
' 30
' 31 #endif
' 32
' 33 program demo( PVSYS ",debug=1" )
' 34
' 35 /* options */
' 36 option +r;
' 37
' 38 /* control variables and transition points for light control */
2011-04-06 ben.franksen 39 #if 0
18:59:29 ' 40 /* trying to assign a long variable now gives a compiler error on 64 bit systems */
2000-04-04 William 41 long light;
2011-04-06 ben.franksen 42 #endif
18:59:29 ' 43 int light;
2000-04-04 William 44 assign light to LIGHT;
03:23:15 ' 45
' 46 double lightOn;
' 47 assign lightOn to LIGHTON;
' 48 monitor lightOn;
' 49
' 50 double lightOff;
' 51 assign lightOff to LIGHTOFF;
' 52 monitor lightOff;
' 53
' 54 /* control variables and limits for voltage control */
' 55 double voltage;
' 56 assign voltage to VOLTAGE;
' 57 monitor voltage;
' 58
' 59 double loLimit;
' 60 assign loLimit to LOLIMIT;
' 61 monitor loLimit;
' 62 evflag loFlag;
' 63 sync loLimit to loFlag;
' 64
' 65 double hiLimit;
' 66 assign hiLimit to HILIMIT;
' 67 monitor hiLimit;
' 68 evflag hiFlag;
' 69 sync hiLimit to hiFlag;
' 70
' 71 #if 0
' 72 double x[2][100];
' 73 assign x to {"apple", "orange"};
' 74 monitor x;
' 75 evflag xFlag;
' 76 sync x[0] xFlag;
' 77
' 78 %%TS_STAMP t;
' 79 long i;
' 80 #endif
' 81
' 82 /* temporary timer stuff */
' 83 #if 0
' 84 double frac;
' 85 long done;
' 86 %%void doStuff( double frac );
' 87 %%double getFractionalSecond();
' 88 #endif
' 89
' 90 /* entry handler (called in context of first state-set before other threads
' 91 are created) */
' 92 entry {
' 93 #if defined( UNIX ) && TRUE
' 94 %%#include "logClient.h"
' 95 iocLogInit();
' 96 #endif
' 97 }
' 98
' 99 /* light control state-set */
' 100 ss light {
' 101 state START {
' 102 when () {
' 103 light = 0;
' 104 pvPut( light );
' 105 } state LIGHT_OFF
' 106 }
' 107
' 108 state LIGHT_OFF {
' 109 when ( voltage > lightOn ) {
' 110 light = 1;
' 111 pvPut( light );
' 112 PRINTF( "light_off -> light_on\n" );
' 113 } state LIGHT_ON
' 114 }
' 115
' 116 state LIGHT_ON {
' 117 when ( voltage < lightOff ) {
' 118 light = 0;
' 119 pvPut( light );
' 120 PRINTF( "light_on -> light_off\n" );
' 121 } state LIGHT_OFF
' 122 }
' 123 }
' 124
' 125 /* voltage ramp state set */
' 126 ss ramp {
' 127 state START {
' 128 when () {
' 129 voltage = loLimit;
' 130 pvPut( voltage );
' 131 PRINTF("start -> ramp_up\n");
' 132 } state RAMP_UP
' 133 }
' 134
' 135 state RAMP_UP {
' 136 when ( voltage > hiLimit ) {
' 137 PRINTF("ramp_up -> ramp_down\n");
' 138 } state RAMP_DOWN
' 139
' 140 when ( delay( 0.1 ) ) {
' 141 voltage += 0.1;
' 142 if ( pvPut( voltage ) < 0 )
' 143 PRINTF( "pvPut( voltage ) failed\n" );
' 144 /* PRINTF( "voltage increment\n" ); */
' 145 } state RAMP_UP
' 146 }
' 147
' 148 state RAMP_DOWN {
' 149 when ( voltage < loLimit ) {
' 150 PRINTF("ramp_down -> ramp_up\n");
' 151 } state RAMP_UP
' 152
' 153 when ( delay( 0.1 ) ) {
' 154 voltage -= 0.1;
' 155 if ( pvPut( voltage ) < 0 )
' 156 PRINTF( "pvPut( voltage ) failed\n" );
' 157 /* PRINTF( "voltage decrement\n" ); */
' 158 } state RAMP_DOWN
' 159 }
' 160 }
' 161
' 162 /* hi / lo limit constraint state set */
' 163 ss limit {
' 164 state START {
' 165 when ( efTestAndClear( loFlag ) && loLimit > hiLimit ) {
' 166 hiLimit = loLimit;
' 167 pvPut( hiLimit );
' 168 } state START
' 169
' 170 when ( efTestAndClear( hiFlag ) && hiLimit < loLimit ) {
' 171 loLimit = hiLimit;
' 172 pvPut( loLimit );
' 173 } state START
' 174 }
' 175 }
' 176
' 177 #if 0
' 178 /* apples and oranges */
' 179 ss apples {
' 180 state init {
' 181 when ( efTestAndClear( xFlag ) ) {
' 182 PRINTF( "xFlag\n" );
' 183 for ( i = 0; i < 100; i++ )
' 184 x[1][i] = x[0][i] + 2;
' 185 pvPut( x[1] );
' 186 if ( pvStatus( x[0] ) == pvStatOK ) {
' 187 t = pvTimeStamp( x[0] );
' 188 printf( "status=%d, severity=%d, timestamp=%d %d\n",
' 189 pvStatus( x[0] ), pvSeverity( x[0] ),
' 190 t.secPastEpoch, t.nsec );
' 191 }
' 192 } state init
' 193 }
' 194 }
' 195 #endif
' 196
' 197 #if 0
' 198 /* test timers */
' 199 ss timer {
' 200
' 201 state START {
' 202 when () {
' 203 frac = 0.0;
' 204 done = FALSE;
' 205 } state POLL
' 206 }
' 207
' 208 state POLL {
' 209 when ( delay( 0.1 ) ) {
' 210 frac = getFractionalSecond();
' 211 } state POLL
' 212
' 213 when ( !done && frac >= 0.5 ) {
' 214 doStuff( frac );
' 215 done = TRUE;
' 216 } state POLL
' 217
' 218 when ( done && frac < 0.5 ) {
' 219 done = FALSE;
' 220 } state DONE
' 221 }
' 222 }
' 223
' 224 %%#include <sys/time.h>
' 225
' 226 %{
' 227
' 228 double getFractionalSecond() {
' 229 struct timeval tv;
' 230 ( void ) gettimeofday( &tv, NULL );
' 231 return ( ( double ) tv.tv_usec ) / 1e6;
' 232 }
' 233
' 234 void doStuff( double frac ) {
' 235 printf( "doStuff at frac = %g\n", frac );
' 236 }
' 237
' 238 }%
' 239 #endif