first commit
This commit is contained in:
+1022
File diff suppressed because it is too large
Load Diff
+179
@@ -0,0 +1,179 @@
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Begin=0x00;
|
||||
|
||||
|
||||
|
||||
/* 8*16�������� */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Num[10][16]=
|
||||
{
|
||||
{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00}, /* '0' */
|
||||
{0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00}, /* '1' */
|
||||
{0x30,0x18,0x08,0x08,0x88,0xF8,0x70,0x00,0x18,0x1C,0x16,0x13,0x11,0x18,0x18,0x00}, /* '2' */
|
||||
{0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x18,0x20,0x21,0x21,0x22,0x1C,0x00}, /* '3' */
|
||||
{0x00,0x00,0x80,0x40,0x30,0xF8,0x00,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x24,0x24}, /* '4' */
|
||||
{0x00,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x20,0x20,0x20,0x11,0x0E,0x00}, /* '5' */
|
||||
{0xC0,0xE0,0xB0,0x98,0x88,0x88,0x00,0x00,0x0F,0x1F,0x10,0x10,0x10,0x1F,0x0F,0x00}, /* '6' */
|
||||
{0x18,0x18,0x08,0x88,0xC8,0x78,0x38,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00}, /* '7' */
|
||||
{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00}, /* '8' */
|
||||
{0x70,0xF8,0x88,0x88,0x88,0xF8,0xF0,0x00,0x00,0x10,0x10,0x18,0x0C,0x07,0x03,0x00} /* '9' */
|
||||
};
|
||||
/* 8*16�����Ǻ�*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Star[16]={0x20,0x80,0xC0,0xE0,0xC0,0x80,0x20,0x00,0x09,0x03,0x07,0x0F,0x07,0x03,0x09,0x00};
|
||||
/*8*16����б�ܷ���*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Slash[16]={0x00,0x00,0x00,0x80,0x70,0x08,0x00,0x00,0x00,0x10,0x0E,0x01,0x00,0x00,0x00,0x00};
|
||||
/* 8*16��������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Dot[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00};
|
||||
/* 8*16����*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Comma[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x1C,0x0C,0x00,0x00,0x00};
|
||||
/* 8*16����ո�*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Space[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
/* 8*16�������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Sub[16]={0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
/* 8*16������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_across[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80};
|
||||
/* 8*16����ʵ�����ͷ*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Arrow[16]={0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F};
|
||||
/* 8*16������ں�*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Above[16]={0x00,0x18,0x30,0x60,0xC0,0x80,0x00,0x00,0x00,0x18,0x0C,0x06,0x03,0x01,0x00,0x00};
|
||||
/* 8*16����С�ں�*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Below[16]={0x00,0x80,0xC0,0x60,0x30,0x18,0x00,0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x00,0x00};
|
||||
/* 8*16����̾��*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Claim[16]={0x00,0x00,0x00,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x33,0x00,0x00,0x00};
|
||||
/* 8*16����ð��*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Colon[16]={0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00};
|
||||
/* 8*16����������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_LBrack[16]={0x00,0x00,0xF0,0xF8,0x0C,0x04,0x00,0x00,0x00,0x00,0x0F,0x1F,0x30,0x20,0x00,0x00};
|
||||
/* 8*16����������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_RBrack[16]={0x00,0x00,0x04,0x0C,0xF8,0xF0,0x00,0x00,0x00,0x00,0x20,0x30,0x1F,0x0F,0x00,0x00};
|
||||
/* 8*16����Թ�*/
|
||||
//__attribute__((section(".data"))) unsigned char ASC16_Right[16]={0x80,0x00,0x00,0x00,0x80,0xC0,0x60,0x00,0x01,0x03,0x06,0x03,0x01,0x00,0x00,0x00};
|
||||
/* 8*16�����ʺ�*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_What[16]={0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00};
|
||||
/* 8*16����������*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_LFBrack[16]={0x00,0x00,0x00,0xFC,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x3F,0x20,0x20,0x00,0x00};
|
||||
/* 8*16�����ҷ�����*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_RFBrack[16]={0x00,0x00,0x04,0x04,0xFC,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x00,0x00,0x00};
|
||||
/*8*16���� I */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_IChar[16]={0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
|
||||
/*8*16���� P */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_PChar[16]={0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00};
|
||||
/*8*16����D*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_DChar[16]={0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00};
|
||||
/*8*16����N*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_NChar[16]={0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00};
|
||||
/*8*16����S*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_SChar[16]={0x00,0x60,0x90,0x10,0x10,0x30,0x00,0x00,0x00,0x18,0x10,0x11,0x11,0x0E,0x00,0x00};
|
||||
/*8*16����T*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_TChar[16]={0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00};
|
||||
/*8*16����a*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_aChar[16]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20};
|
||||
/*8*16����g*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_gChar[16]={0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00};
|
||||
/*8*16����x*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_xChar[16]={0x00,0x40,0xC0,0x00,0x00,0xC0,0x40,0x00,0x00,0x10,0x18,0x07,0x07,0x18,0x10,0x00};
|
||||
/*8*16����A*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_A_Char[16]={0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20};//{0x00,0x00,0xC0,0x30,0xC0,0x00,0x00,0x00,0x10,0x1C,0x13,0x02,0x13,0x1C,0x10,0x00};
|
||||
/*8*16����B*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_BChar[16]={0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00};
|
||||
/*8*16����B*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_B_Char[16]={0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00};
|
||||
/*8*16����C*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_CChar[16]={0xE0,0x10,0x08,0x08,0x08,0x08,0x10,0x00,0x0F,0x10,0x20,0x20,0x20,0x20,0x10,0x00};
|
||||
/*8*16����D*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_D_Char[16]={0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00};
|
||||
/*8*16����E*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_EChar[16]={0x00,0xF8,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x3F,0x21,0x21,0x21,0x21,0x20,0x00};
|
||||
/*8*16����E*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_E_Char[16]={0x00,0xFC,0x84,0x84,0x84,0x84,0x04,0x00,0x00,0x1F,0x10,0x10,0x10,0x10,0x10,0x00};
|
||||
/*8*16����F*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_F_Char[16]={0x04,0xFC,0x84,0x84,0xE4,0x04,0x04,0x00,0x10,0x1F,0x10,0x10,0x03,0x00,0x00,0x00};
|
||||
/*8*16����U*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_U_Char[16]={0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00};
|
||||
/*8*16����K*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_K_Char[16]={0x00,0x10,0xF0,0x90,0x40,0x30,0x10,0x00,0x00,0x10,0x1F,0x11,0x03,0x1C,0x10,0x00};
|
||||
/*8*16����M*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_M_Char[16]={0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x01,0x3E,0x01,0x3F,0x20,0x00};
|
||||
/*8*16����G*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_G_Char[16]={0xE0,0x18,0x04,0x04,0x04,0x1C,0x00,0x00,0x03,0x0C,0x10,0x10,0x11,0x0F,0x01,0x00};
|
||||
/*8*16����W*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_WChar[16]={0x08,0xF8,0x00,0xF8,0x00,0xF8,0x08,0x00,0x00,0x03,0x3E,0x01,0x3E,0x03,0x00,0x00};
|
||||
/*8*16����O*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_OChar[16]={0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00};
|
||||
/*8*16����K*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_KChar[16]={0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00};
|
||||
/*8*16����_*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_DnLine[16]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x00};
|
||||
/*8*16����X*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_X_Char[16]={0x08,0x18,0x68,0x80,0x68,0x18,0x08,0x00,0x10,0x18,0x16,0x01,0x16,0x18,0x10,0x00};
|
||||
/*8*16����Y*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Y_Char[16]={0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00};
|
||||
/*8*16����Z*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_Z_Char[16]={0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00};
|
||||
/*8*16����R*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_R_Char[16]={0x10,0xF0,0x90,0x90,0x90,0x60,0x00,0x00,0x10,0x1F,0x10,0x01,0x06,0x18,0x10,0x00};
|
||||
/*8*16����L*/
|
||||
__attribute__((section(".data"))) unsigned char ASC16_L_Char[16]={0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00};
|
||||
/* *8*16����'N' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_N_Char[16]={0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00};//{0x13,0xc7,0x20,0x13,0xc1,0x00,0x41,0xf4,0x03,0x31,0xf0,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
/* *8*16����'S' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_S_Char[16]={0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00};
|
||||
|
||||
/* *8*16����'J' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_J_Char[16]={0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x40,0x80,0x80,0x80,0x7F,0x00,0x00,0x00};
|
||||
|
||||
/* *8*16����'H' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_H_Char[16]={0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20};
|
||||
|
||||
/* *8*16����'r' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_r_Char[16]={0x00,0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x20,0x3F,0x21,0x20,0x00,0x01,0x00};
|
||||
|
||||
/* *8*16����'d' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_d_Char[16]={0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20};
|
||||
|
||||
/* 'V' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_V_Char[16]={0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00};
|
||||
|
||||
/* *8*16����'o' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_o_Char[16]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00};
|
||||
|
||||
/* *8*16����'m' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_m_Char[16]={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F};
|
||||
|
||||
/* *8*16����'a' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_a_Char[16]={0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x19,0x24,0x24,0x12,0x3F,0x20,0x00};
|
||||
|
||||
/* *8*16����'l' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_l_Char[16]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};
|
||||
|
||||
/* *8*16����'e' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_e_Char[16]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x24,0x24,0x24,0x24,0x17,0x00};
|
||||
|
||||
/* *8*16����'n' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_n_Char[16]={0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20};
|
||||
|
||||
/* *8*16����'t' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_t_Char[16]={0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x10,0x00};
|
||||
|
||||
/* *8*16����'y' */
|
||||
__attribute__((section(".data"))) unsigned char ASC16_y_Char[16]={0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x81,0x86,0x78,0x18,0x06,0x01,0x00};
|
||||
|
||||
/* 'S' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_S_Char[16]={0x00,0x0E,0x11,0x10,0x10,0x10,0x1C,0x00,0x00,0x1C,0x04,0xC4,0x38,0x00,0x00,0x00};
|
||||
/* 'Z' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_Z_Char[16]={0x00,0x00,0x00,0x7E,0x84,0x04,0x08,0x08,0x10,0x20,0x20,0x42,0x42,0xFC,0x00,0x00};
|
||||
/* 'M' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_M_Char[16]={0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x50,0x50,0x00,0x00,0x00,0x00};
|
||||
/* '0' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_0_Char[16]={0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x50,0x50,0x00,0x00,0x00,0x00};
|
||||
/* '4' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_4_Char[16]={0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x50,0x50,0x00,0x00,0x00,0x00};
|
||||
/* '-' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_sub_Char[16]={0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x50,0x50,0x00,0x00,0x00,0x00};
|
||||
/* 'B' */
|
||||
__attribute__((section(".data"))) unsigned char ASC12_B_Char[16]={0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x50,0x50,0x00,0x00,0x00,0x00};
|
||||
|
||||
|
||||
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC16_End=0xFF;
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
/* 6*8点阵数字*/
|
||||
unsigned char ASC8_Num[16][6]=
|
||||
{
|
||||
{0x3E,0x41,0x41,0x41,0x3E,0x00}, /*'0'*/
|
||||
{0x00,0x42,0x7F,0x40,0x00,0x00}, /*'1'*/
|
||||
{0x62,0x51,0x49,0x49,0x66,0x00}, /*'2'*/
|
||||
{0x22,0x49,0x49,0x49,0x36,0x00}, /*'3'*/
|
||||
{0x18,0x14,0x12,0x7F,0x10,0x00}, /*'4'*/
|
||||
{0x2F,0x49,0x49,0x49,0x31,0x00}, /*'5'*/
|
||||
{0x3C,0x4A,0x49,0x49,0x30,0x00}, /*'6'*/
|
||||
{0x03,0x71,0x09,0x05,0x03,0x00}, /*'7'*/
|
||||
{0x36,0x49,0x49,0x49,0x36,0x00}, /*'8'*/
|
||||
{0x06,0x49,0x49,0x29,0x1E,0x00}, /*'9'*/
|
||||
{0x60,0x1C,0x0B,0x1C,0x60,0x00}, /*'A'*/
|
||||
{0x00,0x7F,0x49,0x49,0x36,0x00}, /*'B'*/
|
||||
{0x1C,0x22,0x41,0x41,0x22,0x00}, /*'C'*/
|
||||
{0x7F,0x41,0x41,0x22,0x1C,0x00}, /*'D'*/
|
||||
{0x7F,0x49,0x49,0x49,0x41,0x00}, /*'E'*/
|
||||
{0x7F,0x09,0x09,0x09,0x01,0x00} /*'F'*/
|
||||
};
|
||||
/* 6*8点阵小数点*/
|
||||
unsigned char ASC8_Dot[6]={0x00,0x60,0x60,0x00,0x00,0x00};
|
||||
/* 6*8点阵逗号*/
|
||||
unsigned char ASC8_Comma[6]={0x00,0x40,0x30,0x10,0x00,0x00};
|
||||
/* 6*8点阵空格*/
|
||||
unsigned char ASC8_Space[6]={0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
/* 6*8点阵减号*/
|
||||
//unsigned char ASC8_Sub[6]={0x08,0x08,0x08,0x08,0x08,0x00};
|
||||
/* 6*8点阵星号*/
|
||||
unsigned char ASC8_Star[6]={0x2A,0x1C,0x3E,0x1C,0x2A,0x00};
|
||||
/* 6*8点阵下划线*/
|
||||
unsigned char ASC8_Line[6]={0x80,0x80,0x80,0x80,0x80,0x00};
|
||||
/* 6*8点阵冒号*/
|
||||
unsigned char ASC8_Colon[6]={0x00,0x00,0x66,0x66,0x00,0x00};
|
||||
/* 6*8点阵对勾*/
|
||||
//unsigned char ASC8_Right[6]={0x10,0x20,0x10,0x08,0x04,0x02};
|
||||
/* 6*8点阵叉号*/
|
||||
//unsigned char ASC8_Cross[6]={0x42,0x24,0x18,0x18,0x24,0x42};
|
||||
/* 6*8点阵斜线*/
|
||||
unsigned char ASC8_Bias[6]={0x40,0x20,0x10,0x08,0x04,0x02};
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_a[8]={0x06,0x60,0x54,0x54,0x54,0x7C,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_b[8]={0x06,0x7F,0x48,0x48,0x48,0x30,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_c[8]={0x05,0x38,0x44,0x44,0x44,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_d[8]={0x06,0x30,0x48,0x48,0x48,0x7F,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_e[8]={0x06,0x38,0x54,0x54,0x54,0x58,0x00,0x00};
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_f[8]={0x04,0x08,0xFF,0x09,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_g[8]={0x06,0x98,0xA4,0xA4,0xA4,0x78,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_h[8]={0x05,0x7F,0x08,0x08,0x78,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_i[8]={0x02,0x7A,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_j[8]={0x03,0x80,0xFA,0x00,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_k[8]={0x06,0x7F,0x10,0x28,0x48,0x44,0x00,0x00};
|
||||
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_l[8]={0x03,0x7F,0x40,0x00,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_m[8]={0x06,0x7C,0x04,0x78,0x04,0x7C,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_n[8]={0x05,0x7C,0x04,0x04,0x7C,0x00,0x00,0x00};
|
||||
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_o[8]={0x06,0x38,0x44,0x44,0x44,0x38,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_p[8]={0x06,0xFC,0x24,0x24,0x24,0x18,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_q[8]={0x06,0x18,0x24,0x24,0x24,0xFC,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_r[8]={0x04,0x7C,0x08,0x04,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_s[8]={0x05,0x48,0x54,0x54,0x64,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_t[8]={0x04,0x04,0x7E,0x44,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_u[8]={0x05,0x7C,0x40,0x40,0x7C,0x00,0x00,0x00};
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_v[8]={0x06,0x1C,0x20,0x40,0x20,0x1C,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_w[8]={0x06,0x3C,0x60,0x1C,0x60,0x3C,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_x[8]={0x06,0x44,0x28,0x10,0x28,0x44,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_y[8]={0x05,0x9C,0xA0,0x60,0x1C,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_z[8]={0x06,0x44,0x64,0x54,0x4C,0x44,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_space[8]={0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
//逗号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_comma[8]={0x04,0x80,0x60,0x00,0x00,0x00,0x00,0x00};
|
||||
//句号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_ponit[8]={0x04,0x00,0x40,0x00,0x00,0x00,0x00,0x00};
|
||||
//冒号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_colon[8]={0x04,0x00,0x24,0x00,0x00,0x00,0x00,0x00};
|
||||
//感叹号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_exclam[8]={0x04,0x00,0x5E,0x00,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_slope[8]={0x04,0x80,0x70,0x1C,0x03,0x00,0x00,0x00};
|
||||
|
||||
//下划线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_down_line[8]={0x06,0x80,0x80,0x80,0x80,0x80,0x00,0x00};
|
||||
|
||||
|
||||
|
||||
//分号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_semicolon[8]={0x04,0x80,0x50,0x00,0x00,0x00,0x00,0x00};
|
||||
//单引号
|
||||
__attribute__((section(".data"))) unsigned char ASC8_sin_quotes[8]={0x03,0x08,0x0E,0x00,0x00,0x00,0x00,0x00};
|
||||
//横线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_horiz[8]={0x04,0x08,0x08,0x08,0x08,0x00,0x00,0x00};
|
||||
//横上线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_horiz_up[8]={0x04,0x08,0x0F,0x08,0x08,0x00,0x00,0x00};
|
||||
//横下线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_horiz_down[8]={0x04,0x08,0xF8,0x08,0x08,0x00,0x00,0x00};
|
||||
|
||||
//竖线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_vert[8]={0x04,0x00,0xFF,0x00,0x00,0x00,0x00,0x00};
|
||||
//竖左线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_vert_right[8]={0x04,0x08,0xFF,0x00,0x00,0x00,0x00,0x00};
|
||||
//竖右线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_vert_left[8]={0x04,0x00,0xFF,0x08,0x08,0x00,0x00,0x00};
|
||||
//十字线
|
||||
__attribute__((section(".data"))) unsigned char ASC8_across[8]={0x04,0x08,0xFF,0x08,0x08,0x00,0x00,0x00};
|
||||
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_lefttop_corner[8]={0x04,0x00,0xF8,0x08,0x08,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_righttop_corner[8]={0x04,0x08,0xF8,0x00,0x00,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_leftbottom_corner[8]={0x04,0x00,0x0F,0x08,0x08,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_rightbottom_corner[8]={0x04,0x08,0x0F,0x00,0x00,0x00,0x00,0x00};
|
||||
|
||||
|
||||
__attribute__((section(".data"))) unsigned char ASC8_0[8]={0x06,0x7E,0x81,0x81,0x81,0x7E,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_1[8]={0x06,0x00,0x81,0xFF,0x80,0x00,0x00,0x00};
|
||||
//__attribute__((section(".data"))) unsigned char ASC8_2[8]={0x06,0xC2,0xA1,0x91,0x8E,0x00,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_2[8]={0x06,0xC2,0xA1,0x91,0x89,0x86,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_3[8]={0x06,0x42,0x89,0x89,0x89,0x76,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_4[8]={0x06,0x38,0x24,0x22,0xFF,0x20,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_5[8]={0x06,0x4F,0x89,0x89,0x89,0x70,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_6[8]={0x06,0x7E,0x89,0x89,0x89,0x72,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_7[8]={0x06,0x01,0x81,0x61,0x19,0x07,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_8[8]={0x06,0x76,0x89,0x89,0x89,0x76,0x00,0x00};
|
||||
__attribute__((section(".data"))) unsigned char ASC8_9[8]={0x06,0x4E,0x91,0x91,0x91,0x7E,0x00,0x00};
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
/***
|
||||
* @文件名称: ctranscode.c
|
||||
* @系统名称: 公共库
|
||||
* @模块名称: 底层函数库
|
||||
* @功能说明: 编码转换函数
|
||||
* @当前版本: 1.0.0
|
||||
* @修改说明: 创建文件
|
||||
*/
|
||||
|
||||
#include "public.h"
|
||||
#include "define.h"
|
||||
|
||||
//static BYTE szHexByte[] =
|
||||
//{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9','A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
int Table_ASC_HEX[]={
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
|
||||
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
||||
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
|
||||
0x40,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f
|
||||
};
|
||||
|
||||
|
||||
const char HexToAsc1[]="0123456789ABCDEF";
|
||||
|
||||
void Byte2String(int len, unsigned char *InBuf, unsigned char *OutBuf)
|
||||
{
|
||||
for(; len>0; len--)
|
||||
{
|
||||
(*OutBuf++) = HexToAsc1[((*InBuf)>>4)&0xf];
|
||||
(*OutBuf++) = HexToAsc1[(*InBuf++)&0xf];
|
||||
}
|
||||
}
|
||||
|
||||
void String2Byte(int len, unsigned char *InBuf, unsigned char *OutBuf)
|
||||
{
|
||||
for(; len>0; len-=2, InBuf+=2)
|
||||
{
|
||||
(*OutBuf++) = (Table_ASC_HEX[(*InBuf)]<<4)|Table_ASC_HEX[*(InBuf+1)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void hextoasc(unsigned char *asc,unsigned char *hex,int len)
|
||||
{
|
||||
int i;
|
||||
int ch;
|
||||
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
|
||||
ch=hex[i]>>4;
|
||||
if(ch>=0&&ch<=9)
|
||||
{
|
||||
asc[i*2]=ch+'0';
|
||||
}
|
||||
if(ch>=0xA&&ch<=0xF)
|
||||
{
|
||||
asc[i*2]=ch-0xa+'A';
|
||||
}
|
||||
|
||||
|
||||
ch=hex[i]&0x0F;
|
||||
if(ch>=0&&ch<=9)
|
||||
{
|
||||
asc[i*2+1]=ch+'0';
|
||||
}
|
||||
if(ch>=0xA&&ch<=0xF)
|
||||
{
|
||||
asc[i*2+1]=ch-0xa+'A';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void asctohex(unsigned char *hex,unsigned char *asc,int len)
|
||||
{
|
||||
int i;
|
||||
unsigned char ch;
|
||||
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
ch=asc[i];
|
||||
if(ch>='0'&&ch<='9')
|
||||
{
|
||||
ch-='0';
|
||||
}
|
||||
if(ch>='a'&&ch<='f')
|
||||
{
|
||||
ch=ch-'a';
|
||||
ch=ch+10;
|
||||
}
|
||||
if(ch>='A'&&ch<='F')
|
||||
{
|
||||
ch=ch-'A';
|
||||
ch=ch+10;
|
||||
}
|
||||
|
||||
if(i%2==0)
|
||||
{
|
||||
hex[i/2]=ch<<4;
|
||||
}else
|
||||
{
|
||||
hex[i/2]=hex[i/2]|ch;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void asctoebcd(unsigned char *ebcd,unsigned char *asc,int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i=0;i<len;i++)
|
||||
{
|
||||
if((asc[i]>='0') && (asc[i]<='9'))
|
||||
ebcd[i]=asc[i]-'0' + 0xF0;
|
||||
if((asc[i]>='A') && (asc[i]<='F'))
|
||||
ebcd[i]=asc[i]-'A' + 0xC1;
|
||||
if((asc[i]>='a') && (asc[i]<='f'))
|
||||
ebcd[i]=asc[i]-'a' + 0xC1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
unsigned char Frame; //画面号
|
||||
unsigned int MenuItem; //光标所在菜单项
|
||||
unsigned int FreshItem = 0;
|
||||
|
||||
int card_flag = 0x00;
|
||||
|
||||
unsigned char TO_ADMIN_OR_MOR_FLAG; //初始化后,进入管理程序或编核押程序标志 2串口服务1 管理程序 0 编核押
|
||||
unsigned char ADMIN_LOCATE_FLAG; //安控员登录定位标志 0:安控员一登录界面 1:安控员二登录界面 2:管理菜单管理员登录界面
|
||||
|
||||
|
||||
unsigned char MANAGE_UMAKE_FLAG; //管理员盾制作标志0:安控员一制作界面1:安控员二制作界面3:安控员三制作界面
|
||||
unsigned char DEBLOCK_FLAG; //0;IC卡解锁1;U盾解锁
|
||||
unsigned char UKEY_MAKE_FLAG; //管理员盾制作标志0:制作一级管理员盾1;制作二级管理员盾2;制作三级管理员盾3;制作密钥备份盾4;制作密钥发行盾5;发行卡制作
|
||||
unsigned char SUPPER_UMAKE_FLAG; // 管理员盾制作标志 0 : 超级管理员 1: 非超级管理员( 针对超级管理员,需要插卡录入 )
|
||||
unsigned char UKEY_OPERATE_FLAG; //0;U盾导出对称密钥分量1;U盾分量合成对称密钥2;U盾导出数字信封3;U盾导入数字信封
|
||||
unsigned char PWD_CHANGE_FLAG; //0:IC卡口令1:IC卡管理口令 2:U盾口令 3:U盾管理口令
|
||||
|
||||
unsigned char NETLOGIN_FLAG; //网络服务登录1:普通交易登录2:授权状态登录
|
||||
unsigned char LMK_RECOVER_FLAG; //恢复主密钥定位标记1:恢复分量一2:恢复分量二3:恢复分量三
|
||||
unsigned char LMK_BAK_FLAG; //备份主密钥定位标记1:备份分量一2:备份分量二3:备份分量三
|
||||
unsigned char LMK_GENERATE_FLAG; //产生主密钥方式1:新生成2:分量恢复
|
||||
unsigned char LMK_FLAG; //判断LMK 是否正常0:正常1:不正常
|
||||
unsigned char MAKE_OPR_FLAG; //制作密钥管理员1:密钥管理员一2:密钥管理员二
|
||||
unsigned char AUTHORIZATION_LOGIN; //网络交易授权状态1:授权登录0:配置管理员登录
|
||||
unsigned char NetService_Change; //交易状态切换0,非切换状态1,普通到授权,2,授权到普通
|
||||
unsigned char cmp_combine;//对比错误
|
||||
|
||||
unsigned char MenuItem_num; //返回到上一帧菜单项被选中号,优先级高
|
||||
unsigned char EXIT_Frame; //返回到上一帧界面号 比Function优先级高
|
||||
unsigned char EXIT_Frame_Flag[8]; //存放一个功能菜单的EXIT_Frame
|
||||
unsigned char MenuItem_num_Flag[8]; //存放一个功能菜单的MenuItem_num 返回到上一帧菜单项被选中号
|
||||
unsigned char NETWARE_NUM; //网卡号
|
||||
unsigned char XTZMY_Function_Num; //区分是第一次开机生成系统主密钥 0 /管理菜单选择生成系统主密钥 1
|
||||
unsigned char Store_Card_Num; //备份下级行密钥的IC卡编号 默认为1
|
||||
unsigned char TIMEOUT; //串口数据传输超时标志位 TIMEOUT=1表示超时
|
||||
unsigned int TIMENUM_NUM; //超时时间倍数计数
|
||||
unsigned int Timenum; //超时时间倍数计数
|
||||
unsigned char INPUT_OR_OUTPUT_KEY_BIT; //导入或导出的密钥位数 2:两位 3:三位
|
||||
int ExData; //全局变量,单字节共享时用
|
||||
int totalnum = 0;
|
||||
unsigned int QueryCnt,QueryPtr,DispAddr;
|
||||
unsigned int P_Flag= 0 ;
|
||||
unsigned char LEDSTATE ;
|
||||
//unsigned char *Buffer[22]; //用户行显示内容的指针全局变量
|
||||
unsigned char *Buffer[44]; //用户行显示内容的指针全局变量
|
||||
|
||||
unsigned char DataTmp[256] = {0x00}; //全局变量,多字节共享unsigned char Buf[256] = {0x00};
|
||||
unsigned char SynBuf[80] = {0x00};
|
||||
unsigned char inbuf[20] = {0x00};
|
||||
unsigned char Buf[512] = {0x00};
|
||||
unsigned char Int_flag;
|
||||
unsigned char func_3s_flag = 0x00;
|
||||
unsigned char keybuff[20] = {0x00};
|
||||
int bufindex = 0;
|
||||
int AllKeyLen = 0;
|
||||
unsigned char *g_key_buff;
|
||||
unsigned char power;
|
||||
unsigned char NUM_SERIER_REV;
|
||||
int SerialPort_PID;
|
||||
int PCfd =-1;
|
||||
unsigned char IC_Copy_tmp[12*1024] ={0x00};
|
||||
char IC_Copy_role[17]={0x00};
|
||||
char IC_Copy_roleLen = 0;
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
|
||||
#include "define.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int rv;
|
||||
rv = serial_open(115200);
|
||||
if (rv < 0)
|
||||
{
|
||||
printf("[SRL] Open Serial Err");
|
||||
sleep(1);
|
||||
exit(0);
|
||||
}
|
||||
printf("Open Serial Success\n");
|
||||
PrintFormatStr(1, 15, STR_QMYQFWQ, 7, NORMAL);
|
||||
PrintFormatStr(3, 25, STR_SYD1888, 9, NORMAL);
|
||||
PrintFormatStr(5, 40, STR_V300, 5, NORMAL);
|
||||
|
||||
buffer_flush(0xFF);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+3430
File diff suppressed because it is too large
Load Diff
+1612
File diff suppressed because it is too large
Load Diff
+498
@@ -0,0 +1,498 @@
|
||||
#include "global.h"
|
||||
|
||||
#include "error_no.h"
|
||||
|
||||
#include "usboperate.h"
|
||||
#include "define.h"
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
int icdev = -1;
|
||||
|
||||
static unsigned char serial_buf[4096];
|
||||
//static unsigned char serial_buf[1030];
|
||||
|
||||
unsigned char Display_Stx[4]= {0x55,0xAA,0x88,0x66};
|
||||
unsigned char CleanScr_Stx[4]= {0x55,0xAA,0x66,0x88};
|
||||
|
||||
int serial_buff_init()
|
||||
{
|
||||
memset(serial_buf,0,1030);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serial_buff_black()
|
||||
{
|
||||
memset(serial_buf,0xff,1030);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//int serial_write_buff(unsigned char page,unsigned char col,unsigned char dat)
|
||||
int serial_write_buff(unsigned int page,unsigned int col,unsigned int dat)
|
||||
{
|
||||
if(page<0||page>7)
|
||||
return -1;
|
||||
if(col<0||col>127)
|
||||
return -1;
|
||||
unsigned int pos=0;
|
||||
/* modify for the header by mukesong from 3 to 4 */
|
||||
pos=page*128+col+4;
|
||||
serial_buf[pos]=dat;
|
||||
return 0;
|
||||
}
|
||||
/************************************************************************************
|
||||
* serial_open [history:15:06:12,23-06-2009]
|
||||
* Discription : -无阻塞模式打开串口: 数据位8;停止位1;效应位无;流控制无 ;DTR无; RTS无;
|
||||
* Parameter : - baud_rate:波特率
|
||||
* Return : - 文件名描述符
|
||||
************************************************************************************/
|
||||
void icdev_get(char *dev)
|
||||
{
|
||||
FILE * FP = NULL;
|
||||
char cmd[512];
|
||||
sprintf(cmd,"sg_map -i | grep SUNYARD | awk '{ print $2}'");
|
||||
FP = popen(cmd,"r");
|
||||
int num = fread(dev,8,1,FP);
|
||||
if(num == -1)
|
||||
printf("fread error\n");
|
||||
pclose(FP);
|
||||
}
|
||||
#if 0
|
||||
int serial_open(int baud_rate)
|
||||
{
|
||||
char dev_path[12];
|
||||
char outbuf[128];
|
||||
int k;
|
||||
sprintf(dev_path, "/dev/sdg");
|
||||
if((icdev = open(dev_path, O_RDONLY)) < 0)
|
||||
{
|
||||
printf(dev_path);
|
||||
printf(" open fail ret:%d\n",icdev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* It is prudent to check we have a sg device by trying an ioctl */
|
||||
if ((ioctl(icdev, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000))
|
||||
{
|
||||
printf("%s is not an sg device, or old sg driver\n", dev_path);
|
||||
close(icdev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(scsi_inquiry(icdev, (unsigned char *)outbuf) == 0)
|
||||
{
|
||||
if(memcmp(outbuf + 8, "SUNYARD", 6) == 0) //find ukey
|
||||
{
|
||||
// *fd = icdev;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
close(icdev);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
close(icdev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
int serial_open(int baud_rate)
|
||||
{
|
||||
char dev[20];
|
||||
icdev_get(dev);
|
||||
dev[8]='\0';
|
||||
if((icdev=open(dev,O_RDONLY))<0)
|
||||
{
|
||||
printf("device open err\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* serial_write [history:16:12:12,22-06-2009]
|
||||
* Discription : - 写接口
|
||||
* Parameter : -
|
||||
* Return : -
|
||||
************************************************************************************/
|
||||
int serial_write(unsigned char * data,int len)
|
||||
{
|
||||
/*
|
||||
int rv;
|
||||
unsigned char buff[2048];
|
||||
read(FD,buff,sizeof(buff));//clear the data cache
|
||||
//PrintHex("write",data,len);
|
||||
rv=write(FD,data,len);
|
||||
return rv;
|
||||
*/
|
||||
printf("serial write ");
|
||||
close(icdev);
|
||||
return 0;
|
||||
}
|
||||
/************************************************************************************
|
||||
* serial_read [history:16:12:48,22-06-2009]
|
||||
* Discription : - 读接口
|
||||
* Parameter : -
|
||||
* Return : -
|
||||
************************************************************************************/
|
||||
int serial_read(unsigned char * data,int len)
|
||||
{
|
||||
//int rv = 0,remain;
|
||||
//int state;
|
||||
int ret,pos=0;
|
||||
//int i,j;
|
||||
unsigned char tmpstr[2048];
|
||||
unsigned char tmprstr[2048];
|
||||
unsigned char bufw[4096];
|
||||
unsigned char bufr[4096];
|
||||
unsigned char head[4]= {0x55,0xaa,0x88,0x66};
|
||||
//unsigned char tmp[6] = {0x00};
|
||||
memset(data,0,len);
|
||||
//add by louyunchuan 20130107
|
||||
// printf("begin to usbicwrite\n");
|
||||
// printf("end open shebei \n");
|
||||
do
|
||||
{
|
||||
pos = 0;
|
||||
memset(data,0,len);
|
||||
memset(bufw,0,sizeof(bufw));
|
||||
memset(bufr,0,sizeof(bufr));
|
||||
memset(tmpstr,0,sizeof(tmpstr));
|
||||
memset(tmprstr,0,sizeof(tmprstr));
|
||||
|
||||
tmpstr[pos++]=0x00; //SEQ
|
||||
tmpstr[pos++]=0x47;//0x47; //TAG
|
||||
tmpstr[pos++]=0; //LEN
|
||||
tmpstr[pos++]=0;//0x00; //LEN
|
||||
Check_LRC(tmpstr,pos);
|
||||
pos+=2;
|
||||
memcpy(bufw,head,4);
|
||||
// hextoasc(bufw+4,tmpstr,pos);
|
||||
memcpy(bufw+4,tmpstr,pos);
|
||||
bufw[pos+4]=3;
|
||||
// PrintHex("wdata",bufw,64);
|
||||
// PrintHex("write data1",bufw,64);
|
||||
ret = USBWrite(icdev,bufw,pos+5,SCSI_TIMEOUT);
|
||||
if(ret != 0)
|
||||
{
|
||||
printf("write hid failed!\n");
|
||||
return IC_READ_ERR;
|
||||
}
|
||||
memset(bufr,0,sizeof(bufr));
|
||||
// printf("retb2 = %d \n",ret);
|
||||
|
||||
ret = USBRead(icdev,bufr,len+12,SCSI_TIMEOUT);//sizeof(bufr));
|
||||
// PrintHex("rdata",bufr,64);
|
||||
if(ret != 0)
|
||||
{
|
||||
printf("read hid failed!\n");
|
||||
// close(icdev);
|
||||
return IC_READ_ERR;
|
||||
}
|
||||
|
||||
|
||||
// printf("retb3 = %d \n",ret);
|
||||
// asctohex(tmprstr,bufr+4,64-5);
|
||||
|
||||
// printf("data of write:\t%s\n",bufw+4);
|
||||
// printf("A!\n");
|
||||
if(bufr[8] == 0x00 && bufr[5] == 0x47)
|
||||
{
|
||||
// close(icdev);
|
||||
data[0]=0x55;
|
||||
data[1]=0xAA;
|
||||
data[2]=0x88;
|
||||
data[3] = 0x66;
|
||||
data[4] = 0x02;
|
||||
memcpy(data+5,bufr+9,1);
|
||||
return ret;
|
||||
}
|
||||
// printf("waitkeyin\n");
|
||||
}
|
||||
while(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int serial_read_once(unsigned char * data,int len)
|
||||
{
|
||||
//int rv,timeout;
|
||||
//int state;
|
||||
int ret,pos=0;
|
||||
//int i,j;
|
||||
unsigned char tmpstr[2048];
|
||||
unsigned char tmprstr[2048];
|
||||
unsigned char bufw[4096];
|
||||
unsigned char bufr[4096];
|
||||
unsigned char head[4]= {0x55,0xaa,0x88,0x66};
|
||||
// sleep(1);
|
||||
// do{
|
||||
pos = 0;
|
||||
memset(data,0,len);
|
||||
memset(bufw,0,sizeof(bufw));
|
||||
memset(bufr,0,sizeof(bufr));
|
||||
memset(tmpstr,0,sizeof(tmpstr));
|
||||
memset(tmprstr,0,sizeof(tmprstr));
|
||||
|
||||
tmpstr[pos++]=0x00; //SEQ
|
||||
tmpstr[pos++]=0x47;//0x47; //TAG
|
||||
tmpstr[pos++]=0; //LEN
|
||||
tmpstr[pos++]=0;//0x00; //LEN
|
||||
Check_LRC(tmpstr,pos);
|
||||
pos+=2;
|
||||
memcpy(bufw,head,4);
|
||||
// hextoasc(bufw+4,tmpstr,pos);
|
||||
memcpy(bufw+4,tmpstr,pos);
|
||||
|
||||
bufw[pos+4]=3;
|
||||
// PrintHex("wdata",bufw,64);
|
||||
// PrintHex("write data1",bufw,64);
|
||||
ret = USBWrite(icdev,bufw,pos+5,SCSI_TIMEOUT);
|
||||
if(ret != 0)
|
||||
{
|
||||
printf("write hid failed!\n");
|
||||
// close(icdev);
|
||||
return IC_WRITE_ERR;
|
||||
}
|
||||
memset(bufr,0,sizeof(bufr));
|
||||
// printf("retb2 = %d \n",ret);
|
||||
|
||||
ret = USBRead(icdev,bufr,4096,SCSI_TIMEOUT);//sizeof(bufr));
|
||||
// PrintHex("rdata",bufr,64);
|
||||
if(ret!=0)
|
||||
{
|
||||
printf("read hid failed!\n");
|
||||
// close(icdev);
|
||||
return IC_READ_ERR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// printf("retb3 = %d \n",ret);
|
||||
// asctohex(tmprstr,bufr+4,64-5);
|
||||
|
||||
// printf("data of write:\t%s\n",bufw+4);
|
||||
// printf("A!\n");
|
||||
if(bufr[8] == 0x00 && bufr[5] == 0x47)
|
||||
{
|
||||
// close(icdev);
|
||||
data[0]=0x55;
|
||||
data[1]=0xAA;
|
||||
data[2]=0x88;
|
||||
data[3] = 0x66;
|
||||
data[4] = 0x02;
|
||||
memcpy(data+5,bufr+9,1);
|
||||
return ret;
|
||||
}
|
||||
else if(bufr[8] == 0x00&& bufr[5] == 0x47)
|
||||
{
|
||||
//timeout--;
|
||||
memset(data,0,len);
|
||||
//continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// PrintHex("rdata",bufr,64);
|
||||
// close(icdev);
|
||||
memset(data,0,len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// timeout--;
|
||||
//PrintHex("rec data is :", data, 6);
|
||||
// }while(((data[0]!=0x55)||(data[1]!=0xAA)
|
||||
// || (data[2] != 0x88) || (data[3] != 0x66) ||(data[4] != 0x02)));
|
||||
//tcflush(FD, TCIFLUSH);
|
||||
// close(icdev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* serial_flush [history:16:12:12,22-06-2009]
|
||||
* Discription : - 清空缓存接口
|
||||
* Parameter : -
|
||||
* Return : -
|
||||
************************************************************************************/
|
||||
int serial_flush(unsigned char LineBit)
|
||||
{
|
||||
int pos = 0, loop = 0;
|
||||
//int rv = 0, remain = 0, inLoop = 0;
|
||||
// int timeout, timeout1;
|
||||
//UINT lrc = 0;
|
||||
unsigned char rush[20] = {0x00}, line = 0;
|
||||
unsigned char Send_buf[136] = {0X00};
|
||||
//int fd;
|
||||
unsigned char tmpstr[2048];
|
||||
unsigned char tmprstr[2048];
|
||||
unsigned char bufw[4096];
|
||||
unsigned char bufr[4096];
|
||||
unsigned char head[4]= {0x55,0xaa,0x88,0x66};
|
||||
int ret;
|
||||
//int i;
|
||||
// int j;
|
||||
|
||||
memset(rush,0,10);
|
||||
// timeout=9000000;
|
||||
// timeout1=9000000;
|
||||
memcpy(Send_buf, Display_Stx, 4);
|
||||
for(loop=0; loop < 8; loop++)
|
||||
{
|
||||
pos =0;
|
||||
if(0x01 == (LineBit>>loop &0x01) )
|
||||
{
|
||||
line = (unsigned char)loop;
|
||||
memset(bufw,0,sizeof(bufw));
|
||||
memset(tmpstr,0,sizeof(tmpstr));
|
||||
memset(tmprstr,0,sizeof(tmprstr));
|
||||
|
||||
tmpstr[pos++]=0x00; //SEQ
|
||||
tmpstr[pos++]=0x46;//0x46; //TAG
|
||||
tmpstr[pos++]=133/256; //LEN
|
||||
tmpstr[pos++]=133%256;//0x00; //LEN
|
||||
|
||||
if(0x04 == (LEDSTATE&0x04))
|
||||
{
|
||||
tmpstr[pos++]=0xF0;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmpstr[pos++]=0x0F; //ADDR
|
||||
}
|
||||
tmpstr[pos++]=line; //ADDR
|
||||
tmpstr[pos++]=0x00; //ADDR
|
||||
tmpstr[pos++]=128/256;
|
||||
tmpstr[pos++]=128%256;
|
||||
memcpy(tmpstr + pos,serial_buf+loop*128 + 3,128);
|
||||
pos = pos + 128;
|
||||
Check_LRC(tmpstr,pos);
|
||||
pos+=2;
|
||||
memcpy(bufw,head,4);
|
||||
memcpy(bufw+4,tmpstr,pos);
|
||||
|
||||
bufw[pos+4]=3;
|
||||
|
||||
ret = USBWrite(icdev,bufw,pos+5,SCSI_TIMEOUT);
|
||||
if(ret != 0)
|
||||
{
|
||||
printf("write hid failed!\n");
|
||||
return IC_NOT_EXIST;
|
||||
}
|
||||
memset(bufr,0,sizeof(bufr));
|
||||
// j=0;
|
||||
|
||||
ret = USBRead(icdev,bufr,4096,SCSI_TIMEOUT);
|
||||
if(ret!=0){
|
||||
printf("read hid failed!\n");
|
||||
return IC_READ_ERR;
|
||||
}
|
||||
|
||||
if(bufr[8] == 0x00 && bufr[5] == 0x46){
|
||||
;
|
||||
}else{
|
||||
printf("|%s|%s|%d| : the data return from USBRead is wrong !\n", __FILE__, __func__, __LINE__);
|
||||
return ERR_SYSTEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************************
|
||||
** Function name: make_Protocol_Package
|
||||
** Descriptions: 数据组包
|
||||
** input parameters: ucCmd:操作命令
|
||||
pData:发送的数据
|
||||
DataLen:发送的数据长度
|
||||
** output parameters: pPackData:组包后的数据
|
||||
packLen:组包后的数据长度
|
||||
** Returned value:
|
||||
** Created by: zheh.zhang
|
||||
** Created date: 2022/8/5
|
||||
**-----------------------------------------------------------------------------------------
|
||||
** Modified by:
|
||||
** Modified date:
|
||||
******************************************************************************************/
|
||||
void make_Protocol_Package(unsigned char ucCmd, unsigned char *pData, unsigned short usDataLen, unsigned char *pPackData, unsigned short *packLen)
|
||||
{
|
||||
unsigned char packageBuf[2048];
|
||||
unsigned char Packagelen = 0;
|
||||
unsigned char packageHead[4]= {0X55, 0XAA, 0X88, 0X66};
|
||||
|
||||
memcpy(packageBuf, packageHead, 4); /* 协议头 */
|
||||
|
||||
packageBuf[4] = 0x00; /* SEQ */
|
||||
packageBuf[5] = ucCmd; /* CMD */
|
||||
|
||||
/* 数据长度 */
|
||||
packageBuf[6] = usDataLen>>8;
|
||||
packageBuf[7] = usDataLen&0xff;
|
||||
|
||||
/* 包数据 */
|
||||
memcpy(packageBuf + 8, pData, usDataLen);
|
||||
|
||||
/* LRC校验码 */
|
||||
Packagelen = usDataLen + 8;
|
||||
Check_LRC(packageBuf+4, Packagelen - 4);
|
||||
Packagelen += 2;
|
||||
|
||||
packageBuf[Packagelen++] = 0x03; /* 协议尾 */
|
||||
|
||||
*packLen = Packagelen;
|
||||
memcpy(pPackData, packageBuf, Packagelen);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
** Function name: get_hmi_version
|
||||
** Descriptions: 获取液晶控制面板版本
|
||||
** input parameters: len:buf的长度
|
||||
** output parameters: data:返回的数据
|
||||
** Returned value: none
|
||||
** Created by: zheh.zhang
|
||||
** Created date: 2022/9/28
|
||||
**-----------------------------------------------------------------------------------------
|
||||
** Modified by:
|
||||
** Modified date:
|
||||
******************************************************************************************/
|
||||
int get_hmi_version(unsigned char *data, int len)
|
||||
{
|
||||
int ret;
|
||||
unsigned int sendLen = 0;
|
||||
unsigned int recvLen = 16;
|
||||
unsigned char usbSendBuf[32] = {0};
|
||||
unsigned char usbRecvBuf[32] = {0};
|
||||
|
||||
make_Protocol_Package(0x45, 0, 0, usbSendBuf, (unsigned short *)&sendLen);
|
||||
|
||||
// showhexbuf("CMD_KEY send", usbSendBuf, sendLen);
|
||||
|
||||
ret = USBWrite(icdev, usbSendBuf, sendLen, SCSI_TIMEOUT);
|
||||
if(ret<0){
|
||||
printf(" get_hmi_version write failed!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = USBRead(icdev, usbRecvBuf, recvLen, SCSI_TIMEOUT);
|
||||
if(ret<0){
|
||||
printf("get_hmi_version read failed! ret = %d \n",ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// showhexbuf("CMD_KEY recv", usbRecvBuf, recvLen);
|
||||
if(usbRecvBuf[8] == 0x00 && usbRecvBuf[5] == 0x45) {
|
||||
data[0] = usbRecvBuf[9];
|
||||
data[1] = usbRecvBuf[10];
|
||||
return ret;
|
||||
} else {
|
||||
memset(data, 0, len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
#include "public.h"
|
||||
#include "define.h"
|
||||
#include "custom.h"
|
||||
|
||||
int msgid_recvq;
|
||||
int msgid_sendq;
|
||||
int msgid_print; //message queue to printer
|
||||
int msgid_log; //message queue to log process
|
||||
int msgid_fd;
|
||||
int efd;
|
||||
|
||||
key_t SemKeyCard = 0x46B;//密码卡信号量键值
|
||||
|
||||
struDataPA *g_PA = NULL; // 20141104 nifei add
|
||||
unsigned long long g_TradeCount = 0;
|
||||
|
||||
/*信号*/
|
||||
|
||||
int semid_KeyCard;//密码卡信号量
|
||||
|
||||
|
||||
|
||||
|
||||
/*信号键*/
|
||||
key_t SemHourKey=0x461;
|
||||
key_t SemDayKey=0x462;
|
||||
key_t SemCountKey=0x463;
|
||||
key_t SemConnectionsKey=0x464;
|
||||
key_t SemMsgInQueueCountKey=0x465;
|
||||
key_t SemKeycountKey=0x466;
|
||||
key_t SemTradeStatus=0x467;
|
||||
key_t SemPrintErrorCode=0x468;
|
||||
key_t SemThreadSwitch = 0x469;
|
||||
key_t SemManageUser = 0x46A;
|
||||
|
||||
int _icdev; //IC卡读卡器
|
||||
key_t _icdevKey = 0x570;
|
||||
|
||||
/*******初始化IC卡个数初始值*********/
|
||||
int InitKeyCard(int semid)
|
||||
{
|
||||
return semctl(semid, 0, SETVAL, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ------------------------------- 建立信号量 ----------------------------- */
|
||||
int initsem(int *semid, key_t semkey)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
if ((*semid = semget(semkey, 1, IPC_CREAT | 0666)) == -1) /* 全局变量 */
|
||||
{
|
||||
perror("semget");
|
||||
}
|
||||
else
|
||||
status = semctl(*semid, 0, SETVAL, 1);
|
||||
|
||||
if (*semid == -1 || status == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
/* ------------------------------- V 操作 ---------up-------------------------- */
|
||||
int V(int Semid, int flag)
|
||||
{
|
||||
struct sembuf sops[1];
|
||||
int rtn;
|
||||
sops[0].sem_num = flag;
|
||||
sops[0].sem_op = +1;
|
||||
sops[0].sem_flg = SEM_UNDO;
|
||||
rtn = semop(Semid, sops, 1);
|
||||
if(rtn == -1)
|
||||
{
|
||||
printf("V error\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------- P 操作 ------down----------------------------- */
|
||||
int P(int Semid, int flag, int senconds)
|
||||
{
|
||||
|
||||
|
||||
struct sembuf sops[1];
|
||||
int rtn;
|
||||
sops[0].sem_num = flag;
|
||||
sops[0].sem_op = -1;
|
||||
sops[0].sem_flg = SEM_UNDO;
|
||||
|
||||
rtn=semop(Semid,sops,1);
|
||||
|
||||
if(rtn==-1)
|
||||
{
|
||||
printf("P error\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------ 建消息队列,共享内存,信号量 --------------------- */
|
||||
int CreateIpc()
|
||||
{
|
||||
initsem(&_icdev,_icdevKey);
|
||||
|
||||
//访问密码卡信号量
|
||||
initsem(&semid_KeyCard, SemKeyCard);
|
||||
InitKeyCard(semid_KeyCard);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------ delete 消息队列,共享内存,信号量 ------------------- */
|
||||
int DeleteIpc()
|
||||
{
|
||||
//struct shmid_ds shmds;
|
||||
semctl(_icdev,_icdevKey,IPC_RMID, 0);
|
||||
//访问密码卡信号量
|
||||
semctl(semid_KeyCard, SemKeyCard, IPC_RMID, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------- 建立消息队列 ----------------------------- */
|
||||
int CreateMsgQueue(int *msgid, key_t msgkey)
|
||||
{
|
||||
int status = 0;
|
||||
if((status = msgget(msgkey, IPC_CREAT | 0666)) == -1) /* 全局变量 */
|
||||
{
|
||||
perror("msgget error!");
|
||||
return -1;
|
||||
}
|
||||
*msgid=status;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_efd_lock(void)
|
||||
{
|
||||
uint64_t e_val = 0;
|
||||
int ret;
|
||||
ret = read(efd, &e_val, sizeof(uint64_t));
|
||||
if(ret > 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int put_efd_lock(void)
|
||||
{
|
||||
uint64_t e_val = 1;
|
||||
int ret;
|
||||
ret = write(efd, &e_val, sizeof(uint64_t));
|
||||
if(ret > 0)
|
||||
return 0;
|
||||
else
|
||||
{
|
||||
printf("Failed to write efd.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
|
||||
#include "usb.h"
|
||||
|
||||
#include "public.h"
|
||||
|
||||
|
||||
int usbWrite(int sg_fd, unsigned char * pData,unsigned int nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char pCDB[12]={0};
|
||||
int nCDBLen=12;
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
//int rv = 0;
|
||||
|
||||
pCDB[0]=0xfe;
|
||||
pCDB[1]=1;
|
||||
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
//perror(" fd invalid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen;
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一般用于错误信息返回)
|
||||
io_hdr.dxfer_direction = SG_DXFER_TO_DEV; //写入标记
|
||||
io_hdr.dxfer_len = nLength; //写入数据长度
|
||||
io_hdr.dxferp = pData; //写入数据
|
||||
io_hdr.cmdp = pCDB; //命令
|
||||
io_hdr.sbp = sense_buffer; //存储错误返回信息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Write-> SG_IO ioctl error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Write-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Write-> SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Write-> host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Write-> driver_status=0x%x\n", io_hdr.driver_status);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int usbRead(int sg_fd, unsigned char * pData,unsigned int nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char pCDB[12]={0};
|
||||
int nCDBLen=12;
|
||||
//int rv = 0;
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
pCDB[0]=0xfe;
|
||||
pCDB[1]=2;
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror(" fd invalid");
|
||||
return -1;
|
||||
}
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen; //命令长度
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一般用于错误信息返回)
|
||||
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; //读标记
|
||||
io_hdr.dxfer_len = nLength; //读入数据长度
|
||||
io_hdr.dxferp = pData; //读入数据
|
||||
io_hdr.cmdp = pCDB; //命令
|
||||
io_hdr.sbp = sense_buffer; //存储错误返回信息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Read-> SG_IO ioctl error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Read-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Read SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Read host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Read driver_status=0x%x\n", io_hdr.driver_status);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,490 @@
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <scsi/sg.h> /* take care: fetches glibc's /usr/include/scsi/sg.h */
|
||||
#include <linux/capability.h>
|
||||
#include "public.h"
|
||||
|
||||
#include "define.h"
|
||||
#include "sham.h"
|
||||
|
||||
|
||||
//INQUIRY COMMAND
|
||||
|
||||
extern int _icdev;
|
||||
|
||||
int USBWrite(int sg_fd, unsigned char * pData,unsigned int nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char pCDB[12]={0};
|
||||
int nCDBLen=12;
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
int rv = 0;
|
||||
|
||||
// rv = P(_icdev, 0, 10);
|
||||
// if(rv == -1)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
pCDB[0]=0xfe;
|
||||
pCDB[1]=1;
|
||||
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror(" fd invalid 111");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen; //锟斤拷锟筋长锟斤拷
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷息锟斤拷锟斤拷)
|
||||
io_hdr.dxfer_direction = SG_DXFER_TO_DEV; //写锟斤拷锟斤拷
|
||||
io_hdr.dxfer_len = nLength; //写锟斤拷锟斤拷锟捷筹拷锟斤拷
|
||||
io_hdr.dxferp = pData; //写锟斤拷锟斤拷锟斤拷
|
||||
io_hdr.cmdp = pCDB; //锟斤拷锟斤拷
|
||||
io_hdr.sbp = sense_buffer; //锟芥储锟斤拷锟襟返伙拷锟斤拷息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Write-> SG_IO ioctl error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Write-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Write-> SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Write-> host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Write-> driver_status=0x%x\n", io_hdr.driver_status);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int USBRead(int sg_fd, unsigned char * pData,unsigned int nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char pCDB[12]={0};
|
||||
int nCDBLen=12,rv = 0;
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
pCDB[0]=0xfe;
|
||||
pCDB[1]=2;
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror(" fd invalid 222");
|
||||
// rv = V(_icdev, 0);
|
||||
// if(rv == -1)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
return -1;
|
||||
}
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen; //锟斤拷锟筋长锟斤拷
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷息锟斤拷锟斤拷)
|
||||
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; //锟斤拷锟斤拷锟?
|
||||
io_hdr.dxfer_len = nLength; //锟斤拷锟斤拷锟斤拷锟捷筹拷锟斤拷
|
||||
io_hdr.dxferp = pData; //锟斤拷锟斤拷锟斤拷锟斤拷
|
||||
io_hdr.cmdp = pCDB; //锟斤拷锟斤拷
|
||||
io_hdr.sbp = sense_buffer; //锟芥储锟斤拷锟襟返伙拷锟斤拷息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Read-> SG_IO ioctl error");
|
||||
// rv = V(_icdev, 0);
|
||||
// if(rv == -1)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Read-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Read SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Read host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Read driver_status=0x%x\n", io_hdr.driver_status);
|
||||
// rv = V(_icdev, 0);
|
||||
// if(rv == -1)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
return -1;
|
||||
}
|
||||
// rv = V(_icdev, 0);
|
||||
// if(rv == -1)
|
||||
// {
|
||||
// return -1;
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
int scsi_inquiry(int sg_fd, unsigned char * pData)
|
||||
{
|
||||
/* This is a "standard" SCSI INQUIRY command. It is standard because the
|
||||
* CMDDT and EVPD bits (in the second byte) are zero. All SCSI targets
|
||||
* should respond promptly to a standard INQUIRY */
|
||||
unsigned char inqCmdBlk[INQ_CMD_LEN] = {INQ_CMD_CODE, 0, 0, 0, INQ_REPLY_LEN, 0};
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror("Inquiry fd invalid 333");
|
||||
return -1;
|
||||
}
|
||||
/* Prepare INQUIRY command */
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = sizeof(inqCmdBlk);//锟斤拷锟筋长锟斤拷
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer);
|
||||
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV;
|
||||
io_hdr.dxfer_len = INQ_REPLY_LEN; //锟斤拷锟截筹拷锟斤拷?
|
||||
io_hdr.dxferp = pData; //锟斤拷锟斤拷buffer?
|
||||
io_hdr.cmdp = inqCmdBlk; //锟斤拷锟斤拷buffer
|
||||
io_hdr.sbp = sense_buffer;
|
||||
io_hdr.timeout = 20000; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("Inquiry SG_IO ioctl error");
|
||||
// return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf(" sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("INQUIRY SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("INQUIRY host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("INQUIRY driver_status=0x%x\n", io_hdr.driver_status);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int USBSCSIWrite(int sg_fd, unsigned char * pCDB,int nCDBLen, unsigned char * pData,unsigned int nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror(" fd invalid 444 ");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen; //锟斤拷锟筋长锟斤拷
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷息锟斤拷锟斤拷)
|
||||
io_hdr.dxfer_direction = SG_DXFER_TO_DEV; //写锟斤拷锟斤拷
|
||||
io_hdr.dxfer_len = nLength; //写锟斤拷锟斤拷锟捷筹拷锟斤拷
|
||||
io_hdr.dxferp = pData; //写锟斤拷锟斤拷锟斤拷
|
||||
io_hdr.cmdp = pCDB; //锟斤拷锟斤拷
|
||||
io_hdr.sbp = sense_buffer; //锟芥储锟斤拷锟襟返伙拷锟斤拷息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Write-> SG_IO ioctl error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Write-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Write-> SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Write-> host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Write-> driver_status=0x%x\n", io_hdr.driver_status);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int USBSCSIRead(int sg_fd, unsigned char * pCDB,int nCDBLen, unsigned char * pData,unsigned int * nLength,int nTimeOut)
|
||||
{
|
||||
unsigned char sense_buffer[32];
|
||||
sg_io_hdr_t io_hdr;
|
||||
|
||||
if(sg_fd < 0)
|
||||
{
|
||||
perror(" fd invalid 555");
|
||||
return -1;
|
||||
}
|
||||
memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
|
||||
io_hdr.interface_id = 'S';
|
||||
io_hdr.cmd_len = nCDBLen; //锟斤拷锟筋长锟斤拷
|
||||
/* io_hdr.iovec_count = 0; */ /* memset takes care of this */
|
||||
io_hdr.mx_sb_len = sizeof(sense_buffer); //max sense buffer length(一锟斤拷锟斤拷锟节达拷锟斤拷锟斤拷息锟斤拷锟斤拷)
|
||||
io_hdr.dxfer_direction = SG_DXFER_FROM_DEV; //锟斤拷锟斤拷锟?
|
||||
io_hdr.dxfer_len = *nLength; //锟斤拷锟斤拷锟斤拷锟捷筹拷锟斤拷
|
||||
io_hdr.dxferp = pData; //锟斤拷锟斤拷锟斤拷锟斤拷
|
||||
io_hdr.cmdp = pCDB; //锟斤拷锟斤拷
|
||||
io_hdr.sbp = sense_buffer; //锟芥储锟斤拷锟襟返伙拷锟斤拷息
|
||||
io_hdr.timeout = nTimeOut; /* 20000 millisecs == 20 seconds */
|
||||
/* io_hdr.flags = 0; */ /* take defaults: indirect IO, etc */
|
||||
/* io_hdr.pack_id = 0; */
|
||||
/* io_hdr.usr_ptr = NULL; */
|
||||
|
||||
if (ioctl(sg_fd, SG_IO, &io_hdr) < 0)
|
||||
{
|
||||
perror("USB Read-> SG_IO ioctl error");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* now for the error processing */
|
||||
if ((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK)
|
||||
{
|
||||
if (io_hdr.sb_len_wr > 0)
|
||||
{
|
||||
printf("USB Read-> sense data: ");
|
||||
int k;
|
||||
for (k = 0; k < io_hdr.sb_len_wr; ++k)
|
||||
{
|
||||
if ((k > 0) && (0 == (k % 10)))
|
||||
printf("\n ");
|
||||
printf("0x%02x ", sense_buffer[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
if (io_hdr.masked_status)
|
||||
printf("USB Read SCSI status=0x%x\n", io_hdr.status);
|
||||
if (io_hdr.host_status)
|
||||
printf("USB Read host_status=0x%x\n", io_hdr.host_status);
|
||||
if (io_hdr.driver_status)
|
||||
printf("USB Read driver_status=0x%x\n", io_hdr.driver_status);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------do with package---------------------------
|
||||
/*
|
||||
func: send data and command
|
||||
para:
|
||||
return: success-RT_OK
|
||||
fail-RT_FAIL
|
||||
*/
|
||||
int CD_SendPackage(int sg_fd, TPCCmd tPCCmd, unsigned char * pData)
|
||||
{
|
||||
unsigned char CDB[12];
|
||||
CDB[0] = 0xFE;
|
||||
CDB[1] = 0x01;
|
||||
memcpy(CDB + 2, &tPCCmd, sizeof(tPCCmd));
|
||||
|
||||
if(USBSCSIWrite(sg_fd,CDB, 12, pData, tPCCmd.LC, SCSI_TIMEOUT) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
func: receive status and data package
|
||||
para:
|
||||
return: success-RT_OK
|
||||
fail-RT_FAIL
|
||||
*/
|
||||
int CD_RecvPackage(int sg_fd, unsigned char * pData, unsigned int * lRecvLen)
|
||||
{
|
||||
unsigned char CDB[12]={0};
|
||||
|
||||
CDB[0]=0xFE;
|
||||
CDB[1]=0x02;
|
||||
|
||||
if(USBSCSIRead(sg_fd,CDB,10,pData, lRecvLen, SCSI_TIMEOUT) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
int OpenUDisk(int id, int * fd)
|
||||
{
|
||||
char dev_path[12];
|
||||
//char outbuf[128];
|
||||
|
||||
int sg_fd, k;
|
||||
//for(i = 0; i < 10; i++)
|
||||
{
|
||||
sprintf(dev_path, "/dev/sr0");
|
||||
if((sg_fd = open(dev_path, O_RDONLY)) < 0)
|
||||
{
|
||||
printf(dev_path);
|
||||
printf(" open fail ret:%d\n",sg_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* It is prudent to check we have a sg device by trying an ioctl */
|
||||
if ((ioctl(sg_fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000))
|
||||
{
|
||||
printf("%s is not an sg device, or old sg driver\n", dev_path);
|
||||
close(sg_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if(scsi_inquiry(sg_fd, (unsigned char *)outbuf) == 0)
|
||||
{
|
||||
// if(memcmp(outbuf + 8, "Sydtec", 6) == 0) //find ukey
|
||||
{
|
||||
*fd = sg_fd;
|
||||
// return 1;
|
||||
}
|
||||
// else
|
||||
{
|
||||
// puts(outbuf);
|
||||
// printf("compare sydtec fail\n");
|
||||
}
|
||||
}
|
||||
// close(sg_fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int OpenUDisk(int id, int * fd)
|
||||
{
|
||||
char dev_path[12];
|
||||
char outbuf[128];
|
||||
|
||||
int sg_fd, k;
|
||||
//for(i = 0; i < 10; i++)
|
||||
{
|
||||
sprintf(dev_path, "/dev/sr0");
|
||||
if((sg_fd = open(dev_path, O_RDONLY)) < 0)
|
||||
{
|
||||
printf("%s\n",dev_path);
|
||||
printf(" open fail ret:%d\n",sg_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* It is prudent to check we have a sg device by trying an ioctl */
|
||||
if ((ioctl(sg_fd, SG_GET_VERSION_NUM, &k) < 0) || (k < 30000))
|
||||
{
|
||||
printf("%s is not an sg device, or old sg driver\n", dev_path);
|
||||
close(sg_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(scsi_inquiry(sg_fd, (unsigned char *)outbuf) == 0)
|
||||
{
|
||||
if(memcmp(outbuf + 8, "SUNYARD", 6) == 0) //find ukey
|
||||
{
|
||||
*fd = sg_fd;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
close(sg_fd);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
close(sg_fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
int CloseUsb(int fd)
|
||||
{
|
||||
|
||||
if(fd > 0)
|
||||
{
|
||||
printf("\nCloseUsb \n");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
+369
@@ -0,0 +1,369 @@
|
||||
/***
|
||||
* @文件名称: utils.cpp
|
||||
* @系统名称: 公共库
|
||||
* @模块名称: 底层函数操作库
|
||||
* @功能说明: 工具类函数
|
||||
* @当前版本: 1.0.0
|
||||
* @修改人员: 吕世健
|
||||
* @修改日期: 2012-06-01
|
||||
* @修改说明: 创建文件
|
||||
*/
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
void EntireSleep(UINT nEntireSecs)
|
||||
{
|
||||
struct timeval struTimeout;
|
||||
|
||||
struTimeout.tv_sec = nEntireSecs % 10000000;
|
||||
struTimeout.tv_usec = 0;
|
||||
|
||||
select(0, NULL, NULL, NULL, &struTimeout);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MilliSleep(UINT nMilliSecs)
|
||||
{
|
||||
struct timeval struTimeout;
|
||||
|
||||
struTimeout.tv_sec = nMilliSecs / 1000;
|
||||
struTimeout.tv_usec = (nMilliSecs % 1000) * 1000;
|
||||
|
||||
select(0, NULL, NULL, NULL, &struTimeout);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int killprg(char *prgname,int sig)
|
||||
{
|
||||
FILE *fp;
|
||||
char *p1, *p2;
|
||||
int i;
|
||||
long pid[200];
|
||||
int ret=0;
|
||||
char temp_prgname[80];
|
||||
int account = 0;
|
||||
char buffer[256];
|
||||
|
||||
signal(SIGTERM, SIG_IGN); /*防止被自己kill掉*/
|
||||
|
||||
memset(temp_prgname, 0, sizeof(temp_prgname));
|
||||
p1 = strtok(prgname, "/");
|
||||
if (p1 == NULL)
|
||||
return 0;
|
||||
p2 = p1;
|
||||
for ( ; ; )
|
||||
{
|
||||
p1 = strtok(NULL, "/");
|
||||
if (p1 == NULL)
|
||||
break;
|
||||
else
|
||||
p2 = p1;
|
||||
}
|
||||
strcpy(temp_prgname, p2);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, "ps -ef|grep -v grep|grep %s|grep start|awk '{print $2}'|cut -c -5", temp_prgname);
|
||||
if ((fp = popen(buffer, "r")) == NULL)
|
||||
return -1;
|
||||
|
||||
while (!feof(fp))
|
||||
{
|
||||
memset(buffer, '\0', sizeof(buffer));
|
||||
ret=fscanf(fp, "%s", buffer);
|
||||
if( ret == -1)
|
||||
return ret;
|
||||
pid[account++] = atoi(buffer);
|
||||
}
|
||||
pclose(fp);
|
||||
|
||||
for (i = 0;i < account - 1;i++)
|
||||
{
|
||||
if(kill(pid[i],sig) == -1)
|
||||
{
|
||||
//fprintf(stderr,"向进程发送SIGTERM信号失败,可能是进程已经被关闭!\n");
|
||||
}
|
||||
}
|
||||
/*如果上面没有关闭程序,那么进行强行关闭*/
|
||||
MilliSleep(200);
|
||||
account = 0;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, "ps -ef|grep -v grep|grep %s|grep start|awk '{print $2}'|cut -c -5", temp_prgname);
|
||||
if ((fp = popen(buffer, "r")) == NULL)
|
||||
return -1;
|
||||
|
||||
while (!feof(fp))
|
||||
{
|
||||
memset(buffer, '\0', sizeof(buffer));
|
||||
ret = fscanf(fp, "%s", buffer);
|
||||
if( ret == -1)
|
||||
return ret;
|
||||
pid[account++] = atoi(buffer);
|
||||
}
|
||||
pclose(fp);
|
||||
|
||||
for (i = 0;i < account - 1;i++)
|
||||
{
|
||||
if(kill(pid[i], SIGKILL) == -1)
|
||||
{
|
||||
fprintf(stderr,"Send Singal SIGKILL hsm_test Failed ,maybe hsm_test Closed \n");
|
||||
return account;
|
||||
}
|
||||
fprintf(stderr,"exit hsm_test successful \n");
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数说明:创建进程号记录文件
|
||||
* @pszProgName: 要创建的进程文件名称
|
||||
* @返回说明: 成功NO_ERROR 失败 ERROR_FALSE
|
||||
*/
|
||||
int CreateIdFile(PSTR pszProgName)
|
||||
{
|
||||
FILE *pstruFile;
|
||||
STR szFileName[MAX_PATH_LEN];
|
||||
|
||||
memset(szFileName, 0, sizeof(szFileName));
|
||||
/* snprintf(szFileName, sizeof(szFileName),"%s/.%sid", \
|
||||
getenv("HOME"), pszProgName);*/
|
||||
snprintf(szFileName, sizeof(szFileName),"/tmp/.%sid", pszProgName);
|
||||
|
||||
pstruFile = fopen(szFileName,"w");
|
||||
if(pstruFile == NULL)
|
||||
{
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
fprintf(pstruFile,"%d",getpid());
|
||||
fclose(pstruFile);
|
||||
|
||||
chmod(szFileName, 0600);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数说明:停止进程的执行
|
||||
* @pszProgName: 要停止的进程名称
|
||||
* @返回说明: 无
|
||||
*/
|
||||
void stopPrg(PSTR pszProgName)
|
||||
{
|
||||
FILE *pstruFile;
|
||||
STR szFileName[MAX_PATH_LEN];
|
||||
UINT nProgId;
|
||||
int ret;
|
||||
memset(szFileName, 0, sizeof(szFileName));
|
||||
/* snprintf(szFileName, sizeof(szFileName), "%s/.%sid", \
|
||||
getenv("HOME"), pszProgName);*/
|
||||
snprintf(szFileName, sizeof(szFileName), "/tmp/.%sid", pszProgName);
|
||||
|
||||
pstruFile = fopen(szFileName,"r");
|
||||
if(pstruFile == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"close %s failed ... the process maybe not start or Access denied\n", \
|
||||
pszProgName);
|
||||
return;
|
||||
}
|
||||
ret = fscanf(pstruFile, "%d", &nProgId);
|
||||
if( ret == -1)
|
||||
return;
|
||||
if(kill(nProgId, SIGTERM) == -1)
|
||||
{
|
||||
EntireSleep(1);
|
||||
if(kill(nProgId, SIGKILL) == -1)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"close %s failed ... the process maybe not start or Access denied\n", \
|
||||
pszProgName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"close %s successful \n", pszProgName);
|
||||
}
|
||||
|
||||
fclose(pstruFile);
|
||||
unlink(szFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数说明:判断进程是否启动
|
||||
* @pszProgName: 要判断的进程名称
|
||||
* @返回说明: 进程启动返回NO_ERROR 否则返回ERROR_FALSE
|
||||
*/
|
||||
int TestPrgStat(PSTR pszProgName)
|
||||
{
|
||||
STR szFileName[MAX_PATH_LEN];
|
||||
STR szShellCmd[MAX_STR_LEN];
|
||||
UINT nProgId;
|
||||
UINT nTempLen;
|
||||
FILE *pstruFile;
|
||||
int ret;
|
||||
memset(szFileName, 0, sizeof(szFileName));
|
||||
/* snprintf(szFileName, sizeof(szFileName), "%s/.%sid", \
|
||||
getenv("HOME"), pszProgName);*/
|
||||
snprintf(szFileName, sizeof(szFileName), "/tmp/.%sid", pszProgName);
|
||||
|
||||
pstruFile = fopen(szFileName, "r");
|
||||
if(pstruFile == NULL)
|
||||
{
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
nProgId = 0;
|
||||
ret = fscanf(pstruFile, "%d", &nProgId);
|
||||
if( ret == -1)
|
||||
return ret;
|
||||
fclose(pstruFile);
|
||||
if(nProgId < 1)
|
||||
{
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
memset(szShellCmd, 0, sizeof(szShellCmd));
|
||||
snprintf(szShellCmd, sizeof(szShellCmd), \
|
||||
"ps -e|awk '$1 == %d {print $4}'", nProgId);
|
||||
|
||||
pstruFile = popen(szShellCmd, "r");
|
||||
if(pstruFile == NULL)
|
||||
{
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
char * iRet = fgets(szFileName, sizeof(szFileName), pstruFile);
|
||||
if( iRet == NULL)
|
||||
return ERROR_FALSE;
|
||||
fclose(pstruFile);
|
||||
nTempLen = strlen(szFileName);
|
||||
if(nTempLen < 1)
|
||||
{
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
szFileName[nTempLen - 1]='\0';
|
||||
if(strcmp(szFileName, pszProgName) == 0)
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数说明:将进程变为后台起动进程
|
||||
* @返回说明: 进程启动返回NO_ERROR 否则返回ERROR_FALSE
|
||||
*/
|
||||
RESULT DaemonStart()
|
||||
{
|
||||
register int nChildProgId;
|
||||
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
signal(SIGTTIN, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
||||
nChildProgId = fork();
|
||||
if(nChildProgId < 0)
|
||||
{
|
||||
printf("create pid error %s\n", strerror(errno));
|
||||
return ERROR_FALSE;
|
||||
}
|
||||
else if(nChildProgId > 0)
|
||||
exit(0);
|
||||
|
||||
if (setpgrp() == -1)
|
||||
{
|
||||
printf("setpgrp 设置进程组错误 %s\n", \
|
||||
strerror(errno));
|
||||
exit(0);
|
||||
}
|
||||
signal(SIGHUP, SIG_IGN);
|
||||
|
||||
if((nChildProgId = fork()) < 0)
|
||||
{
|
||||
printf("创建第2个子进程错误 %s\n", \
|
||||
strerror(errno));
|
||||
exit(0);
|
||||
}
|
||||
else if(nChildProgId > 0)
|
||||
exit(0);
|
||||
|
||||
//chdir("/");
|
||||
umask(0);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数说明: 扫描目录
|
||||
* @pszDirName: 目录名称
|
||||
* @pstruDirentList: 目录结构
|
||||
* @返回说明: 成功操作返回NO_ERROR 失败操作返回ERROR_FALSE
|
||||
*/
|
||||
int ScanDir(const char *pszDirName, struct dirent ***pstruDirentList)
|
||||
{
|
||||
#ifdef SYSTEM_LINUX
|
||||
return scandir(pszDirName, pstruDirentList, NULL, alphasort);
|
||||
#else
|
||||
DIR *pstruDir;
|
||||
struct dirent *pstruDirent, *pFirst, *pSecond;
|
||||
struct dirent **pDirent;
|
||||
int nNumber, nLeftNumber, nSize;
|
||||
int i,j;
|
||||
|
||||
/*
|
||||
* 打开目录
|
||||
*/
|
||||
if((pstruDir = opendir(pszDirName)) == NULL)
|
||||
{
|
||||
printf("打开目录错误[%s][%s]\n",
|
||||
pszDirName, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
nNumber = 0;
|
||||
pDirent = (struct dirent **)
|
||||
malloc((nNumber + 100) * sizeof(struct dirent *));
|
||||
nLeftNumber = 100;
|
||||
|
||||
/*
|
||||
* 生成数组
|
||||
*/
|
||||
while((pstruDirent = readdir(pstruDir)) != NULL)
|
||||
{
|
||||
nSize = sizeof(struct dirent) + pstruDirent->d_reclen;
|
||||
pDirent[nNumber] = (struct dirent *)malloc(nSize);
|
||||
memset(pDirent[nNumber], 0, nSize);
|
||||
memcpy(pDirent[nNumber], pstruDirent, nSize);
|
||||
nNumber++;
|
||||
nLeftNumber--;
|
||||
if(nLeftNumber == 0)
|
||||
{
|
||||
pDirent = (struct dirent **)realloc(pDirent,
|
||||
(nNumber + 100) * sizeof(struct dirent *));
|
||||
nLeftNumber = 100;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 数组排序
|
||||
*/
|
||||
for(i = 0;i < (nNumber - 1);i++)
|
||||
{
|
||||
pFirst = pDirent[i];
|
||||
for(j = i + 1;j < nNumber;j++)
|
||||
{
|
||||
pSecond = pDirent[j];
|
||||
if(strcmp(pFirst->d_name, pSecond->d_name) > 0)
|
||||
{
|
||||
pstruDirent = pFirst;
|
||||
pDirent[i] = pDirent[j];
|
||||
pDirent[j] = pstruDirent;
|
||||
pFirst = pDirent[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
*pstruDirentList = pDirent;
|
||||
return nNumber;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user