FSNファイルの解析
1、FsnParser.hファイル
2、FsnParser.cppファイル
3、テストコード
#pragma once
#include
#include
#include
#include
#define READ_SIZE 100
/**
* @brief
*/
typedef struct
{
unsigned int Data[32]; /**< */
}BOC_BOC_TImageSNoData;
/**
* @brief
*/
typedef struct
{
short Num; /**< */
short Height, width; /**< */
short Reserve2; /**< 2 */
BOC_BOC_TImageSNoData SNo[12];
}BOC_TImageSNo;
typedef struct
{
USHORT HeadStart[4];
USHORT HeadString[6];
UINT Counter;
USHORT HeadEnd[4];
}BOC_Header_Fromat;
/**
* @brief
*/
typedef struct
{
USHORT Date; /**< Date=((Year-1980)<<9)+(Month<<5)+Day*/ //
USHORT Time; /**< Time=(Hour<<11)+(Minute<<5)+(Second>>1)*/
USHORT tfFlag; /**< 、 、 */ //
USHORT ErrorCode[3]; /**< (3 ) */
USHORT MoneyFlag[4]; /**< */ //
USHORT Ver; /**< */
USHORT Valuta; /**< */ //
USHORT CharNUM; /**< */
USHORT SNo[12]; /**< */ //
USHORT MachineSNo[24]; /**< */
USHORT Operateor_No; /**< 1 */
}BOC_TagData_Fromat;
typedef struct { //
UINT u32_ImgDataLen; //
UINT u32_Image_Width;//
UINT u32_Image_Height;//
UCHAR u8_Filetype[8];// .jpg .bmp
UCHAR Reserve[60]; // 60
}TKTImageSNo_File;
//u32_ImgDataLen
//
typedef struct {
USHORT u16_Date;
USHORT u16_Time;
USHORT u16_tfFlag;
USHORT u16_ErrorCode[3];
USHORT u16_MoneyFlag[4];
USHORT u16_Ver;
USHORT u16_Valuta;
USHORT u16_CharNum;
USHORT u16_SNo[12];
USHORT u16_MachineSNo[24];
USHORT u16_Reservel[20]; // 40
//TKTImageSNo_File ImageSNo_File;
}TKFSN_Record_File;
//2015-10 ,
typedef struct
{
USHORT machineSNo_Length : 4;
USHORT machine_Length : 4;
USHORT machine_Type : 4;
USHORT money_Type : 4;
}FSN_Reserve, *PFSN_Reserve;
#pragma pack()
enum ImageType
{
FSN_IMG_Standard = 0xC0,
FSN_IMG_JPG,
};
typedef struct
{
BOC_TagData_Fromat btf;
USHORT uFileFlag; //
DWORD dwOffset; //
CHAR bSame; //
INT llLen; //
BYTE uFileType; //
int nImgWidth;
int nImgHeight;
}BOC_TagRecord_Data;
struct Money_Info
{
std::string Id;
std::string Value;
std::string Kinds;
std::string IsReal;
std::string time;
std::string CharNum;
std::string MachineSNo;
};
using namespace std;
class FsnParser
{
public:
std::vector ReadTk(std::string &filename,int ncount);
Money_Info InsList(vector& vecRecord, int nStartPos);
vector m_vecRecordData;
private:
vector m_vecMoneyInfo;
};
2、FsnParser.cppファイル
#define _CRT_SECURE_NO_WARNINGS
#include "FSN_Parser.h"
#include
#include
void* __cdecl memcpy(void* dst,const void* src,size_t count)
{
void*ret = dst;
#if defined(_M_MRX000)||defined(_M_ALPHA)||defined(_M_PPC)
{
extern void RtlMoveMemory(void *, const void *, size_t count);
RtlMoveMemory(dst, src, count);
}
#else
while (count--) {
*(char *)dst = *(char *)src;
dst = (char *)dst + 1;
src = (char *)src + 1;
}
#endif
return (ret);
}
// FSN
//BOC_TagData_Fromat *btf = (BOC_TagData_Fromat*)malloc(sizeof(BOC_TagData_Fromat*));
//int len = sizeof(BOC_TagData_Fromat*);
std::vector FsnParser::ReadTk(std::string &filename,int ncount)
{
FILE *myf = fopen(filename.c_str(), "rb");
if (myf == nullptr)
{
cout << "Error opening file";
exit(1);
}
char buffer[3072] = { 0 };
int iread_offset = 0;
iread_offset += sizeof(BOC_Header_Fromat);
int read_size = READ_SIZE; //
int position = 0;
std::vector Vec_MoneyInfo;
fseek(myf, 0, 2);
int fileSize = ftell(myf); //
while (!feof(myf))
{
fseek(myf, iread_offset, SEEK_SET);
position = ftell(myf);
fread(buffer, read_size, 1, myf);
iread_offset += READ_SIZE;
TKFSN_Record_File *pdata = (TKFSN_Record_File*)buffer;
BOC_TagRecord_Data *bctd = new BOC_TagRecord_Data; //
memset(bctd, 0, sizeof(BOC_TagRecord_Data));
bctd->btf.Date = pdata->u16_Date;
bctd->btf.Time = pdata->u16_Time;
bctd->btf.tfFlag = pdata->u16_tfFlag;
memcpy(bctd->btf.ErrorCode, pdata->u16_ErrorCode, sizeof(bctd->btf.ErrorCode));
memcpy(bctd->btf.MoneyFlag, pdata->u16_MoneyFlag, sizeof(bctd->btf.MoneyFlag));
bctd->btf.CharNUM = pdata->u16_CharNum;
memcpy(bctd->btf.SNo, pdata->u16_SNo, sizeof(bctd->btf.SNo));
memcpy(bctd->btf.MachineSNo, pdata->u16_MachineSNo, sizeof(bctd->btf.MachineSNo));
iread_offset += sizeof(BOC_TImageSNo);
m_vecRecordData.push_back(bctd);
ncount++;
Money_Info m_info = InsList(m_vecRecordData, ncount-1);
Vec_MoneyInfo.push_back(m_info);
}
fclose(myf);
return Vec_MoneyInfo;
}
Money_Info FsnParser::InsList(vector& vecRecord, int nStartPos)
{
int j = 0;
unsigned char idLevel = 0;
int nEndPos = vecRecord.size();
Money_Info m_info; // Money
for (int i = nStartPos; i < nEndPos; i++)
{
BOC_TagData_Fromat* pdata = &vecRecord[i]->btf;
char tmpbuf[26];
//SNo
memset(tmpbuf, 0, 26);
for (j = 0; j < 12; j++)
{
tmpbuf[j] = pdata->SNo[j] & 0xFF;
std::cout << tmpbuf[j] << " ";
}
m_info.Id = tmpbuf;//
//CharNum
memset(tmpbuf, 0, 26);
sprintf_s(tmpbuf, "%d", pdata->CharNUM);
m_info.CharNum = tmpbuf;//
//
memset(tmpbuf, 0, 26);
sprintf_s(tmpbuf, "%d", pdata->Valuta);
m_info.Value = tmpbuf; //
//MomeyId
memset(tmpbuf, 0, 26);
for (j = 0; j < 4; j++)
{
tmpbuf[j] = pdata->MoneyFlag[j] & 0xFF;
}
m_info.Kinds = tmpbuf; //
//
memset(tmpbuf, 0, 26);
sprintf_s(tmpbuf, "%d", pdata->tfFlag);
m_info.IsReal = tmpbuf;
//
memset(tmpbuf, 0, 26);
idLevel = (pdata->ErrorCode[1] >> 8);
//
memset(tmpbuf, 0, 26);
for (j = 0; j < 24; j++)
{
tmpbuf[j] = pdata->MachineSNo[j] & 0xFF;
std::cout << tmpbuf[j];
}
m_info.MachineSNo = tmpbuf;//
//
memset(tmpbuf, 0, 26);
sprintf_s(tmpbuf, "%04d-%02d-%02d %02d:%02d:%02d", (pdata->Date >> 9) + 1980, (pdata->Date >> 5) & 0x0F, pdata->Date & 0x1F,
(pdata->Time >> 11), (pdata->Time >> 5) & 0x3F, (pdata->Time << 1) & 0x3F);
m_info.time = tmpbuf;//
return m_info;
}
}
3、テストコード
int main()
{
int rtn = foo(10);
std::vector Vec_MoneyInfo;
FsnParser ftd ;
std::string path="e:\\095720.FSN";
Vec_MoneyInfo = ftd.ReadTk(path,0);
return 0;
}