📄 sahpi_struct_utils.c
字号:
working.Value.SensorFloat64 = num_float64; } } else { /* No number in string */ num_float64 = 0; } break; default: /* Should never get here */ dbg("Invalid type=%d", type); return(SA_ERR_HPI_INTERNAL_ERROR); } *reading = working; return(SA_OK);}/** * oh_fprint_text: * @stream: File handle. * @buffer: Pointer to SaHpiTextBufferT to be printed. * * Prints the text data contained in SaHpiTextBufferT to a file. Data must * be of type SAHPI_TL_TYPE_TEXT. @buffer->DataLength is ignored. * The MACRO oh_print_text(), uses this function to print to STDOUT. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_DATA - @buffer->DataType not SAHPI_TL_TYPE_TEXT. **/SaErrorT oh_fprint_text(FILE *stream, const SaHpiTextBufferT *buffer){ int err; /* FIXME:: Why not support the other types - most represented as 8-bit ASCII; so can print without a problem */ if (buffer->DataType == SAHPI_TL_TYPE_TEXT) { err = fprintf(stream, "%s\n", buffer->Data); if (err < 0) { return(SA_ERR_HPI_INVALID_PARAMS); } } else { return(SA_ERR_HPI_INVALID_DATA); } return(SA_OK);}/** * oh_fprint_bigtext: * @stream: File handle. * @big_buffer: Pointer to oh_big_textbuffer to be printed. * * Prints the text data contained in oh_big_textbuffer to a file. Data must * be of type SAHPI_TL_TYPE_TEXT. @big_buffer->DataLength is ignored. * The MACRO oh_print_bigtext(), uses this function to print to STDOUT. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_DATA - @big_buffer->DataType not SAHPI_TL_TYPE_TEXT. **/SaErrorT oh_fprint_bigtext(FILE *stream, const oh_big_textbuffer *big_buffer){ int err; if (big_buffer->DataType == SAHPI_TL_TYPE_TEXT) { err = fprintf(stream, "%s\n", big_buffer->Data); if (err < 0) { return(SA_ERR_HPI_INVALID_PARAMS); } } else { return(SA_ERR_HPI_INVALID_DATA); } return(SA_OK);}/** * oh_init_textbuffer: * @buffer: Pointer to an SaHpiTextBufferT. * * Initializes an SaHpiTextBufferT. Assumes an English language set. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - @buffer is NULL. **/SaErrorT oh_init_textbuffer(SaHpiTextBufferT *buffer){ if (!buffer) { return(SA_ERR_HPI_INVALID_PARAMS); } memset(buffer, 0, sizeof(*buffer)); buffer->DataType = SAHPI_TL_TYPE_TEXT; buffer->Language = SAHPI_LANG_ENGLISH; buffer->DataLength = 0; return(SA_OK);}static inline SaErrorT oh_init_bigtext(oh_big_textbuffer *big_buffer){ if (!big_buffer) { return(SA_ERR_HPI_INVALID_PARAMS); } memset(big_buffer, 0, sizeof(*big_buffer)); big_buffer->DataType = SAHPI_TL_TYPE_TEXT; big_buffer->Language = SAHPI_LANG_ENGLISH; big_buffer->DataLength = 0; return(SA_OK);}/** * oh_copy_textbuffer: * @dest: SaHpiTextBufferT to copy into. * @from:SaHpiTextBufferT to copy from. * * Copies one SaHpiTextBufferT structure to another. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT oh_copy_textbuffer(SaHpiTextBufferT *dest, const SaHpiTextBufferT *from){ if (!dest || !from) { return(SA_ERR_HPI_INVALID_PARAMS); } dest->DataType = from->DataType; dest->Language = from->Language; dest->DataLength = from->DataLength; memcpy(dest->Data, from->Data, SAHPI_MAX_TEXT_BUFFER_LENGTH); return(SA_OK);}static inline SaErrorT oh_copy_bigtext(oh_big_textbuffer *dest, const oh_big_textbuffer *from){ if (!dest || !from) { return(SA_ERR_HPI_INVALID_PARAMS); } dest->DataType = from->DataType; dest->Language = from->Language; dest->DataLength = from->DataLength; memcpy(dest->Data, from->Data, OH_MAX_TEXT_BUFFER_LENGTH); return(SA_OK);}/** * oh_append_textbuffer: * @buffer: SaHpiTextBufferT to append to. * @from: String to be appended. * * Appends a string to @buffer->Data. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. * SA_ERR_HPI_OUT_OF_SPACE - @buffer not big enough to accomodate appended string. **/SaErrorT oh_append_textbuffer(SaHpiTextBufferT *buffer, const char *from){ SaHpiUint8T *p; uint size; if (!buffer || !from) { return(SA_ERR_HPI_INVALID_PARAMS); } size = strlen(from); if ((size + buffer->DataLength) >= SAHPI_MAX_TEXT_BUFFER_LENGTH) { dbg("Cannot append to text buffer. Bufsize=%d, size=%u", buffer->DataLength, size); return(SA_ERR_HPI_OUT_OF_SPACE); } /* Can't trust NULLs to be right, so use a targeted strncpy instead */ p = buffer->Data; p += buffer->DataLength; strncpy(p, from, size); buffer->DataLength += size; return(SA_OK);}static inline SaErrorT oh_append_bigtext(oh_big_textbuffer *big_buffer, const char *from){ SaHpiUint8T *p; uint size; if (!big_buffer || !from) { dbg("Invalid parameters"); return(SA_ERR_HPI_INVALID_PARAMS); } size = strlen(from); if ((size + big_buffer->DataLength) >= OH_MAX_TEXT_BUFFER_LENGTH) { dbg("Cannot append to buffer. Bufsize=%d, size=%u", big_buffer->DataLength, size); return(SA_ERR_HPI_INTERNAL_ERROR); } /* Can't trust NULLs to be right, so use a targeted strncpy instead */ p = big_buffer->Data; p += big_buffer->DataLength; strncpy(p, from, size); big_buffer->DataLength += size; return(SA_OK);}static inline SaErrorT oh_append_data(oh_big_textbuffer *big_buffer, const SaHpiUint8T *from, SaHpiUint8T len){ SaHpiUint8T i; if (!big_buffer || !from || len == 0) { dbg("Invalid parameters"); return(SA_ERR_HPI_INVALID_PARAMS); } for (i = 0; i < len; i++) { SaHpiUint8T *p; char buff[10]; int slen; memset(buff, 0 ,sizeof(buff)); snprintf(buff, 10, "%d ", *(from + i)); slen = strlen(buff); if ((slen + big_buffer->DataLength) >= OH_MAX_TEXT_BUFFER_LENGTH) { dbg("Cannot append to buffer. Bufsize=%d, len=%d", big_buffer->DataLength, len); return(SA_ERR_HPI_INTERNAL_ERROR); } p = big_buffer->Data; p += big_buffer->DataLength; strncpy(p, buff, slen); big_buffer->DataLength += slen; } return(SA_OK);}/* Append an arbitrary number of fixed offset strings to a big text buffer */static SaErrorT oh_append_offset(oh_big_textbuffer *buffer, int offsets){ int i; for (i=0; i < offsets; i++) { oh_append_bigtext(buffer, OH_PRINT_OFFSET); } return(SA_OK);}/** * oh_fprint_ctrlrec: * @stream: File handle. * @control: Pointer to SaHpiCtrlRecT to be printed. * @offsets: Number of offsets to start printing structure. * * Prints a control's SaHpiCtrlRecT data to a file. * The MACRO oh_print_ctrlrec(), uses this function to print to STDOUT. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT oh_fprint_ctrlrec(FILE *stream, const SaHpiCtrlRecT *control, int offsets){ SaErrorT err; oh_big_textbuffer buffer; if (!stream || !control) { return(SA_ERR_HPI_INVALID_PARAMS); } oh_init_bigtext(&buffer); err = oh_build_ctrlrec(&buffer, control, offsets); if (err) { return(err); } err = oh_fprint_bigtext(stream, &buffer); if (err) { return(err); } return(SA_OK);}/** * oh_fprint_watchdogrec: * @stream: File handle. * @watchdog: Pointer to SaHpiWatchdogRecT to be printed. * @offsets: Number of offsets to start printing structure. * * Prints a watchdog's SaHpiWatchdogRecT data to a file. * The MACRO oh_print_watchdogrec(), uses this function to print to STDOUT. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT oh_fprint_watchdogrec(FILE *stream, const SaHpiWatchdogRecT *watchdog, int offsets){ SaErrorT err; oh_big_textbuffer buffer; if (!stream || !watchdog) { return(SA_ERR_HPI_INVALID_PARAMS); } oh_init_bigtext(&buffer); err = oh_build_wdogrec(&buffer, watchdog, offsets); if (err) { return(err); } err = oh_fprint_bigtext(stream, &buffer); if (err) { return(err); } return(SA_OK);}/** * oh_fprint_sensorrec: * @stream: File handle. * @sensor: Pointer to SaHpiSensorRecT to be printed. * @offsets: Number of offsets to start printing structure. * * Prints a sensor's SaHpiSensorRecT data to a file. * The MACRO oh_print_sensorrec(), uses this function to print to STDOUT. * * Returns: * SA_OK - normal operation. * SA_ERR_HPI_INVALID_PARAMS - Pointer parameter(s) are NULL. **/SaErrorT oh_fprint_sensorrec(FILE *stream, const SaHpiSensorRecT *sensor, int offsets){ int err; oh_big_textbuffer buffer; if (!stream || !sensor) { return(SA_ERR_HPI_INVALID_PARAMS); } oh_init_bigtext(&buffer); err = oh_build_sensorrec(&buffer, sensor, offsets); if (err) { return(err); } err = oh_fprint_bigtext(stream, &buffer); if (err) { return(err); } return(SA_OK);}static SaErrorT oh_build_sensorrec(oh_big_textbuffer *buffer, const SaHpiSensorRecT *sensor, int offsets){ char str[SAHPI_MAX_TEXT_BUFFER_LENGTH]; SaErrorT err; SaHpiTextBufferT tmpbuffer; /* Sensor Num */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Sensor Num: %d\n", sensor->Num); oh_append_bigtext(buffer, str); offsets++; /* Sensor Type */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Type: %s\n", oh_lookup_sensortype(sensor->Type)); oh_append_bigtext(buffer, str); /* Sensor Category */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "Category: %s\n", oh_lookup_eventcategory(sensor->Category)); oh_append_bigtext(buffer, str); /* Sensor Enable Control */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EnableCtrl: %s\n", (sensor->EnableCtrl == SAHPI_TRUE) ? "TRUE" : "FALSE"); oh_append_bigtext(buffer, str); /* Sensor Event Control */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "EventCtrl: %s\n", oh_lookup_sensoreventctrl(sensor->EventCtrl)); oh_append_bigtext(buffer, str); /* Sensor Supported Events */ oh_append_offset(buffer, offsets); oh_append_bigtext(buffer, "Events: "); err = oh_decode_eventstate(sensor->Events, sensor->Category, &tmpbuffer); if (err) {oh_append_bigtext(buffer, "\n"); return(err); } oh_append_bigtext(buffer, tmpbuffer.Data); oh_append_bigtext(buffer, "\n"); /* Sensor Data Format */ err = oh_build_sensordataformat(buffer, &(sensor->DataFormat), offsets); if (err) { return(err); } /* Sensor Threshold Definition */ err = oh_build_sensorthddefn(buffer, &(sensor->ThresholdDefn), offsets); if (err) { return(err); } /* Sensor OEM Data */ oh_append_offset(buffer, offsets); snprintf(str, SAHPI_MAX_TEXT_BUFFER_LENGTH, "OEM: %x\n", sensor->Oem); oh_append_bigtext(buffer, str);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -