int Ecat7Img::open(const char *fname) { if(!fname) { statmsg = imgmsg[1]; return 1; } // Open file for read fp = fopen(fname, "rb"); if (!fp) { statmsg = imgmsg[3]; return 1; } fileOpen = true; // Read header if (readMainHeader() > 0) { close(); return 1; } // Read matrix list if (readMatrixList() > 0) { close(); return 1; } // Calculate number of planeNr, frameNr if (calculateNr() > 0) { close(); return 1; } // Read subheader and calculate xSize, ySize, zSize and pxlNr if (readSubHeader() > 0) { close(); return 1; } if (alloc(planeNr, xSize, ySize) > 0) { statmsg = imgmsg[2]; close(); return 1; } // Copy information from mainheader headerToImg(); // Set file format setFileFormat(); return 0; }
int CVSCPTable::init() { // Protect int rv = VSCP_ERROR_SUCCESS; struct _vscpFileRecord record; // Open/create main file if ( fileExists( m_path.mbc_str() ) ) { m_ft = fopen( m_path.mbc_str(), "r+b") ; // binary Read Write if ( NULL == m_ft ) return VSCP_ERROR_ERROR; // Failed to open file } else { // Create file m_ft = fopen( m_path.mbc_str(), "w+b") ; // binary Read Write if ( NULL == m_ft ) return VSCP_ERROR_ERROR; // Failed to create file if ( VSCP_TABLE_DYNAMIC == m_vscpFileHead.type ) { m_vscpFileHead.id[0] = 0x55; m_vscpFileHead.id[0] = 0xAA; } else { m_vscpFileHead.id[0] = 0xAA; m_vscpFileHead.id[0] = 0x55; } // Write header if ( sizeof( m_vscpFileHead ) != fwrite( &m_vscpFileHead, 1, sizeof(m_vscpFileHead), m_ft ) ) { return VSCP_ERROR_ERROR; } // If we have a static table we initiate it if ( VSCP_TABLE_STATIC == m_vscpFileHead.type ) { _vscpFileRecord rec; memset( &rec, 0, sizeof(_vscpFileRecord) ); for ( unsigned int i=0; i<m_vscpFileHead.staticSize; i++ ) { if ( sizeof(_vscpFileRecord) != fwrite( &rec, 1, sizeof(_vscpFileRecord), m_ft ) ) { return VSCP_ERROR_ERROR; } } } } //Read header information rv = readMainHeader(); if ( VSCP_TABLE_DYNAMIC == m_vscpFileHead.type ) { // Calculate number of records in file m_number_of_records = ( fdGetFileSize( m_path.mbc_str() ) - sizeof( m_vscpFileHead ))/sizeof(_vscpFileRecord); if ( m_number_of_records ) { // Go to last pos - Read last timestamp fseek( m_ft, sizeof( m_vscpFileHead ) + (m_number_of_records-1) * sizeof(_vscpFileRecord) , SEEK_SET ); (void)fread( &record, 1, sizeof(record), m_ft ); m_timestamp_last = record.timestamp; // Go to first pos - read first timestamp fseek( m_ft, sizeof( m_vscpFileHead ), SEEK_SET ); (void)fread( &record, 1, sizeof(record), m_ft ); m_timestamp_first = record.timestamp; } } else { // STATIC TABLE m_number_of_records = m_vscpFileHead.staticSize; } return rv; }