|
일단 2가지 방법이 있겠네요...
80바이트자리 구조체를 선언하신 후 80바이트를 읽어들이셔서 디코딩하시거나,
아니면 그냥 80바이트를 읽어들이셔서 한바이트씩 읽으신 후에 포맷에 따라 디코딩하시면 되겠네요..
첫번째 방법같은 경우
typedef struct _DataRecord
{
short Year;
byte Month;
byte Day;
.
.
byte Item14;
byte Item58;
.
.
short Item1Data;
short Item2Data;
.
.
short Item32Data;
short unused
} TDataRecord;
TDataRecord stDataRecord;
처럼 구조체를 선언하신후에
infs->ReadBuffer(&stDataRecord;, sizeof(stDataRecord;));
이런식으로 읽어들이신후 각 구조체 원소를 매뉴얼처럼 디코딩을 하시면 될거구요..
두번째 방법은
byte buff[80];
infs->ReadBuffer(buff, sizeof(buff));
로 읽어들이신후에
short Year;
byte Month;
.
.
memcpy(&Year, &buff[0], sizeof(Year));
memcpy(&Month, &buff[2], sizeof(Month)); 또는 Month = buff[2]; // 1byte data이므로
.
.
이런식으로 배열을 쭉 훍어가면서 읽어 내셔도 됩니다.
물론 데이터 파일이 80byte 보다 크다면 블럭으로 계속 읽어들여 처리를 하시던지,
파일크기만큼 읽어들이신 후에 80byte 마다 끊어서 처리하시면 되겠지요..
그럼.. 부디 도움이 되셨기를..
P.S pack data는 byte로 읽어들이신후에 bit 연산자처리를 하셔야 되겠네요..
bigdream 님이 쓰신 글 :
: 답변 정말 감사드립니다.
: 죄송한데 자료형식이 아래와 같이 되어 있다고 합니다.
: 그러면 이 자료는 어떻게 읽어야 하나요?
: 구조체로 해서 읽는 방식이 따로 읽는건가요?
: 이런게 여러줄 있으면 어떻게 읽어야하나요? 한꺼번에 읽어서 처리해주면 되는건가요?
:
:
: *자료 파일 레코드 구조
:
: Dreal file (DLssvvv.dat : 시간)
: Record Size (32 item) ⇒ 80 Byte
:
: Record position Description
: Format
:
: 1, 2 Year (4 digits) : 2byte integer
: 3 Month : 1byte integer
: 4 Day : 1byte integer
: 5 Hour(0-23) : 1byte integer
: 6 Minutes : 1byte integer
:
: 7 Item 1-4 missing data flag pack data
: 8 Item 5-8 missing data flag pack data
: 9 Item 9-12 missing data flag pack data
: 10 Item 13-16 missing data flag pack data
: 11 Item 17-20 missing data flag pack data
: 12 Item 21-24 missing data flag pack data
: 13 Item 25-28 missing data flag pack data
: 14 Item 29-32 missing data flag pack data
:
: 15, 16 Item 1 data : 2byte integer
: 17, 18 Item 2 data : 2byte integer
: 19, 20 Item 3 data : 2byte integer
: 21, 22 Item 4 data : 2byte integer
: 23, 24 Item 5 data : 2byte integer
: . .
: . .
: . .
: 73, 74 Item 30 data : 2byte integer
: 75, 76 Item 31 data : 2byte integer
: 77, 78 Item 32 data : 2byte integer
: 79, 80 unused
:
:
: (1) 1 Byte integer :
: An integer number 1 byte in length with a value from 0 to 255
:
: (2) 2 Byte integer :
: An integer number 2 byte in length with a value from -32768 to +32768
: To calculate the actual density value of an item, the item value is divided
: by 10 raised to the power of the decimal point location value given in the
: DCT.
: For example, if the item value is 500 and the decimal point location value
: is 2 the resulting item value would be 5.0(500/10 power of 2=5.0)
:
: (3) pack data :
: The status of each item at any particular interval is recorded in a 2 bit area.
: Each pack data field is 1 byte in length and contains the value for item 1,
: bits 2 & 3 contain the value for item 2, etc
:
: 2 bit area Description
: 00 Normal data (정상)
: 01 Missing data due to maintenance (조정중)
: 10 Missing data due poor movement (동작불량)
: 11 Missing data due to power down (전원 단절)
:
: pack data byte B7,B6
: B5,B4
: B3,B2
: B1,B0
: item 1-4 position 7 4
: 3
: 2
: 1
: item 5-8 position 8 8
: 7
: 6
: 5
: item 9-12 position 9 12
: 11
: 10
: 9
: item 13-16 position 10 16
: 15
: 14
: 13
:
:
: item 17-20 position 11 20
: 19
: 18
: 17
: item 21-24 position 12 24
: 23
: 22
: 21
: item 25-28 position 13 28
: 27
: 26
: 25
: item 29-32 position 14 32
: 31
: 30
: 29
:
:
:
:
|