PyObject *pv_getter_pvtimestr(pvobject * self, void *closure) { char timeText[80]; if (self->chanId && self->buff != NULL) { (void)tsStampToText(&self->buff->stamp, TS_TEXT_MMDDYY, timeText); return PyString_FromString(timeText); } else { PYCA_ERR("pvtimestr: indef"); } }
static void pvInfoWriteInfo(void) { time_t now; struct tm *tblock; char timeStampStr[TIME_STRING_MAX]; Record *pR; chid chId; char *descVal; #if defined(DBR_CLASS_NAME) && DO_RTYP char *rtypVal; #endif DlElement *pE; char *elementType; static char noType[]="Unknown"; struct dbr_time_string timeVal; char string[1024]; /* Danger: Fixed length */ XmTextPosition curpos = 0; int i, j; /* Free the timeout */ if(pvInfoTimerOn) { XtRemoveTimeOut(pvInfoTimeoutId); pvInfoTimerOn = False; } /* Just clean up and abort if we get called with no pvInfo * (Shouldn't happen) */ if(!pvInfo) return; /* Get timestamp */ time(&now); tblock = localtime(&now); strftime(timeStampStr, TIME_STRING_MAX, STRFTIME_FORMAT"\n", tblock); timeStampStr[TIME_STRING_MAX-1]='\0'; /* Get element type */ pE = pvInfoElement; if(pE && pE->type >= MIN_DL_ELEMENT_TYPE && pE->type <= MAX_DL_ELEMENT_TYPE) { elementType=elementType(pE->type); } else { elementType=noType; } /* Heading */ sprintf(string, " PV Information\n\nObject: %s\n%s\n", elementType, timeStampStr); XmTextSetInsertionPosition(pvInfoMessageBox, 0); XmTextSetString(pvInfoMessageBox, string); curpos+=strlen(string); /* Loop over the records to print information */ for(i=0; i < nPvInfoPvs; i++) { /* Check for a valid record */ if(!pvInfo[i].pvOk) continue; chId = pvInfo[i].pvChid; timeVal = pvInfo[i].timeVal; pR = pvInfo[i].record; /* Name */ sprintf(string, "%s\n" "======================================\n", ca_name(chId)); /* DESC */ descVal = pvInfo[i].descVal; if(pvInfo[i].descOk && descVal) { sprintf(string, "%sDESC: %s\n", string, descVal); } else { sprintf(string, "%sDESC: %s\n", string, NOT_AVAILABLE); } if(pvInfo[i].descChid) ca_clear_channel(pvInfo[i].descChid); #if defined(DBR_CLASS_NAME) && DO_RTYP /* RTYP */ rtypVal = pvInfo[i].rtypVal; if(pvInfo[i].rtypOk && rtypVal && *rtypVal) { sprintf(string, "%sRTYP: %s\n", string, rtypVal); } else { sprintf(string, "%sRTYP: %s\n", string, NOT_AVAILABLE); } #endif /* Items from chid */ sprintf(string, "%sTYPE: %s\n", string, dbf_type_to_text(ca_field_type(chId))); /* ca_element_count is defined differently in 3.14 vs. 3.13 */ sprintf(string, "%sCOUNT: %lu\n", string, (unsigned long)ca_element_count(chId)); sprintf(string, "%sACCESS: %s%s\n", string, ca_read_access(chId)?"R":"", ca_write_access(chId)?"W":""); sprintf(string, "%sIOC: %s\n", string, ca_host_name(chId)); if(timeVal.value) { char fracPart[10]; /* Do the value */ if(ca_element_count(chId) == 1) { sprintf(string, "%sVALUE: %s\n", string, timeVal.value); } else { sprintf(string, "%sFIRST VALUE: %s\n", string, timeVal.value); } /* Convert the seconds part of the timestamp to UNIX time */ now = timeVal.stamp.secPastEpoch + 631152000ul; tblock = localtime(&now); strftime(timeStampStr, TIME_STRING_MAX, "%a %b %d, %Y %H:%M:%S", tblock); timeStampStr[TIME_STRING_MAX-1]='\0'; /* Get the fractional part. This assumes strftime truncates seconds rather than rounding them, which seems to be the case. */ sprintf(fracPart, "%09d",timeVal.stamp.nsec); /* Truncate to 3 figures */ fracPart[3]='\0'; sprintf(timeStampStr,"%s.%s", timeStampStr, fracPart); timeStampStr[TIME_STRING_MAX-1]='\0'; sprintf(string, "%sSTAMP: %s\n", string, timeStampStr); #if DEBUG_TIMESTAMP /* This prints 9 significant figures and requires 3.13 base */ { char tsTxt[32]; sprintf(string,"%sSTAMP: %s\n",string, tsStampToText(&timeVal.stamp,TS_TEXT_MONDDYYYY,tsTxt)); } #endif } else { sprintf(string, "%sVALUE: %s\n", string, NOT_AVAILABLE); sprintf(string, "%sSTAMP: %s\n", string, NOT_AVAILABLE); } XmTextInsert(pvInfoMessageBox, curpos, string); curpos+=strlen(string); /* Alarms */ switch(pR->severity) { case NO_ALARM: sprintf(string, "ALARM: NO\n"); break; case MINOR_ALARM: sprintf(string, "ALARM: MINOR\n"); break; case MAJOR_ALARM: sprintf(string, "ALARM: MAJOR\n"); break; case INVALID_ALARM: sprintf(string, "ALARM: INVALID\n"); break; default: sprintf(string, "ALARM: Unknown\n"); break; } XmTextInsert(pvInfoMessageBox, curpos, string); curpos+=strlen(string); /* Items from record */ sprintf(string, "\n"); switch(ca_field_type(chId)) { case DBF_STRING: break; case DBF_ENUM: sprintf(string, "%sSTATES: %d\n", string, (int)(pR->hopr+1.1)); /* KE: Bad way to use a double */ if(pR->hopr) { for (j=0; j <= pR->hopr; j++) { sprintf(string, "%sSTATE %2d: %s\n", string, j, pR->stateStrings[j]); } } break; case DBF_CHAR: case DBF_INT: case DBF_LONG: sprintf(string, "%sHOPR: %g LOPR: %g\n", string, pR->hopr, pR->lopr); break; case DBF_FLOAT: case DBF_DOUBLE: if(pR->precision >= 0 && pR->precision <= 17) { sprintf(string, "%sPRECISION: %d\n", string, pR->precision); } else { sprintf(string, "%sPRECISION: %d [Bad Value]\n", string, pR->precision); } sprintf(string, "%sHOPR: %g LOPR: %g\n", string, pR->hopr, pR->lopr); break; default: break; } sprintf(string, "%s\n", string); XmTextInsert(pvInfoMessageBox, curpos, string); curpos+=strlen(string); } /* Pop it up unless we have left EXECUTE mode */ if(globalDisplayListTraversalMode == DL_EXECUTE) { XtSetSensitive(pvInfoS, True); XtPopup(pvInfoS, XtGrabNone); } /* Free space */ if(pvInfo) free((char *)pvInfo); pvInfo = NULL; pvInfoElement = NULL; }