Commit 8808c371 authored by Claes Sjofors's avatar Claes Sjofors

NMps, added new Function CheckObjects for cells to automatically remove deleted objects

parent 9b8554db
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#define NMPS_CELLFUNC_DELETE 4 #define NMPS_CELLFUNC_DELETE 4
#define NMPS_CELLFUNC_RESETDELETE 8 #define NMPS_CELLFUNC_RESETDELETE 8
#define NMPS_CELLFUNC_BACKUP 16 #define NMPS_CELLFUNC_BACKUP 16
#define NMPS_CELLFUNC_CHECKOBJECTS 32
#define NMPS_TRPFUNC_UNIT 1 #define NMPS_TRPFUNC_UNIT 1
#define NMPS_TRPFUNC_ALL 2 #define NMPS_TRPFUNC_ALL 2
......
...@@ -359,7 +359,7 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80* ...@@ -359,7 +359,7 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80*
/* Allocate memory for the data objects array in applctx */ /* Allocate memory for the data objects array in applctx */
if (options & nmpsappl_mOption_Remove) if (options & nmpsappl_mOption_Remove)
/* Remove requires the dubbel size */ /* Remove requires the double size */
applctx->datainfo = (nmpsappl_t_datainfo*)calloc( applctx->datainfo = (nmpsappl_t_datainfo*)calloc(
applctx->total_cellsize * 2, sizeof(nmpsappl_t_datainfo)); applctx->total_cellsize * 2, sizeof(nmpsappl_t_datainfo));
else else
...@@ -379,16 +379,12 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80* ...@@ -379,16 +379,12 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80*
*@brief Update mirroring. *@brief Update mirroring.
* *
* nmpsappl_Mirror mirrors the content of one or several cells into an * nmpsappl_Mirror mirrors the content of one or several cells into an
*application * application program.
* program.
* *
* The function handles direct link of cells and dataobjects, and returns a list * The function handles direct link of cells and dataobjects, and returns a list
*of * of data objects to the application together with information about front, back,
* data objects to the application together with information about front, back, * select properties, and which data objects are new or has disappeard. The
*select * application also receives a pointer to each data object.
* properties, and which data objects are new or has disappeard. The application
*also
* receives a pointer to each data object.
* *
* The mirroring is initiated by calling nmpsappl_MirrorInit. The cells are * The mirroring is initiated by calling nmpsappl_MirrorInit. The cells are
* mirrored are specified in this call. Then nmpsappl_Mirror is called cyclic * mirrored are specified in this call. Then nmpsappl_Mirror is called cyclic
...@@ -399,7 +395,7 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80* ...@@ -399,7 +395,7 @@ pwr_tStatus nmpsappl_MirrorInit(pwr_tString80*
* Several mirroring can be handled in the same application (max 32), and each * Several mirroring can be handled in the same application (max 32), and each
* mirroring can handle maximum 32 cells. * mirroring can handle maximum 32 cells.
* *
* Exempel * Example
* @code * @code
* #include "pwr_inc:pwr.h" * #include "pwr_inc:pwr.h"
* #include "ssab_inc:rs_nmps_appl.h" * #include "ssab_inc:rs_nmps_appl.h"
......
...@@ -165,6 +165,44 @@ void NMpsCell_exec(plc_sThread* tp, pwr_sClass_NMpsCell* object) ...@@ -165,6 +165,44 @@ void NMpsCell_exec(plc_sThread* tp, pwr_sClass_NMpsCell* object)
object->BackupNow = 1; object->BackupNow = 1;
} }
} }
if ( object->Function & NMPS_CELLFUNC_CHECKOBJECTS) {
data_index = (plc_t_DataInfo*)&object->Data1P;
for ( i = 0; i < object->LastIndex; i++) {
sts = gdh_CheckLocalObject(data_index->DataP.Aref.Objid);
if ( EVEN(sts)) {
/* Remove object */
sts = gdh_DLUnrefObjectInfo(data_index->Data_Dlid);
if (i < object->LastIndex) {
size = (object->LastIndex - i) * sizeof(*data_max);
#if defined OS_LINUX
tmp_buf = malloc(size);
memcpy(tmp_buf, (char*)data_index + sizeof(*data_max), size);
memcpy(data_index, tmp_buf, size);
free(tmp_buf);
#else
memcpy(data_index, (char*)data_index + sizeof(*data_max), size);
#endif
}
data_last = (plc_t_DataInfo*)&object->Data1P;
data_last += object->LastIndex - 1;
memset(data_last, 0, sizeof(*data_last));
object->CellFull = 0;
object->LastIndex--;
if (object->LastIndex > 0) {
data_last--;
memcpy(&object->DataLP, data_last, sizeof(*data_last));
memcpy(&object->DataLastP, data_last, sizeof(*data_last));
} else {
memset(&object->DataLP, 0, sizeof(*data_last));
memset(&object->DataLastP, 0, sizeof(*data_last));
}
i--;
}
else
data_index++;
}
}
if (object->ExternFlag) { if (object->ExternFlag) {
/* Insert new object in Front position */ /* Insert new object in Front position */
...@@ -180,6 +218,19 @@ void NMpsCell_exec(plc_sThread* tp, pwr_sClass_NMpsCell* object) ...@@ -180,6 +218,19 @@ void NMpsCell_exec(plc_sThread* tp, pwr_sClass_NMpsCell* object)
else if (object->ExternIndex > object->LastIndex + 1) else if (object->ExternIndex > object->LastIndex + 1)
object->ExternStatus = 2; /* Felkod !!! */ object->ExternStatus = 2; /* Felkod !!! */
else { else {
data_index = (plc_t_DataInfo*)&object->Data1P;
for ( i = 0; i < object->LastIndex; i++) {
if ( cdh_ObjidIsEqual(data_index->DataP.Aref.Objid, object->ExternObjId)) {
object->ExternStatus = 2;
object->ExternFlag = 0;
data_index = 0;
break;
}
data_index++;
}
if ( !data_index)
break;
extern_attrref.Objid = object->ExternObjId; extern_attrref.Objid = object->ExternObjId;
extern_attrref.Offset = 0; extern_attrref.Offset = 0;
extern_attrref.Size = 4; extern_attrref.Size = 4;
...@@ -694,6 +745,40 @@ void NMpsStoreCell_exec(plc_sThread* tp, pwr_sClass_NMpsStoreCell* object) ...@@ -694,6 +745,40 @@ void NMpsStoreCell_exec(plc_sThread* tp, pwr_sClass_NMpsStoreCell* object)
object->BackupNow = 1; object->BackupNow = 1;
} }
} }
if ( object->Function & NMPS_CELLFUNC_CHECKOBJECTS) {
data_index = (plc_t_DataInfo*)&object->Data1P;
for ( i = 0; i < object->LastIndex; i++) {
sts = gdh_CheckLocalObject(data_index->DataP.Aref.Objid);
if ( EVEN(sts)) {
/* Remove object */
sts = gdh_DLUnrefObjectInfo(data_index->Data_Dlid);
if (i < object->LastIndex) {
size = (object->LastIndex - i) * sizeof(*data_max);
#if defined OS_LINUX
tmp_buf = malloc(size);
memcpy(tmp_buf, (char*)data_index + sizeof(*data_max), size);
memcpy(data_index, tmp_buf, size);
free(tmp_buf);
#else
memcpy(data_index, (char*)data_index + sizeof(*data_max), size);
#endif
}
data_last = (plc_t_DataInfo*)&object->Data1P;
data_last += object->LastIndex - 1;
memset(data_last, 0, sizeof(*data_last));
object->CellFull = 0;
object->LastIndex--;
if ((object->SelectIndex != 0)
&& (object->SelectIndex > i))
object->SelectIndex--;
i--;
}
else
data_index++;
}
}
if (object->ExternFlag) { if (object->ExternFlag) {
/* Insert new object in Front position */ /* Insert new object in Front position */
...@@ -710,6 +795,19 @@ void NMpsStoreCell_exec(plc_sThread* tp, pwr_sClass_NMpsStoreCell* object) ...@@ -710,6 +795,19 @@ void NMpsStoreCell_exec(plc_sThread* tp, pwr_sClass_NMpsStoreCell* object)
else if (object->ExternIndex > object->LastIndex + 1) else if (object->ExternIndex > object->LastIndex + 1)
object->ExternStatus = 2; /* Felkod !!! */ object->ExternStatus = 2; /* Felkod !!! */
else { else {
data_index = (plc_t_DataInfo*)&object->Data1P;
for ( i = 0; i < object->LastIndex; i++) {
if ( cdh_ObjidIsEqual(data_index->DataP.Aref.Objid, object->ExternObjId)) {
object->ExternStatus = 2;
object->ExternFlag = 0;
data_index = 0;
break;
}
data_index++;
}
if ( !data_index)
break;
extern_attrref.Objid = object->ExternObjId; extern_attrref.Objid = object->ExternObjId;
extern_attrref.Offset = 0; extern_attrref.Offset = 0;
extern_attrref.Size = 4; extern_attrref.Size = 4;
......
Volume NMps $ClassVolume 0.0.1.1 Volume NMps $ClassVolume 0.0.1.1
Body SysBody 01-JAN-1970 01:00:00.00 Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X89" Attr NextOix = "_X91"
EndBody EndBody
Object Type $TypeHier 2 07-JUL-2017 13:58:14.00 Object Type $TypeHier 2 07-JUL-2017 13:58:14.00
Object CellFunctionMask $TypeDef 1 07-JUL-2017 13:58:14.00 Object CellFunctionMask $TypeDef 1 07-JUL-2017 13:58:14.00
...@@ -30,6 +30,13 @@ Volume NMps $ClassVolume 0.0.1.1 ...@@ -30,6 +30,13 @@ Volume NMps $ClassVolume 0.0.1.1
Attr Value = 16 Attr Value = 16
EndBody EndBody
EndObject EndObject
Object CheckObjects $Bit 90 03-DEC-2018 16:17:11.48
Body SysBody 03-DEC-2018 16:17:19.07
Attr Text = "CheckObjects"
Attr PgmName = "CheckObjects"
Attr Value = 32
EndBody
EndObject
EndObject EndObject
Object OutCellFunctionMask $TypeDef 2 07-JUL-2017 13:58:14.00 Object OutCellFunctionMask $TypeDef 2 07-JUL-2017 13:58:14.00
Body SysBody 01-JAN-1970 01:00:00.00 Body SysBody 01-JAN-1970 01:00:00.00
...@@ -86,6 +93,13 @@ Volume NMps $ClassVolume 0.0.1.1 ...@@ -86,6 +93,13 @@ Volume NMps $ClassVolume 0.0.1.1
Attr Value = 16 Attr Value = 16
EndBody EndBody
EndObject EndObject
Object CheckObjects $Bit 91 03-DEC-2018 16:17:24.71
Body SysBody 03-DEC-2018 16:17:24.71
Attr Text = "CheckObjects"
Attr PgmName = "CheckObjects"
Attr Value = 32
EndBody
EndObject
EndObject EndObject
Object TrpFunctionMask $TypeDef 4 07-JUL-2017 13:58:14.00 Object TrpFunctionMask $TypeDef 4 07-JUL-2017 13:58:14.00
Body SysBody 01-JAN-1970 01:00:00.00 Body SysBody 01-JAN-1970 01:00:00.00
...@@ -5869,7 +5883,7 @@ Volume NMps $ClassVolume 0.0.1.1 ...@@ -5869,7 +5883,7 @@ Volume NMps $ClassVolume 0.0.1.1
!/** !/**
! @Group MaterialPlanning,Plc ! @Group MaterialPlanning,Plc
! !
! Note! Obsolete since V5.2 ! NoteObsolete since V5.2
! Replaced by GetDataRefp. ! Replaced by GetDataRefp.
!*/ !*/
Object GetDap $ClassDef 19 07-JUL-2017 13:58:14.00 Object GetDap $ClassDef 19 07-JUL-2017 13:58:14.00
......
...@@ -5243,6 +5243,20 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -5243,6 +5243,20 @@ pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
return GDH__SUCCESS; return GDH__SUCCESS;
} }
pwr_tStatus gdh_CheckLocalObject(pwr_tOid oid)
{
pwr_tStatus sts;
gdb_sObject *op;
gdh_ScopeLock {
op = vol_OidToObject(&sts, oid, gdb_mLo_local, vol_mTrans_none, cvol_eHint_none);
} gdh_ScopeUnlock;
if (op == NULL)
return sts;
return GDH__SUCCESS;
}
/** /**
* @brief Thread save function to fetch a direct linked absolute time value. * @brief Thread save function to fetch a direct linked absolute time value.
* Sets the time lock to ensure that the time is not modified during * Sets the time lock to ensure that the time is not modified during
...@@ -5477,3 +5491,4 @@ pwr_tStatus gdh_SetObjectInfoStr(char* name, /**< Attribute name */ ...@@ -5477,3 +5491,4 @@ pwr_tStatus gdh_SetObjectInfoStr(char* name, /**< Attribute name */
lck_Unlock(lck_eLock_Str); lck_Unlock(lck_eLock_Str);
return sts; return sts;
} }
...@@ -435,6 +435,8 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, ...@@ -435,6 +435,8 @@ pwr_tStatus gdh_GetGlobalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects, pwr_tStatus gdh_GetLocalClassList(int cidcnt, pwr_tCid* cid, int attrobjects,
pwr_tAttrRef* classlist[], int* listcnt); pwr_tAttrRef* classlist[], int* listcnt);
pwr_tStatus gdh_CheckLocalObject(pwr_tOid oid);
/* Thread safe functions for times and strings */ /* Thread safe functions for times and strings */
void gdh_GetTimeDL(pwr_tTime* atp, pwr_tTime* time); void gdh_GetTimeDL(pwr_tTime* atp, pwr_tTime* time);
void gdh_SetTimeDL(pwr_tTime* atp, pwr_tTime* time); void gdh_SetTimeDL(pwr_tTime* atp, pwr_tTime* time);
......
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