写在前面:文章内容为本人的学习过程,路过大神不喜勿喷!
一、背景条件
以.dca为后缀的文件并非标准化格式,其含义和用途因软件、领域或上下文而异,可能是游戏存档、音频资源等游戏相关文件,或是特定软件的配置项目文件、编译中间文件,也可能是数据库备份、配置自动化等数据文件,亦或是加密专有格式或用户误写的自定义扩展名。
此处我遇到的.dca文件是设备上抛出来的文件,其中包含了设备所有点位的连续值的关键信息。
二、代码部分
1、dcafilebinary.h头文件:这里的头文件内容应该是包含了解析.dca文件的关键方法和属性。按照我的理解,其实是具体解析.dca文件的DLL动态链接库中的一些关键方法的接口映射,具体的功能的写法,已经在DLL文件中实现,这里只是定义如何调用。
#pragma once
//-------------------------------------------------------
// Copyright (c) 1998 by General Electric Company, U.S.A.
// Published in only a limited, copyright sense, and all
// rights, including trade secret rights are reserved.
//-------------------------------------------------------
//-----------------------------------------------------------------------------
// TITLE: VMS DCA File I/O Class Declarations
// FILE NAME: DCAFileBinary.hxx
// PREPARED BY: Metal Industries Process Automation
// General Electric Company
// 1501 Roanoke Blvd.
// SALEM, VIRGINIA
// CUSTOMER: STANDARD
//-----------------------------------------------------------------------------
// REVISIONS:
// level review date author change content
// ----- ----------- ------------ --------------------------------------
// 01.0 10/01/98 S.R. Pixley HM Original for Hoogovens DSP
// 02.0 06/10/99 S.R. Pixley Original NT Version
// 03.0 03/22/00 S.R. Pixley no bool, bool free, int forever
// 04.0 12/12/02 S.R. Pixley MString class addition to cpprtu
// 07.1 10/07/03 P.V.Vernekar filenames case sensitive on linux
// 07.2 16-FEB-04 RLM fix compiliation error for Linux/g++ porting
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// ABSTRACT:
// This declaration file describes the data structures, and related classes
// used by various data collection subsystems to manage vms generated
// dca file information retrieval and storage.
//-----------------------------------------------------------------------------
#ifndef __DCAFILEBINARY_HXX__
#define __DCAFILEBINARY_HXX__
#include "dca.h"
#include <cstdio>
/*******************************************************************************/
// The CDCAFileBinary object knows a little about how to read or write a file.
class PADCAFileBinary
{
public:
int tempa[2];
FILE* DCAfp; // DCA file
int tempb[2];
DCAW_FileHeaderType m_FileHdr;
DCAW_FileCollectionHeaderType m_CollHdr;
char* m_pExtraHeader;
int fstatus;
// Construction, destruction
public:
PADCAFileBinary();
~PADCAFileBinary();
// Base functionality
public:
int GetRecordsProcessed() {
return(m_RecordsProcessed); }
int GetBytesProcessed() {
return(m_RecordsProcessed * m_RecordLen); }
int IsOpen();
int Close();
int OpenForWrite(const char* Fname,
DCAW_FileCollectionHeaderType* pCollHdr,
int NumRecordsToBuffer,
int ExtraHeaderLen,
char* pExtraHeader);
int WriteSignalHeader(DCAW_FileSignalHeaderType* pSigHdr);
//int OpenAndWriteAllHeaders(const char *Fname, CDCACollConfig &CollConfig, int NumRecordsToBuffer, int ExtraHeaderLen=0, char *pExtraHeader=NULL);
int WriteDataRecord(void* pBuff);
int UpdateExtraHeader(int ExtraHeaderLen,
char* pExtraHeader);
int Flush(int UpdateHeader);
int OpenForRead(const char* Fname);
int ReadSignalHeader(DCAW_FileSignalHeaderType& SigHdr);
int ReadDataRecord(void* pBuff);
const char* GetLastErrorString() {
return(""); }
int GetLastErrorCode() {
return(m_LastWindowsError); }
private:
typedef enum {
DCA_FILE_CLOSED,
DCA_FILE_OPEN_WRITE,
DCA_FILE_OPEN_READ
} CurrentFileState;
CurrentFileState m_State;
int m_RecordLen;
unsigned long m_BuffLenInRecords; // Num Records to buffer for writes.
unsigned long m_RecordsInBuffer; // Num records remaining to be written.
char* m_pBuff; // Write buffer.
int m_RecordsProcessed; // Num data recoreds read or written.
int m_SigHeadersRead;
int m_LastWindowsError; // From GetLastError
// Helpers
private:
int WriteBytes(void* pBuff, int NumBytes);
int ReadBytes(void* pBuff, int NumBytes);
void StoreLastError(const char* Msg, int ErrorCode = -1);
};
/*******************************************************************************/
#endif
2、DCA.h头文件:这里的头文件内容应该是包含了一些关键常量参数以及一些结构体的参数组成。
#pragma once
#ifndef __DCA_H__
#define __DCA_H__
#ifdef __vms
#include <pthread.h> // for timespecc typedef
#define _TIMESPEC_DEFINED_
#define __timespec_defined
#pragma __environment save
#pragma message save
#pragma message disable check
#pragma nomember_alignment
#endif
#if defined (__linux__)
#if !defined (__int64)
#define __int64 long long
#endif
#endif
#ifdef ULONG_MAX
inline void Int64ToDwords(__int64 big, unsigned long& dw_high, unsigned long& dw_low)
{
dw_high = 0;
while (big > (__int64)(ULONG_MAX))
{
dw_high++;
big -= (__int64)((__int64)ULONG_MAX + (__int64)1);
}
dw_low = (unsigned long)big;
}
inline void DwordsToInt64(unsigned long dw_high, unsigned long dw_low, __int64& big)
{
big = dw_low;
while (dw_high > 0)
{
big += (__int64)(ULONG_MAX)+(__int64)1;
dw_high--;
}
}
#endif /* defined ULONG_MAX */
#pragma pack(1)
#if !defined (_TIMESPEC_DEFINED_) && !defined (__timespec_defined)
struct timespecc {
unsigned long tv_sec; /* seconds */
long tv_nsec; /* nano seconds */
};
#define _TIMESPEC_DEFINED_
#define __timespec_defined /* for linux */
#endif
#define DCA_SERVER_PORT 5320
#define DCA_FILE_MAGIC_STRING "DCAW Data File\032"
#define DCA_VARIABLE_FILE_MAGIC_STRING "DCAV Data File\032"
const int DCA_NewestFileRev = 1;
const int DCA_VariableFileRev = 1;
const int DCA_FileMagicLen = 16; /* All lengths for strings include NULL. */
const int DCA_HostNameLen = 40;
const int DCA_NetNameLen = 20;
const int DCA_CollNameLen = 20;
const int DCA_CollDescriptionLen = 50;
const int DCA_SigNameLen = 34;
const int DCA_SigDescriptionLen = 50;
const int DCA_SigUnitsLen = 12;
const int DCA_SigDatatypeLen = 40;
const int DCA_MaxTokens = 10;
const int DCA_MaxErrorStringLen = 200;
const int DCA_MaxDirectoryNameLen = 200;
/* //