/* C code for program sncKepco, generated by snc from ../sncKepco.st */ #include #include #include #include #include "seq_snc.h" # line 16 "../sncKepco.st" #include # line 17 "../sncKepco.st" #include # line 18 "../sncKepco.st" #include # line 19 "../sncKepco.st" #include # line 20 "../sncKepco.st" #include /* Variable declarations */ struct seqg_vars { # line 26 "../sncKepco.st" float iPV; # line 29 "../sncKepco.st" float vPV; # line 32 "../sncKepco.st" short pause; # line 36 "../sncKepco.st" char *hostname; # line 37 "../sncKepco.st" int *pI; # line 38 "../sncKepco.st" int *pV; }; /* Function declarations */ #define seqg_var (*(struct seqg_vars *const *)seqg_env) /* Program init func */ static void seqg_init(PROG_ID seqg_env) { } /****** Code for state "init" in state set "pollOrPause" ******/ /* Event function for state "init" in state set "pollOrPause" */ static seqBool seqg_event_pollOrPause_0_init(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { if (TRUE) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "init" in state set "pollOrPause" */ static void seqg_action_pollOrPause_0_init(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 47 "../sncKepco.st" seqg_var->hostname = seq_macValueGet(seqg_env, "NETNAME"); # line 48 "../sncKepco.st" if (1) # line 48 "../sncKepco.st" printf("pollOrPause state init: host name = %s\n", seqg_var->hostname); } return; } } /****** Code for state "polling" in state set "pollOrPause" ******/ /* Event function for state "polling" in state set "pollOrPause" */ static seqBool seqg_event_pollOrPause_0_polling(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 54 "../sncKepco.st" if (!seqg_var->pause && seq_delay(seqg_env, 2.0)) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } # line 108 "../sncKepco.st" if (seqg_var->pause) { *seqg_pnst = 2; *seqg_ptrn = 1; return TRUE; } return FALSE; } /* Action function for state "polling" in state set "pollOrPause" */ static void seqg_action_pollOrPause_0_polling(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 56 "../sncKepco.st" if (1) # line 56 "../sncKepco.st" printf("pollOrPause state polling entered\n"); struct sockaddr_in device; struct hostent *hp; int sd; int n; char rbuf[64]; float val; sd = socket (AF_INET,SOCK_STREAM,0); if(1) printf("pollOrPause state polling created socket %d\n", sd); device.sin_family = AF_INET; hp = gethostbyname(pVar->hostname); memcpy(&device.sin_addr, hp->h_addr_list[0], hp->h_length); device.sin_port = htons(5025); if(connect(sd, (struct sockaddr *) &device, sizeof(device))) { printf("Failed to connect to %s\n", pVar->hostname); } else { if(1) printf("pollOrPause state polling connect to %s\n", pVar->hostname); n = send(sd, "MEAS:VOLT?\r\n", 12, 0 ); if(1) printf("pollOrPause state polling sent %d characters\n", n); n = recv(sd, rbuf, sizeof(rbuf), 0); rbuf[n] = 0; if(1) printf("pollOrPause state polling received %d characters: %s\n", n, rbuf); sscanf(rbuf,"%f",&val); pVar->vPV = val; n = send(sd, "MEAS:CURR?\r\n", 12, 0 ); if(1) printf("pollOrPause state polling sent %d characters\n", n); n = recv(sd, rbuf, sizeof(rbuf), 0); rbuf[n] = 0; if(1) printf("pollOrPause state polling received %d characters: %s\n", n, rbuf); sscanf(rbuf,"%f",&val); pVar->iPV = val; send(sd, "SYST:KLOC OFF\r\n", 15, 0 ); close(sd); if(1) printf("pollOrPause state polling closed network connection\n"); } # line 104 "../sncKepco.st" seq_pvPutTmo(seqg_env, 1/*vPV*/, DEFAULT, DEFAULT_TIMEOUT); # line 105 "../sncKepco.st" seq_pvPutTmo(seqg_env, 0/*iPV*/, DEFAULT, DEFAULT_TIMEOUT); } return; case 1: { # line 110 "../sncKepco.st" if (1) # line 110 "../sncKepco.st" printf("pollOrPause state polling going to paused\n"); } return; } } /****** Code for state "paused" in state set "pollOrPause" ******/ /* Event function for state "paused" in state set "pollOrPause" */ static seqBool seqg_event_pollOrPause_0_paused(SS_ID seqg_env, int *seqg_ptrn, int *seqg_pnst) { # line 116 "../sncKepco.st" if (!seqg_var->pause) { *seqg_pnst = 1; *seqg_ptrn = 0; return TRUE; } return FALSE; } /* Action function for state "paused" in state set "pollOrPause" */ static void seqg_action_pollOrPause_0_paused(SS_ID seqg_env, int seqg_trn, int *seqg_pnst) { switch(seqg_trn) { case 0: { # line 118 "../sncKepco.st" if (1) # line 118 "../sncKepco.st" printf("pollOrPause state paused going to polling\n"); } return; } } #undef seqg_var /************************ Tables ************************/ /* Channel table */ static seqChan seqg_chans[] = { /* chName, offset, varName, varType, count, eventNum, efId, monitored, queueSize, queueIndex */ {"{DEV}I{INST}", offsetof(struct seqg_vars, iPV), "iPV", P_FLOAT, 1, 1, 0, 0, 0, 0}, {"{DEV}V{INST}", offsetof(struct seqg_vars, vPV), "vPV", P_FLOAT, 1, 2, 0, 0, 0, 0}, {"{DEV}PAUSE{INST}", offsetof(struct seqg_vars, pause), "pause", P_SHORT, 1, 3, 0, 1, 0, 0}, }; /* Event masks for state set "pollOrPause" */ static const seqMask seqg_mask_pollOrPause_0_init[] = { 0x00000000, }; static const seqMask seqg_mask_pollOrPause_0_polling[] = { 0x00000008, }; static const seqMask seqg_mask_pollOrPause_0_paused[] = { 0x00000008, }; /* State table for state set "pollOrPause" */ static seqState seqg_states_pollOrPause[] = { { /* state name */ "init", /* action function */ seqg_action_pollOrPause_0_init, /* event function */ seqg_event_pollOrPause_0_init, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_pollOrPause_0_init, /* state options */ (0) }, { /* state name */ "polling", /* action function */ seqg_action_pollOrPause_0_polling, /* event function */ seqg_event_pollOrPause_0_polling, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_pollOrPause_0_polling, /* state options */ (0) }, { /* state name */ "paused", /* action function */ seqg_action_pollOrPause_0_paused, /* event function */ seqg_event_pollOrPause_0_paused, /* entry function */ 0, /* exit function */ 0, /* event mask array */ seqg_mask_pollOrPause_0_paused, /* state options */ (0) }, }; /* State set table */ static seqSS seqg_statesets[] = { { /* state set name */ "pollOrPause", /* states */ seqg_states_pollOrPause, /* number of states */ 3 }, }; /* Program table (global) */ seqProgram sncKepco = { /* magic number */ 2002004, /* program name */ "sncKepco", /* channels */ seqg_chans, /* num. channels */ 3, /* state sets */ seqg_statesets, /* num. state sets */ 1, /* user var size */ sizeof(struct seqg_vars), /* param */ "", /* num. event flags */ 0, /* encoded options */ (0 | OPT_CONN | OPT_DEBUG | OPT_NEWEF | OPT_REENT), /* init func */ seqg_init, /* entry func */ 0, /* exit func */ 0, /* num. queues */ 0 }; /* Register sequencer commands and program */ #include "epicsExport.h" static void sncKepcoRegistrar (void) { seqRegisterSequencerCommands(); seqRegisterSequencerProgram (&sncKepco); } epicsExportRegistrar(sncKepcoRegistrar);