Commit b497960f authored by claes's avatar claes

Soft restart

parent 06a43bd8
...@@ -58,6 +58,9 @@ ...@@ -58,6 +58,9 @@
#include "co_time.h" #include "co_time.h"
#include "rt_gdh.h" #include "rt_gdh.h"
#include "rt_errh.h" #include "rt_errh.h"
#include "rt_qcom.h"
#include "rt_ini_event.h"
#include "rt_qcom_msg.h"
#include "rt_mh_msg.h" #include "rt_mh_msg.h"
#include "rt_mh_net.h" #include "rt_mh_net.h"
#include "rt_mh_appl.h" #include "rt_mh_appl.h"
...@@ -274,6 +277,9 @@ static int nmpstrans_request_data( trans_ctx transctx, ...@@ -274,6 +277,9 @@ static int nmpstrans_request_data( trans_ctx transctx,
int position, int position,
translist_t_entry **translist_list, translist_t_entry **translist_list,
nmpstrans_t_req_list *req_ptr); nmpstrans_t_req_list *req_ptr);
static void nmpstrans_reqlist_close( trans_ctx transctx);
static void nmpstrans_rcvlist_close( trans_ctx transctx);
static void nmpstrans_sndlist_close( trans_ctx transctx);
static pwr_tStatus nmpstrans_reqlist_add( static pwr_tStatus nmpstrans_reqlist_add(
trans_ctx transctx, trans_ctx transctx,
pwr_tObjid objid, pwr_tObjid objid,
...@@ -298,7 +304,6 @@ static int nmpstrans_send_datasend( trans_ctx transctx, ...@@ -298,7 +304,6 @@ static int nmpstrans_send_datasend( trans_ctx transctx,
translist_t_entry **translist_list, translist_t_entry **translist_list,
nmpstrans_t_snd_list *snd_ptr); nmpstrans_t_snd_list *snd_ptr);
static pwr_tStatus nmpstrans_trans_handler( trans_ctx transctx); static pwr_tStatus nmpstrans_trans_handler( trans_ctx transctx);
static pwr_tStatus nmpstrans_free( trans_ctx transctx);
static int nmpstrans_connect_alarm(); static int nmpstrans_connect_alarm();
static int nmpstrans_alarm_send( static int nmpstrans_alarm_send(
char *alarm_text, char *alarm_text,
...@@ -1534,6 +1539,43 @@ static int nmpstrans_rcv_reset_detected( trans_ctx transctx, ...@@ -1534,6 +1539,43 @@ static int nmpstrans_rcv_reset_detected( trans_ctx transctx,
/****************************************************************************
* Name: nmpstrans_reqlist_close()
*
* Type void
*
* Type Parameter IOGF Description
*
* Description:
* Unref and free reqlist.
*
**************************************************************************/
static void nmpstrans_reqlist_close( trans_ctx transctx)
{
nmpstrans_t_req_list *reqlist_ptr;
int i;
pwr_tStatus sts;
reqlist_ptr = transctx->reqlist;
for ( i = 0; i < transctx->req_count; i++) {
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->subid);
if ( reqlist_ptr->req->Function & NMPS_REQUESTFUNC_DISPLAYOBJECT)
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->display_object_subid);
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->send_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->send_remtransbuff_subid);
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->rcv_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->rcv_remtransbuff_subid);
if ( reqlist_ptr->req->Function & NMPS_REQUESTFUNC_CELLINSERT)
sts = gdh_DLUnrefObjectInfo( reqlist_ptr->cell_subid);
free( reqlist_ptr->conv_table);
reqlist_ptr->conv_table = 0;
reqlist_ptr++;
}
free( transctx->reqlist);
transctx->reqlist = 0;
transctx->req_count = 0;
}
/**************************************************************************** /****************************************************************************
* Name: nmpstrans_reqlist_add() * Name: nmpstrans_reqlist_add()
...@@ -1724,6 +1766,46 @@ static pwr_tStatus nmpstrans_reqlist_add( ...@@ -1724,6 +1766,46 @@ static pwr_tStatus nmpstrans_reqlist_add(
return NMPS__SUCCESS; return NMPS__SUCCESS;
} }
/****************************************************************************
* Name: nmpstrans_rcvlist_close()
*
* Type pwr_tStatus
*
* Type Parameter IOGF Description
*
* Description:
* Unref and free the rcvlist.
*
**************************************************************************/
static void nmpstrans_rcvlist_close( trans_ctx transctx)
{
nmpstrans_t_rcv_list *rcvlist_ptr;
int i;
pwr_tStatus sts;
rcvlist_ptr = transctx->rcvlist;
for ( i = 0; i < transctx->rcv_count; i++) {
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->subid);
if ( rcvlist_ptr->rcv->Function & NMPS_DATARCVFUNC_DISPLAYOBJECT)
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->display_object_subid);
if ( rcvlist_ptr->rcv->Function & NMPS_DATARCVFUNC_ACK) {
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->send_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->send_remtransbuff_subid);
}
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->rcv_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->rcv_remtransbuff_subid);
if ( rcvlist_ptr->rcv->Function & NMPS_DATARCVFUNC_CELLINSERT)
sts = gdh_DLUnrefObjectInfo( rcvlist_ptr->cell_subid);
free( rcvlist_ptr->conv_table);
rcvlist_ptr->conv_table = 0;
rcvlist_ptr++;
}
free( transctx->rcvlist);
transctx->rcvlist = 0;
transctx->rcv_count = 0;
}
/**************************************************************************** /****************************************************************************
* Name: nmpstrans_rcvlist_add() * Name: nmpstrans_rcvlist_add()
...@@ -1912,6 +1994,42 @@ static pwr_tStatus nmpstrans_rcvlist_add( ...@@ -1912,6 +1994,42 @@ static pwr_tStatus nmpstrans_rcvlist_add(
return NMPS__SUCCESS; return NMPS__SUCCESS;
} }
/****************************************************************************
* Name: nmpstrans_sndlist_close()
*
* Type void
*
* Type Parameter IOGF Description
*
* Description:
* Unref and free the sndlist.
*
**************************************************************************/
static void nmpstrans_sndlist_close( trans_ctx transctx)
{
nmpstrans_t_snd_list *sndlist_ptr;
int i;
pwr_tStatus sts;
sndlist_ptr = transctx->sndlist;
for ( i = 0; i < transctx->snd_count; i++) {
sts = gdh_DLUnrefObjectInfo( sndlist_ptr->subid);
sts = gdh_DLUnrefObjectInfo( sndlist_ptr->send_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( sndlist_ptr->send_remtransbuff_subid);
if ( sndlist_ptr->snd->Function & NMPS_DATASENDFUNC_ACK) {
sts = gdh_DLUnrefObjectInfo( sndlist_ptr->rcv_remtrans_subid);
sts = gdh_DLUnrefObjectInfo( sndlist_ptr->rcv_remtransbuff_subid);
}
free( sndlist_ptr->conv_table);
sndlist_ptr++;
}
free( transctx->sndlist);
transctx->sndlist = 0;
transctx->snd_count = 0;
}
/**************************************************************************** /****************************************************************************
* Name: nmpstrans_sndlist_add() * Name: nmpstrans_sndlist_add()
...@@ -2611,54 +2729,47 @@ static pwr_tStatus nmpstrans_trans_handler( trans_ctx transctx) ...@@ -2611,54 +2729,47 @@ static pwr_tStatus nmpstrans_trans_handler( trans_ctx transctx)
return NMPS__SUCCESS; return NMPS__SUCCESS;
} }
/****************************************************************************
* Name: nmpstrans_free()
*
* Type pwr_tStatus
*
* Type Parameter IOGF Description
*
* Description:
* Free the nmpstrans context.
*
**************************************************************************/
static pwr_tStatus nmpstrans_free( trans_ctx transctx)
{
nmpstrans_t_req_list *req_ptr;
int i;
/* Loop through the req objects */
req_ptr = transctx->reqlist;
for ( i = 0; i < transctx->req_count; i++)
{
free( req_ptr->conv_table);
req_ptr++;
}
free( transctx->reqlist);
free( transctx);
return NMPS__SUCCESS;
}
int main() int main()
{ {
trans_ctx transctx; trans_ctx transctx;
pwr_tStatus sts; pwr_tStatus sts;
float scantime; qcom_sQid qini;
qcom_sQattr qAttr;
int tmo;
char mp[2000];
qcom_sQid qid = qcom_cNQid;
qcom_sGet get;
int swap = 0;
/* Init pams and gdh */ /* Init pams and gdh */
sts = gdh_Init("rt_nmps_trans"); sts = gdh_Init("rs_nmps_trans");
if (EVEN(sts)) LogAndExit(sts) if (EVEN(sts)) LogAndExit(sts);
/* Init qcom and bind event que */
if (!qcom_Init(&sts, 0, "rs_nmps_trans")) {
errh_Fatal("qcom_Init, %m", sts);
exit(sts);
}
qAttr.type = qcom_eQtype_private;
qAttr.quota = 100;
if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
errh_Fatal("qcom_CreateQ, %m", sts);
exit(sts);
}
qini = qcom_cQini;
if (!qcom_Bind(&sts, &qid, &qini)) {
errh_Fatal("qcom_Bind(Qini), %m", sts);
exit(-1);
}
/* Wait for the plcpgm has flagged initizated */ /* Wait for the plcpgm has flagged initizated */
plc_UtlWaitForPlc(); plc_UtlWaitForPlc();
for (;;)
{
transctx = calloc( 1 , sizeof( *transctx)); transctx = calloc( 1 , sizeof( *transctx));
if ( transctx == 0 ) LogAndExit( NMPS__NOMEMORY) if ( transctx == 0 ) LogAndExit( NMPS__NOMEMORY);
sts = nmps_get_transconfig( transctx); sts = nmps_get_transconfig( transctx);
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
...@@ -2672,22 +2783,43 @@ int main() ...@@ -2672,22 +2783,43 @@ int main()
sts = nmpstrans_datasend_init( transctx); sts = nmpstrans_datasend_init( transctx);
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
for (;;) tmo = 1000 * transctx->transconfig->CycleTime - 1;
{
scantime = transctx->transconfig->CycleTime;
for (;;) {
get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get( &sts, &qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
if ( !swap) {
sts = nmpstrans_trans_handler( transctx); sts = nmpstrans_trans_handler( transctx);
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
transctx->transconfig->LoopCount++;
}
}
else {
ini_mEvent new_event;
qcom_sEvent *ep = (qcom_sEvent*) get.data;
new_event.m = ep->mask;
if (new_event.b.oldPlcStop && !swap) {
swap = 1;
nmpstrans_reqlist_close( transctx);
nmpstrans_rcvlist_close( transctx);
nmpstrans_sndlist_close( transctx);
} else if (new_event.b.swapDone && swap) {
swap = 0;
sts = nmpstrans_datareq_init( transctx);
if (EVEN(sts)) LogAndExit( sts);
sutl_sleep( scantime); sts = nmpstrans_datarcv_init( transctx);
if (EVEN(sts)) LogAndExit( sts);
if ( transctx->transconfig->Initialize) sts = nmpstrans_datasend_init( transctx);
{ if (EVEN(sts)) LogAndExit( sts);
transctx->transconfig->Initialize = 0;
nmpstrans_free( transctx); errh_Info("Warm restart completed");
break;
} }
transctx->transconfig->LoopCount++;
} }
} }
} }
...@@ -6,18 +6,9 @@ ...@@ -6,18 +6,9 @@
This file contains the access routines to the datastorage This file contains the access routines to the datastorage
of data to trendplot. */ of data to trendplot. */
#if defined OS_ELN #if defined OS_VMS
# include stdio
# include stdlib
# include signal
# include "rt_plc_loop.h"
#elif defined OS_VMS
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
# include <signal.h>
# include <descrip.h>
# include <starlet.h>
# include "rt_plc_loop.h"
#elif defined OS_LYNX || defined OS_LINUX #elif defined OS_LYNX || defined OS_LINUX
# include <stdio.h> # include <stdio.h>
# include <stdlib.h> # include <stdlib.h>
...@@ -37,6 +28,9 @@ ...@@ -37,6 +28,9 @@
#include "rt_gdh.h" #include "rt_gdh.h"
#include "rt_ds_msg.h" #include "rt_ds_msg.h"
#include "rt_gdh_msg.h" #include "rt_gdh_msg.h"
#include "rt_qcom_msg.h"
#include "rt_qcom.h"
#include "rt_ini_event.h"
#define Log_Error(a, b) errh_CErrLog(DS__ERROR, errh_ErrArgAF(b), errh_ErrArgMsg(a), NULL) #define Log_Error(a, b) errh_CErrLog(DS__ERROR, errh_ErrArgAF(b), errh_ErrArgMsg(a), NULL)
#define Log(b) errh_CErrLog(DS__LOG, errh_ErrArgAF(b), NULL) #define Log(b) errh_CErrLog(DS__LOG, errh_ErrArgAF(b), NULL)
...@@ -56,6 +50,7 @@ struct s_LstNode ...@@ -56,6 +50,7 @@ struct s_LstNode
static sLstNode *LstHead = NULL; static sLstNode *LstHead = NULL;
static pwr_tStatus InitTrendList(); static pwr_tStatus InitTrendList();
static void CloseTrendList();
static pwr_tBoolean IsValidType(pwr_eTix Type); static pwr_tBoolean IsValidType(pwr_eTix Type);
static void StoreData(); static void StoreData();
...@@ -66,27 +61,39 @@ int main (int argc, char **argv) ...@@ -66,27 +61,39 @@ int main (int argc, char **argv)
pwr_tObjid ObjId; pwr_tObjid ObjId;
pwr_sClass_DsTrendConf *TConfP; pwr_sClass_DsTrendConf *TConfP;
pwr_tBoolean InitOK; pwr_tBoolean InitOK;
pwr_tInt32 ScanTime = 1; /* Later it will be fetched from a pwr_tInt32 ScanTime = 1;
* configuration object.
*/
#ifdef OS_VMS
extern int plc_ConvMSToLI(pwr_tUInt32 Time, pwr_tVaxTime *TimeLI);
unsigned int TimerFlag;
pwr_tVaxTime DeltaTime;
#elif defined OS_ELN
pwr_tVaxTime NextTime;
pwr_tVaxTime DeltaTime;
#elif defined OS_LYNX || defined OS_LINUX
pwr_tTime CurrentTime, LastScan, NextScan; pwr_tTime CurrentTime, LastScan, NextScan;
pwr_tDeltaTime ScanDeltaTime, WaitTime; pwr_tDeltaTime ScanDeltaTime, WaitTime;
#endif qcom_sQid qini;
qcom_sQattr qAttr;
int tmo;
char mp[2000];
qcom_sQid qid = qcom_cNQid;
qcom_sGet get;
int swap = 0;
errh_Init("pwr_trend"); errh_Init("pwr_trend");
sts = gdh_Init("pwr_trend"); sts = gdh_Init("ds_trend");
If_Error_Log_Exit(sts, "gdh_Init"); If_Error_Log_Exit(sts, "gdh_Init");
if (!qcom_Init(&sts, 0, "pwr_trend")) {
errh_Fatal("qcom_Init, %m", sts);
exit(sts);
}
qAttr.type = qcom_eQtype_private;
qAttr.quota = 100;
if (!qcom_CreateQ(&sts, &qid, &qAttr, "events")) {
errh_Fatal("qcom_CreateQ, %m", sts);
exit(sts);
}
qini = qcom_cQini;
if (!qcom_Bind(&sts, &qid, &qini)) {
errh_Fatal("qcom_Bind(Qini), %m", sts);
exit(-1);
}
/* Wait until local nethandler has started */ /* Wait until local nethandler has started */
while(EVEN(gdh_NethandlerRunning())) while(EVEN(gdh_NethandlerRunning()))
sleep(1); sleep(1);
...@@ -117,53 +124,45 @@ int main (int argc, char **argv) ...@@ -117,53 +124,45 @@ int main (int argc, char **argv)
/* If even sts, just wait for init message */ /* If even sts, just wait for init message */
#if defined OS_VMS
plc_ConvMSToLI(ScanTime * 1000, &DeltaTime);
sts = lib$get_ef(&TimerFlag);
if (EVEN(sts)) {
Log_Error_Exit(sts,"Couldn't allocate event flag for timer");
}
#elif defined OS_ELN
plc_ConvMSToLI(ScanTime * 1000, &DeltaTime);
sts = plc_LoopInit(&NextTime);
if (EVEN(sts)) {
Log_Error_Exit(sts,"Couldn't initialize timer loop");
}
#elif defined OS_LYNX || defined OS_LINUX
clock_gettime(CLOCK_REALTIME, &LastScan); clock_gettime(CLOCK_REALTIME, &LastScan);
ScanDeltaTime.tv_sec = ScanTime; ScanDeltaTime.tv_sec = ScanTime;
ScanDeltaTime.tv_nsec = 0; ScanDeltaTime.tv_nsec = 0;
#endif
while (InitOK) {
/* We cannot do anything if there is a slip */
#if defined OS_VMS
sys$clref(TimerFlag);
sys$setimr(TimerFlag, &DeltaTime, 0, 2, 0);
StoreData(LstHead);
sys$waitfr(TimerFlag);
#elif defined OS_ELN
StoreData(LstHead);
sts = plc_LoopWait( NULL, &DeltaTime, &NextTime, NULL);
#else for (;;) {
StoreData(LstHead);
clock_gettime(CLOCK_REALTIME, &CurrentTime); clock_gettime(CLOCK_REALTIME, &CurrentTime);
time_Aadd(&NextScan, &LastScan, &ScanDeltaTime); time_Aadd(&NextScan, &LastScan, &ScanDeltaTime);
if (time_Acomp(&CurrentTime, &NextScan) < 0) { if (time_Acomp(&CurrentTime, &NextScan) < 0) {
time_Adiff(&WaitTime, &NextScan, &CurrentTime); time_Adiff(&WaitTime, &NextScan, &CurrentTime);
nanosleep((struct timespec *)&WaitTime, NULL); tmo = 1000 * time_DToFloat( 0, &WaitTime);
get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get( &sts, &qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
if ( !swap)
StoreData(LstHead);
}
else {
ini_mEvent new_event;
qcom_sEvent *ep = (qcom_sEvent*) get.data;
new_event.m = ep->mask;
if (new_event.b.oldPlcStop && !swap) {
swap = 1;
CloseTrendList( &LstHead);
}
else if (new_event.b.swapDone && swap) {
swap = 0;
sts = InitTrendList( ScanTime, &LstHead);
errh_Info("Warm restart completed");
} }
}
}
else if ( !swap)
StoreData(LstHead);
LastScan = NextScan; LastScan = NextScan;
#endif
} }
return 1; return 1;
...@@ -172,21 +171,12 @@ int main (int argc, char **argv) ...@@ -172,21 +171,12 @@ int main (int argc, char **argv)
/* Set up subscriptions for every local DsTrend object and /* Set up subscriptions for every local DsTrend object and
initialize the DsTrend objects. */ initialize the DsTrend objects. */
static pwr_tStatus static void
InitTrendList ( CloseTrendList (
pwr_tInt32 ScanTime,
sLstNode **LstHead sLstNode **LstHead
) )
{ {
sLstNode *LstNode, *TmpNode; sLstNode *LstNode, *TmpNode;
pwr_tStatus sts;
pwr_tUInt32 Dummy;
pwr_tTypeId Type;
int Tix;
pwr_tObjid ObjId;
char Name[81];
pwr_sClass_DsTrend *Trend;
/* Free old list */ /* Free old list */
...@@ -199,6 +189,22 @@ InitTrendList ( ...@@ -199,6 +189,22 @@ InitTrendList (
free(TmpNode); free(TmpNode);
} }
*LstHead = NULL; *LstHead = NULL;
}
static pwr_tStatus
InitTrendList (
pwr_tInt32 ScanTime,
sLstNode **LstHead
)
{
sLstNode *LstNode;
pwr_tStatus sts;
pwr_tUInt32 Dummy;
pwr_tTypeId Type;
int Tix;
pwr_tObjid ObjId;
char Name[81];
pwr_sClass_DsTrend *Trend;
sts = gdh_GetClassList(pwr_cClass_DsTrend, &ObjId); sts = gdh_GetClassList(pwr_cClass_DsTrend, &ObjId);
if (EVEN(sts)) { if (EVEN(sts)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment