Commit eaf77a39 authored by claes's avatar claes

Handling of swap and terminate event from Qcom added

parent 20cd46d1
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "pwr_nmpsclasses.h" #include "pwr_nmpsclasses.h"
#include "co_cdh.h" #include "co_cdh.h"
#include "co_time.h" #include "co_time.h"
#include "co_dcli.h"
#include "rt_gdh.h" #include "rt_gdh.h"
#include "rt_errh.h" #include "rt_errh.h"
#include "rt_gdh_msg.h" #include "rt_gdh_msg.h"
...@@ -63,6 +64,9 @@ ...@@ -63,6 +64,9 @@
#include "rs_nmps.h" #include "rs_nmps.h"
#include "rs_nmps_msg.h" #include "rs_nmps_msg.h"
#include "rs_sutl.h" #include "rs_sutl.h"
#include "rt_qcom.h"
#include "rt_qcom_msg.h"
#include "rt_ini_event.h"
/*_Globala variabler______________________________________________________*/ /*_Globala variabler______________________________________________________*/
...@@ -286,6 +290,7 @@ int nmpsbck_get_filename( ...@@ -286,6 +290,7 @@ int nmpsbck_get_filename(
*s = 0; *s = 0;
strcat( outname, ext); strcat( outname, ext);
} }
dcli_translate_filename( outname, outname);
return NMPS__SUCCESS; return NMPS__SUCCESS;
} }
...@@ -1092,7 +1097,7 @@ static pwr_tStatus nmpsbck_open_file( bck_ctx bckctx) ...@@ -1092,7 +1097,7 @@ static pwr_tStatus nmpsbck_open_file( bck_ctx bckctx)
{ {
nmpsbck_t_fileheader fileheader; nmpsbck_t_fileheader fileheader;
pwr_tUInt32 csts; pwr_tUInt32 csts;
char filename[80]; char filename[200];
float reopen_time = 10; float reopen_time = 10;
int first_time; int first_time;
int wait_some_time; int wait_some_time;
...@@ -1555,7 +1560,7 @@ static pwr_tStatus nmpsbck_read( bck_ctx bckctx) ...@@ -1555,7 +1560,7 @@ static pwr_tStatus nmpsbck_read( bck_ctx bckctx)
nmpsbck_t_data_list *data_ptr; nmpsbck_t_data_list *data_ptr;
nmpsbck_t_data_list *next_ptr; nmpsbck_t_data_list *next_ptr;
char *objectp; char *objectp;
char filename[80]; char filename[200];
int file_num = 1; int file_num = 1;
int record_count; int record_count;
pwr_tUInt32 cellarea_start[NMPSBCK_MAX_RECORDS]; pwr_tUInt32 cellarea_start[NMPSBCK_MAX_RECORDS];
...@@ -2393,13 +2398,38 @@ int main() ...@@ -2393,13 +2398,38 @@ int main()
int count; int count;
int first_scan = 1; int first_scan = 1;
int file_reopen = 0; int file_reopen = 0;
qcom_sQid qid = qcom_cNQid;
qcom_sQattr qAttr;
qcom_sQid qini;
int tmo;
int swap = 0;
char mp[2000];
qcom_sGet get;
errh_Init("rs_nmps_bck", 0);
if (!qcom_Init(&sts, 0, "rs_nmps_bck")) {
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);
}
/* Init pams and gdh */
sts = gdh_Init("rs_nmps_bck"); sts = gdh_Init("rs_nmps_bck");
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
for (;;) for (;;) {
{
bckctx = calloc( 1 , sizeof( *bckctx)); bckctx = calloc( 1 , sizeof( *bckctx));
if ( bckctx == 0 ) return NMPS__NOMEMORY; if ( bckctx == 0 ) return NMPS__NOMEMORY;
...@@ -2408,13 +2438,11 @@ int main() ...@@ -2408,13 +2438,11 @@ int main()
sts = nmps_get_bckconfig( bckctx); sts = nmps_get_bckconfig( bckctx);
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
if ( !bckctx->bckconfig->NoRead) if ( !bckctx->bckconfig->NoRead) {
{
/* Restore the old backup file */ /* Restore the old backup file */
sts = nmpsbck_read( bckctx); sts = nmpsbck_read( bckctx);
} }
else else {
{
/* Release the cells by setting backup done flag */ /* Release the cells by setting backup done flag */
sts = nmpsbck_set_cell_backup_done(); sts = nmpsbck_set_cell_backup_done();
if (EVEN(sts)) LogAndExit( sts); if (EVEN(sts)) LogAndExit( sts);
...@@ -2428,15 +2456,27 @@ int main() ...@@ -2428,15 +2456,27 @@ int main()
scantime = bckctx->bckconfig->IncrementCycleTime; scantime = bckctx->bckconfig->IncrementCycleTime;
full_scan = bckctx->bckconfig->FullCycleTime / scantime + FLT_EPSILON; full_scan = bckctx->bckconfig->FullCycleTime / scantime + FLT_EPSILON;
tmo = (int) scantime * 1000;
count = 0; count = 0;
for (;;) for (;;) {
{ get.maxSize = sizeof(mp);
get.data = mp;
qcom_Get(&sts,&qid, &get, tmo);
if (sts == QCOM__TMO || sts == QCOM__QEMPTY) {
if ( swap)
continue;
if ( bckctx->bckconfig->Initialize) {
bckctx->bckconfig->Initialize = 0;
nmpsbck_free( bckctx);
break;
}
count++; count++;
if ( count > full_scan || first_scan || file_reopen || if ( count > full_scan || first_scan || file_reopen ||
bckctx->record_count >= NMPSBCK_MAX_RECORDS - 1 || bckctx->record_count >= NMPSBCK_MAX_RECORDS - 1 ||
bckctx->bckconfig->ForceFullBackup) bckctx->bckconfig->ForceFullBackup) {
{
/* Time for full backup */ /* Time for full backup */
if ( bckctx->bckconfig->ForceFullBackup) if ( bckctx->bckconfig->ForceFullBackup)
bckctx->bckconfig->ForceFullBackup = 0; bckctx->bckconfig->ForceFullBackup = 0;
...@@ -2444,8 +2484,7 @@ int main() ...@@ -2444,8 +2484,7 @@ int main()
count = 0; count = 0;
/* Toggle file */ /* Toggle file */
if ( !file_reopen) if ( !file_reopen) {
{
if ( bckctx->file_num == 1) if ( bckctx->file_num == 1)
bckctx->file_num = 2; bckctx->file_num = 2;
else else
...@@ -2458,8 +2497,7 @@ int main() ...@@ -2458,8 +2497,7 @@ int main()
bckctx->increment = 1; bckctx->increment = 1;
sts = nmpsbck_cell_handler( bckctx); sts = nmpsbck_cell_handler( bckctx);
if ( sts == NMPS__FILEREOPEN) if ( sts == NMPS__FILEREOPEN) {
{
/* New file is opened, write a full backup */ /* New file is opened, write a full backup */
file_reopen = 1; file_reopen = 1;
continue; continue;
...@@ -2471,15 +2509,32 @@ int main() ...@@ -2471,15 +2509,32 @@ int main()
else if (EVEN(sts)) LogAndExit( sts); else if (EVEN(sts)) LogAndExit( sts);
#endif #endif
sutl_sleep( scantime);
if ( bckctx->bckconfig->Initialize) // sutl_sleep( scantime);
{
bckctx->bckconfig->Initialize = 0; first_scan = 0;
}
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;
nmpsbck_free( bckctx); nmpsbck_free( bckctx);
break; break;
} }
first_scan = 0; else if (new_event.b.swapDone && swap) {
swap = 0;
}
else if (new_event.b.terminate) {
exit(0);
}
}
} }
} }
} }
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