You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
8.3 KiB
C

2 years ago
#ifndef _BASE_TYPE_H_
#define _BASE_TYPE_H_
#define __WIN_32_VC__
#ifdef __WIN_32_VC__
#include <windows.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#endif
#ifdef __WIN_32_BCB__
#include <vcl.h>
#endif
#ifdef __WIN_32_BCB__
typedef unsigned __int8 BYTE;
typedef unsigned __int8 UINT8;
typedef unsigned __int16 UINT16;
typedef unsigned __int32 UINT32;
typedef __int8 INT8;
typedef __int16 INT16;
typedef __int32 INT32;
#endif
#ifdef __DOS_16_BC__
typedef unsigned char BYTE;
typedef unsigned char UINT8;
typedef unsigned int UINT16;
typedef unsigned long UINT32;
typedef char INT8;
typedef int INT16;
typedef long INT32;
#endif
#ifdef __DJGPP__
typedef unsigned char BYTE;
typedef unsigned char UINT8;
typedef unsigned int UINT16;
typedef unsigned long UINT32;
typedef char INT8;
typedef int INT16;
typedef long INT32;
#endif
#ifdef __WIN_32_VC__
typedef unsigned char BYTE;
typedef unsigned char UINT8;
typedef unsigned __int16 UINT16;
typedef unsigned int UINT32;
typedef __int16 INT16;
typedef int INT32;
#endif
#ifndef __WIN_32_BCB__
#ifdef __BORLANDC__
typedef unsigned char BOOL;
const BOOL FALSE = 0;
const BOOL TRUE = 1;
#endif
#endif
namespace FRAMELIB
{
#define ROUND_INT8(v) ((INT8)((floor)(v+0.5)))
#define ROUND_UINT8(v) ((UINT8)((floor)(v+0.5)))
#define ROUND_INT16(v) ((INT16)((floor)(v+0.5)))
#define ROUND_UINT16(v) ((UINT16)((floor)(v+0.5)))
#define ROUND_INT32(v) ((INT32)((floor)(v+0.5)))
#define ROUND_UINT32(v) ((UINT32)((floor)(v+0.5)))
const double PI = 3.141592653589793238462643383279502884197169399;
const double PI2 = PI * 2;
const double PI_2 = PI * 0.5;
const double PI_3 = PI / 3;
const double PI_4 = PI * 0.25;
const double RAD2DEG = 57.295779513082322864647721871733665466308593750000;
}
template< class T> inline const int SIGN(const T& x)
{
return x < 0 ? -1 : 1;
}
template< class T> inline const T ABS(const T& x)
{
return x < 0 ? -x : x;
}
struct struCHECK
{
struCHECK(){C0=C1=0;};
BYTE C0;
BYTE C1;
};
const UINT16 CRC8TAB[256] =
{
//0
0x0000, 0x0031, 0x0062, 0x0053, 0x00C4, 0x00F5, 0x00A6, 0x0097,
0x00B9, 0x0088, 0x00DB, 0x00EA, 0x007D, 0x004C, 0x001F, 0x002E,
//1
0x0043, 0x0072, 0x0021, 0x0010, 0x0087, 0x00B6, 0x00E5, 0x00D4,
0x00FA, 0x00CB, 0x0098, 0x00A9, 0x003E, 0x000F, 0x005C, 0x006D,
//2
0x0086, 0x00B7, 0x00E4, 0x00D5, 0x0042, 0x0073, 0x0020, 0x0011,
0x003F, 0x000E, 0x005D, 0x006C, 0x00FB, 0x00CA, 0x0099, 0x00A8,
//3
0x00C5, 0x00F4, 0x00A7, 0x0096, 0x0001, 0x0030, 0x0063, 0x0052,
0x007C, 0x004D, 0x001E, 0x002F, 0x00B8, 0x0089, 0x00DA, 0x00EB,
//4
0x003D, 0x000C, 0x005F, 0x006E, 0x00F9, 0x00C8, 0x009B, 0x00AA,
0x0084, 0x00B5, 0x00E6, 0x00D7, 0x0040, 0x0071, 0x0022, 0x0013,
//5
0x007E, 0x004F, 0x001C, 0x002D, 0x00BA, 0x008B, 0x00D8, 0x00E9,
0x00C7, 0x00F6, 0x00A5, 0x0094, 0x0003, 0x0032, 0x0061, 0x0050,
//6
0x00BB, 0x008A, 0x00D9, 0x00E8, 0x007F, 0x004E, 0x001D, 0x002C,
0x0002, 0x0033, 0x0060, 0x0051, 0x00C6, 0x00F7, 0x00A4, 0x0095,
//7
0x00F8, 0x00C9, 0x009A, 0x00AB, 0x003C, 0x000D, 0x005E, 0x006F,
0x0041, 0x0070, 0x0023, 0x0012, 0x0085, 0x00B4, 0x00E7, 0x00D6,
//8
0x007A, 0x004B, 0x0018, 0x0029, 0x00BE, 0x008F, 0x00DC, 0x00ED,
0x00C3, 0x00F2, 0x00A1, 0x0090, 0x0007, 0x0036, 0x0065, 0x0054,
//9
0x0039, 0x0008, 0x005B, 0x006A, 0x00FD, 0x00CC, 0x009F, 0x00AE,
0x0080, 0x00B1, 0x00E2, 0x00D3, 0x0044, 0x0075, 0x0026, 0x0017,
//A
0x00FC, 0x00CD, 0x009E, 0x00AF, 0x0038, 0x0009, 0x005A, 0x006B,
0x0045, 0x0074, 0x0027, 0x0016, 0x0081, 0x00B0, 0x00E3, 0x00D2,
//B
0x00BF, 0x008E, 0x00DD, 0x00EC, 0x007B, 0x004A, 0x0019, 0x0028,
0x0006, 0x0037, 0x0064, 0x0055, 0x00C2, 0x00F3, 0x00A0, 0x0091,
//C
0x0047, 0x0076, 0x0025, 0x0014, 0x0083, 0x00B2, 0x00E1, 0x00D0,
0x00FE, 0x00CF, 0x009C, 0x00AD, 0x003A, 0x000B, 0x0058, 0x0069,
//D
0x0004, 0x0035, 0x0066, 0x0057, 0x00C0, 0x00F1, 0x00A2, 0x0093,
0x00BD, 0x008C, 0x00DF, 0x00FE, 0x0079, 0x0048, 0x001B, 0x002A,
//E
0x00C1, 0x00F0, 0x00A3, 0x0092, 0x0005, 0x0034, 0x0067, 0x0056,
0x0078, 0x0049, 0x001A, 0x002B, 0x00BC, 0x008D, 0x00DE, 0x00EF,
//F
0x0082, 0x00B3, 0x00E0, 0x00D1, 0x0046, 0x0077, 0x0024, 0x0015,
0x003B, 0x000A, 0x0059, 0x0068, 0x00FF, 0x00CE, 0x009D, 0x00AC
};
//206,902,96<39>õ<EFBFBD>CRCУ<43><D0A3><EFBFBD><EFBFBD>
const unsigned char CRCLIST[512] = {
0x0,0x0,0x89,0x11,0x12,0x23,0x9b,0x32,0x24,0x46,0xad,0x57,0x36,0x65,0xbf,0x74,
0x48,0x8c,0xc1,0x9d,0x5a,0xaf,0xd3,0xbe,0x6c,0xca,0xe5,0xdb,0x7e,0xe9,0xf7,0xf8,
0x81,0x10,0x8,0x1,0x93,0x33,0x1a,0x22,0xa5,0x56,0x2c,0x47,0xb7,0x75,0x3e,0x64,
0xc9,0x9c,0x40,0x8d,0xdb,0xbf,0x52,0xae,0xed,0xda,0x64,0xcb,0xff,0xf9,0x76,0xe8,
0x2,0x21,0x8b,0x30,0x10,0x2,0x99,0x13,0x26,0x67,0xaf,0x76,0x34,0x44,0xbd,0x55,
0x4a,0xad,0xc3,0xbc,0x58,0x8e,0xd1,0x9f,0x6e,0xeb,0xe7,0xfa,0x7c,0xc8,0xf5,0xd9,
0x83,0x31,0xa,0x20,0x91,0x12,0x18,0x3,0xa7,0x77,0x2e,0x66,0xb5,0x54,0x3c,0x45,
0xcb,0xbd,0x42,0xac,0xd9,0x9e,0x50,0x8f,0xef,0xfb,0x66,0xea,0xfd,0xd8,0x74,0xc9,
0x4,0x42,0x8d,0x53,0x16,0x61,0x9f,0x70,0x20,0x4,0xa9,0x15,0x32,0x27,0xbb,0x36,
0x4c,0xce,0xc5,0xdf,0x5e,0xed,0xd7,0xfc,0x68,0x88,0xe1,0x99,0x7a,0xab,0xf3,0xba,
0x85,0x52,0xc,0x43,0x97,0x71,0x1e,0x60,0xa1,0x14,0x28,0x5,0xb3,0x37,0x3a,0x26,
0xcd,0xde,0x44,0xcf,0xdf,0xfd,0x56,0xec,0xe9,0x98,0x60,0x89,0xfb,0xbb,0x72,0xaa,
0x6,0x63,0x8f,0x72,0x14,0x40,0x9d,0x51,0x22,0x25,0xab,0x34,0x30,0x6,0xb9,0x17,
0x4e,0xef,0xc7,0xfe,0x5c,0xcc,0xd5,0xdd,0x6a,0xa9,0xe3,0xb8,0x78,0x8a,0xf1,0x9b,
0x87,0x73,0xe,0x62,0x95,0x50,0x1c,0x41,0xa3,0x35,0x2a,0x24,0xb1,0x16,0x38,0x7,
0xcf,0xff,0x46,0xee,0xdd,0xdc,0x54,0xcd,0xeb,0xb9,0x62,0xa8,0xf9,0x9a,0x70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2d,0xeb,0x3c,0x70,0xe,0xf9,0x1f,
0x8f,0xf7,0x6,0xe6,0x9d,0xd4,0x14,0xc5,0xab,0xb1,0x22,0xa0,0xb9,0x92,0x30,0x83,
0xc7,0x7b,0x4e,0x6a,0xd5,0x58,0x5c,0x49,0xe3,0x3d,0x6a,0x2c,0xf1,0x1e,0x78,0xf
};
inline struCHECK MakeCheckCRC(UINT8 *ptr,UINT8 len)
{
struCHECK ck;
int count = 0;
unsigned char C0,C1,Y0,Y1,Z0,Z1;
C0=C1=Y0=Y1=Z0=Z1=0;
BYTE *pData = ptr;
while(count < len)
{
//make crc
unsigned int idx = (unsigned int)(*pData);
idx = idx << 1;
Y0=(CRCLIST[idx]^C1) & 0x00FF;
Y1=(CRCLIST[idx+1]) & 0x00FF;
idx = ((unsigned int)C0) << 1;
Z0=CRCLIST[idx] & 0x00FF;
Z1=CRCLIST[idx+1] & 0x00FF;
C0=(Y0^Z0) & 0x00FF;
C1=(Y1^Z1) & 0x00FF;
pData++;
count++;
}
ck.C0=C0;
ck.C1=C1;
return ck;// return crc result
}
inline struCHECK getCRC8(UINT8* data, int len)
{
UINT16 crc = 0;
int i=0;
while (len-- > 0)
{
crc = CRC8TAB[crc ^ (data[i]&0x00FF)];
i++;
}
struCHECK ck;
ck.C1=(crc>>8);
ck.C0=(crc&0x00ff);
return ck;
}
//<2F><>У<EFBFBD><D0A3>
//inline UINT8 MakeCheckSum(UINT8 *ptr, UINT8 len)
inline struCHECK MakeCheckSum(UINT8 *ptr, UINT8 len)
{
UINT8 i;
UINT8 CK_A=0;
BYTE *pData = ptr;
for (i=0; i < len; ++i )
{
CK_A = CK_A + ptr[i];
}
//return CK_A;
struCHECK ck;
ck.C0=CK_A;
ck.C1=0x00;
return ck;
}
2 years ago
#endif//_BASE_TYPE_H_