static pwr_tStatus tlog_qual_to_time( char *in_str, pwr_tTime *time) { pwr_tStatus sts; char *s; pwr_tDeltaTime one_day_time; pwr_tTime current_time; char str[64]; char timstr[64]; if ( !strcmp( in_str, "") || !strncmp( in_str, "TODAY", strlen(in_str))) { time_GetTime( ¤t_time); time_AtoAscii( ¤t_time, time_eFormat_DateAndTime, timstr, sizeof(timstr)); timstr[12] = 0; strcat( timstr, " 00:00:00.00"); sts = time_AsciiToA( timstr, time); } else if ( !strncmp( in_str, "YESTERDAY", strlen(in_str))) { time_GetTime( ¤t_time); time_AtoAscii( ¤t_time, time_eFormat_DateAndTime, timstr, sizeof(timstr)); timstr[12] = 0; strcat( timstr, " 00:00:00.00"); sts = time_AsciiToA( timstr, ¤t_time); strcpy( timstr, "1 00:00:00"); sts = time_AsciiToD( timstr, &one_day_time); time_Dneg( &one_day_time, &one_day_time); time_Aadd( time, ¤t_time, &one_day_time); } else { strcpy( str, in_str); if ( s = strchr( str, '-')) { /* Date is supplied, replace ':' to space */ if ( s = strchr( str, ':')) *s = ' '; strcpy( timstr, str); } else { /* No date is supplied, add current date as default */ time_GetTime( ¤t_time); time_AtoAscii( ¤t_time, time_eFormat_DateAndTime, timstr, sizeof(timstr)); timstr[12] = 0; strcat( timstr, " "); strcat( timstr, str); } sts = time_AsciiToA( timstr, time); if (EVEN(sts)) return sts; } return TLOG__SUCCESS; }
void RunTimeCounterFo_exec( plc_sThread *tp, pwr_sClass_RunTimeCounterFo *o) { pwr_tDeltaTime TimeSince; pwr_sClass_RunTimeCounter *co = (pwr_sClass_RunTimeCounter *) o->PlcConnectP; if ( !co) return; if ( *o->ResetP && !o->OldReset) co->TripReset = 1; time_FloatToD( &TimeSince, *o->ScanTime); /* Test if New Trip */ if (co->TripReset) { co->OldTripNOfStarts = co->TripNOfStarts; co->OldTripUsage = co->TripUsage; co->OldTripTime = co->TripTime; co->OldTripRunTime = co->TripRunTime; co->TripNOfStarts = 0; co->TripRunTime.tv_sec = co->TripRunTime.tv_nsec = 0; co->TripTime.tv_sec = co->TripTime.tv_nsec = 0; time_GetTime( &co->ResetTime); co->TripReset = 0; } /* Update Calendar time */ time_Dadd( &co->TotalTime, &co->TotalTime, &TimeSince); time_Dadd( &co->TripTime, &co->TripTime, &TimeSince); /* Test if running */ o->Start = 0; if (*o->RunningP) { /* New start ? */ if ( !o->Running) { o->Start = 1; co->TotalNOfStarts++; co->TripNOfStarts++; time_GetTime( &co->StartTime); } /* End if new start */ /* Update Running Time */ time_Dadd( &co->TripRunTime, &co->TripRunTime, &TimeSince); time_Dadd( &co->TotalRunTime, &co->TotalRunTime, &TimeSince); } /* End if Running */ o->Running = co->Running = *o->RunningP; /* Calculate usage % */ if ( co->TotalRunTime.tv_sec) co->TotalUsage = ((float)co->TotalRunTime.tv_sec) / co->TotalTime.tv_sec * 100; if ( co->TripTime.tv_sec) co->TripUsage = ((float)co->TripRunTime.tv_sec) / co->TripTime.tv_sec * 100; o->OldReset = *o->ResetP; }
bool wb_session::commit() { if (!m_vrep->erep()->check_lock((char*)m_vrep->name(), m_vrep->dbtype())) { m_sts = LDH__LOCKSTOLEN; return false; } // Store time in volume object pwr_tOid oid = pwr_cNOid; pwr_tTime time; time_GetTime(&time); oid.vid = m_vrep->vid(); wb_orep* orep = m_vrep->object(&m_sts, oid); if (oddSts()) { orep->ref(); wb_attribute modtime(m_sts, orep, "SysBody", "Modified"); if (modtime.oddSts()) writeAttribute(modtime, &time); orep->unref(); } return m_srep->commit(&m_sts); }
//----------------------------------------------------------------------------- LTRESULT CLTBenchmarkMgr::StartGraphicsBenchmarking(LTFLOAT fTestDuration) { // If we're already benchmarking, return if (m_bIsGraphicsBenchmarking) return LT_ERROR; // Re-init our results struct ClearGraphicsBenchmarkingInfo(); m_ltBenchGraphicsTest.m_dwMinFrameRate = MAX_DWORD; m_ltBenchGraphicsTest.m_dwMinPolyCount = MAX_DWORD; // Keep track of our state m_bIsGraphicsBenchmarking = LTTRUE; // Determine when we need to end m_fGraphicsTestDuration = fTestDuration; m_dwGraphicsTestCurrentTime = (uint32)time_GetTime(); m_dwGraphicsTestStartTime = m_dwGraphicsTestCurrentTime; m_dwGraphicsTestEndTime = 0; if (m_fGraphicsTestDuration > 0.0f) m_dwGraphicsTestEndTime = m_dwGraphicsTestStartTime + (uint32)(1000 * fTestDuration); m_dwUpdateCount = 0; m_dwFrameCount = 0; m_dwPolyCount = 0; return LT_OK; }
int rt_sysmon::alarm_send( pwr_tOid oid, char *alarm_text, char *alarm_name, int alarm_prio ) { mh_sApplMessage mh_msg; pwr_tUInt32 mh_id; int sts; sts = connect_alarm(); if ( EVEN(sts)) return sts; mh_msg.Object = oid; mh_msg.EventFlags = (mh_mEventFlags)(mh_mEventFlags_Returned | mh_mEventFlags_NoObject | mh_mEventFlags_Bell); time_GetTime( &mh_msg.EventTime); mh_msg.SupObject = pwr_cNObjid; mh_msg.Outunit = pwr_cNObjid; strcpy ( mh_msg.EventName , alarm_name); strcpy ( mh_msg.EventText , alarm_text); mh_msg.EventType = mh_eEvent_Alarm; mh_msg.SupInfo.SupType = mh_eSupType_None; mh_msg.EventPrio = (mh_eEventPrio) alarm_prio; sts = mh_ApplMessage( &mh_id, &mh_msg); if( EVEN(sts)) return sts; return SMON__SUCCESS; }
mh_sBlockDb * mh_BlockDbGet ( mh_sBlockDb *dp, pwr_tUInt32 *size, char *buffer ) { register mh_sBlockDbHead *hp = &dp->Head; char msg[512]; time_GetTime(&hp->GetTime); hp->GetCount++; if (fseek(dp->File, hp->SectPos, SEEK_SET) != 0) goto error; if (fread(buffer, hp->SegSize, 1, dp->File) != 1) goto error; *size = hp->SegSize; return(dp); error: #if defined OS_VMS || defined OS_ELN sprintf(msg, "BlockDbGet: %s", strerror(errno, vaxc$errno)); #else sprintf(msg, "BlockDbGet: %s", strerror(errno)); #endif Log(msg); return mh_BlockDbClose(dp); }
void sev_repair::clean_item( int idx, int print_idx) { pwr_tTime currenttime, limit; time_GetTime(¤ttime); if ( m_db->m_items[idx].deleted) return; if ( m_db->m_items[idx].storagetime.tv_sec == 0) return; time_Asub( &limit, ¤ttime, &m_db->m_items[idx].storagetime); if( m_db->m_items[idx].attrnum > 1 ) { if ( print_idx) printf( "-- Processing %d (%u) %s\n", idx, m_db->m_items.size(), m_db->m_items[idx].tablename); else printf( "-- Processing %s\n", m_db->m_items[idx].tablename); m_db->delete_old_objectdata( &m_sts, m_db->m_items[idx].tablename, m_db->m_items[idx].options, limit, m_db->m_items[idx].scantime, (float)0xEFFFFFFF); } else { if ( print_idx) printf( "-- Processing %d (%u) %s\n", idx, m_db->m_items.size(), m_db->m_items[idx].tablename); else printf( "-- Processing %s\n", m_db->m_items[idx].tablename); m_db->delete_old_data( &m_sts, m_db->m_items[idx].tablename, m_db->m_items[idx].options, limit, m_db->m_items[idx].scantime, (float)0xEFFFFFFF); } }
/* Supervise emon server process */ void pwrs_Node_SupEmon ( ) { int i = errh_eAnix_emon - 1; pwr_tTime current_time; pwr_tDeltaTime diff; static float timeout = 3; if ( !np) { pwr_tOid oid; pwr_tStatus sts; sts = gdh_GetNodeObject( 0, &oid); if ( ODD(sts)) gdh_ObjidToPointer( oid, (void **) &np); if ( EVEN(sts)) return; } if ( !np) return; if ( np->ProcStatus[i] != 0 && np->ProcStatus[i] != PWR__PTIMEOUT) { time_GetTime( ¤t_time); time_Adiff( &diff, ¤t_time, &np->ProcTimeStamp[i]); if ( time_DToFloat( 0, &diff) > timeout) { if ( errh_Severity( np->ProcStatus[i]) < errh_Severity(PWR__PTIMEOUT)) { np->ProcStatus[i] = PWR__PTIMEOUT; np->SystemStatus = PWR__PTIMEOUT; } } } }
ItemMsg::ItemMsg( MsgList *item_msglist, const char *item_name, char *item_text, int item_severity, brow_tNode dest, flow_eDest dest_code): msglist(item_msglist), severity(item_severity) { char type_str[8]; char time_str[40]; type = msglist_eItemType_Msg; strncpy( text, item_text, sizeof(text)); text[sizeof(text)-1] = 0; // Remove newline at end if ( text[strlen(text)-1] == '\n') text[strlen(text)-1] = 0; switch ( severity) { case 'S': brow_CreateNode( msglist->brow->ctx, (char *)"Success", msglist->brow->nc_success, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, "S"); break; case 'I': brow_CreateNode( msglist->brow->ctx, (char *)"Info", msglist->brow->nc_info, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, "I"); break; case 'E': brow_CreateNode( msglist->brow->ctx, (char *)"Error", msglist->brow->nc_error, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, "E"); break; case 'W': brow_CreateNode( msglist->brow->ctx, (char *)"Warning", msglist->brow->nc_warning, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, "W"); break; case 'F': brow_CreateNode( msglist->brow->ctx, (char *)"Fatal", msglist->brow->nc_fatal, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, "F"); break; default: brow_CreateNode( msglist->brow->ctx, (char *)"Default", msglist->brow->nc_default, dest, dest_code, (void *) this, 1, &node); strcpy( type_str, ""); } brow_SetAnnotation( node, 0, type_str, strlen(type_str)); time_GetTime( &time); time_AtoAscii( &time, time_eFormat_ComprDateAndTime, time_str, sizeof(time_str)); time_str[17] = 0; brow_SetAnnotation( node, 1, time_str, strlen(time_str)); brow_SetAnnotation( node, 2, text, strlen(text)); // brow_SetAnnotPixmap( node, 0, msglist->brow->pixmap_leaf); }
static void detect ( pwr_sClass_NodeLinkSup *o, pwr_tBoolean con, sNode *np ) { /* For DSup we compare with control position, but for NodeLink we only detect LinkDown */ if (o->LinkUp) { if (o->Action) o->Action = FALSE; if (o->ReturnCheck) { time_GetTime(&o->ReturnTime); o->ReturnCheck = FALSE; o->ReturnSend = TRUE; } if (o->AlarmCheck && !o->DetectCheck) { o->TimerFlag = FALSE; o->DetectCheck = TRUE; } } else if (con) { if (!o->Action) o->Action = TRUE; if (o->AlarmCheck && o->DetectOn && !o->Blocked) { if (o->DetectCheck) { o->TimerCount = (o->TimerTime * 1000) / cTimerTimeDetect; if (!o->TimerFlag && o->TimerCount > 0) { if (!LstInl(&np->timer_l)) { LstIns(&timer_l, np, timer_l); } o->TimerFlag = TRUE; } time_GetTime(&o->DetectTime); o->DetectCheck = FALSE; } if (!o->TimerFlag) { o->DetectSend = TRUE; o->ReturnCheck = TRUE; o->Acked = FALSE; o->AlarmCheck = FALSE; } } } }
static unsigned int pkg_random() { pwr_tTime t; time_GetTime( &t); int itime = t.tv_nsec + t.tv_sec % 10000; srand( itime); return (unsigned int)((double) rand() / ((double) RAND_MAX + 1) * 999999); }
/************************************************************************* * * Name: logg_get_filename * * Typ int * * Typ Parameter IOGF Beskrivning * * Beskrivning: * Adderar extention till filname om det saknas. * **************************************************************************/ static int logg_get_filename( char *inname, char *outname, char *ext) { char *s; char *s2; pwr_tFileName timestr; char comp_timestr[80]; pwr_tTime time; dcli_translate_filename( outname, inname); /* Look for extension in filename */ if ( ext != NULL) { s = strrchr( outname, ':'); if ( s == 0) s = outname; s2 = strrchr( s, '>'); if ( s2 == 0) { s2 = strrchr( s, ']'); if ( s2 == 0) s2 = s; } s = strrchr( s2, '.'); if ( s != 0) *s = 0; strcat( outname, ext); } #if defined OS_LYNX || defined OS_LINUX /* Get current time to use as "version number" */ time_GetTime( &time); time_AtoAscii( &time, time_eFormat_ComprDateAndTime, timestr, sizeof(timestr)); comp_timestr[0] = '.'; memcpy(&comp_timestr[1], ×tr[0], 2); memcpy(&comp_timestr[3], ×tr[3], 2); memcpy(&comp_timestr[5], ×tr[6], 2); memcpy(&comp_timestr[7], ×tr[9], 2); memcpy(&comp_timestr[9], ×tr[12], 2); memcpy(&comp_timestr[11], ×tr[15], 2); comp_timestr[13] = 0; // strcat(outname, comp_timestr); #endif return REM__SUCCESS; }
static void logg( const char *str) { pwr_tTime t; char timstr[40]; time_GetTime( &t); time_AtoAscii( 0, time_eFormat_Time, timstr, sizeof(timstr)); timstr[9] = 0; fprintf( fp, "%s%04lld %s\n", timstr, t.tv_nsec/100000, str); }
bool wb_db::importRbody(pwr_tOid oid, size_t size, void *body) { wb_db_rbody b(this, oid, size, body); wb_db_ohead oh(this, oid); pwr_tTime time; time_GetTime(&time); oh.get(m_txn); oh.rbTime(time); oh.put(m_txn); b.put(m_txn); return true; }
bool wb_dbms::importDbody(pwr_tOid oid, size_t size, void *body) { wb_dbms_dbody b(this, oid, size, body); wb_dbms_ohead oh(this, oid); pwr_tTime time; time_GetTime( &time); oh.get(m_txn); oh.dbTime(time); oh.upd(m_txn); b.ins(m_txn); return true; }
static pwr_tStatus logg_open_file( logg_t_loggconf_list *conflist_ptr, int first_time) { int csts; char filename[80]; pwr_tTime time; char timestr[80]; if ( !first_time) { /* Check if it's time for a new try to open the file */ conflist_ptr->wait_count++; if (conflist_ptr->wait_count < 10) return REM__SUCCESS; conflist_ptr->wait_count = 0; } /* Open file */ logg_get_filename( conflist_ptr->loggconf->LoggFile, filename, LOGG_FILE_EXT); #if defined OS_LYNX || defined OS_LINUX conflist_ptr->outfile = fopen( filename, "a+"); #else conflist_ptr->outfile = fopen( filename, "w+", "shr=get"); #endif if (conflist_ptr->outfile != NULL) { /* Write a file header */ time_GetTime( &time); time_AtoAscii( &time, time_eFormat_DateAndTime, timestr, sizeof(timestr)); csts = fprintf( conflist_ptr->outfile, "RemLogg file opened at %s\n\n", timestr); if (csts >= 0) { conflist_ptr->loggconf->FileOpenCount++; #if defined OS_ELN || defined OS_VMS fgetname( conflist_ptr->outfile, filename); #endif errh_CErrLog( REM__LOGGFILEOPEN, errh_ErrArgAF(filename), NULL); conflist_ptr->file_open = 1; return REM__SUCCESS; } else { fclose( conflist_ptr->outfile); } } errh_CErrLog( REM__LOGGFILE, errh_ErrArgAF(filename), NULL); return REM__LOGGFILE; }
static void time_PeriodSec( pwr_tTime *from, pwr_tTime *to, pwr_tTime *center, int sec) { pwr_tStatus sts; pwr_tTime current; sts = time_GetTime( ¤t); to->tv_sec = center->tv_sec + sec/2; to->tv_nsec = center->tv_nsec; if ( time_Acomp( to, ¤t) == 1) *to = current; from->tv_sec = to->tv_sec - sec; from->tv_nsec = to->tv_nsec; }
pwr_tBoolean qos_WaitQue ( pwr_tStatus *status, qdb_sQue *qp, int tmo ) { pwr_tDeltaTime dtime; pwr_tTime atime; struct timespec atime_ts; int ok; pwr_tBoolean signal = FALSE; pwr_dStatus (sts, status, QCOM__SUCCESS); qdb_AssumeLocked; if (tmo == qcom_cTmoNone) return FALSE; pthread_mutex_lock(&qp->lock.mutex); qp->lock.waiting = TRUE; qp->lock.pid = 0; qdb_Unlock; if (tmo != qcom_cTmoEternal) { time_GetTime(&atime); time_MsToD(&dtime, tmo); time_Aadd(&atime, &atime, &dtime); atime_ts.tv_sec = atime.tv_sec; atime_ts.tv_nsec = atime.tv_nsec; ok = pthread_cond_timedwait(&qp->lock.cond, &qp->lock.mutex, &atime_ts); } else { ok = pthread_cond_wait(&qp->lock.cond, &qp->lock.mutex); } pthread_mutex_unlock(&qp->lock.mutex); qdb_Lock; if ((qp->lock.waiting) || (ok == ETIMEDOUT)) { *sts = QCOM__TMO; qp->lock.waiting = FALSE; } else { signal = TRUE; } return signal; }
void time_AtoFormAscii ( pwr_tTime *ts, short dissolution, short formType, char buf[], int bufsize ) { int len; struct tm *tmpTm; char tmphs[16]; pwr_tTime time, *tp; if (ts == NULL) { time_GetTime(&time); tp = &time; } else { tp = ts; } switch (formType) { case GB: case SWE: default: { time_t sec = tp->tv_sec; tmpTm = localtime(&sec); switch (dissolution) { case HUNDRED: len = strftime(buf, bufsize, "%Y-%m-%d %H:%M:%S", tmpTm); if (len != 0 && len + 4 <= bufsize) { sprintf(tmphs, ".%02d", (int)(tp->tv_nsec / 10000000)); strcat(buf, tmphs); } break; case MINUTE: strftime(buf, bufsize, "%Y-%m-%d %H:%M", tmpTm); break; case SECOND: default: strftime(buf, bufsize, "%Y-%m-%d %H:%M:%S", tmpTm); break; } } } }
int XttVideoMgmAimetis::check_session() { pwr_tTime current; pwr_tDeltaTime timeout = {300,0}; pwr_tDeltaTime dt; int sts = 1; // Check that current session hasn't timed out time_GetTime( ¤t); time_Adiff_NE( &dt, ¤t, &m_last_auth); if ( time_Dcomp( &dt, &timeout) == 1) sts = authorize( m_op->User, m_op->Password); return sts; }
time_tOs * time_Os ( pwr_tStatus *status, time_tOs *tp ) { static time_tOs os_time; pwr_dStatus(sts, status, TIME__SUCCESS); if (tp == NULL) tp = &os_time; time_GetTime(tp); return tp; }
bool CNetMgr::Init(char *pPlayerName) { m_PlayerName[0] = 0; m_LatentPacketBank.SetCacheSize(256); m_nDroppedPackets = 0; m_pCurPrefix = ""; LTStrCpy(m_PlayerName, pPlayerName, sizeof(m_PlayerName)); m_fLastTime = time_GetTime( ); SetAppGuid(LTNULL); SetMainDriver(LTNULL); return true; }
void subcm_CheckTimeout () { pool_sQlink *cl; sub_sClient *cp; pwr_tTime curtim; pwr_tTime restim; pwr_tDeltaTime tmotim; pwr_tInt32 n; pwr_tInt32 i; gdb_AssumeLocked; gdbroot->db->tmocnt++; /* Statistics */ time_GetTime( &curtim); /* Calculate # of remote object clients to process this time */ n = gdbroot->db->subt_lc; if (n == 0) n = MIN(1, gdbroot->db->subt_lc); for (i=0; i<n; i++) { /* Temporarily remove the first entry from the queue for processing. */ cl = pool_QremoveSucc(NULL, gdbroot->pool, &gdbroot->db->subt_lh); cp = pool_Qitem(cl, sub_sClient, subt_ll); /* Find out if the client has timed out */ if (!cp->old) { /* cp->tmo in 10ths of seconds */ tmotim.tv_sec = cp->tmo / 10; tmotim.tv_nsec = (cp->tmo - tmotim.tv_sec * 10) * 100000000; time_Aadd(&restim, &cp->lastupdate, &tmotim); /* curtim >= tmotim + lastupdate */ if (time_Acomp(&curtim, &restim) >= 0) subc_SetOld(cp); } /* If it was old already */ /* Reinsert the entry last in the queue. */ pool_QinsertPred(NULL, gdbroot->pool, cl, &gdbroot->db->subt_lh); } }
void bck_ForceBackup ( void **context) { pwr_tInt32 sts; pwr_tTime *t; #ifdef OS_VMS $DESCRIPTOR (efcname, BCK_EFC_NAME); #endif /* * Initialize */ #ifdef OS_ELN if (!areas_mapped) { BCK_MAP_AREAS; areas_mapped = TRUE; } #endif /* * Build the context block (i.e. current time) */ if (context != NULL) { t = malloc (sizeof *t); time_GetTime(t); *context = t; } /* * Kick the backup processes */ #ifdef OS_ELN ker$signal (NULL, bck_forced_activation); #else sts = sys$ascefc (BCK_EFC, &efcname, 0, 0); if (EVEN (sts)) lib$signal (sts); sts = sys$setef (BCK_ACTIVATE); if (EVEN (sts)) lib$signal (sts); #endif } /* bck_ForceBackup */
pwr_tStatus time_AtoAscii ( pwr_tTime *ts, time_eFormat format, char *buf, int bufsize ) { struct tm *tmpTm; int buflen; char tmpStr[16]; pwr_tTime time; pwr_tTime *tp; if (ts == NULL) { time_GetTime(&time); tp = &time; } else tp = ts; time_t sec = tp->tv_sec; tmpTm = localtime(&sec); if (EVEN(time_TmToAscii(tmpTm, format, buf, bufsize))) return TIME__RANGE; buflen = strlen(buf); switch (format) { case time_eFormat_FileDateAndTime: case time_eFormat_FileDate: break; default: sprintf(tmpStr, ".%02d", (int)(tp->tv_nsec / 10000000)); if (strlen(tmpStr) + buflen < (unsigned int) bufsize) strcpy(&buf[buflen], tmpStr); } return TIME__SUCCESS; }
static int usbio_reconnect( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp) { io_sLocal *local = cp->Local; io_sLocalUSB *localUSB = (io_sLocalUSB *)rp->Local; pwr_sClass_MotionControl_USBIO *op = (pwr_sClass_MotionControl_USBIO *)cp->op; pwr_tTime time; pwr_tDeltaTime diff; unsigned int snum; int handle; int i; int status; time_GetTime( &time); time_Adiff( &diff, &time, &local->ConnectRetry); if ( time_DToFloat( 0, &diff) > 1.0) { for ( i = 0; i < (int)sizeof(localUSB->USB_Handle); i++) { status = USBIO_Open( &handle); if ( status) break; status = USBIO_GetSerialNr( &handle, &snum); if ( snum == op->Super.Address) { local->USB_Handle = localUSB->USB_Handle[local->Idx] = handle; op->Status = status; op->Super.ErrorCount = 0; IoCardClose( ctx, ap, rp, cp); IoCardInit( ctx, ap, rp, cp); errh_Info( "USBIO card reconnected '%s'", cp->Name); return 1; } } } return 0; }
static void scan_nodes () { LstLink(sNode) *nl; pwr_tStatus sts; pwr_tBoolean Old; pwr_tTime LastUpdate, Timeout, CurrentTime; pwr_tDeltaTime Delta; pwr_tBoolean LinkUp; time_GetTime(&CurrentTime); for (nl = LstFir(&node_l); nl != LstEnd(&node_l); nl = LstNex(nl)) { sNode *np = LstObj(nl); pwr_sClass_NodeLinkSup *o = np->o; LinkUp = 0; sts = gdh_GetSubscriptionOldness (o->SubId, &Old, &LastUpdate, NULL); if (ODD(sts)) { /* IF (CurrentTime < LastUpdate + TimeoutTime) THEN LinkUp */ Delta.tv_sec = o->TimeoutTime; Delta.tv_nsec = 0; time_Aadd(&Timeout, &LastUpdate, &Delta); if (time_Acomp(&CurrentTime, &Timeout) < 0) LinkUp = 1; o->SystemStatus = *np->subvalue; } if (o->LinkUp && !LinkUp) { o->LinkUp = 0; o->DownTime = CurrentTime; o->SystemStatus = PWR__NETTIMEOUT; } else if (!o->LinkUp && LinkUp) { o->LinkUp = 1; o->UpTime = CurrentTime; o->UpCount++; } detect(o, 1, np); } }
wb_dbs::wb_dbs(wb_vrep *v) : m_oid(pwr_cNOid), m_rtonly(0), m_warnings(0), m_errors(0), m_nObjects(0), m_nTreeObjects(0), m_nClassObjects(0), m_nNameObjects(0), m_nRbodyObjects(0), m_nDbodyObjects(0), m_oep(0) { pwr_tStatus sts; memset(m_fileName, 0, sizeof(m_fileName)); memset(&m_volume, 0, sizeof(m_volume)); memset(m_sect, 0, sizeof(m_sect)); time_GetTime(&m_volume.time); m_v = v; m_volume.vid = m_v->vid(); strcpy(m_volume.name, m_v->name()); m_volume.cid = m_v->cid(); //@todo strcpy(m_volume.className, m_ohp->chp->db.name.data); m_volume.dvVersion = getDvVersion( m_v); sprintf(m_fileName, dbs_cNameVolume, dbs_cDirectory, cdh_Low(m_v->name())); dcli_translate_filename(m_fileName, m_fileName); m_oid_th = tree_CreateTable(&sts, sizeof(pwr_tOid), offsetof(sOentry, o.oid), sizeof(sOentry), 1000, tree_Comp_oid); m_name_th = tree_CreateTable(&sts, sizeof(dbs_sName), offsetof(sNentry, n), sizeof(sNentry), 1000, comp_dbs_name); m_class_th = tree_CreateTable(&sts, sizeof(pwr_tCid), offsetof(sCentry, c), sizeof(sCentry), 1000, tree_Comp_cid); m_vol_th = tree_CreateTable(&sts, sizeof(pwr_tVid), offsetof(sVentry, v.vid), sizeof(sVentry), 10, tree_Comp_vid); }
pwr_tDeltaTime * time_Uptime ( pwr_tStatus *status, pwr_tDeltaTime *tp, pwr_tDeltaTime *ap ) { pwr_tDeltaTime time; unsigned long tics; static pwr_tUInt64 tics_64; struct tms buff; static int tics_per_sec = 0; static pwr_tTime boot_time = {0,0}; static pwr_tDeltaTime max_diff = {0, 20000000}; pwr_tDeltaTime uptime_tics; pwr_tTime current_time; pwr_tDeltaTime diff; static pwr_tUInt16 msb_flips = 0; static pwr_tBoolean old_high_bit = 0; pwr_tBoolean high_bit; lldiv_t uptime_s; pwr_dStatus(sts, status, TIME__SUCCESS); if ( !tics_per_sec) tics_per_sec = sysconf(_SC_CLK_TCK); if (tp == NULL) tp = &time; tics = times(&buff); high_bit = tics >> (32 - 1); if (!high_bit && old_high_bit) msb_flips++; old_high_bit = high_bit; tics_64 = ((pwr_tUInt64) msb_flips << 32) | tics; uptime_s = lldiv(tics_64, (pwr_tInt64) tics_per_sec); uptime_tics.tv_sec = (pwr_tInt64) uptime_s.quot; uptime_tics.tv_nsec = ((pwr_tUInt64) uptime_s.rem) * (1000000000 / tics_per_sec); // pwr_Assert(tp->tv_sec >= 0 && tp->tv_nsec >= 0); time_GetTime( ¤t_time); if ( !boot_time.tv_sec) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; } else { time_Adiff( tp, ¤t_time, &boot_time); time_Dsub( &diff, tp, &uptime_tics); time_Dabs(NULL, &diff); if ( time_Dcomp(&diff, &max_diff) > 0) { time_Asub( &boot_time, ¤t_time, &uptime_tics); *tp = uptime_tics; if (status != NULL) { *status = TIME__CLKCHANGE; } } } if (ap != NULL) return time_Dadd(tp, tp, ap); else return tp; }
static void *mb_receive( void *data) { io_sRack *rp = ((mb_sCondata *)data)->rp; int l_idx = ((mb_sCondata *)data)->idx; io_sServerLocal* local = rp->Local; int c_socket = local->connections[l_idx].c_socket; pwr_sClass_Modbus_TCP_Server *op = (pwr_sClass_Modbus_TCP_Server *) rp->op; ssize_t data_size; rec_buf *rb; unsigned char fc; unsigned char exception_code; ssize_t ssts; int size_of_msg; free( data); op->Connections++; while ( 1) { size_of_msg = 0; data_size = recv(c_socket, rcv_buffer, sizeof(rec_buf), 0); if ( data_size < 0) { op->ErrorCount++; continue; } if ( data_size == 0) { /* Disconnected */ op->Connections--; close( c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } if ( op->DisableServer) continue; while ( data_size > 0) { if (data_size < sizeof(mbap_header)) break; op->RX_packets++; rb = (rec_buf *) &rcv_buffer[size_of_msg]; if ( rb->head.length == 0) break; size_of_msg += ntohs(rb->head.length) + 6; data_size -= ntohs(rb->head.length) + 6; fc = (unsigned char) *rb->buf; time_GetTime( &local->connections[l_idx].last_req_time); exception_code = 0; switch ( fc) { case pwr_eModbus_FCEnum_ReadHoldingRegisters: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; read_req *rmsg = (read_req *)rb; rsp_read msg; int found; short addr = ntohs( rmsg->addr); short quant = ntohs( rmsg->quant); unsigned char unit_id = rmsg->head.unit_id; if ( quant < 1 || quant >= 0x07d0) { exception_code = 3; break; } /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } addr -= mp->ReadAddress; if ( addr < 0 || addr + quant * 2 > local_card->output_size) { exception_code = 2; break; } msg.fc = fc; msg.bc = quant * 2; msg.head.trans_id = rmsg->head.trans_id; // msg.head.length = htons( sizeof(msg) - 6); msg.head.length = htons( sizeof(msg) - sizeof(msg.buf) + quant * 2 - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; thread_MutexLock( &local->mutex); memcpy( msg.buf, (char *)local_card->output_area + addr, quant * 2); thread_MutexUnlock( &local->mutex); ssts = send( c_socket, &msg, ntohs(msg.head.length) + 6, MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case pwr_eModbus_FCEnum_ReadCoils: case pwr_eModbus_FCEnum_ReadDiscreteInputs: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; read_req *rmsg = (read_req *)rb; rsp_read msg; int found; unsigned char mask; unsigned int bytes; int i; int offs; short addr = ntohs( rmsg->addr); short quant = ntohs( rmsg->quant); unsigned char unit_id = rmsg->head.unit_id; if ( quant < 1 || quant >= 0x07d0) { exception_code = 3; break; } /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } offs = addr / 8; bytes = (addr + quant) / 8 + (((addr + quant) % 8 == 0) ? 0 : 1) - offs; if ( addr < 0 || offs + bytes + local_card->do_offset > local_card->output_size || offs + bytes > local_card->do_size) { exception_code = 2; break; } memset( &msg, 0, sizeof(msg)); msg.fc = fc; msg.bc = bytes; msg.head.trans_id = rmsg->head.trans_id; // msg.head.length = htons( sizeof(msg) - 6); msg.head.length = htons( sizeof(msg) - sizeof(msg.buf) + bytes - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; thread_MutexLock( &local->mutex); if ( addr % 8 == 0) { memcpy( msg.buf, (char *)local_card->output_area + local_card->do_offset + addr/8, bytes); mask = 0; for ( i = 0; i < quant % 8; i++) mask |= 1 << i; if ( quant % 8 != 0) { unsigned char *b = (unsigned char *) msg.buf; b[bytes - 1] &= mask; } } else { mb_shift_read( (unsigned char *)local_card->output_area + local_card->do_offset + addr / 8, (unsigned char *)msg.buf, addr % 8, quant); } thread_MutexUnlock( &local->mutex); ssts = send( c_socket, &msg, ntohs(msg.head.length) + 6, MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case pwr_eModbus_FCEnum_WriteSingleRegister: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; write_single_req *rmsg = (write_single_req *)rb; rsp_single_write msg; int found; short addr = ntohs( rmsg->addr); unsigned char unit_id = rmsg->head.unit_id; /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } addr -= mp->WriteAddress; if ( addr < 0 || addr + 2 > local_card->input_size) { exception_code = 2; break; } thread_MutexLock( &local->mutex); memcpy( (char *)local_card->input_area + addr, &rmsg->value, 2); thread_MutexUnlock( &local->mutex); msg.fc = fc; msg.addr = rmsg->addr; msg.value = rmsg->value; msg.head.trans_id = rmsg->head.trans_id; msg.head.length = htons( sizeof(msg) - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; ssts = send( c_socket, &msg, sizeof(msg), MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case pwr_eModbus_FCEnum_WriteMultipleRegisters: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; write_reg_req *rmsg = (write_reg_req *)rb; rsp_write msg; int found; short addr = ntohs( rmsg->addr); short quant = ntohs( rmsg->quant); unsigned char unit_id = rmsg->head.unit_id; if ( quant < 1 || quant >= 0x07d0) { exception_code = 3; break; } /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } addr -= mp->WriteAddress; if ( addr < 0 || addr + quant * 2 > local_card->input_size) { exception_code = 2; break; } thread_MutexLock( &local->mutex); memcpy( (char *)local_card->input_area + addr, rmsg->reg, quant * 2); thread_MutexUnlock( &local->mutex); msg.fc = fc; msg.addr = rmsg->addr; msg.quant = rmsg->quant; msg.head.trans_id = rmsg->head.trans_id; msg.head.length = htons( sizeof(msg) - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; ssts = send( c_socket, &msg, sizeof(msg), MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case pwr_eModbus_FCEnum_WriteSingleCoil: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; write_single_req *rmsg = (write_single_req *)rb; rsp_single_write msg; int found; unsigned char mask; int offs; short addr = ntohs( rmsg->addr); unsigned short value = ntohs( rmsg->value); unsigned char unit_id = rmsg->head.unit_id; /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } offs = addr / 8; if ( addr < 0 || offs + local_card->di_offset >= local_card->input_size || offs >= local_card->di_size) { exception_code = 2; break; } mask = 1 << (addr % 8); if ( value == 0xFF00 || value == 0) { thread_MutexLock( &local->mutex); if ( value == 0xFF00) *((char *)local_card->input_area + local_card->di_offset + offs) |= mask; else *((char *)local_card->input_area + local_card->di_offset + offs) &= ~mask; thread_MutexUnlock( &local->mutex); } msg.fc = fc; msg.addr = rmsg->addr; msg.value = rmsg->value; msg.head.trans_id = rmsg->head.trans_id; msg.head.length = htons( sizeof(msg) - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; ssts = send( c_socket, &msg, sizeof(msg), MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case pwr_eModbus_FCEnum_WriteMultipleCoils: { io_sCard *cardp; io_sServerModuleLocal *local_card; pwr_sClass_Modbus_TCP_ServerModule *mp; write_reg_req *rmsg = (write_reg_req *)rb; rsp_write msg; int found; unsigned char mask; unsigned int bytes; int i; int offs; short addr = ntohs( rmsg->addr); short quant = ntohs( rmsg->quant); unsigned char unit_id = rmsg->head.unit_id; if ( quant < 1 || quant >= 0x07d0) { exception_code = 3; break; } /* Check the address */ found = 0; for ( cardp = rp->cardlist; cardp; cardp = cardp->next) { mp = (pwr_sClass_Modbus_TCP_ServerModule *) cardp->op; if ( mp->UnitId == unit_id) { local_card = cardp->Local; found = 1; break; } } if ( !found) { exception_code = 2; break; } offs = addr / 8; bytes = (addr + quant) / 8 + (((addr + quant) % 8 == 0) ? 0 : 1) - offs; if ( addr < 0 || offs + bytes + local_card->di_offset > local_card->input_size || offs + bytes > local_card->di_size) { exception_code = 2; break; } thread_MutexLock( &local->mutex); if ( addr % 8 == 0) { if ( quant % 8 != 0) { mask = 0; for ( i = 0; i < quant % 8; i++) mask |= 1 << i; memcpy( (char *)local_card->input_area + local_card->di_offset + addr / 8, rmsg->reg, bytes - 1); *((char *)local_card->input_area + local_card->di_offset + addr / 8 + bytes - 1) &= ~mask; *((char *)local_card->input_area + local_card->di_offset + addr / 8 + bytes - 1) |= *((char *)rmsg->reg + bytes - 1) & mask; } else memcpy( (char *)local_card->input_area + local_card->di_offset + addr / 8, rmsg->reg, bytes); } else { mb_shift_write( (unsigned char *)rmsg->reg, (unsigned char *)local_card->input_area + local_card->di_offset + addr / 8, addr % 8, quant); } thread_MutexUnlock( &local->mutex); msg.fc = fc; msg.addr = rmsg->addr; msg.quant = rmsg->quant; msg.head.trans_id = rmsg->head.trans_id; msg.head.length = htons( sizeof(msg) - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; ssts = send( c_socket, &msg, sizeof(msg), MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } case 43: { /* Encapsulated Interface Transport, Read Device Identification */ read_dev_id_req *rmsg = (read_dev_id_req *)rb; rsp_dev_id msg; int i; int len; if ( rmsg->mei_type != 0x2b) { exception_code = 1; break; } if ( rmsg->id_code != 1) { exception_code = 1; break; } if ( rmsg->object_id != 0) { exception_code = 1; break; } msg.fc = rmsg->fc; msg.mei_type = rmsg->mei_type; msg.id_code = rmsg->id_code; msg.conformity_level = 1; msg.more_follows = 0; msg.next_object_id = 0; msg.number_of_objects = 3; i = 0; /* Vendor name */ msg.list[i++] = 0; len = strlen("Proview"); msg.list[i++] = len; strncpy( (char *)&msg.list[i], "Proview", len); i += len; /* Product code */ msg.list[i++] = 0; len = strlen("-"); msg.list[i++] = len; strncpy( (char *)&msg.list[i], "-", len); i += len; /* Major Minor Revision */ msg.list[i++] = 0; len = strlen(pwrv_cPwrVersionStr); msg.list[i++] = len; strncpy( (char *)&msg.list[i], pwrv_cPwrVersionStr, len); i += len; msg.head.trans_id = rmsg->head.trans_id; msg.head.length = htons( sizeof(msg) - sizeof(msg.list) + i - 6); msg.head.unit_id = rmsg->head.unit_id; msg.head.proto_id = rmsg->head.proto_id; ssts = send( c_socket, &msg, ntohs(msg.head.length) + 6, MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; break; } default: exception_code = 1; } if ( exception_code) { rsp_fault rsp_f; rsp_f.fc = fc + 0x80; rsp_f.ec = exception_code; rsp_f.head.trans_id = rb->head.trans_id; rsp_f.head.length = htons( sizeof(rsp_f) - 6); rsp_f.head.unit_id = rb->head.unit_id; ssts = send( c_socket, &rsp_f, sizeof(rsp_f), MSG_DONTWAIT); if (ssts < 0) { op->Connections--; close(c_socket); local->connections[l_idx].occupied = 0; errh_Error( "Connection lost for IO modbus tcp server %s, %d", rp->Name, c_socket); return 0; } op->TX_packets++; } } } return 0; }