Commit c06174f7 authored by Claes Sjofors's avatar Claes Sjofors

Plc, serveral processes, handling of error log and process status (refs #96)

parent a27a2074
......@@ -1072,11 +1072,11 @@ struct pwr_s_Node {
pwr_tDeltaTime RestartStallTime pwr_dAlignLW;
pwr_tTime SystemTime pwr_dAlignLW;
pwr_tNetStatus SystemStatus pwr_dAlignW;
pwr_tStatus ProcStatus[60] pwr_dAlignW;
pwr_tStatus ProcMsgSeverity[60] pwr_dAlignW;
pwr_tString80 ProcMessage[60] pwr_dAlignW;
pwr_tOid ProcObject[60] pwr_dAlignW;
pwr_tTime ProcTimeStamp[60] pwr_dAlignLW;
pwr_tStatus ProcStatus[80] pwr_dAlignW;
pwr_tStatus ProcMsgSeverity[80] pwr_dAlignW;
pwr_tString80 ProcMessage[80] pwr_dAlignW;
pwr_tOid ProcObject[80] pwr_dAlignW;
pwr_tTime ProcTimeStamp[80] pwr_dAlignLW;
pwr_tBoolean EmergBreakTrue pwr_dAlignW;
pwr_tUInt32 EmergBreakSelect pwr_dAlignW;
};
......
......@@ -178,7 +178,12 @@ int main (
i = 1/0;
printf("%d\n", i);
*/
pp = init_process();
pp = init_process( argv[0]);
if ( !pp) {
errh_Fatal("Plc process terminated");
errh_SetStatus( PWR__SRVTERM);
exit(sts);
}
qcom_WaitAnd(&sts, &pp->eventQ, &qcom_cQini, ini_mEvent_newPlcInit, qcom_cTmoEternal);
......@@ -255,10 +260,18 @@ int main (
}
static plc_sProcess *
init_process ()
init_process ( char *name)
{
plc_sProcess *pp;
pwr_tStatus sts = PLC__SUCCESS;
pwr_tObjid pp_oid;
int found;
char busidstr[10];
char pp_name[80];
pwr_tObjName oname;
int busid;
char *s;
int idx;
#if 0
thread_SetPrio(NULL, 15);
......@@ -280,6 +293,50 @@ init_process ()
exit(sts);
}
/* Get PlcProcess object */
busid = qcom_MyBus( &sts);
if ( EVEN(sts)) return 0;
sprintf( busidstr, "_%04d_", busid);
s = strstr( name, busidstr);
if ( s) {
strncpy( pp_name, s + 6, sizeof(pp_name));
if ( (s = strchr( pp_name, '.')))
*s = 0;
}
else {
strcpy( pp_name, "");
}
idx = 0;
for ( sts = gdh_GetClassList(pwr_cClass_PlcProcess, &pp_oid);
ODD(sts);
sts = gdh_GetNextObject(pp_oid, &pp_oid)) {
sts = gdh_ObjidToName(pp_oid, oname, sizeof(oname), cdh_mName_object);
if (EVEN(sts)) return 0;
if ( cdh_NoCaseStrcmp( pp_name, oname) == 0) {
found = 1;
break;
}
idx++;
}
if (!found) {
errh_Error("PlcProcess object not found, %s", pp_name);
return 0;
}
pp->index = idx;
pp->oid = pp_oid;
if ( errh_eAnix_plc1 + pp->index < errh_eAnix__)
errh_SetAnix( errh_eAnix_plc1 + pp->index);
errh_SetName( pp_name);
sts = gdh_ObjidToPointer(pp_oid, (void *)&pp->PlcProcess);
if (EVEN(sts)) return 0;
#if defined OS_VMS
qdb->thread_lock.isThreaded = 1;
qdb->thread_lock.cond_signal = thread_CondSignal;
......@@ -311,19 +368,12 @@ init_plc (
{
pwr_tStatus sts = PLC__SUCCESS;
pwr_tObjid oid;
pwr_tObjid pp_oid;
pwr_tObjid io_oid;
pwr_tObjid thread_oid;
int sec;
int msec;
int i;
pwr_tCid cid;
int busid;
int found;
char busidstr[10];
char pp_name[80];
pwr_tObjName oname;
char *s;
sts = gdh_GetNodeObject(0, &oid);
if (EVEN(sts)) {
......@@ -334,40 +384,6 @@ init_plc (
sts = gdh_ObjidToPointer(oid, (void *)&pp->Node);
if (EVEN(sts)) return sts;
busid = qcom_MyBus( &sts);
if ( EVEN(sts)) return sts;
sprintf( busidstr, "_%04d_", busid);
s = strstr( name, busidstr);
if ( s) {
strncpy( pp_name, s + 6, sizeof(pp_name));
if ( (s = strchr( pp_name, '.')))
*s = 0;
}
else {
strcpy( pp_name, "");
}
for ( sts = gdh_GetClassList(pwr_cClass_PlcProcess, &pp_oid);
ODD(sts);
sts = gdh_GetNextObject(pp_oid, &pp_oid)) {
sts = gdh_ObjidToName(pp_oid, oname, sizeof(oname), cdh_mName_object);
if (EVEN(sts)) return sts;
if ( cdh_NoCaseStrcmp( pp_name, oname) == 0) {
found = 1;
break;
}
}
if (!found) {
errh_Error("Found no PlcProcess-object %s", pp_name);
return 0;
}
sts = gdh_ObjidToPointer(pp_oid, (void *)&pp->PlcProcess);
if (EVEN(sts)) return sts;
#if defined OS_LINUX
if ( pp->PlcProcess->CpuMask != 0) {
cpu_set_t mask;
......@@ -387,7 +403,7 @@ init_plc (
#endif
i = 0;
sts = gdh_GetChild( pp_oid, &thread_oid);
sts = gdh_GetChild( pp->oid, &thread_oid);
while ( ODD(sts)) {
sts = gdh_GetObjectClass( thread_oid, &cid);
if ( EVEN(sts)) return sts;
......@@ -400,7 +416,7 @@ init_plc (
for ( ; i > sizeof(pp->PlcProcess->PlcThreadObjects)/sizeof(pp->PlcProcess->PlcThreadObjects[0]); i++)
pp->PlcProcess->PlcThreadObjects[i] = pwr_cNObjid;
aproc_RegisterObject( pp_oid);
aproc_RegisterObject( pp->oid);
sts = gdh_GetClassList(pwr_cClass_IOHandler, &io_oid);
if (EVEN(sts)) {
......
......@@ -63,12 +63,15 @@ pwrs_Node_Exec (
pwr_tDeltaTime diff;
errh_eSeverity severity;
errh_eSeverity system_severity;
errh_eSeverity plc_severity;
int new_idx = -1;
static int supervise[60] = {
static int supervise[80] = {
0,0,0,0,1,1,1,0,1,1,
1,1,1,0,0,1,0,1,1,1,
1,1,1,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1};
static int reboot_done = 0;
......@@ -107,7 +110,25 @@ pwrs_Node_Exec (
else
reboot_done = 0;
/* Calculate plc status */
new_idx = -1;
plc_severity = errh_Severity( np->ProcStatus[errh_eAnix_plc-1]);
for ( i = errh_eAnix_plc1 - 1; i < errh_eAnix_plc1 - 1 + errh_cAnix_PlcSize; i++) {
severity = errh_Severity( np->ProcStatus[i]);
if ( np->ProcStatus[i] != 0 && EVEN(np->ProcStatus[i])) {
if ( severity >= plc_severity) {
new_idx = i;
plc_severity = severity;
}
}
}
if ( new_idx != -1)
np->ProcStatus[errh_eAnix_plc-1] = np->ProcStatus[new_idx];
else if ( EVEN(np->ProcStatus[errh_eAnix_plc-1]))
np->ProcStatus[errh_eAnix_plc-1] = PWR__SRUN;
/* Calculate system status and check timestamp */
new_idx = -1;
system_severity = errh_Severity( np->SystemStatus);
time_GetTime( &current_time);
for ( i = 0; i < sizeof(np->ProcStatus)/sizeof(np->ProcStatus[0]); i++) {
......
......@@ -248,6 +248,17 @@ errh_SetAnix(
errh_anix = anix;
}
/**
* @brief Set application name for the process.
*/
void
errh_SetName(
char *name
)
{
set_name(name);
}
/* Check if a given messagenumber exists,
return string representation if valid. */
......
......@@ -93,6 +93,7 @@ typedef enum {
#define errh_cAnix_SrvSize 40
#define errh_cAnix_PlcSize 20
/**
* Application index
......@@ -122,26 +123,47 @@ typedef enum {
errh_eAnix_post = 21,
errh_eAnix_report = 22,
errh_eAnix_sevhistmon = 23,
errh_eAnix_appl1 = 41,
errh_eAnix_appl2 = 42,
errh_eAnix_appl3 = 43,
errh_eAnix_appl4 = 44,
errh_eAnix_appl5 = 45,
errh_eAnix_appl6 = 46,
errh_eAnix_appl7 = 47,
errh_eAnix_appl8 = 48,
errh_eAnix_appl9 = 49,
errh_eAnix_appl10 = 50,
errh_eAnix_appl11 = 51,
errh_eAnix_appl12 = 52,
errh_eAnix_appl13 = 53,
errh_eAnix_appl14 = 54,
errh_eAnix_appl15 = 55,
errh_eAnix_appl16 = 56,
errh_eAnix_appl17 = 57,
errh_eAnix_appl18 = 58,
errh_eAnix_appl19 = 59,
errh_eAnix_appl20 = 50
errh_eAnix_plc1 = 41,
errh_eAnix_plc2 = 42,
errh_eAnix_plc3 = 43,
errh_eAnix_plc4 = 44,
errh_eAnix_plc5 = 45,
errh_eAnix_plc6 = 46,
errh_eAnix_plc7 = 47,
errh_eAnix_plc8 = 48,
errh_eAnix_plc9 = 49,
errh_eAnix_plc10 = 50,
errh_eAnix_plc11 = 51,
errh_eAnix_plc12 = 52,
errh_eAnix_plc13 = 53,
errh_eAnix_plc14 = 54,
errh_eAnix_plc15 = 55,
errh_eAnix_plc16 = 56,
errh_eAnix_plc17 = 57,
errh_eAnix_plc18 = 58,
errh_eAnix_plc19 = 59,
errh_eAnix_plc20 = 60,
errh_eAnix_appl1 = 61,
errh_eAnix_appl2 = 62,
errh_eAnix_appl3 = 63,
errh_eAnix_appl4 = 64,
errh_eAnix_appl5 = 65,
errh_eAnix_appl6 = 66,
errh_eAnix_appl7 = 67,
errh_eAnix_appl8 = 68,
errh_eAnix_appl9 = 69,
errh_eAnix_appl10 = 70,
errh_eAnix_appl11 = 71,
errh_eAnix_appl12 = 72,
errh_eAnix_appl13 = 73,
errh_eAnix_appl14 = 74,
errh_eAnix_appl15 = 75,
errh_eAnix_appl16 = 76,
errh_eAnix_appl17 = 77,
errh_eAnix_appl18 = 78,
errh_eAnix_appl19 = 79,
errh_eAnix_appl20 = 80,
errh_eAnix__ = 81
} errh_eAnix;
/**
......@@ -193,6 +215,7 @@ void errh_CErrLog (pwr_tStatus sts, ...);
char *errh_Message (char *string, char severity, char *msg, ...);
errh_eAnix errh_Anix ();
void errh_SetAnix (errh_eAnix anix);
void errh_SetName (char *name);
errh_eSeverity errh_Severity (pwr_tStatus);
/** @} */
......
......@@ -189,6 +189,8 @@ struct plc_sProcess {
pwr_sClass_PlcProcess *PlcProcess;
pwr_tFullName nodeName;
qcom_sQid eventQ;
pwr_tOid oid;
int index;
thread_sMutex io_copy_mutex;
plc_sArea base;
};
......
......@@ -204,7 +204,7 @@ SObject pwrs:Class
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_ARRAY
Attr Elements = 60
Attr Elements = 80
EndBody
EndObject
!/**
......@@ -216,7 +216,7 @@ SObject pwrs:Class
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_ARRAY
Attr Elements = 60
Attr Elements = 80
EndBody
EndObject
!/**
......@@ -228,7 +228,7 @@ SObject pwrs:Class
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_ARRAY
Attr Elements = 60
Attr Elements = 80
EndBody
EndObject
!/**
......@@ -240,7 +240,7 @@ SObject pwrs:Class
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_ARRAY
Attr Elements = 60
Attr Elements = 80
EndBody
EndObject
!/**
......@@ -252,7 +252,7 @@ SObject pwrs:Class
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_ARRAY
Attr Elements = 60
Attr Elements = 80
EndBody
EndObject
!/**
......
This diff is collapsed.
This diff is collapsed.
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