📄 mylib.h
字号:
/***************************************************************************/
/* file: MYLIB.H */
/* data: 20010420 */
/****************************************************************************/
#ifndef MYLIB_H
#define MYLIB_H
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
#ifndef ulong
#define ulong unsigned long
#endif
/****************************************************************************/
#define setflag(N, F) ((N)|=(F))
#define clsflag(N, F) ((N)&=~(F))
#define getflag(N, F) ((N)&(F))
#define bitpos(N) (1U<<(N))
#define setbit(N, P) (setflag((N), bitpos(P)))
#define clsbit(N, P) (clsflag(N, bitpos(P)))
#define getbit(N, P) (getflag(N, bitpos(P)))
//#define max(a,b) (((a) > (b)) ? (a) : (b))
//#define min(a,b) (((a) < (b)) ? (a) : (b))
#define LowB(w) ((uchar)(w))
#define HighB(w) ((uchar)(((uint)(w) >> 8) & 0xFF))
#define bb2i(high, low) ( (uint)( ((uchar)(low) ) | ( ((uint)((uchar)(high))) << 8) ))
#define LowW(l) ((uint)(ulong)(l))
#define HighW(l) ((uint)((((ulong)(l)) >> 16) & 0xFFFF))
#define CheckLen(v) ((uint)(v)&0x0FFF | (uint)(( (uint)(v) & 0x000F + ((uint)(v) >> 4) & 0x000F + ((uint)(v) >> 8) & 0x000F ) & 0x000F)<<8)
/* CRC*/
uchar BCH(uchar *pBuf);
uint CRC16(uchar *pBuf, int len);
uchar CDTCRC(uchar *buf);
uint CRC12(uchar *buf, int len);
uint CRC12B(uint crc, uchar buf);
uint CRC12BEnd(uint crc);
/****************************************************************************/
/* SM2 BIT*/
void Set_SM2(uchar *value); /* odd check set SM2 = 1 */
void Cls_SM2(uchar *value); /* odd check set SM2 = 0 */
/****************************************************************************/
/* HEX */
uint b2fix(uchar *buf, long *value);
uint fix2b(long value, int mult, uchar *buf);
int hex8fixEx(uchar *buf,int mult);
uint hex8fix(uchar *buf, long *value);
void fix8hex(long value, int mult, uchar *buf);
void i8hex(uint value, uchar *buf);
uint hex8i(uchar *buf);
void b8hex(uchar value, uchar *buf);
uchar hex8b(uchar *buf);
void hex2buf(uchar *buf, int len);
void buf2hex(uchar *buf, uchar *hexbuf, int buflen);
void oppsortbuf(uchar *buf, int len);
void b2hex(uchar value, uchar *buf);
uchar hex2b(uchar *buf);
void i2hex(uint value, uchar *buf);
uint hex2i(uchar *buf);
/****************************************************************************/
/*asiic*/
int buf2asc(uchar *buf, int len, uchar *asc);
int asc2buf(uchar *asc, int len, uchar *buf);
/****************************************************************************/
/* BCD*/
uint bcd2i(uchar *buf);
/* INT*/
uint b2i(uchar *buf);
void i2b(uint value, uchar *buf);
//uint bb2i(uchar bh, uchar bl);
/****************************************************************************/
int CDT_Head(uchar *buf);
/* string*/
int fix2s(int value, int format, char *str);
int s2fix(char *str, int *value); /* str=220.4 value=2204, rt=10 */
char* scpy(char *s1, char *s2);
int slen(char *s);
char *scat(char *s1, char *s2);
int scmp(char *str, char *str2, int len);
char* sword(char *buf, char *wordstr);
int left_nrm(char *str, int len);
char *timestr(uchar* tbuf, char* str);
char* time2s(int hh, int mm, int ss, char *str);
char* date2s(int yy, int mm, int dd, char *str);
int GetItemCount(const char *str);
int GetItem(int value, const char *str, char *word); /*value = 1 str="自动\n手动", then word=手动, rt=index */
int TextFormat(char *buf, char *fmt, int data);
/****************************************************************************/
/* ad value*/
/****************************************************************************/
int ad2abs(int value);
int ad2i(uint value);
ulong CalcSqrt(ulong Data);
void Sort_Buf(uint *buf, int bufsize);
/****************************************************************************/
/* filter */
uint Check_Len(uint value);
int Filter_Avg(int *buf, int bufsize);
void Filter_Midst(int *buf, int bufsize, int width);
int Midst(int *buf, int width);
int pid_seti(int setv, int value);
/****************************************************************************/
/* bitbuf */
uchar GetBufBit(uchar *buf, uint index);
void SetBufBit(uchar *buf, uint index, uchar value);
/****************************************************************************/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -