// Barcode_app.c
/*************************************************
Copyright (C), 2013-2113, XXX. Co., Ltd.
文件名: barcode_app.C
Author: XXX
Version: V1.0
Date: 2013-03-15
Description: 条码的相关处理C文件
History:
<author> <time> <version > <desc>
XXX 13/8/15 1.0 build this moudle
*************************************************/
#include "type.h"
#include "BarCode_app.h"
#include "PrtBuf.h"
#include "CmdSet.h"
#include "BarCode.h"
#include "yc_timer.h"
//#define SIZE_3
//#define BYTE_LEN 8
//#define CLR_WDG //清理看门狗,如果有这这加上宏,如果没有可去掉
//#ifdef SIZE_3 //如果定义了3寸
//#define LINE_DOTS 640 // 3寸的点数
//#else
//#define LINE_DOTS 384 // 2寸的点数
//#endif
//#define PRINT_QUEUE_SIZE 24 //打印队列的长度
//#define PAGES //自定义大小
//#define PAGES_SIZE //自定义大小
//unsigned short CursorX; //X坐标值
//unsigned char aPrintBuf[PAGES][PAGES_SIZE]; //打印缓存区
/*typedef struct Tag_SPrint
{
u8 Mode; //打印的模式
u8 PrintRow; //打印PrintRow点行
u8 SpaceRow; //走纸SpaceRow点行
u8 AllRow; //所有的行
u8 WideAmp; //宽的放大倍数
u8 HihgAmp; //高的放大倍数
u16 Dph; //打印缓冲区序号
}TagSPrint;
TagSPrint PrintQueue[PRINT_QUEUE_SIZE]; //打印队列,大小为20 */
//TagSPrint * pPrintQueueIn = PrintQueue; //打印队列的入队指针
//TagSPrint * pPrintQueueOut = PrintQueue; //打印队列的出队指针
//u16 PrintBuf_Head = 0; //打印缓冲区的头
//u16 PrintBuf_Tail = 0; //打印缓冲区的尾
//code39的编码库
const unsigned short aCode39[44][2] =
{
0x30,0x0A6D, //0 0 101001101101
0x31,0x0D2B, 11 110100101011
0x32,0x0B2B, //2//2 101100101011
0x33,0x0D95, //3//3 110110010101
0x34,0x0A6B, //4//4 101001101011
0x35,0x0D35, //5 5 110100110101
0x36,0x0B35, //6 6 101100110101
0x37,0x0A5B, //7 7 101001011011
0x38,0x0D2D, //8 8 110100101101
0x39,0x0B2D, //9 9 101100101101
0x41,0x0D4B, //10 A 110101001011
0x42,0x0B4B, //11 B 101101001011
0x43,0x0DA5, //12 C 110110100101
0x44,0x0ACB, //13 D 101011001011
0x45,0x0D65, //14 E 110101100101
0x46,0x0B65, //15 F 101101100101
0x47,0x0A9B, //16 G 101010011011
0x48,0x0D4D, //17 H 110101001101
0x49,0x0B4D, //18 I 101101001101
0x4a,0x0ACD, //19 J 101011001101
0x4b,0x0D53, //20 K 110101010011
0x4c,0x0B53, //21 L 101101010011
0x4d,0x0DA9, //22 M 110110101001
0x4e,0x0AD3, //23 N 101011010011
0x4f,0x0D69, //24 O 110101101001
0x50,0x0B69, //25 P 101101101001
0x51,0x0AB3, //26 Q 101010110011
0x52,0x0D59, //27 R 110101011001
0x53,0x0B59, //28 S 101101011001
0x54,0x0AD9, //29 T 101011011001
0x55,0x0CAB, //30 U 110010101011
0x56,0x09AB, //31 V 100110101011
0x57,0x0CD5, //32 W 110011010101
0x58,0x096B, //33 X 100101101011
0x59,0x0CB5, //34 Y 110010110101
0x5a,0x09B5, //35 Z 100110110101
0x2d,0x095B, //36 - 100101011011
0x2e,0x0CAD, //37 . 110010101101
0x20,0x09AD, //38 SPACE 100110101101
0x24,0x0925, //39 $ 100100100101
0x2f,0x0929, //40 / 100100101001
0x2b,0x0949, //41 + 100101001001
0x25,0x0A49, //42 % 101001001001
0x2a,0x096D //n/a* 100101101101
};
//code128的编码库
const unsigned short aCode128[107] =
{
0x06CC,0x066C,0x0666,0x0498,0x048C,0x044C,0x04C8,0x04C4,0x0464,0x0648,0x0644,0x0624,0x059C,0x04DC,0x04CE,0x05CC,
0x04EC,0x04E6,0x0672,0x065C,0x064E,0x06E4,0x0674,0x076E,0x074C,0x072C,0x0726,0x0764,0x0734,0x0732,0x06D8,0x06C6,
0x0636,0x0518,0x0458,0x0446,0x0588,0x0468,0x0462,0x0688,0x0628,0x0622,0x05B8,0x058E,0x046E,0x05D8,0x05C6,0x0476,
0x0776,0x068E,0x062E,0x06E8,0x06E2,0x06EE,0x0758,0x0746,0x0716,0x0768,0x0762,0x071A,0x03BA,0x0642,0x078A,0x0530,
0x050C,0x04B0,0x0486,0x042C,0x0426,0x0590,0x0584,0x04D0,0x04C2,0x0434,0x0432,0x0612,0x0650,0x07BA,0x0614,0x047A,
0x053C,0x04BC,0x049E,0x05E4,0x04F4,0x04F2,0x07A4,0x0794,0x0792,0x06DE,0x06F6,0x07B6,0x0578,0x051E,0x045E,0x05E8,
0x05E2,0x07A8,0x07A2,0x05DE,0x05EE,0x075E,0x07AE,0x0684,0x0690,0x069C,0x18eb
};
//EAN13码奇偶校验
const unsigned char aEanParity[10]={0x00,0x0b,0x0d,0x0e,0x13,0x19,0x1c,0x15,0x16,0x1a};//0表示ODD,1表示EVEN
//EAN13的编码库
const unsigned char aEan[33]=
{
//0 1 2 3 4 5 6 7 8 9
0x0d,0x19,0x13,0x3d,0x23,0x31,0x2f,0x3b,0x37,0x0b, //Left ODD
0x27,0x33,0x1b,0x21,0x1d,0x39,0x05,0x11,0x09,0x17, //Left EVEN(第5个由0x1e改为0x1d)
0x72,0x66,0x6c,0x42,0x5c,0x4e,0x50,0x44,0x48,0x74, //Right
0x05,//START FLAG
0x0a,//MID FLAG
0x05 //END FLAG
};
//UPCE码奇偶校验
const unsigned char aUpceParity[10] = {0x38,0x34,0x32,0x31,0x2C,0x26,0x23,0x2A,0x29,0x25}; 0表示ODD,1表示EVEN
//UPCE的编码库
const unsigned char aUpce[22]=
{
//0 1 2 3 4 5 6 7 8 9
0x0d,0x19,0x13,0x3d,0x23,0x31,0x2f,0x3b,0x37,0x0b, //奇
0x27,0x33,0x1b,0x21,0x1d,0x39,0x05,0x11,0x09,0x17, //偶
0x05, //START FLAG
0x15 //END FLAG
};
//code93的编码库(含校验字符10(数字) + 26(大小字母) +7(特殊字符) +5(2模校验码)+1(结束符))
const unsigned short aCode93[49] =
{
0x0114,0x0148,0x0144,0x0142,0x0128,0x0124,0x0122,0x0150,0x0112,0x010A,
0x01A8,0x01A4,0x01A2,0x0194,0x0192,0x018A,0x0168,0x0164,0x0162,0x0134,
0x011A,0x0158,0x014C,0x0146,0x012C,0x0116,0x01B4,0x01B2,0x01AC,0x01A6,
0x0196, 0x019A,0x016C,0x0166,0x0136,0x013A,0x012E,0x01D4,0x01D2,0x01CA,
0x016E, 0x0176,0x01AE,0x0126,0x01DA,0x01D6,0x0132,0x015E,0x0001
};
//CodaBar的编码库(含校验字符10(数字) + 6(特殊字符) + 4(A/B/C/D))
const unsigned char aCodaBar[20] =
{
0x03,0x06,0x09,0x60,0x12,0x42,0x21,0x24,0x30,0x48, //0~9
0x0C,0x18,0x45,0x51,0x54,0x15,0x1A,0x29,0x0B,0x0E //特殊字符/A/B/C/D
};
//ITF的编码库
const unsigned char aITF[12] =
{
//0 1 2 3 4 5 6 7 8 9
0x06,0x11,0x09,0x18,0x05,0x14,0x0C,0x03,0x12,0x0A, //0~9
0x0A,0x1D //起始符及结束符
};
//#define PM_NORMAL 0 //正常打印模式
//#define VOID_PAGE 0xfffe //无打印页
unsigned int GetUpceDat(unsigned char Dat);
unsigned int GetCode93Dat(unsigned char Dat);
unsigned int GetCode39Dat(unsigned char Dat);
unsigned int GetCode128Dat(unsigned char Dat);
unsigned int GetEanDat(unsigned char Dat);
//unsigned int GetEan8Dat(unsigned char Dat);
void PrintOneBarCode39(void);
void PrintOneBarCode128(void);
void PrintOneBarEan8(void);
void PrintOneBarEan13(void);
void PrintOneBarUPCA(void);
void PrintOneBarUPCE(void);
void PrintOneBarITF(void);
void PrintOneBarCodaBar(void);
void PrintOneBarCode93(void);
/*************************************************
Function: PrintQueueIn
Description: 打印队列的写指针后移动
Input: void
Output: void
Return: void
Others:
*************************************************/
//void PrintQueueIn(void)
//{
//}
/*************************************************************
Name: SetByteFromEnd
Description: 改变一个字节的低几位
Input: *pDat - 要改变的字节的指针
ucResLen - 剩下的长度
ucactionLen - 实际要写入的长度
ucDat - 低位要写入的新内容
Return: void
Others:
**************************************************************/
void SetByteFromLow(unsigned char* pDat,unsigned char ucResLen,unsigned char ucactionLen,unsigned char ucDat)
{
(*pDat) = ((*pDat)&(0xff<<ucResLen))|(ucDat<<(ucResLen-ucactionLen));
}
/*************************************************************
Name: SetByteFromEnd
Description: 改变一个字节的高几位
Input: pDat - 要改变的字节的指针
ucLen - 写入的长度
ucDat - 低位要写入的新内容
Return: void
Others:
**************************************************************/
void SetByteFromHigh(unsigned char* pDat,unsigned char ucLen,unsigned char ucDat)
{
(*pDat) = ((*pDat)&(0xff>>ucLen))|(ucDat<<(8-ucLen));
}
/*************************************************************
Name: GetCutByte
Description: 从传入指针所指向的数据中,截取指定长度的数据,
Input: Pdat - 数据的指针
ucLen - 截取的长度
ucSelfLen - 经过处理之后的数据本身长度
每移位后,数据本身的长度都会减少
Return: 返回截取的8BIT长度的数据
Others:
**************************************************************/
unsigned char GetCutByte(int Dat,unsigned char ucLen,unsigned char ucSelfLen)
{
unsigned char ret =0;
ret = ((unsigned char)( Dat>>(ucSelfLen-ucLen)))&(0xff>>(8-ucLen));
return ret;
}
/*************************************************
Function: DatLineToPrintBuf
Description: 输出一个字符的条码到打印缓冲区
Input: void
Output: void
Return: void
Others: 无
*************************************************/
void DatLineToPrintBuf(int ulDat,unsigned char ucDatLen)//,unsigned short usCurX,unsigned char ucline)
{
unsigned char temp,bit,cData,wide;
for(bit=0; bit<ucDatLen; bit++)
{
temp=( ( ulDat>> (ucDatLen-bit-1) ) & 0x01 );
if(temp)
cData = 0xff;
else
cData =0x00;
for(wide=0;wide<tag_OneBar.WideAmp;wide++)//填充放大倍数
{
PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn] = cData;
iCurrentFillColumn++;
}
}
}
/*************************************************
Function: BarOut
Description: 输出一个字符的条码到打印缓冲区
Input: Dat:输入的字符数据
Output: void
Return: void
Others: 无
*************************************************/
unsigned char BarOut(unsigned char Dat,unsigned char style)
{
unsigned char ucTmpLen; //一行的BIT个数
// unsigned short usTmpCurX; //临时的X光标
int ulTmpRowCh = 0 ; //一行数据的内容
if(style == CODE39)
{
ucTmpLen = CODE39_LEN; 一个code39条码的长度 12个基本单元,由 1表示 暗,0 表示亮
ulTmpRowCh = GetCode39Dat(Dat); //获取字符对应的码元信息(如 0 对应 101001101101)
if (ERROR_CHAR == ulTmpRowCh)
{
return ERROR_CHAR;
}
}
else
if(style == ITF)
{
if(Dat == ITF_BLACK_WITDH) //宽条
{
ucTmpLen = ITF_WIDTH_LEN;
ulTmpRowCh = (unsigned int)0x03;
}
else //窄条
{
ucTmpLen = ITF_NARROW_LEN;
ulTmpRowCh = (unsigned int)0x01;
}
}
else
if(style == CODE93)
{
if(Dat == CODE93_LASTONEDOT) //如果是最后一位的话用一个点表示
{
ucTmpLen = CODE93_LASTLEN;
}
else
{
ucTmpLen = CODE93_LEN;
}
ulTmpRowCh = GetCode93Dat(Dat); //输入的是ID号
}
else
if(style == CODABAR)
{
if(Dat == CODABAR_BLACK_SINGLE)
{
ucTmpLen = CODABAR_THIN_LEN;
ulTmpRowCh = (unsigned int)0x01;
}
else
{
ucTmpLen = CODABAR_THICK_LEN;
ulTmpRowCh = (unsigned int)0x03;
}
}
else
if(style == UPCE)
{
if(Dat == UPCE_START)
{
ucTmpLen = UPCE_START_LEN;
}
else
if(Dat == UPCE_END)
{
ucTmpLen = UPCE_END_LEN;
}
else
{
ucTmpLen = UPCE_LEN;
}
ulTmpRowCh = GetUpceDat(Dat); //输入的是转换后的对应值
}
else
if(style == CODE128)
{
if ( CODE128_START_STOP == Dat )
{
ucTmpLen = CODE128_END_LEN; //CODE128的结束符长度为13,与普通起始符长度和码元长度11不同
}
else
{
ucTmpLen = CODE128_LEN; //普通起始符长度和码元长度11
}
ulTmpRowCh = GetCode128Dat(Dat); //获取128码元信息
}
else
if((style == EAN13) || (style == EAN8))
{
if( (EAN_START == Dat)||(EAN_END == Dat) ) //EAN8和EAN13的起始符号,长度,字元信息都一样
{
ucTmpLen = EAN_SEG_LEN; // EAN8和EAN13的起始符号长度都是 3
}
else
if (EAN_MID == Dat)
{
ucTmpLen = EAN_MID_LEN; // EAN8和EAN13的中间符号长度都是 5
}
else
{
ucTmpLen = EAN_LEN; // EAN8和EAN13的码元信息都是7
}
ulTmpRowCh = GetEanDat(Dat); //获取对应的码元信息
}
// usTmpCurX = iCurrentFillColumn;//CursorX; //获取坐标信息
DatLineToPrintBuf(ulTmpRowCh,ucTmpLen);//,usTmpCurX,0); //把对应码元信息发送到点行中去
if ( CODE39 == style ) //发送完一个码元之后,坐标X的值要往后移动
{
//CursorX += (CODE39_LEN+CODE_GAP); // 因为CODE39与其他条码不同,码元之间有一个 空隙 GAP 隔开
iCurrentFillColumn += CODE_GAP*tag_OneBar.WideAmp;
}
else
{
;//CursorX += ucTmpLen; //移动码元所占的长度即可
}
if (iCurrentFillColumn >= LINE_DOTS) //如果条码此时长度溢出纸张长度,报警出错
{
return ERROR_LEN;
}
else
{
return SUCSS_BAR1;
}
}
/*************************************************************
Name: GetCode39Dat
Description: 获取39条码
Input: void
Output: void
Return: 返回码元信息
Others: 无
**************************************************************/
unsigned int GetCode39Dat(unsigned char Dat)
{
unsigned char i;
for (i=0;i<sizeof(aCode39)/sizeof(aCode39[0]);i++)
{
if (aCode39[i][0]==Dat)
{
return aCode39[i][1]; //返回码元信息
}
}
return ERROR_CHAR;
}
/*************************************************************
Name: Code93CharToId
Description: 输入的CODE93字符转换为对应的ID
Input: void
Output: void
Return:
Others: 参照编码规则详解
**************************************************************/
unsigned char Code93CharToId(unsigned char Dat)
{
unsigned char i;
if(Dat == 32)
{
i = 38;
}
else
if(Dat == 36)
{
i = 39;
}
else
if(Dat == 37)
{
i = 42;
}
else
if(Dat == 43)
{
i = 41;
}
else
if(Dat == 45)
{
i = 36;
}
else
if(Dat == 46)
{
i = 37;
}
else
if(Dat == 47)
{
i = 40;
}
else
if((Dat <= 57) && (Dat >= 48)) //10个数字
{
i = Dat - 48;
}
else
if((Dat <= 90) && (Dat >= 65)) //26个大小字母
{
i = Dat - 55;
}
else //如果输入不合法
{
return CODE93_INPUT_ERROR;
}
return i;
}
/*************************************************************
Name: GetCode93Dat
Description: 获取93条码
Input: Dat -输入为ID号
Output: void
Return: CHECKSUM
Others:
**************************************************************/
unsigned int GetCode93Dat(unsigned char Dat)
{
return aCode93[Dat];
}
/*************************************************************
Name: CodaBarCharToId
Description: 输入的CodaBar字符转换为对应的ID
Input: void
Output: void
Return:
Others: 参照编码规则详解
**************************************************************/
unsigned char CodaBarCharToId(unsigned char Dat)
{
unsigned char i;
if(Dat == '$')
{
i = 11;
}
else
if(Dat == '+')
{
i = 15;
}
else
if(Dat == '-')
{
i = 10;
}
else
if(Dat == '.')
{
i = 14;
}
else
if(Dat == '/')
{
i = 13;
}
else
if((Dat <= '9') && (Dat >= '0'))
{
i = Dat - 48;
}
else
if(Dat == ':')
{
i = 12;
}
else
if((Dat <= 'D') && (Dat >= 'A'))
{
i = Dat - 49;
}
else
{
return CODABAR_INPUT_ERROR;
}
return i;
}
/*************************************************************
Name: GetUpceDat
Description: 获取Upce条码
Input: Dat -
Output: void
Return: CHECKSUM
Others:
**************************************************************/
unsigned int GetUpceDat(unsigned char Dat)
{
return aUpce[Dat];
}
/*************************************************************
Name: GetCode128Dat
Description: 获取128条码
Input: void
Output: void
Return: CHECKSUM
Others: 具体的数字分界点的含义参考CODE128编码规则
**************************************************************/
unsigned char GetCode128Id(unsigned char Dat)
{
unsigned char i=0;
if (Dat < 32)
{
i= 64+Dat;
}
else
if (Dat < 96)
{
i= Dat-32;
}
else
if (Dat < 127)
{
i = 64+(Dat-96);
}
else
if ( (Dat >= 200)&&(Dat <= 211))
{
i = 95 +(Dat-200);
}
else
{
return 0;
}
return i;
}
/*************************************************************
Name: GetCode128Dat
Description: 获取128条码
Input: void
Output: void
Return: CHECKSUM
Others: 具体的数字分界点的含义参考CODE128编码规则
**************************************************************/
unsigned int GetCode128Dat(unsigned char Dat)
{
unsigned char i;
if (Dat < 32)
{
i= 64+Dat;
}
else
if (Dat < 96)
{
i= Dat-32;
}
else
if (Dat < 127)
{
i = 64+(Dat-96);
}
else
if ( (Dat >= 200)&&(Dat <= 211))
{
i = 95 +(Dat-200);
}
else
{
return 0;
}
return aCode128[i];
}
/*************************************************************
Name: GetEanDat
Description: 获取ean13条码
Input: void
Output: void
Return: ean13的条码
Others: 无
**************************************************************/
unsigned int GetEanDat(unsigned char Dat)
{
return aEan[Dat];
}
/*************************************************************
Name: RightShift
Description: 数组右移K位,左边补零
Input: void
Output: void
Return:
Others:
*************************************************************/
void RightShift(unsigned char *Array, unsigned char n, unsigned char k)
{
unsigned char i;
while(k--)
{
for(i = n - 1; i > 0; i--)
{
Array[i] = Array[i - 1];
}
Array[0] = '0'; //左边补零
}
}
/*************************************************************
Name: PrintOneBarCode93
Description: 打印Code93 条码
Input: void
Output: void
Return:
Others:
**************************************************************/
void PrintOneBarCode93(void)
{
unsigned char i,j;
unsigned short usChkC = 0, usChkK = 0;
unsigned int ulChkSumId = 0;
if(((tag_OneBar.ucNum + 4)*CODE93_LEN + CODE93_LASTLEN)*tag_OneBar.WideAmp > LINE_DOTS) //起始符各1位、校验码2位
{
PrintStr("设置错误!超出宽度", 1); //超过宽度报警
return;
}
for(i = 0; i < tag_OneBar.ucNum; i++)
{
if(Code93CharToId(tag_OneBar.aBarDat[i]) == CODE93_INPUT_ERROR)
{
PrintStr("设置错误!字元不支持",1); //不在 字元支持符里
return;
}
}
// for(i = 0; i < tag_OneBar.ucHigh; i++) //打印高度在此设置
{
/*if(pPrintQueueIn->Dph == VOID_PAGE)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印模式,此处与条码无关系
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //高度放大系数,无条码无关
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //条码宽度设置
pPrintQueueIn->PrintRow = 1; //申请一行
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行数
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请打印缓存区
if(pPrintQueueIn->Dph == VOID_PAGE)
{
return; //失败返回
}
} */
//CursorX = tag_OneBar.usLeftSpace; //定义光标X的位置
BarOut(CODE93_START_END, CODE93); //起始符*,此时输入的是ID号
ulChkSumId = 0; //校验和清空
for(j = 0; j < tag_OneBar.ucNum; j++) //条码信息,此时输入的是ID号
{
BarOut(Code93CharToId(tag_OneBar.aBarDat[j]), CODE93); //此时输入的是ID号
ulChkSumId += (tag_OneBar.ucNum - j)*Code93CharToId(tag_OneBar.aBarDat[j]);
}
usChkC = ulChkSumId%47; //计算校验C码
BarOut(usChkC, CODE93); //输出 校验C码
ulChkSumId = 0;
for(j = 0; j < tag_OneBar.ucNum; j++) //条码信息,此时输入的是ID号
{
ulChkSumId += (tag_OneBar.ucNum + 1 - j)*Code93CharToId(tag_OneBar.aBarDat[j]);
}
ulChkSumId += usChkC;
usChkK = ulChkSumId%47; //计算校验K码
BarOut(usChkK, CODE93); //输出 校验K码
BarOut(CODE93_START_END, CODE93); //结束符*,此时输入的是ID号
BarOut(CODE93_LASTONEDOT, CODE93); //结束比起始多一个 1 条纹
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarUPCE
Description: 打印UPCE 条码
Input: void
Output: void
Return:
Others:
**************************************************************/
void PrintOneBarUPCE(void)
{
unsigned char i,j,k;
// unsigned short usCharCusX;
unsigned char ucParity;
unsigned char a,b;
if(tag_OneBar.ucNum != 6) //必须输入6个字元
{
PrintStr("设置错误!字元个数不为6",1);
return;
}
for (i = 0; i < 6; i++)
{
/*if(i == 0)
{
if(tag_OneBar.aBarDat[i] != '0') //输入的第一位不为0,报警出错
{
PrintStr("设置错误!第一位不为0", 1);
return;
}
}
else
{*/
if((tag_OneBar.aBarDat[i] < '0') || (tag_OneBar.aBarDat[i] > '9'))
{
PrintStr("设置错误!字元不支持", 1); //不在 0~9的码元 ,报警出错
return;
}
//}
}
RightShift(tag_OneBar.aBarDat, tag_OneBar.ucNum+1, 1);// 数组右移1位,左边补零
if((6*UPCE_LEN + UPCE_START_LEN + UPCE_END_LEN)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度",1); //长度出错报警
return;
}
/**********生成校验码算法 add by yxm***********/
a=(tag_OneBar.aBarDat[1] + tag_OneBar.aBarDat[3] + tag_OneBar.aBarDat[5] - 0x90);
b=(tag_OneBar.aBarDat[2] + tag_OneBar.aBarDat[4] + tag_OneBar.aBarDat[6] - 0x90)* 3;
if((a+b)%10)
{
tag_OneBar.aBarDat[7] = 10 - (a+b)%10;
}
else
{
tag_OneBar.aBarDat[7] = 0;
}
//SerialSendByte(tag_OneBar.aBarDat[7]);
//1、奇数位相加乘3后
//2、偶数位相加
//1+2后,10-(1+2)%10的结果即为校验码
/***************************************************/
/*if(pPrintQueueIn->Dph == VOID_PAGE)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //此处设置对条码设置无意义
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //条码宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一个点行
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行数
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请需要的行数
if(pPrintQueueIn->Dph == VOID_PAGE)
{
return; //申请失败返回
}
} */
//CursorX = tag_OneBar.usLeftSpace; //定义X坐标的初始值
BarOut(UPCE_START, UPCE); //开始符101
ucParity = aUpceParity[tag_OneBar.aBarDat[7]]; //最后一位决定奇偶
for(j = 1; j < 7; j++) //6个具体条码信息
{
k = (ucParity >> (6 - j))&0x01;
BarOut((10*k + (tag_OneBar.aBarDat[j] - '0')), UPCE);
}
BarOut(UPCE_END, UPCE); //结束符010101
//PrintQueueIn(); //入队,打印
}
/*************************************************************
Name: PrintOneBarITF
Description: 打印ITF条码
Input: void
Output: void
Return: void
Others: void
**************************************************************/
void PrintOneBarITF(void)
{
unsigned char i, j, k;
// unsigned short usCharCusX;
for(i = 0; i < tag_OneBar.ucNum; i++)
{
if((tag_OneBar.aBarDat[i] < '0') || (tag_OneBar.aBarDat[i] > '9'))
{
PrintStr("设置错误!字元不支持", 1); //ITF码元只支持 0~9
return;
}
}
if(tag_OneBar.ucNum%2 == 1) //如果是奇数第一位补零,ITF必须由偶数位组成
{
tag_OneBar.ucNum += 1; //数量加一变为偶数
RightShift(tag_OneBar.aBarDat, tag_OneBar.ucNum, 1); //左边补0,其余位右移一位
}
if((tag_OneBar.ucNum *(2*3 + 2) + 9)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度",1); //宽度溢出纸张报警
return;
}
//for(i = 0; i < tag_OneBar.ucHigh; i++) //条码打印高度在此设置
{
/*if(pPrintQueueIn->Dph == VOID_PAGE)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //此处设置对条码设置无意义
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //条码宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一个点行
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行数
if(pPrintQueueIn->Dph == VOID_PAGE)
{
return; //申请失败返回
}
} */
//CursorX = tag_OneBar.usLeftSpace; //定义X坐标的初始值
for(j = 0; j < 4; j++) //ITF起始符 1010
{
if((aITF[ITF_START] >> (3-j))&0x01)
{
BarOut(ITF_BLACK_NARROW, ITF);
}
else
{
//CursorX += 1;
iCurrentFillColumn += 1*tag_OneBar.WideAmp;
}
}
for(j = 0; j < tag_OneBar.ucNum; j+=2) //打印规定数量字符条码信息
{
//以2个字符为一组输入,第一个以条输入,第二个以空输入
for(k = 0; k < 5; k++)
{
//第一个字符输入的是 窄条或者宽条
if((aITF[tag_OneBar.aBarDat[j] - '0'] >> (4-k))&0x01)
{
BarOut(ITF_BLACK_WITDH, ITF);
}
else
{
BarOut(ITF_BLACK_NARROW, ITF);
}
//第一个字符输入的是 窄空或者宽空
if((aITF[tag_OneBar.aBarDat[j+1] - '0'] >> (4-k))&0x01)
{
//CursorX += ITF_WIDTH_LEN;
iCurrentFillColumn += ITF_WIDTH_LEN*tag_OneBar.WideAmp;
}
else
{
//CursorX += 1;
iCurrentFillColumn += 1*tag_OneBar.WideAmp;
}
}
}
for(j = 0; j < 5; j++) //ITF结束符 1101
{
if((aITF[ITF_END] >> (4-j))&0x01)
{
BarOut(ITF_BLACK_NARROW, ITF);
}
else
{
//CursorX += 1;
iCurrentFillColumn += 1*tag_OneBar.WideAmp;
}
}
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarCodaBar
Description: 打印CodaBar条码
Input: void
Output: void
Return: void
Others: void
**************************************************************/
void PrintOneBarCodaBar(void)
{
unsigned char i,j, k;
// unsigned short usCharCusX;
// unsigned int ulChkSumId = 0;
for(i = 0; i < tag_OneBar.ucNum; i++)
{
if((i == 0) || (i == tag_OneBar.ucNum - 1))
{
if((tag_OneBar.aBarDat[i] < 'A') || (tag_OneBar.aBarDat[i] > 'D'))
{
PrintStr("设置错误!起始符或终止符不在A~D", 1); //起始符号不再 A~D判断为错误
return;
}
}
else
{
if(CodaBarCharToId(tag_OneBar.aBarDat[i]) == CODABAR_INPUT_ERROR)
{
PrintStr("设置错误!字元不支持",1); //字元不支持报警
return;
}
}
}
if(tag_OneBar.ucNum*7*tag_OneBar.WideAmp>LINE_DOTS)
{
PrintStr("设置错误!超出宽度", 1); //超过宽度报警
return;
}
//for(i = 0; i < tag_OneBar.ucHigh; i++)
{
/*if(pPrintQueueIn->Dph == VOID_PAGE)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //此处设置对条码设置无意义
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //条码宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一个点行
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行数
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请需要的行数
if(pPrintQueueIn->Dph == VOID_PAGE)
{
return; //申请失败返回
}
}*/
//CursorX = tag_OneBar.usLeftSpace; //定义X坐标的初始值
for(j = 0; j < tag_OneBar.ucNum; j++) //打印所有的码元
{
for(k = 0; k < 7; k++) //每个条码有7位
{
if(k%2) //偶数位上用 白线条
{
if((aCodaBar[CodaBarCharToId(tag_OneBar.aBarDat[j])] >> (6 - k))&0x01)
{
//CursorX += 2;
iCurrentFillColumn += 2*tag_OneBar.WideAmp;
}
else
{
//CursorX += 1;
iCurrentFillColumn += 1*tag_OneBar.WideAmp;
}
}
else //奇数位上用 黑线条
{
if((aCodaBar[CodaBarCharToId(tag_OneBar.aBarDat[j])] >> (6 - k))&0x01)
{
BarOut(CODABAR_BLACK_DOUBLE, CODABAR);
}
else
{
BarOut(CODABAR_BLACK_SINGLE, CODABAR);
}
}
}
//CursorX += 1; //字符之间分隔符
iCurrentFillColumn += 1*tag_OneBar.WideAmp;
}
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarUPCA
Description: 打印UPCA条码
Input: void
Output: void
Return:
Others: EAN13与UPCA区别在于:
EAN13必须输入12个字元
UCPA必须输入11个字元
**************************************************************/
void PrintOneBarUPCA(void)
{
unsigned char i,j,k;
//unsigned short usCharCusX;
unsigned char ucChkSum = 0;
if (tag_OneBar.ucNum != 11) //UPCA必须打11个字元,否则错误
{
PrintStr("设置错误!字元个数不为11",1);
return;
}
for (i=0; i<11; i++)
{
if ((tag_OneBar.aBarDat[i] < '0')||(tag_OneBar.aBarDat[i] > '9')) //只能打0~9的数字
{
PrintStr("设置错误!字元不在0~9",1);
return;
}
}
if ((2*EAN_SEG_LEN + EAN_MID_LEN + 12*EAN_LEN)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度",1);
return;
}
for (k=0; k<11; k++) //计算校验码
{
if (k%2)
{
ucChkSum += 1*(tag_OneBar.aBarDat[k]-'0');
}
else
{
ucChkSum += 3*(tag_OneBar.aBarDat[k]-'0');
}
}
ucChkSum = ucChkSum%10;
ucChkSum = (10-ucChkSum)==10 ? 0:(10-ucChkSum);
tag_OneBar.aBarDat[11] = ucChkSum + '0'; //校验码放入数组
// for ( i=0; i<tag_OneBar.ucHigh; i++ )
{
/*if (VOID_PAGE == pPrintQueueIn->Dph)
{
pPrintQueueIn->Mode = PM_NORMAL;
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp;
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp;
pPrintQueueIn->PrintRow = 1;
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow;
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow);
if (VOID_PAGE == pPrintQueueIn->Dph)
{
return;
}
}*/
//CursorX = tag_OneBar.usLeftSpace;
BarOut(EAN_START, EAN13); //开始符
for (j=0; j<6; j++) //前6个数字
{
BarOut((tag_OneBar.aBarDat[j] - '0'), EAN13);
}
BarOut(EAN_MID,EAN13); //中间符
for (j=6; j<11; j++) //后6个数字
{
BarOut(20 + tag_OneBar.aBarDat[j] - '0', EAN13);
}
BarOut(20 + ucChkSum, EAN13); //校验符
BarOut(EAN_END, EAN13); //结束符
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarCode39
Description: 打印39条码
Input: void
Output: void
Return: void
Others: 无
**************************************************************/
void PrintOneBarCode39(void)
{
unsigned char i,j ;
// unsigned short usCharCusX;
//超出纸张的范围告警
if (((tag_OneBar.ucNum + 2)*CODE39_LEN)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度", 1);
return;
}
//不在码元支持的范围内报警
for (i=0; i<tag_OneBar.ucNum; i++)
{
if (ERROR_CHAR == GetCode39Dat(tag_OneBar.aBarDat[i]))
{
PrintStr("设置错误!字元不支持", 1);
return;
}
}
if((2+tag_OneBar.ucNum)*tag_OneBar.WideAmp*12>LINE_DOTS)
{
PrintStr("设置错误!超出宽度", 1); //超过宽度报警
return;
}
//for (i=0;i<tag_OneBar.ucHigh;i++) //条码要打印多高在此设置
{
/*if ( VOID_PAGE == pPrintQueueIn->Dph )
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //此处设置对条码设置无意义
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //条码宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一个点行
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行数
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请需要的行数
if (VOID_PAGE == pPrintQueueIn->Dph)
{
return;
}
} */
//CursorX = tag_OneBar.usLeftSpace; //定义X坐标的初始值
BarOut('*',CODE39); //CODE39码以*开始
for (j=0;j<tag_OneBar.ucNum;j++)
{
BarOut(tag_OneBar.aBarDat[j],CODE39); //真正要打印的 字元信息
}
BarOut('*',CODE39); //CODE39码以*结束
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarCode128
Description: 打印128条码
Input: void
Output: void
Return:
Others: 无
**************************************************************/
void PrintOneBarCode128(void)
{
unsigned char j;
// unsigned short usCharCusX;
int ulChkSumId =0;
unsigned char ucChkDat;
if (((tag_OneBar.ucNum + 2)*CODE128_LEN + CODE128_END_LEN)*tag_OneBar.WideAmp > LINE_DOTS )
{
PrintStr("设置错误!超出宽度",1); //超出纸张的范围告警
return;
}
//for (i=0; i<tag_OneBar.ucHigh; i++) //条码要打印多高在通过tag_OneBar.ucHigh来设置
{
/*if ( VOID_PAGE == pPrintQueueIn->Dph )
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印模式,与条码部分无关系
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //高度系数,与条码部分无关系
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //宽度系数,一条暗条纹或者亮条纹的宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一行即可
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请打印缓存区的行数
if (VOID_PAGE == pPrintQueueIn->Dph)
{
return;
}
}*/
//CursorX = tag_OneBar.usLeftSpace; //重新定义X坐标值
ulChkSumId =0; //校验码清空
if (tag_OneBar.aBarDat[0]<32) //32在ASSII表之前为特殊控制字符,按照CODE128的标准选择A模式才能打印,不过在打印机行业中一般
//要打印实实在在的字符,所以控制字符很少用,一般情况用B模式即可
{
BarOut(CODE128_START_A,CODE128); //A模式起始符
ulChkSumId += GetCode128Id(CODE128_START_A); //把字符累加
}
else
{
BarOut(CODE128_START_B,CODE128); //B模式起始符
ulChkSumId += GetCode128Id(CODE128_START_B); //把字符累加
}
for (j=0;j<tag_OneBar.ucNum;j++) //输出真正要打印的码元信息
{
BarOut(tag_OneBar.aBarDat[j],CODE128);
ulChkSumId += (j+1)*GetCode128Id(tag_OneBar.aBarDat[j]); //检验码的累加
}
ucChkDat = (ulChkSumId%103)<95 ? ((ulChkSumId%103)+32) : ((ulChkSumId%103)+105); //计算出检验码
BarOut(ucChkDat,CODE128); //输出CODE128验证码
BarOut(CODE128_START_STOP,CODE128); //输出CODE128结束符
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarEan8
Description: 打印EAN8条码
Input: void
Output: void
Return:
Others: 无
**************************************************************/
void PrintOneBarEan8(void)
{
unsigned char i,j,k;
// unsigned short usCharCusX;
unsigned char ucChkSum = 0;
if (tag_OneBar.ucNum != 7)
{
PrintStr("设置错误!字元个数不为7",1); //EAN8必须为7个信息码元,校验码由软件自己计算
return;
}
for (i=0; i<7; i++)
{
if ((tag_OneBar.aBarDat[i] < '0')||(tag_OneBar.aBarDat[i] > '9'))
{
PrintStr("设置错误!字元不在0~9",1); //码元只能输入0~9
return;
}
}
if ((2*EAN_SEG_LEN + EAN_MID_LEN + 8*EAN_LEN)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度",1); //超出纸张告警
return;
}
for (k=0; k<7; k++) //计算校验码
{
if (k%2)
{
ucChkSum += 1*(tag_OneBar.aBarDat[k]-'0'); //偶数乘以1,而EAN13是偶数乘以3
}
else
{
ucChkSum += 3*(tag_OneBar.aBarDat[k]-'0'); //奇数乘以3,而EAN13是奇数乘以1
}
}
ucChkSum = ucChkSum%10;
ucChkSum = (10-ucChkSum)==10 ? 0:(10-ucChkSum); //计算出最终的校验码
tag_OneBar.aBarDat[7] = ucChkSum + '0'; //校验码放入数组
// for (i=0; i<tag_OneBar.ucHigh; i++)
{
/*if (VOID_PAGE == pPrintQueueIn->Dph)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印模式,与条码部分无关系
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //高度系数,与条码部分无关系
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //宽度系数,一条暗条纹或者亮条纹的宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一行即可
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow; //总的申请行
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请打印缓存区的行数
if (VOID_PAGE == pPrintQueueIn->Dph)
{
return; //申请不到返回
}
} */
//CursorX = tag_OneBar.usLeftSpace;
BarOut(EAN_START,EAN8); //开始符
for ( j=0;j<4;j++ ) //前4个数字
{
BarOut((tag_OneBar.aBarDat[j]-'0'),EAN8);
}
BarOut(EAN_MID,EAN8); //中间符
for ( j=4;j<7;j++ ) //后面3个数字
{
BarOut(20+tag_OneBar.aBarDat[j]-'0',EAN8);
}
BarOut(20+ucChkSum,EAN8); //校验符
BarOut(EAN_END,EAN8); //结束符
//PrintQueueIn(); //入队,打印
}
}
/*************************************************************
Name: PrintOneBarEan13
Description: 打印EAN13条码
Input: void
Output: void
Return:
Others: 无
**************************************************************/
void PrintOneBarEan13(void)
{
unsigned char i,j,k;
// unsigned short usCharCusX;
unsigned char ucParity;
unsigned char ucChkSum = 0;
if (tag_OneBar.ucNum != 12)
{
PrintStr("设置错误!字元个数不为12",1); // EAN13必须输入12个码元,验证码由程序自动生成
return;
}
for (i=0; i<12; i++)
{
if ((tag_OneBar.aBarDat[i] < '0')||(tag_OneBar.aBarDat[i] > '9'))
{
PrintStr("设置错误!字元不在0~9",1); //码元只能输入0~9
return;
}
}
if ((2*EAN_SEG_LEN + EAN_MID_LEN + 12*EAN_LEN)*tag_OneBar.WideAmp > LINE_DOTS)
{
PrintStr("设置错误!超出宽度",1); //超出纸张告警
return;
}
for (k=0; k<12; k++) //计算EAN13的校验码
{
if (k%2)
{
ucChkSum += 3*(tag_OneBar.aBarDat[k]-'0'); //偶数乘以3,而EAN8是偶数乘以1
}
else
{
ucChkSum += 1*(tag_OneBar.aBarDat[k]-'0'); //奇数乘以1 ,而EAN8是奇数乘以3
}
}
ucChkSum = ucChkSum%10;
ucChkSum = (10-ucChkSum)==10 ? 0:(10-ucChkSum); //最终的校验码
tag_OneBar.aBarDat[12] = ucChkSum + '0'; //校验码放入数组的最后一位
// for (i=0; i<tag_OneBar.ucHigh; i++)
{
/*if (VOID_PAGE == pPrintQueueIn->Dph)
{
pPrintQueueIn->Mode = PM_NORMAL; //正常打印模式,与条码部分无关系
pPrintQueueIn->HihgAmp = tag_OneBar.HighAmp; //高度系数,与条码部分无关系
pPrintQueueIn->WideAmp = tag_OneBar.WideAmp; //宽度系数,一条暗条纹或者亮条纹的宽度在此设置
pPrintQueueIn->PrintRow = 1; //申请一行即可
pPrintQueueIn->AllRow = pPrintQueueIn->PrintRow;
pPrintQueueIn->Dph = MallocPrintBuf(pPrintQueueIn->AllRow); //申请打印缓存区的行数
if (VOID_PAGE == pPrintQueueIn->Dph)
{
return; //申请不到缓存区返回
}
}*/
// CursorX = tag_OneBar.usLeftSpace; //重新定义X坐标值
ucParity = aEanParity[tag_OneBar.aBarDat[0] - '0'];
BarOut(EAN_START, EAN13); //开始符
for (j=1; j<7; j++) //前6个数字
{
k = (ucParity>>(6-j))&0x01;
BarOut((10*k) + (tag_OneBar.aBarDat[j] - '0'), EAN13);
}
BarOut(EAN_MID,EAN13); //中间符
for (j=7; j<12; j++) //后5个数字
{
BarOut(20 + tag_OneBar.aBarDat[j] - '0', EAN13); //这里加个20是为了在 aEan数组中偏移20个字节
}
BarOut(20 + ucChkSum, EAN13); //校验符 ,这里加个20是为了在 aEan数组中偏移20个字节
BarOut(EAN_END, EAN13); //结束符
//PrintQueueIn(); //入队,打印
}
}
/*************************************************
Function: PrintOneBar
Description: 打印一维条码
Input: style - 打印方式
Output: void
Return: void
Others: 无
*************************************************/
/*void PrintOneBar(unsigned char style)
{
switch (style)
{
case UPCA:
PrintOneBarUPCA();
break;
case UPCE:
PrintOneBarUPCE();
break;
case EAN13:
PrintOneBarEan13();
break;
case EAN8:
PrintOneBarEan8();
break;
case CODE39:
PrintOneBarCode39();
break;
case ITF:
PrintOneBarITF();
break;
case CODABAR:
PrintOneBarCodaBar();
break;
case CODE93:
PrintOneBarCode93();
break;
case CODE128:
PrintOneBarCode128();
break;
}
}*/
// BarCode_app.h
/*************************************************
Copyright (C), 2013-2113, XXX. Co., Ltd.
文件名: barcode_app.h
Author: XXX
Version: V1.0
Date: 2013-08-15
Description: 条码的相关处理头文件
History:
<author> <time> <version > <desc>
XXX 13/8/15 1.0 build this moudle
*************************************************/
#ifndef __BARCODE__APP__
#define __BARCODE__APP__
#define SUCSS_BAR1 0
#define ERROR_CHAR 1
#define ERROR_LEN 2
#define ERROR_NOT_12 3
#define CODE93_INPUT_ERROR 49 //code93码输入不合法
#define CODABAR_INPUT_ERROR 20 //code93码输入不合法
#define HRI_NO 0 //HRI在条码位置-无HRI
#define HRI_UP 1 //HRI在条码位置-上
#define HRI_DN 2 //HRI在条码位置-下
#define HRI_UP_DN 3 //HRI在条码位置-上下
#define CODE39_LEN 12 //code39条码的长度
#define CODE_GAP 1 //字符条码的宽度
#define CODE93_LEN 9 //code93条码的长度
#define CODE93_LASTLEN 1 //code93最后一位附加一个1
#define CODABAR_THIN_LEN 1 //codabar 细条宽度为1
#define CODABAR_THICK_LEN 2 //codabar 宽条宽度为2
#define CODABAR_BLACK_SINGLE 0 //codabar 黑色线条细
#define CODABAR_BLACK_DOUBLE 1 //codabar 黑色线条粗
#define UPCE_LEN 7 //UPCE条码的长度
#define UPCE_START_LEN 3 //UPCE开始条码长度
#define UPCE_END_LEN 6 //UPCE结束条码长度
#define CODE128_LEN 11 //CODE128条码长度
#define CODE128_END_LEN 13 //CODE128码的结束符长度
#define ITF_BLACK_WITDH 0 //codabar 黑色线条细
#define ITF_BLACK_NARROW 1 //codabar 黑色线条粗
#define ITF_WIDTH_LEN 2
#define ITF_NARROW_LEN 1
#define EAN_LEN 7 //EAN13条码长度
#define EAN_SEG_LEN 3 //EAN13开始及结束条码长度
#define EAN_MID_LEN 5 //EAN13中间条码长度
#define UPCA 0x41
#define UPCE 0x42
#define EAN13 0x43
#define EAN8 0x44
#define CODE39 0x45
#define ITF 0x46
#define CODABAR 0x47
#define CODE93 0x48
#define CODE128 0x49
#define CODE128_START_A 208
#define CODE128_START_B 209
#define CODE128_START_C 210
#define CODE128_START_STOP 211
#define EAN_START 30
#define EAN_MID 31
#define EAN_END 32
#define CODE93_START_END 47
#define CODE93_LASTONEDOT 48
#define ITF_START 10
#define ITF_END 11
#define UPCE_START 20
#define UPCE_END 21
unsigned int GetCode39Dat(unsigned char Dat);
unsigned int GetCode128Dat(unsigned char Dat);
unsigned int GetEanDat(unsigned char Dat);
//unsigned int GetEan8Dat(unsigned char Dat);
extern void PrintOneBarCode39(void);
extern void PrintOneBarCode128(void);
extern void PrintOneBarEan8(void);
extern void PrintOneBarEan13(void);
extern void PrintOneBarUPCA(void);
extern void PrintOneBarUPCE(void);
extern void PrintOneBarITF(void);
extern void PrintOneBarCodaBar(void);
extern void PrintOneBarCode93(void);
#ifdef SIZE_3 //濡傛灉瀹氫箟浜?瀵?
#define LINE_DOTS 640 // 3瀵哥殑鐐规暟
#else
#define LINE_DOTS 384 // 打印头点数
#endif
#endif
// BaseTimeEvent.c
空文件
// BaseTimeEvent.h
空文件
// BatDet.c
#include "board_config.h"
#include "yc_timer.h"
#include "PrtBuf.h"
#include "Interface.h"
#include "CmdSet.h"
#include "RcvBuf.h"
#include "yc3121.h"
#include "PrtHead.h"
// CmdSet.c
/***************************************************************************************************
* File :CmdSet.c
* Date :12, 18, 2010
* Description :ESC/POS command set program
* Designer :*****************
****************************************************************************************************/
#include "type.h"
#include "RcvBuf.h"
#include "PrtBuf.h"
#include "Interface.h"
#include "PrtHead.h"
#include "string.h"
#include "BarCode.h"
#include "yc_timer.h"
#include "yc_wdt.h"
#include "yc_qspi.h"
#include "yc_bt.h"
#include "board_config.h"
#include "CmdSet.h"
#include "PrtBuf.h"
#include "BT_BLE.h"
#include "Sensor.h"
#include "LcdMenu.h"
#include "api_font_img.h"
volatile unsigned char SetTphDensitycounter=0;
unsigned char bBTPrintingFlag = 0; //蓝牙打印标志
unsigned char bIOSPrintingClearFlag = 0; //苹果清屏标志
unsigned char bHaveDrivePrintFlag = 0; //有驱打印标志
unsigned char bOpenCashAfterPrt = 0;
unsigned char cChasNums = 0;
unsigned int iOpenCashTimer = 0;
unsigned int iCloseCashTimer = 0;
unsigned int ionedotlineFlag = 0; //每一点行标记
extern uint16_t ble_send_handle;
extern uint16_t spp_send_handle;
void DLE_ACK_soft_version(void);
//------------------------------------------------------
void save_databuffer_2(void) //针对有驱
{
unsigned int buffer=0;
//打印数据缓存
EXT_DEV.dlabel_save_counter=20;
if(Rcv_Port == RCV_TYPE_USB)
{
while(EXT_DEV.dlabel_save_counter) //缓冲数据
{
IWDG_Reload;
usb_main();
// KEY_Main();
}
}
}
/****************************************************************************************************
ASCII----ETB nL nH sL sH fw m L1L2D1D2D3D4
nL、nH:表示本次打印标签的实际内容的总长度为nL+nH*256个点
sL、sH:表示本次打印标签纵向的起始偏移量长度为sL+sH*256个点
fw:表示标签纸的实际宽度为fw毫米
m:表示打印设备是android还是iOS,m=0表示android,m=1表示iOS
L1:表示本次打印标签的总份数
L2:表示当前打印标签为第几张,从1开始计数
D1D2D3D4:表示本次标签的总字节数据,低位在前高位在后
nl nh sl sh fw m L1 L2 D1 D2 D3 D4
17 80 02 00 00 32 01 01 01 3F 0C 00 00
标签实际内容总长nl nh:0x0280 --640点
标签纵向偏移sl,sh:0x0000
标签实际宽度:0x32---40mm
m:0x01,IOS
L1:1总份数1
L2:1当前第1张
总字节数:0x000C3F01---数据的总字节数不包含17指令及其参数。
*****************************************************************************************************/
uint16_t paper_size_fw;
uint8_t pape_current;
uint8_t page_tatal;
uint8_t os_type;
void ETBCmd(void){
uint8_t temp_array[4];
uint32_t data_byte_tatal;
// bPrt_Statu_flag = 1; //打印状态标志
// MyPrintf("ETBCmd_0 \n");
temp_array[0] = GetDataFromRcvBuf();
temp_array[1] = GetDataFromRcvBuf();
PAPER.print_size = (uint16_t)(temp_array[1]<<8|temp_array[0]); //打印每份内容总长度(纵向的实际内容长度)
// MyPrintf("PAPER.print_size=%d \n",PAPER.print_size); //打印50*30的黑块 PAPER.print_size=240 打印非黑块时PAPER.print_size=232 8dot=1mm
temp_array[0] = GetDataFromRcvBuf();
temp_array[1] = GetDataFromRcvBuf();
PAPER.offest_fh = (uint16_t)(temp_array[1]<<8|temp_array[0]); //纵向偏移
// MyPrintf("PAPER.offest_fh=%d \n",PAPER.offest_fh);
paper_size_fw = GetDataFromRcvBuf(); //打印宽度
if(paper_size_fw > (MaxDotPos>>3)){
paper_size_fw = (MaxDotPos>>3);
}
// MyPrintf("paper_size_fw=%d \n",paper_size_fw);
os_type = GetDataFromRcvBuf(); //上位机操作系统类型
page_tatal = GetDataFromRcvBuf(); //上位机下发打印的总份数
// MyPrintf("page_tatal=%d \n",page_tatal);
pape_current = GetDataFromRcvBuf(); //当前打印的是第几张
temp_array[0] = GetDataFromRcvBuf();
temp_array[1] = GetDataFromRcvBuf();
temp_array[2] = GetDataFromRcvBuf();
temp_array[3] = GetDataFromRcvBuf();
data_byte_tatal = temp_array[3];
data_byte_tatal <<= 8;
data_byte_tatal |= temp_array[2];
data_byte_tatal <<= 8;
data_byte_tatal |= temp_array[1];
data_byte_tatal <<= 8;
data_byte_tatal |= temp_array[0]; //data_byte_tatal保存每份总字节数据
// MyPrintf("data_byte_tatal= %d \n",data_byte_tatal);
if(bHaveDrivePrintFlag==1) {
// MyPrintf("ETBCmd_1 \n");
save_databuffer_2(); //有驱执行
}
else
{
// MyPrintf("ETBCmd_2 \n");
//_ save_databuffer(data_byte_tatal); //缓冲数据 这里屏蔽之后目前没影响打印
}
//MyPrintf("RemainSize= %d \n",RemainSize);
//MyPrintf("bRcvBufFull= %d \n",bRcvBufFull);
SetMotorSpeedTime(); //设置电机速度
SetTphDensitySetTime(); //设置浓度
// MyPrintf("pape_current=%d \n",pape_current);
//------------------------------------------------
if(PAPER.type == E_PAPER_TYPE_CONTINUE) return;
//打印的回退距离
if(pape_current == 1)
{
MOTOR.iLFStepNum = 0;
PAPER.paper_start_offset = 0;
if((DIS_TPH_TO_CUT/one_dotline_lfstep_num) > PAPER.offest_fh) //DIS_TPH_TO_CUT(138)/one_dotline_lfstep_num (4) PAPER.offest_fh纵向偏移为0 无驱打印间隙纸第一张进入
{
// MyPrintf("ETBCmd_3 \n");
MOTOR.bLFForward = 0;
StartKeyFeedPaper((DIS_TPH_TO_CUT/one_dotline_lfstep_num) - PAPER.offest_fh,LFacc5); //走切纸位回退到打印位的距离 //offest_fh:打印内容纵向偏移量
WaitMotorStop();
//_ delay_ms(100); //
}
else if((DIS_TPH_TO_CUT/one_dotline_lfstep_num) < PAPER.offest_fh)
{
// MyPrintf("ETBCmd_4 \n");
MOTOR.bLFForward = 1;
StartKeyFeedPaper(PAPER.offest_fh - (DIS_TPH_TO_CUT/one_dotline_lfstep_num),LFconst);
WaitMotorStop();
}
}
else
{
// MyPrintf("ETBCmd_5 \n");
MOTOR.bLFForward = 1;
StartKeyFeedPaper(PAPER.offest_fh,LFconst); //LFconst =31
WaitMotorStop();
}
}
//----------------------------------------------------------------------
void save_databuffer(unsigned int data_len)
{
unsigned int buffer=0;
//打印数据缓存
if(Rcv_Port == RCV_TYPE_SPP )
{
buffer=data_len*0.3;
}
else if(Rcv_Port == RCV_TYPE_BLE)
{
buffer=data_len*0.5;
}
else if(Rcv_Port == RCV_TYPE_USB)
{
buffer=data_len;
}
//打印数据的 缓存
if(Rcv_Port == RCV_TYPE_SPP||Rcv_Port == RCV_TYPE_BLE )
{
while(RemainSize>(RcvBufSize-buffer)) //缓冲数据
{
IWDG_Reload;
BT_Progress();
//_ KEY_Main();
}
// MyPrintf("save_ok_1\r\n");
}
else if(Rcv_Port == RCV_TYPE_USB)
{
while(RemainSize>(RcvBufSize-buffer)) //缓冲数据 RemainSize在FillRcvBuf()中--, 有驱打印第二张时RemainSize=8909
{
// MyPrintf("RemainSize=%d\r\n",RemainSize);
// MyPrintf("buffer=%d\r\n",buffer);
IWDG_Reload;
usb_main();
//_ KEY_Main();
// MyPrintf("save_ok_2 \r\n");
}
}
}
/*****************************************************
ASCII CAN n1 d1…dn n2 d………NULL 0x18指令
n1:表示不同图形数据的个数
n2:表示相同图形数据的个数
d1 d2…dn:不同图形数据,按横向一点行方式排列,每个字节左边为高位,右边为低位。
d: 相同图形数据,按横向一点行方式排列,每个字节左边为高位,右边为低位。
NULL: 表示结束符,打印机收到NULL后将立即打印当前行。
*****************************************************/
void CANCmd(void){
uint8_t data_head;
uint8_t same_data;
uint8_t different_data;
uint16_t i;
uint8_t *p1;
unsigned char cNextLine;
unsigned char cTempStep;
unsigned char cTempStatus;
// unsigned char one_print_line_h = 0;
// if(one_dotline_lfstep_num_change_flage==0)
// {
// one_dotline_lfstep_num_change_flage=1;
//
// // MyPrintf("!11_ \n");
// }
// else
// {
// one_dotline_lfstep_num_change_flage=0;
// // MyPrintf("!22_ \n");
// }
//one_dotline_lfstep_num=ONEDOTSTEPNUM-1;
// one_dotline_lfstep_num=ONEDOTSTEPNUM;
ionedotlineFlag++;
one_dotline_lfstep_num=ONEDOTSTEPNUM;
// have print data
cNextLine = cCurrentFillRow + 1;
if(cNextLine == NumOfCharLine)
{
// MyPrintf("!33_ \n");
cNextLine = 0;
}
else
{
// MyPrintf("!44_ \n");
;
}
// fill the line attribute
PrtBuf[cCurrentFillRow].cNextCharLine = cNextLine;
PrtBuf[cCurrentFillRow].iCurrentPrtDot = 1;
PrtBuf[cCurrentFillRow].bPrtRleBmp = 1;//中断中取数据不同寻常
PrtBuf[cCurrentFillRow].iPrtStep = one_dotline_lfstep_num;
memset((u8 *)&PrtBuf[cCurrentFillRow].ByteLine[0],0,MaxDotPos>>3);
if(bAlign == Align_Left) //每一点行都会执行
{
// MyPrintf("!55_ \n");
iCurrentFillColumn = (MaxDotPos - (paper_size_fw<<3));
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn>>3];
}
else if(bAlign == Align_Right) //app下发打印任务之后不执行
{
// MyPrintf("!66_ \n");
iCurrentFillColumn = 0;
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[0];
}
else //app下发打印任务之后不执行
{
// MyPrintf("!77_ \n");
iCurrentFillColumn = (MaxDotPos - (paper_size_fw<<3))>>1;
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn>>3];
}
do
{
data_head = GetDataFromRcvBuf();
if(data_head == 0)//null 结束符号
{
// CloseAllInt;
if(PrtBuf[cCurrentPrtCharLine].Status == Empty) //每一点行结束之后很少执行这里边的代码
// if((PrtBuf[cCurrentPrtCharLine].Status == Empty)&&(PrtBuf[cCurrentPrtCharLine].Status != Printing))
{
// MyPrintf("!88_ \n");
// OpenAllInt;
cCurrentPrtCharLine = cCurrentFillRow;
MOTOR.iLFStepNum = (PrtBuf[cCurrentPrtCharLine].iPrtStep);
StartLFMotor(); //屏蔽了的话走纸卡顿且打印空白
bTimer2Prt = 1;
}
else
{
// MyPrintf("!aa_ \n");
// printing is continued don't need restart
PrtBuf[cCurrentFillRow].Status = WaitForPrint;
cTempStep = cCurrentPrtCharLine;
// OpenAllInt;
do
{
// CloseAllInt;
cTempStatus = PrtBuf[cTempStep].Status;
BT_Progress();
//_ usb_main();
// OpenAllInt;
}while(cTempStatus != Empty);
}
cCurrentFillRow = cNextLine;
iCurrentFillColumn = 0;
return;
}
if(data_head&0x80)
{
// MyPrintf("!99_ \n");
same_data = GetDataFromRcvBuf(); //这个是相同的数据
// MyPrintf("data_head=%2x\n",data_head);
for(i=0;i<(data_head&0x7F);i++)
{
// same_data = GetDataFromRcvBuf(); //这个是相同的数据
// f_lable_printing = 1;
if(iCurrentFillColumn <(MaxDotPos - 8))
{
*p1 = same_data;
p1++;
iCurrentFillColumn += 8;
}
else if(iCurrentFillColumn ==(MaxDotPos - 8))
{
*p1 = same_data;
}
}
}
else
{
for(i=0;i<(data_head&0x7F);i++)
{
// MyPrintf("!00_ \n");
different_data = GetDataFromRcvBuf(); //这个不是相同数据
if(iCurrentFillColumn <(MaxDotPos - 8))
{
// f_lable_printing = 1;
*p1 = different_data;
p1++;
iCurrentFillColumn += 8;
}
else if(iCurrentFillColumn ==(MaxDotPos - 8))
{
*p1 = different_data;
}
}
}
}while(1);
}
//-------------------------------------------------
void SYNCmd(void)
{
uint8_t data_head;
uint8_t same_data;
uint16_t i;
uint8_t *p1;
unsigned char cNextLine;
unsigned char cTempStep;
unsigned char cTempStatus;
// unsigned char one_print_line_h = 0;
// MyPrintf("!4_ \n");
// have print data
ionedotlineFlag++;
cNextLine = cCurrentFillRow + 1; //填充行
if(cNextLine == NumOfCharLine) //字符行数 NumOfCharLine =2
{
cNextLine = 0;
}
else
{
;
}
// fill the line attribute
//one_dotline_lfstep_num=ONEDOTSTEPNUM-1;
one_dotline_lfstep_num=ONEDOTSTEPNUM;
PrtBuf[cCurrentFillRow].cNextCharLine = cNextLine;
PrtBuf[cCurrentFillRow].iPrtStep = one_dotline_lfstep_num;
PrtBuf[cCurrentFillRow].iCurrentPrtDot = 1;
PrtBuf[cCurrentFillRow].bPrtRleBmp = 1; //中断中取数据不同寻常
memset((u8*)&PrtBuf[cCurrentFillRow].ByteLine[0],0,MaxDotPos>>3); //MaxDotPos>>3 换算成字节
if(bAlign == Align_Left) //
{
iCurrentFillColumn = (MaxDotPos - (paper_size_fw<<3)); //当前填充位置计数 paper_size_fw:在0x17指令中设置
// MyPrintf("iCurrentFillColumn=%d \n",iCurrentFillColumn); //无驱打印时 iCurrentFillColumn=0(打印50*30间隙纸)
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn>>3];
}
else if(bAlign == Align_Right)
{
iCurrentFillColumn = 0;
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[0];
}
else
{
iCurrentFillColumn = (MaxDotPos - (paper_size_fw<<3))>>1;
p1= (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn>>3];
}
data_head = GetDataFromRcvBuf(); //打印50*30的间隙纸时打印出来:data_head=50 (可能是一字符行的字节数)
// MyPrintf("data_head=%d \n",data_head); // 打印50*30的间隙纸(打印黑块和其它内容一样) data_head=48
if(data_head&0x80) //bit7=1,表示后面的数据为相同数据
{
same_data = GetDataFromRcvBuf();
// MyPrintf("same_data=%d \n",same_data); //打印的时候不进入这里
for(i=0;i<(data_head&0x7F);i++){
if(iCurrentFillColumn <(MaxDotPos - 8)){
*p1 = same_data;
p1++;
iCurrentFillColumn += 8;
}
else if(iCurrentFillColumn ==(MaxDotPos - 8))
{
*p1 = same_data;
}
}
}
else
{
for(i=0;i<data_head;i++)
{
same_data = GetDataFromRcvBuf(); //打印黑块时:same_data一直等于255
//
if(iCurrentFillColumn <(MaxDotPos - 8)) //打印时 iCurrentFillColumn的值从0开始,8位8位的递增,直到368,收到16指令又开始从0递增
{
//
*p1 = same_data;
p1++;
iCurrentFillColumn += 8;
}
else if(iCurrentFillColumn ==(MaxDotPos - 8))
{
*p1 = same_data;
}
}
}
// MyPrintf("Status=%d \n",PrtBuf[cCurrentPrtCharLine].Status); //第一次执行16指令时进来(Status=0),后边就是3和2
if(PrtBuf[cCurrentPrtCharLine].Status == Empty) //字符行状态为空
{
cCurrentPrtCharLine = cCurrentFillRow;
// MyPrintf("cCurrentPrtCharLine_=%d \n",cCurrentPrtCharLine); //第一个16指令会进来,
MOTOR.iLFStepNum = (PrtBuf[cCurrentPrtCharLine].iPrtStep);
//_ MyPrintf("iLFStepNum_=%d \n",MOTOR.iLFStepNum); //iLFStepNum_ =4
StartLFMotor();
bTimer2Prt = 1;
}
else
{
// printing is continued don't need restart
PrtBuf[cCurrentFillRow].Status = WaitForPrint;
cTempStep = cCurrentPrtCharLine;
// MyPrintf("cTempStep_=%d \n",cTempStep);
// MyPrintf("cCurrentPrtCharLine=%d \n",cCurrentPrtCharLine); cCurrentPrtCharLine只等于0或者1
do
{
cTempStatus = PrtBuf[cTempStep].Status; //cTempStatus开始几次的16指令都不固定,后边都是执行12次cTempStatus=3+1次cTempStatus=0跳出
//_ BT_Progress();
//_ usb_main();
}while(cTempStatus != Empty);
//#if(pr_debug)
//MyPrintf("!4 \n");
test_3(1);
//#endif
}
cCurrentFillRow = cNextLine;
iCurrentFillColumn = 0;
return;
}
/******************************************************
[名称] 空走纸N点行
[格式] ASCII NAK n
********************************************************/
void NAKCmd(void){
uint8_t feed_step;
MOTOR.bLFForward = 1;
feed_step = GetDataFromRcvBuf();
// CloseAllInt;
// state have not changed
if(MOTOR.iLFStepNum < LashStop_Nums + 1)//(const hlod stop) #define LashStop_Nums 2 //hole rush 惯性
{
// OpenAllInt;
FeedPaper(feed_step*one_dotline_lfstep_num);
//StartKeyFeedPaper(feed_step*one_dotline_lfstep_num,LFconst);
WaitMotorStop();
}
else
{
// OpenAllInt;
//MyPrintf("B2:%u\r\n", feed_step);
// in the period of acceleration of constant speed
CountinueLineFeed(feed_step*one_dotline_lfstep_num); //one_dotline_lfstep_num 打印一点行所需要的步数
}
}
//-----------------------------------------------------执行指令---------------------
void ExecuteCmd(unsigned char data)//
{
// unsigned char data_buff[20];
// unsigned char dsp_start_x;
// dsp_start_x = (128-120)>>1;
MyPrintf("com=0x%02x \n",data);
switch(data)
{
case HT:
HTCmd();//定位
break;
case LF: //0X0a 自测打印
LFCmd();//打印并走纸
break;
case CR: //
CRCmd();//打印并走纸
break;
case DLE://0x10 安卓打印完进来
// MyPrintf("----------------DLE=0X10------------------");
WaitMotorStop();
DLECmd(); //从接收缓冲取一个字节并查询打印状态 把打印状态上传给上层
break;
case ESC: //0x1b
ESCCommand(GetDataFromRcvBuf());//ESC指令
break;
case FS: //0x1c
FSCommand(GetDataFromRcvBuf());//FS指令
break;
case GS: //0x1d
f_print_canncel = 0;
// MyPrintf("GS_\n");
GSCommand(GetDataFromRcvBuf());//GS指令 //设置纸张类型
break;
case US:
USCommand(GetDataFromRcvBuf());//自用调试指令
break;
case NAK: //0x15 空走纸n点行
NAKCmd();
break;
case ETB: //0x17设置要打印的标签的参数
f_lable_printing = 1;
f_lable_print_end = 0;
PAPER.paper_start_offset_flag = 0;
//pt20 规定 连上蓝牙就定时10分钟,超过就关机.
//_ poweroff_set();
ESC_ATInit(); //不能屏蔽,屏蔽之后出现在打印自检之后,APP或USB打印会乱码
ETBCmd();
break;
case CAN: //0x18
f_lable_printing = 1;
CANCmd();
SetTphDensitycounter=0;
break;
case SYN: //0X16 打印一点行图形数据
// MyPrintf("11111111111111111111111111111111111111111111111111111\n");
f_lable_printing = 1;
f_lable_print_end = 0;
// test_3(0);
SYNCmd();
SetTphDensitycounter=0;
break;
case FF: //0C
ionedotlineFlag = 0;
// f_lable_print_end = 0;
// MyPrintf("run11111 \n");
if(PAPER.type == E_PAPER_TYPE_CONTINUE) //连续纸
{
MOTOR.bLFForward = 1;
if(page_tatal == pape_current) //当前打印的页数=要打印的总页数
{
// PAPER.move_to_cut_flag =1;
// Paper_Use_Up_Flag =0;
// MyPrintf("run 156 \n");
StartKeyFeedPaper(156,LFconst);
}
else
{
PAPER.move_to_cut_flag =1;
Paper_Use_Up_Flag =0;
StartKeyFeedPaper(28,LFconst);
// MyPrintf("run_28 \n");
}
}
else
{
if(page_tatal == pape_current) //最后一张
{
if(PAPER.type == E_PAPER_TYPE_HOLD) //定位孔纸
{
// MyPrintf("run_a \n");
Paper_Use_Up_Flag =0;
// PAPER.move_to_cut_flag =1;
GS_MoveToCut(4); //原来是GS_MoveToCut(1);
}
else
{
//MyPrintf("PAPER.paper_start_offset = %d \n",PAPER.paper_start_offset);
//MyPrintf("PAPER.paper_start_offset_flag = %d \n",PAPER.paper_start_offset_flag);
//if(PAPER.paper_start_offset_flag && (DIS_GAP_TO_TPH+DIS_TPH_TO_CUT)>(PAPER.paper_start_offset))
if(PAPER.paper_start_offset_flag && (DIS_GAP_TO_TPH+DIS_TPH_TO_CUT)>(PAPER.paper_start_offset+off_seta/2)) //这个是计算到间隙的一个算法 //pc端单张打印会进来
{
// MyPrintf("run_29 \n");
MOTOR.bLFForward = 1;
// PAPER.move_to_cut_flag =1;
Paper_Use_Up_Flag =0;
//StartKeyFeedPaper((DIS_GAP_TO_TPH+DIS_TPH_TO_CUT-PAPER.paper_start_offset)/one_dotline_lfstep_num,LFconst);
StartKeyFeedPaper((DIS_GAP_TO_TPH+DIS_TPH_TO_CUT-PAPER.paper_start_offset-off_seta/2)/one_dotline_lfstep_num,LFconst);
PAPER.paper_start_offset = 0;
}
else //不在裁纸位去打印一张纸时会进来 蓝牙打印单张间隙纸进来
{
// MyPrintf("run_30 \n");
Paper_Use_Up_Flag =0;
// PAPER.move_to_cut_flag =1;
GS_MoveToCut(2); //原来是GS_MoveToCut(1);
}
}
}
else
{
if(PAPER.type == E_PAPER_TYPE_HOLD) //定位孔纸
{
// MyPrintf("run_b \n");
Paper_Use_Up_Flag =0;
// PAPER.move_to_cut_flag =1;
GS_MoveToCut(4); //原来是GS_MoveToCut(1);
}
else
{
//if(PAPER.paper_start_offset_flag && (DIS_GAP_TO_TPH)>PAPER.paper_start_offset)
// MyPrintf("paper_start_offset_flag= %d \n",PAPER.paper_start_offset_flag);
if(PAPER.paper_start_offset_flag && (DIS_GAP_TO_TPH)>PAPER.paper_start_offset+off_setb/2) //安卓打印多张时第2张进来,有时第一张就进来
{
// MyPrintf("run_31 \n");
MOTOR.bLFForward = 1;
// PAPER.move_to_cut_flag =1;
Paper_Use_Up_Flag =0;
//StartKeyFeedPaper((DIS_GAP_TO_TPH-PAPER.paper_start_offset)/one_dotline_lfstep_num,LFconst);
// MyPrintf("one_dotline_lfstep_num = %d \n",one_dotline_lfstep_num); 打印多张间隙纸进来
StartKeyFeedPaper((DIS_GAP_TO_TPH-PAPER.paper_start_offset-off_setb/2)/one_dotline_lfstep_num,LFconst);
PAPER.paper_start_offset = 0;
}
else //安卓打印多张时第一张进来
{
// MyPrintf("run_33 \n");
// PAPER.move_to_cut_flag =1;
GS_MoveToCut(0);
}
}
}
}
// MyPrintf("run_34 \n");
// if(Rcv_Port == RCV_TYPE_BLE/*&&page_tatal == pape_current*/) //IOS通信且打印到最后一张
{
// if(PAPER.move_to_cut_flag ==1)
{ bIOSPrintingClearFlag = 1;
f_lable_printing = 0;
bBTPrintingFlag = 0;
// MyPrintf("run_37 \n");
}
}
break;
default:
break;
}
}
//--------------------------------------------------------------------------
void Updata_finish_information_in_ble(unsigned char data)
{
unsigned char data_buff[12]=0;
data_buff[0]=(ble_send_handle&0xff);
data_buff[1]=((ble_send_handle>>8)&0xff);
data_buff[2]=data;
//data_buff[3]=0x28;
//data_buff[4]=0x48;
//data_buff[5]=num;
//data_buff[6]= 0x00;
//data_buff[7]= 0x46;
//data_buff[8]=0x30;
//data_buff[9]=0x00;
//data_buff[10]=0x00;
PrinterRespond(data_buff,3);
}
void HTCmd(void)
{
unsigned short byts_s=iCurrentFillColumn/8;
unsigned char temp_ji;
byts_s=iCurrentFillColumn/12;
if(iCurrentFillColumn%12)
{
byts_s++;
}
for(temp_ji=0;temp_ji<16;temp_ji++)
{
if(HT_TAB[temp_ji]>byts_s)
{
iCurrentFillColumn=(HT_TAB[temp_ji])*12;
break;
}
if(HT_TAB[temp_ji]==0)
{
break;
}
}
if(iCurrentFillColumn>MaxDotPos)
{
iCurrentFillColumn=MaxDotPos;
}
//;
}
//***********************************************
//* CR --- 0x0d
//*Only Print
//***********************************************
void CRCmd(void)
{
;
}
//***********************************************
//* LF --- 0x0a
//* Print and line feed
//***********************************************
void LFCmd(void)
{
StartupPrint(1);
// MyPrintf("!333");
}
//-------------------------------------------------------------------------打印机状态查询指令
void DLE_ACK(void){
unsigned char bleData[4]={ble_send_handle&0xff,ble_send_handle>>8,0x09};
unsigned char sppData[4]={spp_send_handle&0xff,spp_send_handle>>8,0x09};
unsigned char usbData[4]={0x00,0x00 ,0x09}; //USB 不需要头暂时这么写
unsigned char temp_data = GetDataFromRcvBuf();//收到询问状态指令
// MyPrintf("temp_data=0x%02X\n",temp_data);
if(temp_data == 0x01) //传输打印状态
{
bleData[2] = transfer_state.byte;
sppData[2] = transfer_state.byte;
usbData[2] = transfer_state.byte;
// MyPrintf("transfer_state=0x%02X\n",transfer_state.byte);//0x19
}
else if(temp_data == 0x02)//错误状态
{
bleData[2] = error_state.byte[0];
bleData[3] = error_state.byte[1];
sppData[2] = error_state.byte[0];
sppData[3] = error_state.byte[1];
usbData[2] = error_state.byte[0];
usbData[3] = error_state.byte[1];
LCD.time_event6_50ms = 5;
MyPrintf("error_state.field.B2=0x%02X\n",error_state.field.B2);//error_state=0x00
MyPrintf("error_state0=0x%02X\n",error_state.byte[0]);//error_state1=0x01
MyPrintf("error_state1=0x%02X\n",error_state.byte[1]);//error_state1=0x08
}
/*************************向通讯端发送数据******************************/
if(temp_data == 0x01)
{
if(Rcv_Port == RCV_TYPE_SPP)// 蓝牙写出数据
{
BT_SendSppData(&sppData[2],1);
bBTPrintingFlag = 1;
// MyPrintf("sppData[2]=0x%02X\n ",sppData[2]);
}
else if(Rcv_Port == RCV_TYPE_BLE)// 低功耗蓝牙写出数据 (苹果IOS)
{
BT_SendBleData(bleData,3);
bBTPrintingFlag = 1;
// MyPrintf("bleData[2]=0x%02X\n ",bleData[2]);
}
else if(Rcv_Port == RCV_TYPE_USB)// usb写出数据 PC端发送打印时进入
{
usb1_respond(&usbData[2],1);
// MyPrintf("usbData[2]=0x%02X\n ",usbData[2]);
}
}
if(temp_data == 0x02)
{
if(Rcv_Port == RCV_TYPE_SPP)
{
BT_SendSppData(&sppData[2],2);
// MyPrintf("sppData[2]=0x%02X\n ",sppData[2]);
}
else if(Rcv_Port == RCV_TYPE_BLE)
{
BT_SendBleData(bleData,4);
// MyPrintf("bleData[2]=0x%02X\n ",bleData[2]);
}
else if(Rcv_Port == RCV_TYPE_USB)
{
usb1_respond(&usbData[2],2);
// MyPrintf("usbData[2]=0x%02X\n ",usbData[2]);
}
}
}
//***********************************************
//* DLE--- 0x10 04/05
//* 查询上位机发的指令 PollingExtDev PollingExtDev_1
//***********************************************
void DLECmd(void)
{
switch(GetDataFromRcvBuf())
{
case EOT:
case ENQ:
GetDataFromRcvBuf();
break;
case ACK://私加协议,
// MyPrintf("----------------ACK=0X06------------------\r\n");
f_lable_printing = 0;
// f_lable_print_end = 1;
DLE_ACK();
break;
default:
break;
}
// LCD_Clear();
// LCD_Main();
// PAPER.printing_process_flag =0 ;
}
//***********************************************
//***********************************************
//* ESC SP n
//* Set right-side character spacing
//* 0<=n<=255
void ESC_SP(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
cAsciiRightSpace = cTemp;
}
//***********************************************
//***********************************************
//* ESC J n
//* Print and feed paper
//* 0<=n<=255
void ESC_J(void)
{
unsigned char cTemp;
unsigned char cTempStep;
cTemp = iLineSpaceNumber;
cTempStep = GetDataFromRcvBuf();
if(iCurrentFillColumn)
{
if(cTempStep < PRTLINEHIGHT)
{
iLineSpaceNumber = 0;
}
else
{
iLineSpaceNumber = cTempStep - PRTLINEHIGHT;
}
// MyPrintf("!555");
StartupPrint(1);
}
else
{
CloseAllInt;
// state have not changed
if(MOTOR.iLFStepNum < LashStop_Nums + 1)//(const hlod stop)
{
OpenAllInt;
FeedPaper(cTempStep*one_dotline_lfstep_num);
}
else
{
OpenAllInt;
// in the period of acceleration of constant speed
CountinueLineFeed(cTempStep*one_dotline_lfstep_num);
}
}
iLineSpaceNumber = cTemp;
}
//***********************************************
//***********************************************
//* ESC 3 n
//* Set line spacing
//* 0<=n<=255
void ESC_3(void)
{
unsigned char cTempStep;
cTempStep = GetDataFromRcvBuf();
if(cTempStep < PRTLINEHIGHT)
{
iLineSpaceNumber = 0;
}
else
{
iLineSpaceNumber = cTempStep -PRTLINEHIGHT;
}
}
//***********************************************
//***********************************************
//* ESC M
//* Select Font
void ESC_M(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
switch(cTemp)
{
case 0:
case 48:
bFont12x24 = 1;
break;
case 1:
case 49:
bFont12x24 = 0;
break;
default:
break;
}
}
//***********************************************
//***********************************************
//* ESC R n
//* Select an international character set
//* 0<=n<=10
void ESC_R(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
switch(cTemp)
{
case 0:
cInternationalCharSet = USA;
break;
case 1:
cInternationalCharSet = France;
break;
case 2:
cInternationalCharSet = Germany;
break;
case 3:
cInternationalCharSet = UK;
break;
case 4:
cInternationalCharSet = DenmarkI;
break;
case 5:
cInternationalCharSet = Sweden;
break;
case 6:
cInternationalCharSet = Italy;
break;
case 7:
cInternationalCharSet = SpainI;
break;
case 8:
cInternationalCharSet = Japan;
break;
case 9:
cInternationalCharSet = Norway;
break;
case 10:
cInternationalCharSet = DenmarkII;
break;
case 11:
cInternationalCharSet = SpainII;
break;
case 12:
cInternationalCharSet = Latin;
break;
case 13:
//cInternationalCharSet = Korea;
break;
case 14:
//cInternationalCharSet = Croatia;
break;
case 15:
//cInternationalCharSet = China;
break;
default:
break;
}
}
//***********************************************
//***********************************************
//* ESC 2
//* Select default line spacing
void ESC_2(void)
{
iLineSpaceNumber = LINE_SPACE;
}
//***********************************************
//***********************************************
//* ESC c
//* print KEY Enable or Disable
void ESC_c(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if(cTemp == 0x35)
{
switch(GetDataFromRcvBuf()&LSB)
{
case 0:
//bDisableButtons = 0;
break;
case 1:
// bDisableButtons = 1;
break;
default:
break;
}
}
}
//***********************************************
//***********************************************
//* ESC d
//* print and feed n line
void ESC_dcmd(void)
{
unsigned char cNumOfLine;
///unsigned char cLoop;
unsigned int iTemp;
cNumOfLine = GetDataFromRcvBuf();
// MyPrintf("!666");
StartupPrint(0);
// for(cLoop=0;cLoop<cNumOfLine;cLoop++)
// {
WaitMotorStop();
CloseAllInt;
iTemp = (iLineSpaceNumber+PRTLINEHIGHT)*one_dotline_lfstep_num*cNumOfLine;
OpenAllInt;
FeedPaper(iTemp);
// }
}
//***********************************************
//***********************************************
//* ESC % n
//* Select/cancel user-defined character set
//***********************************************
void ESC_mod(void)
{
bUserChar = GetDataFromRcvBuf() & LSB;
}
//***********************************************
//***********************************************
//* ESC & y c1 c2 [x1 d1...d(y x x1)]...
//* [xk d1...d(y x xk)]
//* Define user-defined characters
//* y=1 or 2
//* 32<=c1<=c2<=126
//* 0<=x<=12 (when Font A(12 x 24)is selected)
//* 0<=x<=9 (when Font B(9 x 17)is selected)
//* 0<=d1...d(y x xk)<=255
//***********************************************
void ESC_and(void)
{
unsigned char y;
unsigned char cUserFirstChar;
unsigned char cUserLastChar;
unsigned int cCounter,cLoopi;
unsigned int cCounterx,cLoopx;
unsigned char cFirst,cSecond,cThree;
unsigned int iAddr;
y = GetDataFromRcvBuf();
if(y != 3)
{
return;
}
cUserFirstChar = GetDataFromRcvBuf(); //Get c1
cUserLastChar = GetDataFromRcvBuf(); //Get c2
if((cUserFirstChar>=32 && cUserFirstChar<=126) &&
cUserLastChar>=32 && cUserLastChar<=126 &&
cUserFirstChar<=cUserLastChar)
{
for(cLoopi=cUserFirstChar;cLoopi<=cUserLastChar;cLoopi++)
{
if(bFont12x24)
{
iAddr=UserCharAddr_12x24|((cLoopi-32)<<12);
SPI_Erase_Sector(iAddr);
SPI_Write_Byte(iAddr,0x01);
}
else
{
iAddr=UserCharAddr_9x17|((cLoopi-32)<<12);
SPI_Erase_Sector(iAddr);
SPI_Write_Byte(iAddr,0x01);
}
}
cCounter = cUserLastChar - 32 + 1;
for(cLoopi=cUserFirstChar-32;cLoopi<cCounter;cLoopi++)
{
cCounterx = GetDataFromRcvBuf();
if(bFont12x24)
{
if(cCounterx > 12)
{
cCounterx = 12;
}
}
else
{
if(cCounterx > 9)
{
cCounterx = 9;
}
}
for(cLoopx=0;cLoopx<cCounterx;cLoopx++) // receive y x xi datas
{
if(bFont12x24)
{
cFirst = GetDataFromRcvBuf();
cSecond = GetDataFromRcvBuf();
cThree = GetDataFromRcvBuf();
iAddr = UserCharAddr_12x24 | (cLoopi<<12) | (1+cLoopx);
SPI_Write_Byte(iAddr,cFirst);
SPI_Write_Byte(iAddr+ASCII_WIDTH,cSecond);
SPI_Write_Byte(iAddr+ASCII_WIDTH*2,cThree);
}
else
{
cFirst = GetDataFromRcvBuf();
cSecond = GetDataFromRcvBuf();
cThree = GetDataFromRcvBuf();
iAddr = (UserCharAddr_9x17 | (cLoopi<<12) | (1+cLoopx));
SPI_Write_Byte(iAddr,cFirst);
SPI_Write_Byte(iAddr+SFONT_WIDTH,cSecond);
SPI_Write_Byte(iAddr+SFONT_WIDTH*2,cThree);
}
}
}
}
}
//***********************************************
//* ESC ? n
//* cancel user-defined character
void ESC_interrogation(void)
{
unsigned char cByte;
unsigned int iAddr;
cByte = GetDataFromRcvBuf();
if(cByte>=32 && cByte<=127)
{
if(bFont12x24)
{
iAddr = UserCharAddr_12x24|((cByte-32)<<12);
SPI_Write_Byte(iAddr,0x00);
}
else
{
iAddr = UserCharAddr_9x17|((cByte-32)<<12);
SPI_Write_Byte(iAddr,0x00);
}
}
}
//* ESC D [d]k NULL
//* Select HT bits
unsigned char HT_TAB[16]={3,6,9,12,15,18,21,24,27,30,33,35,38,41,44,48};
void ESC_D(void)
{
unsigned char temp_ji;
for(temp_ji=0;temp_ji<16;temp_ji++)
{
HT_TAB[temp_ji]=0;
}
for(temp_ji=0;temp_ji<16;temp_ji++)
{
HT_TAB[temp_ji]=GetDataFromRcvBuf();
if(HT_TAB[temp_ji]==0)
{
break;
}
}
}
//***********************************************
//* ESC ! n
//* Select print mode(s)
void ESC_ExcalmatoryMark(void)
{
unsigned char cTemp;
cTemp=GetDataFromRcvBuf();
if(cTemp & LSB)
{
bFont12x24= 0;
}
else
{
bFont12x24= 1;
}
if(cTemp & BIT3)
{
bBold = 1;
}
else
{
bBold = 0;
}
if(cTemp & BIT4)
{
cAsciiHightMultiple= 2;
}
else
{
cAsciiHightMultiple = 1;
}
if(cAsciiHightMultiple_Prt<cAsciiHightMultiple)
{
cAsciiHightMultiple_Prt=cAsciiHightMultiple;
}
if(cTemp & BIT5)
{
cAsciiWidthMultiple= 2;
}
else
{
cAsciiWidthMultiple = 1;
}
if(cTemp & BIT7)
{
bAsciiUnderLine = 1;
}
else
{
bAsciiUnderLine = 0;
}
}
//***********************************************
//***********************************************
//* ESC E n
//*bBold mode
void ESC_E(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if(cTemp&LSB)
{
bBold = 1;
}
else
{
bBold = 0;
}
}
//***********************************************
//***********************************************
//* ESC G n
//*bBold mode
void ESC_G(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if(cTemp&LSB)
{
bBold = 1;
}
else
{
bBold = 0;
}
}
//***********************************************
//***********************************************
//* ESC N n t
//*FLASH中的打印机系统参数设置
void ESC_N(void)
{
unsigned char cTemp;
SPI_Read_nBytes(UndefinedAddr,(uint8_t *)&EEPROM,sizeof(EEPROM_STRUCT));
switch(GetDataFromRcvBuf())
{
case 0x00:
EEPROM.save_flag = 0xff;//恢复出厂设置
break;
case 0x01:
cTemp = GetDataFromRcvBuf();
if(cTemp > 5)
{
return;
}
if(cTemp == 1)
{
iBaudRate = BAUDRATE9600;
}
else if(cTemp == 2)
{
iBaudRate = BAUDRATE19200;
}
else if(cTemp == 3)
{
iBaudRate = BAUDRATE38400;
}
else if(cTemp == 4)
{
iBaudRate = BAUDRATE57600;
}
else if(cTemp == 5)
{
iBaudRate = BAUDRATE115200;
}
USART_Configuration();
EEPROM.SerialBauRate = cTemp;
break;
case 0x02:
cTemp = GetDataFromRcvBuf();
break;
case 0x03:
cTemp = GetDataFromRcvBuf();
if(cTemp&0x01)
{
bChinese = 1;
}
else
{
bChinese = 0;
}
EEPROM.CodePage = cTemp;
break;
case 0x04:
cTemp = GetDataFromRcvBuf();
if(cTemp > 4)
{
return;
}
// MyPrintf("set iDensitySetTime = %d\n",cTemp);
if(cTemp == 1)
{
TPH.iDensitySetTime = DensitySetTimeLevel1;
}
else if(cTemp == 2)
{
TPH.iDensitySetTime = DensitySetTimeLevel2;
}
else if(cTemp == 3)
{
TPH.iDensitySetTime = DensitySetTimeLevel3;
}
else if(cTemp == 4)
{
TPH.iDensitySetTime = DensitySetTimeLevel4;
}
EEPROM.DensitySelect = cTemp;
break;
case 0x05:
cTemp = GetDataFromRcvBuf();
cCodePage = cTemp;
EEPROM.CodePage = cTemp;
break;
default:
cTemp = GetDataFromRcvBuf();
break;
}
SPI_Erase_Sector(UndefinedAddr);
SPI_Write_nBytes(UndefinedAddr,(uint8_t *)&EEPROM,sizeof(EEPROM_STRUCT));
}
//***********************************************
//***********************************************
//* ESC B n t
//* 打印机来单打印蜂鸣提示
//* 0<=n<=9
//* 0<=t<=9
void ESC_B(void)
{
GetDataFromRcvBuf();
GetDataFromRcvBuf();
}
//***********************************************
//***********************************************
//* ESC p m t1 t2
//* Generate pulse
//* m=0,1,48,49
//* 0<=t1<=255
//* 0<=t2<=255
void ESC_p(void)
{
unsigned char m;
unsigned char t1;
unsigned char t2;
unsigned int iOnTime;
unsigned int iOffTime;
m = GetDataFromRcvBuf();
t1 = GetDataFromRcvBuf();
t2 = GetDataFromRcvBuf();
iOnTime = t1 * 2;
if(t2 < t1)
{
t2 = t1;
}
if(t2 < 50)
{
t2 = 50;
}
iOffTime = t2 * 2;
WaitMotorStop();
switch(m)
{
case 0:
case '0':
case 1:
case '1':
bCash_ON;
delay_ms(iOnTime);
bCash_OFF;
delay_ms(iOffTime);
break;
default:
break;
}
}
//***********************************************
//***********************************************
//* ESC q m t1 t2
//* Generate pulse
//* m=0,1,48,49
//* 0<=t1<=255
//* 0<=t2<=255
void ESC_q(void)
{
//unsigned char m;
unsigned char t1;
unsigned char t2;
//unsigned int iOnTime;
//unsigned int iOffTime;
cChasNums = GetDataFromRcvBuf();
t1 = GetDataFromRcvBuf();
t2 = GetDataFromRcvBuf();
iOpenCashTimer = t1 * 2;
if(t2 < t1)
{
t2 = t1;
}
if(t2 < 50)
{
t2 = 50;
}
iCloseCashTimer = t2 * 2;
WaitMotorStop();
bOpenCashAfterPrt = 1;
}
//***********************************************
//***********************************************
//* ESC r
//* open cash after prt
void ESC_r(void)
{
if(bOpenCashAfterPrt == 1)
{
WaitMotorStop();
switch(cChasNums)
{
case 0:
case '0':
case 1:
case '1':
bCash_ON;
delay_ms(iOpenCashTimer);
bCash_OFF;
delay_ms(iCloseCashTimer);
break;
default:
break;
}
bOpenCashAfterPrt = 0;
cChasNums = 0;
iOpenCashTimer = 0;
iCloseCashTimer = 0;
}
}
//***********************************************
//* ESC U n
//*横向放大
void ESC_U(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if((cTemp>0) && (cTemp<5))
{
cAsciiWidthMultiple = cTemp;
}
}
//***********************************************
//***********************************************
//* ESC V n
//*顺时针旋转90度
void ESC_V(void)
{
GetDataFromRcvBuf();
}
//***********************************************
//***********************************************
//* ESC W n (0<n<4)
//*横向纵向放大
void ESC_W(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if((cTemp>0) && (cTemp<5))
{
cAsciiHightMultiple = cTemp;
cAsciiWidthMultiple = cTemp;
}
}
//***********************************************
//***********************************************
//* ESC t n ( 0 <=n <= 10 , 16 <=n <=19)
//*选择字符代码页
void ESC_t(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
cCodePage = cTemp;
}
//***********************************************
//***********************************************
//* ESC - n
//* set ASCII under line
//* ASCII
//* 0 <=n <=2, 48 <=n <=50
void ESC_subb(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
switch(cTemp)
{
case 0:
case 48:
bAsciiUnderLine = 0;//无下划线
break;
case 1:
case 49:
bAsciiUnderLine = 1;//单点下划线
break;
case 2:
case 50:
bAsciiUnderLine = 2;//双点下划线
break;
default:
break;
}
}
/*******************************************************************************
** Function name: ByteHightMultiple
**
** Descriptions: 单个字节变3倍高
**
******************************************************************************/
void ByteHightMultiple(unsigned char *pBytePattern,unsigned char *pByteHightPattern)
{
unsigned int iTemp = 0;
unsigned char cLoop1;
unsigned char cLoop2;
for(cLoop1 = 0;cLoop1<8;cLoop1++)
{
for(cLoop2 = 0;cLoop2 <3;cLoop2++)
{
iTemp = iTemp<<1;
iTemp |= (*pBytePattern>>(7-cLoop1))&0x01;
//iTemp = iTemp<<1;
}
}
*pByteHightPattern = iTemp>>16;
*(pByteHightPattern + 1)= iTemp>>8;
*(pByteHightPattern + 2)= iTemp;
}
//***********************************************
//* ESC * m nL nH d1...dk
//* Select bit-image mode
//* m=0,1,32 ,33
//* 0<=nL<=255
//* 0<=nH<=3
//* 0<=d<=255
void ESC_star(void)
{
unsigned char m;
unsigned char nL;
unsigned char nH;
unsigned char cWidth;
unsigned int iCounter;
unsigned char cTemp[3];
unsigned char cByte1,cByte2,cByte3;
unsigned int iLoop;
unsigned char cLoop;
unsigned char *p1;
unsigned char *p2;
unsigned char *p3;
m = GetDataFromRcvBuf();
switch(m)
{
case 0:
case 32:
cWidth = 2;
break;
case 1:
case 33:
cWidth = 1;
break;
default:
cWidth = 1;
m = 0x01;
break;
}
// MyPrintf("h333");
JudgeExceedByteLine(cWidth);
// nL + 256 * nH
nL = GetDataFromRcvBuf();
nH = GetDataFromRcvBuf();
iCounter = (nL + 256 * nH);
if(iCounter>(iPrtRightMargin-iCurrentFillColumn))
{
iCounter = iPrtRightMargin -iCurrentFillColumn;
}
if((m == 1 )||( m== 0))
{
p1 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn];
p2 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[1].BasePrtLine[iCurrentFillColumn];
p3 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[2].BasePrtLine[iCurrentFillColumn];
for(iLoop = 0;iLoop < iCounter;iLoop ++)
{
if(iCurrentFillColumn+cWidth >= iPrtRightMargin)
{
// exceed the byte line
while(iLoop<iCounter)
{
GetDataFromRcvBuf();
iLoop++;
}
return ;
}
else
{
cByte1 = GetDataFromRcvBuf();
ByteHightMultiple(&cByte1,cTemp);
for(cLoop = 0;cLoop < cWidth;cLoop ++)
{
*p3++ = cTemp[0];
*p2++ = cTemp[1];
*p1++ = cTemp[2];
iCurrentFillColumn ++;
}
}
}
}
else if((m == 32 )||( m== 33))
{
p1 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[0].BasePrtLine[iCurrentFillColumn];
p2 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[1].BasePrtLine[iCurrentFillColumn];
p3 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[2].BasePrtLine[iCurrentFillColumn];
for(iLoop = 0;iLoop<iCounter;iLoop++)
{
if(iCurrentFillColumn >= iPrtRightMargin)
{
// exceed the byte line
while(iLoop<iCounter)
{
GetDataFromRcvBuf();
GetDataFromRcvBuf();
GetDataFromRcvBuf();
iLoop++;
}
return ;
}
else
{
cByte1 = GetDataFromRcvBuf();
cByte2 = GetDataFromRcvBuf();
cByte3 = GetDataFromRcvBuf();
for(cLoop = 0;cLoop < cWidth;cLoop ++)
{
*p3++ = cByte1;
*p2++ = cByte2;
*p1++ = cByte3;
iCurrentFillColumn ++;
}
}
}
}
bHaveFilledRasterDot = 0;
// MyPrintf("!777");
StartupPrint(0);
}
//************************************************
//************************************************
//* ESC { n
//* bInvert Prt content
void ESC_Bigbrace(void)
{
GetDataFromRcvBuf();
}
//************************************************
//************************************************
//* ESC a n
//* Select justification
void ESC_acmd(void)
{
switch(GetDataFromRcvBuf())
{
case 0:
case 48:
if(iCurrentFillColumn == iPrtLeftMargin)
{
bAlign = Align_Left;
}
break;
case 1:
case 49:
if(iCurrentFillColumn == iPrtLeftMargin)
{
bAlign = Align_Middle;
}
break;
case 2:
case 50:
if(iCurrentFillColumn == iPrtLeftMargin)
{
bAlign = Align_Right;
}
break;
default:
break;
}
}
//************************************************
//************************************************
//* ESC v
//* Printer Status
void ESC_v(void)
{
// unsigned char cTemp[1];
// if(f_error_no_paper)
// {
// cTemp[0] = 0x00;
// SerialSendByte(cTemp[0]);
// //USB_Send_Data(cTemp,1);
// }
// else
// {
// cTemp[0] = 0x01;
// SerialSendByte(cTemp[0]);
// //USB_Send_Data(cTemp,1);
// }
}
//************************************************
//************************************************
//* ESC $ nL nH
//* set absolute print position
void ESC_$(void)
{
unsigned char nH;
unsigned char nL;
unsigned int iTemp;
nL = GetDataFromRcvBuf();
nH = GetDataFromRcvBuf();
if(iCurrentFillColumn == 0)
{
iTemp = nH*256+nL;
if(iTemp > MaxDotPos)
{
return;
}
else
{
iCurrentFillColumn = iTemp;
}
}
}
//************************************************
//************************************************
//* ESC \ nL nH
//* set relative print position
void ESC_backslash(void)
{
unsigned char nH;
unsigned char nL;
unsigned int iTemp;
nL = GetDataFromRcvBuf();
nH = GetDataFromRcvBuf();
if(iCurrentFillColumn == iPrtLeftMargin)
{
iTemp = nH*256+nL;
if(iTemp +iCurrentFillColumn > MaxDotPos)
{
return;
}
else
{
iCurrentFillColumn += iTemp;
}
}
}
//***********************************************
//***********************************************
//* FS .
//* Disable Chinese mode
void FS_dot(void)
{
bChinese = 0;
}
//***********************************************
//***********************************************
//* FS &
//* Enable Chinese mode
void FS_and(void)
{
bChinese = 1;
}
//***********************************************
//***********************************************
//* FS S n1 n2
//* Set left- and right-side Kanji character spacing
//* 0<=n1<=32
//* 0<=n2<=32
void FS_S(void)
{
unsigned char n1;
unsigned char n2;
n1 = GetDataFromRcvBuf(); //Get n1
n2 = GetDataFromRcvBuf(); //Get n2
cChineseLeftSpace = n1;
cChineseRightSpace = n2;
}
//***********************************************
//***********************************************
//* FS 2
//* FS 2 c1 c2 d1...dk 定义用户自定义汉字
//* c1 = 0XFE 0XA1 <=c2 <=0XFE 0 <=d <=255 k = 72
//*一个汉字在flash中独占一个扇区
void FS_2(void)
{
unsigned char cLoop;
unsigned char cFirst;
unsigned char cSecond;
unsigned char cThree;
unsigned char c1;
unsigned char c2;
unsigned int iwc;
c1 = GetDataFromRcvBuf();
c2 = GetDataFromRcvBuf();
if(c1==0xfe && c2>=0xa1 && c2<=0xfe)
{
c2 -= 0xa1;
iwc = c2;
SPI_Erase_Sector(UserCharAddr_24x24 | (iwc<<12) );
SPI_Write_Byte(UserCharAddr_24x24 | (iwc<<12),0x01);
for(cLoop=0;cLoop<HZ_WIDTH;cLoop++)
{
cFirst = GetDataFromRcvBuf();
cSecond = GetDataFromRcvBuf();
cThree = GetDataFromRcvBuf();
iwc = UserCharAddr_24x24 | (c2<<12) |(1+cLoop);
SPI_Write_Byte(iwc, cFirst);
SPI_Write_Byte(iwc+HZ_WIDTH, cSecond);
SPI_Write_Byte(iwc+HZ_WIDTH*2, cThree);
}
}
else
{
for(cLoop=0;cLoop<HZ_WIDTH*3;cLoop++)
{
GetDataFromRcvBuf();
}
}
}
//***********************************************
//***********************************************
//* FS ! n
//* Set print mode(s) for Kanji characters
//* 0<=n<=255
void FS_ExcalmatoryMark(void)
{
unsigned char cTemp;
cTemp=GetDataFromRcvBuf();
if(cTemp & BIT2)
{
cChineseWidthMultiple = 2;
}
else
{
cChineseWidthMultiple = 1;
}
if(cTemp & BIT3)
{
cChineseHightMultiple = 2;
}
else
{
cChineseHightMultiple = 1;
}
if(cTemp&BIT7)
{
bChineseUnderLine = 1;
}
else
{
bChineseUnderLine = 0;
}
}
//***********************************************
//***********************************************
//* FS W n
//* Turn quadruple-size mode on/off for Kanji
//* characters
//* 0<=n<=255
void FS_W(void)
{
if(GetDataFromRcvBuf() & LSB)
{
cChineseWidthMultiple = 2;
cChineseHightMultiple = 2;
}
else
{
cChineseWidthMultiple = 1;
cChineseHightMultiple = 1;
}
}
/*******************************************************************************
** Function name: ByteDoubleHightMultiple
**
** Descriptions: 单个字节变2倍高
**
******************************************************************************/
void ByteDoubleHightMultiple(unsigned char *pBytePattern,unsigned char *pByteHightPattern)
{
unsigned int iTemp = 0;
unsigned char cLoop1;
unsigned char cLoop2;
for(cLoop1 = 0;cLoop1<8;cLoop1++)
{
for(cLoop2 = 0;cLoop2 <2;cLoop2++)
{
iTemp = iTemp<<1;
iTemp |= (*pBytePattern>>(7-cLoop1))&0x01;
//iTemp = iTemp<<1;
}
}
*pByteHightPattern = iTemp>>8;
*(pByteHightPattern + 1)= iTemp;
}
#define SectionSize 4096//一个扇区大小
#define SectionCounts 4//每幅图片扇区数量
//***********************************************
//* FS p n m
//* 以m指定的模式打印下载到FLASH中的位图
//*1 <= n <= 5 0 <= m <= 3 , 48 <= m <=51
void FS_p(void)
{
unsigned char n,m,xl,xh,yl,yh;
unsigned char cWidth,cHight;
unsigned char cLoop,cLoop1;
unsigned int iLoop2;
unsigned int iCount = 0;
unsigned char cTemp[2];
unsigned char data;
unsigned int iTransverse;//横向点数
unsigned int iLengthways;//纵向字节
unsigned int iyy;
unsigned char *p1,*p2;
if(iCurrentFillColumn != iPrtLeftMargin)
{
return;
}
n = GetDataFromRcvBuf();//Image 图号
if(n<1||n>BIT_IMAGE_SIZE)
{
return;
}
m = GetDataFromRcvBuf();
switch(m)
{
case 0:
case 48:
cWidth = 1;
cHight = 1;
break;
case 1:
case 49:
cWidth = 2;
cHight = 1;
break;
case 2:
case 50:
cWidth = 1;
cHight = 2;
break;
case 3:
case 51:
cWidth = 2;
cHight = 2;
break;
default:
break;
}
if(SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts) == 0x55)//检测是否有图片
{
xl = SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts + 1);//读信息
xh = SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts + 2);
yl = SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts + 3);
yh = SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts + 4);
iLengthways = yl + yh*256;
iTransverse = xl + xh*256;
if(iTransverse>(MaxDotPos/8))
{
iTransverse = MaxDotPos/8;
}
//if(iLengthways*cHight > PRTBUFHIGHT)//大于一个打印buffer
//{
for(cLoop=0;cLoop<(iLengthways*cHight)/PRTBUFHIGHT+1;cLoop++)
{
/*******************************************************************/
if(cLoop == (iLengthways*cHight)/PRTBUFHIGHT)// 确定每次打印高度
{
iyy = (iLengthways*cHight)%PRTBUFHIGHT;
}
else
{
iyy = PRTBUFHIGHT;
}
/*******************************************************************/
for(cLoop1=iyy;cLoop1>0;cLoop1--)
{
for(iLoop2 = 0;iLoop2<iTransverse*8*cWidth;iLoop2++)
{
data = SPI_Read_Byte(NvImageBaseAddr+(n-1)*SectionSize*SectionCounts + 5 + iCount);
iCount++;
p1 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[cLoop1-1].BasePrtLine[iLoop2];
p2 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[cLoop1-2].BasePrtLine[iLoop2];
if(cHight == 2)
{
ByteDoubleHightMultiple(&data,cTemp);
//
//
*p1 = cTemp[0];
*p2 = cTemp[1];
//cLoop2++;
if(cWidth == 2)
{
//
//
p1++;
p2++;
*p1 = cTemp[0];
*p2 = cTemp[1];
}
//cLoop1--;//yxm 14.03.13
}
else
{
//
*p1 = data;
//cLoop2++;
if(cWidth == 2)
{
p1++;
*p1 = data;
//
}
}
if(iLoop2 >= (MaxDotPos-1))
{
for(iLoop2 = iLoop2;iLoop2<iTransverse*8*cWidth;iLoop2++)
{
iCount++;
iLoop2++;
}
//iLoop2=iTransverse*8*cWidth;
}
if(cWidth == 2)
{
iLoop2++;
}
}
if(cHight == 2)
{
cLoop1--;
}
}
iImageDotHight = iyy*8;
iCurrentFillColumn = iTransverse*8*cWidth;
if(iCurrentFillColumn > MaxDotPos)
{
iCurrentFillColumn = MaxDotPos;
}
bHaveFilledImageDot = 1;
//if(cLoop == (iLengthways*cHight)/PRTBUFHIGHT)
{
;
}
//else
{
StartupPrint(0);//打印
// MyPrintf("!888");
}
}
//}
}
}
//***********************************************
//***********************************************
//* FS q
//* FS q n [xL xH yL yH d1...dk]1...[xL xH yL yH d1...dk]n
//* 定义Flash 位图
//* 0<=n<=255
//*0 <= xL ≤ 255
//*1 <= ( xL + xH x 256) <= 1023
//*1 <= ( yL + yH x 256) <= 288
//*0 <= d <= 255
//*k = ( xL + xHx 256) x( yL +yH x 256) x 8
void FS_q(void)
{
unsigned char n,xl,xh,yl,yh;
unsigned char cLoop;
unsigned int iCount,iCnt;
unsigned int iLoop,iLoop1;
unsigned char data;
if(iCurrentFillColumn != iPrtLeftMargin)
{
return;
}
n = GetDataFromRcvBuf();
if(n<1||n > BIT_IMAGE_SIZE)
{
return;
}
for(cLoop = 0;cLoop<n*SectionCounts;cLoop++)//擦除要重新下载的扇区,每个图片占SectionCounts个扇区
{
SPI_Erase_Sector(NvImageBaseAddr+cLoop*SectionSize);
}
for(cLoop = 0;cLoop<n;cLoop++)
{
xl = GetDataFromRcvBuf();
xh = GetDataFromRcvBuf();
yl = GetDataFromRcvBuf();
yh = GetDataFromRcvBuf();
iCount = (xl+xh*256)*8*(yl+yh*256);
if(iCount > (SectionSize*SectionCounts-5))//数据量大于4K*SectionCounts丢掉
{
PrintStr((unsigned char *)"下载数据超出缓冲区",1);
while(iCount--)
{
GetDataFromRcvBuf();
}
return;
}
if((xl+xh*256)*8 > MaxDotPos)
{
iCnt = MaxDotPos;
}
else
{
iCnt = (xl+xh*256)*8;
}
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts,0x55);//信息头
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts+1,(iCnt/8));
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts+2,(iCnt/8)>>8);
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts+3,yl);
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts+4,yh);
/***********************按排列规律写进FLASH中***************************/
for(iLoop = 0;iLoop<(xl+xh*256)*8;iLoop++)//横向点数
{
for(iLoop1 = 0;iLoop1<(yl+yh*256);iLoop1++)//纵向字节
{
data = GetDataFromRcvBuf();
SPI_Write_Byte(NvImageBaseAddr+cLoop*SectionSize*SectionCounts+5+iLoop+iLoop1*iCnt,data);
if(iLoop1 ==(SectionSize*SectionCounts-5)/iCnt-1)//能接收的最大高度
{
while(iLoop1++ < (yl+yh*256))
{
GetDataFromRcvBuf();
}
}
}
if(iLoop == (MaxDotPos-1))//能接收的最大宽度
{
if(iLoop+1<(xl+xh*256)*8)
{
for(iLoop1 = 0;iLoop1<(yl+yh*256);iLoop1++)//纵向字节
{
GetDataFromRcvBuf();
}
iLoop++;
}
}
}
}
}
//***********************************************
//***********************************************
//* FS - n
//* set characters under line
//* characters
//* 0 <=n <=2, 48 <=n <=50
void FS_subb(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
switch(cTemp)
{
case 0:
case 48:
bChineseUnderLine = 0;
break;
case 1:
case 49:
bChineseUnderLine = 1;
break;
case 2:
case 50:
bChineseUnderLine = 2;
break;
default:
break;
}
}
//***********************************************
//***********************************************
//* ESC @
//*
//*Init Printer
//*
void ESC_ATInit(void)
{
// MyPrintf("ESC_ATInit_1 \n");
WaitMotorStop();
// PAPER.printing_process_flag =0 ;
//* GS ! n
cAsciiWidthMultiple = 1;//字符倍宽1倍
cAsciiHightMultiple = 1;//字符倍高1倍
cAsciiHightMultiple_Prt=1;
//* ESC SP n
cAsciiRightSpace = 0;//字符右边距
//* ESC 2
iLineSpaceNumber = LINE_SPACE;//两行之间点行数
//* FS ! n
cChineseWidthMultiple = 1;//汉字倍宽1倍
cChineseHightMultiple = 1;//汉字倍高1倍
//* FS S n1 n2
cChineseRightSpace = 0;//汉字右边距
cChineseLeftSpace = 0;//汉字左边距
//* FS &
//bChinese = 1;//汉字模式
//* ESC M n
bFont12x24 = 1;//初始化默认大字体
//* ESC a n
bAlign = Align_Left;//左对齐
//* GS B n
bPrtAdverse = 0;//反白打印
//* FS - n
bChineseUnderLine = 0;//汉字下划线
//* ESC - n
bAsciiUnderLine = 0;//字符下划线
//*ESC E n
bBold = 0;//粗体模式
//*ESC R n
cInternationalCharSet = USA;//国际字符集
//*ESC L nL nH
iPrtLeftMargin = 0;//左边距
//*ESC W nL nH
iPrtRightMargin = MaxDotPos;
//?ESC % n
bUserChar = 0;
//memset(&UserDefinedBuf, 0, sizeof(UserDefinedBuf));
ClrCharPrtBuf(0);//初始化打印buffer1
ClrCharPrtBuf(1);//初始化打印buffer2
BarCodeInit();
}
//***********************************************
//***********************************************
//* GS ! n
//* Select print mode(s)
void GS_ExcalmatoryMark(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if(((cTemp&0x0F)>0x03 )|| ((cTemp&0xF0)>0x30))
{
return;
}
else
{
cChineseHightMultiple = (cTemp&0x0F)+1;
cAsciiHightMultiple = (cTemp&0x0F)+1;
cChineseWidthMultiple = ((cTemp>>4)&0x0F)+1;
cAsciiWidthMultiple = ((cTemp>>4)&0x0F)+1;
if(cAsciiHightMultiple_Prt<cAsciiHightMultiple)
{
cAsciiHightMultiple_Prt=cAsciiHightMultiple;
}
}
}
//***********************************************
//***********************************************
//* GS B n
//* 选择/取消反白打印
void GS_B(void)
{
unsigned char cTemp;
cTemp = GetDataFromRcvBuf();
if(cTemp&LSB)
{
bPrtAdverse = 1;
}
else
{
bPrtAdverse = 0;
}
}
//----------------------------------------------------------------控制走纸类型
void GS_MoveToCut(uint8_t mode)
{
// MyPrintf("11a\n");
if(mode==2)
{
PAPER.move_ctl_state = GAP_MOVE_PAPTER_TO_CUT;
}
else if(mode==4)
{
PAPER.move_ctl_state = GAP_MOVE_PAPTER_TO_HOLD;
}
else
{
PAPER.move_ctl_state = GAP_MOVE_PAPTER_TO_TPH;
}
MOTOR.bLFForward = 1;
StartKeyFeedPaper(1200,LFconst);
}
//***********************************************
//***********************************************
//* GS L nL nH
//* 设置左边距
void GS_L(void)
{
unsigned char nH;
unsigned char nL;
nL = GetDataFromRcvBuf();
nH = GetDataFromRcvBuf();
if(iCurrentFillColumn == iPrtLeftMargin)
{
iPrtLeftMargin = nH*256+nL;
if(iPrtLeftMargin > MaxDotPos)
{
iPrtLeftMargin = MaxDotPos;
}
iCurrentFillColumn = iPrtLeftMargin;
}
}
extern void usb0_respond(byte const *buff,byte size);
extern void usb1_respond(byte const *buff,byte size);
//GS I n
//const byte device_name[]= "PT-51DC";
const byte device_name[]= "PT26";
//------------------------------------------------
void GS_I(void){
unsigned char id_type;
id_type = GetDataFromRcvBuf();
if(id_type == 1 || id_type == '1'){//Printer model ID
}
else if(id_type == 2 || id_type == '2'){//Type ID
}
else if(id_type == 3 || id_type == '3'){//Version ID
}
else if(id_type == 0x43){//device name
usb1_respond(device_name, 5);
}
else if(id_type == 0x41){//soft_version
DLE_ACK_soft_version();
}
}
//注意这个版本号和自检里的版本要要统一
void DLE_ACK_soft_version(void)
{
unsigned char bleData[]={ble_send_handle&0xff,ble_send_handle>>8,0x5f,0x30,0x31,0x2e,0x30,0x30,0x31,0x2e,0x30,0x30,0x30,0x30,0x30,0x31,0x00};
unsigned char sppData[]={spp_send_handle&0xff,spp_send_handle>>8,0x5f,0x30,0x31,0x2e,0x30,0x30,0x31,0x2e,0x30,0x30,0x30,0x30,0x30,0x31,0x00};
if(Rcv_Port == RCV_TYPE_SPP){
BT_SendSppData(&sppData[2],15);
//
}
else if(Rcv_Port == RCV_TYPE_BLE){
BT_SendBleData(bleData,17);
//
}
else if(Rcv_Port == RCV_TYPE_USB){
usb1_respond(&error_state.byte[0],1);
}
}
//***********************************************
//***********************************************
//* GS * x y d1...d(x × y × 8) 定义下载位图
//*下载位图
//*0<=x<=48 0<=y<=24
void GS_star(void)
{
}
//************************************************
//************************************************
//* GS / m 打印下载位图
//*打印下载位图
void GS_slash(void)
{
}
/*******************************************************************************
** Function name: ByteWidthMultiple
**
** Descriptions: 单个字节变2倍宽
**
******************************************************************************/
void ByteWidthMultiple(unsigned char *pBytePattern,unsigned char *pByteWidthPattern)
{
unsigned int iTemp = 0;
unsigned char cLoop1;
unsigned char cLoop2;
for(cLoop1 = 0;cLoop1<8;cLoop1++)
{
for(cLoop2 = 0;cLoop2 <2;cLoop2++)
{
iTemp = iTemp<<1;
iTemp |= (*pBytePattern>>(7-cLoop1))&0x01;
}
}
*(pByteWidthPattern)= iTemp>>8;
*(pByteWidthPattern + 1)= iTemp;
}
//***********************************************
//* GS v 0 m xL xH yL yH d1...dk
//* 光栅位图打印模式
#define Min(a,b) ((a)<(b))?(a):(b)
void GS_v(void)
{
unsigned char xH,xL,yH,yL;
unsigned char m;
unsigned char cWidth;
unsigned char cHight;
unsigned int iTransverse;//横向字节
unsigned int iLengthways;//纵向点数
unsigned int iTemp;
unsigned char cLoop,cLoop1,cLoop2;
unsigned char cTempBuf[2];
unsigned char Buf[MaxDotPos/8];
unsigned int iMin;
unsigned char *p1,*p2;
unsigned int iyy;
unsigned char Width_v;
if(bHaveFilledRasterDot)
{
// MyPrintf("!999");
StartupPrint(0);
}
if(iCurrentFillColumn != iPrtLeftMargin)
{
return;
}
if(GetDataFromRcvBuf() == 0x30)//默认
{
m = GetDataFromRcvBuf();//判断打印模式倍高倍宽
switch(m)
{
case 0:
case 48:
cWidth = 1;
cHight = 1;
break;
case 1:
case 49:
cWidth = 2;
cHight = 1;
break;
case 2:
case 50:
cWidth = 1;
cHight = 2;
break;
case 3:
case 51:
cWidth = 2;
cHight = 2;
break;
default:
break;
}
/*得到横向字节数和纵向点数*/
xL = GetDataFromRcvBuf();//xl < 48
xH = GetDataFromRcvBuf();//xh = 0
yL = GetDataFromRcvBuf();//yl <8*24
yH = GetDataFromRcvBuf();//yh = 0
iLengthways = (yL + yH*256)*cHight;//纵向点数
iTransverse = xL + xH*256;//横向字节数
if(iLengthways == 0||iTransverse == 0)
{
return;
}
//if((iLengthways-1)/(PRTBUFHIGHT*8))//数据多出一个打印buf
//{
for(cLoop2 = 0;cLoop2<iLengthways/(PRTBUFHIGHT*8)+1;cLoop2++)//填充整个打印buf循环n次
{
/*******************************************************************/
if(cLoop2 == iLengthways/(PRTBUFHIGHT*8))// 确定每次打印高度
{
iyy = iLengthways%(PRTBUFHIGHT*8);
}
else
{
iyy = PRTBUFHIGHT*8;
}
/*******************************************************************/
for(cLoop = iyy;cLoop > 0;cLoop--)//填充(PRTBUFHIGHT*8)点行
{
iMin = Min(MaxDotPos/8,iTransverse);//每点行最少数据
iTemp = ((cLoop-1)%8)*(MaxDotPos/8);//填充起始位置
for(cLoop1 = 0;cLoop1<iTransverse;cLoop1++)//收一点行数据,多了丢掉
{
if(cLoop1<MaxDotPos/8)
{
Buf[cLoop1] = GetDataFromRcvBuf();
}
else
{
GetDataFromRcvBuf();
}
}
if(cWidth == 2)//倍宽变化
{
unsigned char Buf1[MaxDotPos/16];
for(cLoop1 = 0;cLoop1<iMin;cLoop1++)
{
Buf1[cLoop1]=Buf[cLoop1];
}
for(cLoop1 = 0;cLoop1<iMin;cLoop1++)
{
ByteWidthMultiple(&Buf1[cLoop1],cTempBuf);
Buf[cLoop1*2] = cTempBuf[0];
Buf[cLoop1*2+1] = cTempBuf[1];
}
}
if(cHight == 1)//普通高度填充数据
{
p1 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[(cLoop-1)/8].BasePrtLine[iTemp];
if(cWidth==2)
{
Width_v=iMin*2;
if(Width_v>48)
{
Width_v=48;
}
}
else
{
Width_v=iMin;
}
for(cLoop1 = 0;cLoop1<Width_v;cLoop1++)
{
//
*p1++ = Buf[cLoop1];
}
}
else//倍高填充数据
{
if(cWidth==2)
{
Width_v=iMin*2;
if(Width_v>48)
{
Width_v=48;
}
}
else
{
Width_v=iMin;
}
p1 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[(cLoop-1)/8].BasePrtLine[iTemp];
p2 = (unsigned char *)&PrtBuf[cCurrentFillRow].ByteLine[(cLoop-1)/8].BasePrtLine[iTemp-(MaxDotPos/8)];
for(cLoop1 = 0;cLoop1<Width_v;cLoop1++)
{
//
//
*p1++ = Buf[cLoop1];
*p2++ = Buf[cLoop1];
}
cLoop --;
}
}
/*******************************************************************/
iRasterDotHight = iyy;
iCurrentFillColumn = MaxDotPos;
bHaveFilledRasterDot = 1;
if(cLoop2 == iLengthways/(PRTBUFHIGHT*8))
{
;
}
else
{
StartupPrint(0);//打印
}
}
//}
}
}
//***********************************************
//***********************************************
//* GS W nL nH
//* 设置打印区域
void GS_W(void)
{
unsigned char nH;
unsigned char nL;
unsigned int iTemp;
nL = GetDataFromRcvBuf();
nH = GetDataFromRcvBuf();
if((iCurrentFillColumn == iPrtLeftMargin)/*||((iCurrentFillColumn == iLeftMargin)&&(!iLeftMargin))*/)
{
iTemp = nH*256+nL;
if(iPrtLeftMargin + iTemp > MaxDotPos)
{
iTemp = MaxDotPos - iPrtLeftMargin;
}
iPrtRightMargin = iPrtLeftMargin + iTemp;
}
}
//***********************************************
//***********************************************
//* GS H n
//*0 ≤ n ≤ 3, 48 ≤ n ≤ 51
//* 选择HRI 字符的打印位置
void GS_H(void)
{
unsigned char n;
n = GetDataFromRcvBuf();
n=n & 0x03;
BarCode.cFontPosition = n;
}
//***********************************************
//***********************************************
//* GS f n
//* n = 0, 1, 48, 49
//* 选择 HRI 使用字体
void GS_f(void)
{
unsigned char n;
n = GetDataFromRcvBuf();
switch(n)
{
case 0:
case 48:
BarCode.cFont = 0;
break;
case 1:
case 49:
BarCode.cFont = 1;
break;
default:
break;
}
}
//***********************************************
//***********************************************
//* GS k m d1...dk NUL /d1... dn
//* 打印一维条码
void GS_k(void)
{
unsigned char m;
unsigned char n;
unsigned char cTemp;
// unsigned char i;
// unsigned char bHRIOnBarCode = 0;
// unsigned char bHRIUnderBarCode = 0;
// unsigned int iLong;
unsigned int iAddr;
unsigned char cTempBuf[256];
// unsigned char cBarCodeBuf[256];
// unsigned char bHRIFontSize;
m = GetDataFromRcvBuf();
if(iCurrentFillColumn != iPrtLeftMargin)
{
return;
}
if(m < 7)
{
for(cTemp = 0;cTemp < 256;cTemp ++)
{
cTempBuf[cTemp] = GetDataFromRcvBuf();
if(cTempBuf[cTemp] == 0x00)
{
break;
}
}
switch(m)
{
case 0://UPC-A
PrintBarCode_UPCA(cTempBuf,cTemp);
break;
case 1://UPC-E
PrintBarCode_UPCE(cTempBuf,cTemp);
break;
case 2://EAN13(JAN13)
PrintBarCode_EAN13(cTempBuf,cTemp);
break;
case 3://JAN8
PrintBarCode_JAN8(cTempBuf,cTemp);
break;
case 4://CODE39
PrintBarCode_CODE39(cTempBuf,cTemp);
break;
case 5://ITF
PrintBarCode_ITF(cTempBuf,cTemp);
break;
case 6://CODEBAR
PrintBarCode_CODEBAR(cTempBuf,cTemp);
break;
default:
break;
}
}
else if('A'<= m <='I')
{
n = GetDataFromRcvBuf();
for(cTemp = 0;cTemp < n;cTemp ++)
{
cTempBuf[cTemp] = GetDataFromRcvBuf();
}
switch(m)
{
case 'A'://UPC-A
PrintBarCode_UPCA(cTempBuf,cTemp);
break;
case 'B'://UPC-E
PrintBarCode_UPCE(cTempBuf,cTemp);
break;
case 'C'://EAN13
PrintBarCode_EAN13(cTempBuf,cTemp);
break;
case 'D'://EAN8
PrintBarCode_JAN8(cTempBuf,cTemp);
break;
case 'E'://CODE39
PrintBarCode_CODE39(cTempBuf,cTemp);
break;
case 'F'://ITF
PrintBarCode_ITF(cTempBuf,cTemp);
break;
case 'G'://CODEBAR
PrintBarCode_CODEBAR(cTempBuf,cTemp);
break;
case 'H'://CODE93
PrintBarCode_CODE93(cTempBuf,cTemp);
break;
case 'I'://CODE128
PrintBarCode_CODE128(cTempBuf,cTemp);
break;
default:
break;
}
}
}
//***********************************************
//***********************************************
//* GS h n
//* 设置一维条码高度
void GS_h(void)
{
BarCode.cHight = GetDataFromRcvBuf();
}
//***********************************************
//***********************************************
//* GS w n
//* 设置一维条码宽度
void GS_w(void)
{
BarCode.cWidth = GetDataFromRcvBuf();
}
/****************************************************************************************************
蓝牙连接成功,主机端发送:
0x1D 0x28 0x4B 0x03 0x00 0x33 0x30 0x00
0x1D 0x28 0x4B 0x03 0x00 0x30 0x30 0x09
0x1D 0x28 0x4B 0x03 0x00 0x31 0x30 0x04
ASCII :GS ( K pL pH fn m
*****************************************************************************************************/
void GS_1D28(void){
unsigned char bleData[]={ble_send_handle&0xff,ble_send_handle>>8,'O','K'};
unsigned char sppData[]={spp_send_handle&0xff,spp_send_handle>>8,'O','K'};
unsigned char data_buff[20];
// unsigned char nData =0;
unsigned int comman_type,leng,i;
unsigned char pl,ph;
unsigned char fm,fn;
volatile unsigned int buff,buf1,buf2;
comman_type = GetDataFromRcvBuf();//comman_type = 0x48--蓝牙接口,0x49--wifi接口
switch(comman_type){
case 0x4B: //USB
// MyPrintf("comman_type_\n");
pl = GetDataFromRcvBuf();
ph = GetDataFromRcvBuf();
leng = (u16)(ph<<8|pl);
// MyPrintf("leng=%d\n",leng);
for(i=0;i<leng;i++){
data_buff[i] = GetDataFromRcvBuf();
}
fm = data_buff[0];
fn = data_buff[1];
if(fm == 0x30 && fn == 0x30) //设置浓度
{
if(data_buff[2] <= 16)
{
/*
//不是0的就是设置这个命令.
if(data_buff[2]==0)//等于零就是跟随现在的浓度。就不管了
{
PAPER.print_density=PAPER.print_density;
}
else if(data_buff[2]>15)
{
PAPER.print_density = 15;
}
else
{
PAPER.print_density = data_buff[2];
}
*/
if(data_buff[2]>=15)
{
PAPER.print_density = 14;
}
else
{
if(data_buff[2]>4)
PAPER.print_density = data_buff[2]-1;
else
PAPER.print_density = data_buff[2];
}
MyPrintf("PAPER.print_density=%d\n",PAPER.print_density);
SetTphDensitySetTime();
}
}
else if(fm == 0x31 && fn == 0x30)
{//设置速度
/*
if(data_buff[2] ==0)
{
PAPER.print_speed = PAPER.print_speed;//跟随
}
else if(data_buff[2] <= 5)
{
PAPER.print_speed = data_buff[2];
SetMotorSpeedTime();
}
*/
if(data_buff[2] <= 4)
{
// if(Rcv_Port == RCV_TYPE_BLE)
// {
// PAPER.print_speed = 2;
// }
// else
PAPER.print_speed = data_buff[2];
SetMotorSpeedTime();
}
}
else if(fm == 0x33 && fn == 0x30)
{//设置纸张类型,n=0:连续纸 n=1:黑标纸 n=2:间隙纸 n=3:定位孔? n=4:
if(data_buff[2] <= 4)
PAPER.type = data_buff[2];
}
else if(fm == 0x34 && fn == 0x30)
{
// nData = data_buff[2] ; //进入驱动打印,0x00退出驱动打印
if(data_buff[2] == 0x01) //有驱
{
bHaveDrivePrintFlag = 1;
f_lable_printing = 1;
// PollingExtDev_1(0);
// PollingExtDev_2(0);
ESC_ATInit();
save_databuffer_2();
}
else //无驱
{
bHaveDrivePrintFlag = 0;
}
}
else if(fm == 0x35 && fn == 0x30) //设置打印机有效打印宽度
{
PAPER.print_speed = 4;
PAPER.print_size = (uint16_t)(data_buff[5]<<8|data_buff[4]);
paper_size_fw = (uint16_t)(data_buff[3]<<8|data_buff[2]);
if(paper_size_fw > 48){
paper_size_fw = 48;
}
SetMotorSpeedTime();
//MyPrintf("paper_size_fw = %d\n",paper_size_fw);
//MyPrintf("PAPER.print_size = %d\n",PAPER.print_size);
}
if(Rcv_Port == RCV_TYPE_SPP && EXT_DEV.spp_link_flag )
{
BT_SendSppData(bleData+2,2);
}
else if(Rcv_Port == RCV_TYPE_BLE && EXT_DEV.ble_link_flag)
{
BT_SendBleData(bleData,4);
}
// if(nData == 0x00)
// bHaveDrivePrintFlag = 0;
break;
case 'H':// 0x48 蓝牙
GetDataFromRcvBuf();
GetDataFromRcvBuf();
fn=GetDataFromRcvBuf();
GetDataFromRcvBuf();
if(fn==0x34) //这个格式要检查检查
{
//该机型能够存储标签模板的最大高度:打印机共返回9个字节信息:前4字节为均为00,可以忽略,
//第5、6字节为该机型能够存储标签模板的最大高度,低位在前高位在后;
//单位:点行;十六进制发送例子(蓝牙接口):1D 28 48 02 00 34 30
//MyPrintf("comman_type = %02x \n",comman_type);
//MyPrintf("Rcv_Port = %02x \n",Rcv_Port);
//MyPrintf("EXT_DEV.ble_link_flag = %02x \n",EXT_DEV.ble_link_flag);
//MyPrintf("bleData[0] = %02x \n",bleData[0]);
//MyPrintf("bleData[1] = %02x \n",bleData[1]);
buff=RcvBufSize;
// MyPrintf("buff = %02x \n",buff); //0x9000
buf1=buff/(MaxDotPos/8);
buf2=buf1;
// MyPrintf("buf1 = %02x,buf2 = %02x\n",buf1,buf2); //0x300
data_buff[2]=(buf1&0xff);
buff=(buf2>>8);
data_buff[3]=(buff&0xff);
// MyPrintf("data_buff[2] = %02x,data_buff[3] = %02x\n",data_buff[6],data_buff[7]); //data_buff[2]=02 data_buff[3]=00
if(Rcv_Port == RCV_TYPE_BLE)
{
data_buff[0]=bleData[0];
data_buff[1]=bleData[1];
//data_buff[2]=0x00;
//data_buff[3]=0x00;
//data_buff[4]=0x00;
//data_buff[5]=0x00;
//data_buff[6]=0x55;
//data_buff[7]=0x55; //这个数据要整改
//data_buff[8]=0x00;
//data_buff[9]=0x00;
//data_buff[10]=0x00;
PrinterRespond(data_buff,4);
}
// if(Rcv_Port == RCV_TYPE_SPP)
// {
// data_buff[0]=sppData[0];
// data_buff[1]=sppData[1];
// data_buff[2]=0x00;
// data_buff[3]=0x00;
// data_buff[4]=0x00;
// data_buff[5]=0x00;
// //data_buff[6]=0x55;
// //data_buff[7]=0x55; //这个数据要整改
//
// data_buff[8]=0x00;
// data_buff[9]=0x00;
// data_buff[10]=0x00;
// PrinterRespond(data_buff,11);
//
// }
}
if(fn==0x36)//查询剩余缓存大小
{
//这个帧的格式是什么格式?
// if(Rcv_Port == RCV_TYPE_USB)
// {
// buff=RemainSize;
// MyPrintf("RemainSize = %02x \n",RemainSize);
// buf1=buff/(MaxDotPos/8);
// buf2=buf1;
// MyPrintf("buf1 = %02x,buf2 = %02x\n",buf1,buf2);
//
// data_buff[0]=(buf1&0xff);
//
// buff=(buf2>>8);
// data_buff[1]=(buff&0xff);
// MyPrintf("data_buff[0] = %02x,data_buff[1] = %02x\n",data_buff[0],data_buff[1]);
// PrinterRespond(data_buff,2);
// }
// buff=RemainSize;
buff=BluetoothBuf.BufSize-BluetoothBuf.count;
if(buff>258)
{
buff=buff-258;
}
else
{
buff=0;
}
MyPrintf("buff = %02x \n",buff);
buf1=buff/(MaxDotPos/8);
buf2=buf1;
MyPrintf("buf1 = %02x,buf2 = %02x\n",buf1,buf2);
data_buff[2]=(buf1&0xff);
buff=(buf2>>8);
data_buff[3]=(buff&0xff);
MyPrintf("data_buff[2] = %02x,data_buff[3] = %02x\n",data_buff[6],data_buff[7]);
if(Rcv_Port == RCV_TYPE_BLE)//ble蓝牙流控
{
data_buff[0]=bleData[0];
data_buff[1]=bleData[1];
//data_buff[2]=0x00;
//data_buff[3]=0x00;
MyPrintf("Rcv_Port == RCV_TYPE_BLE\n");
PrinterRespond(data_buff,4);
}
if(Rcv_Port == RCV_TYPE_SPP)//经典蓝牙,流控
{
buff=RemainSize;//0x9000
// MyPrintf("RemainSize = %02x \n",RemainSize);
buf1=buff/(MaxDotPos/8);
buf2=buf1;
MyPrintf("buf1 = %02x,buf2 = %02x\n",buf1,buf2);
data_buff[0]=(buf1&0xff);
buff=(buf2>>8);
data_buff[1]=(buff&0xff);
MyPrintf("RCV_TYPE_SPP~~~~~~~~~~~data_buff[0] = %02x,data_buff[1] = %02x\n",data_buff[0],data_buff[1]);
PrinterRespond(data_buff,2);
}
}
break;
case 0x4C:
GetDataFromRcvBuf();
GetDataFromRcvBuf();
GetDataFromRcvBuf();
GetDataFromRcvBuf();
break;
default:
break;
}
}
/***********************************************
*************************************************/
//***********************************************
//* US DC
//*
//* yxm test
//*
//void OneByteToHightMultiple(unsigned char ByteData,unsigned char *pByteHightPattern,unsigned char m);
void US_DC(void)
{
unsigned char cTemp;
#if(BT2417 == 1)
unsigned int iBaudRate;
unsigned char cLoop;
unsigned char cBTBuf[32] = {0x00};
unsigned char m;
unsigned char cTmpBuf[32];
#endif
cTemp = GetDataFromRcvBuf();
switch(cTemp)
{
case 0x01:
//SerialSendByte(AD_Value[pe]>>8);
//SerialSendByte(AD_Value[pe]);
//SerialSendByte(AD_Value[thermal]>>8);
//SerialSendByte(AD_Value[thermal]);
break;
case 0x02:
//SerialSendByte(SPI_Read_Byte(0xc4));
//SerialSendByte(SPI_Read_Byte(0xc5));
//SerialSendByte(SPI_Read_Byte(0xc6));
//SerialSendByte(SPI_Read_Byte(0xc7));
//SerialSendByte(SPI_Read_Byte(0xc8));
//SPI_Erase_Sector(0);
//SPI_Write_Byte(0,0x55);
//for(i = 0;i<10;i++)
//SerialSendByte(cBuf[i]);
//SPI_Write_nBytes(0,cBuf,1024*4);
break;
case 0x03:
HexPrint();//enter hex mode
break;
case 0x04:
SelfTestPrint();//
break;
case 0x05:
bFontBig5 = 1;
break;
case 0x06:
bFontBig5 = 0;
break;
case 0x07:
break;
default:
break;
}
}
//***********************************************
//*US ESC m nL nH d1... dn
//* 设置代码页
void US_ESC(void)
{
// unsigned int iLoop;
unsigned char cTemp;
if(GetDataFromRcvBuf() == 0x1f)
{
cTemp = GetDataFromRcvBuf();
SPI_Read_nBytes(UndefinedAddr,(uint8_t *)&EEPROM,sizeof(EEPROM_STRUCT));
if(cTemp == 0xff)
{
EEPROM.CodePage = GetDataFromRcvBuf();
SPI_Erase_Sector(UndefinedAddr);
SPI_Write_nBytes(UndefinedAddr,(uint8_t *)&EEPROM,sizeof(EEPROM_STRUCT));
cCodePage = EEPROM.CodePage;
}
else if(cTemp == 0xfd)
{
EEPROM.SerialBauRate = GetDataFromRcvBuf();
switch(EEPROM.SerialBauRate)
{
case 0:
iBaudRate = 4800;
break;
case 1:
iBaudRate = BAUDRATE9600;
break;
case 2:
iBaudRate = BAUDRATE19200;
break;
case 3:
iBaudRate = BAUDRATE38400;
break;
case 4:
iBaudRate = BAUDRATE57600;
break;
case 5:
iBaudRate = BAUDRATE115200;
break;
case 6:
iBaudRate = 2400;
break;
case 7:
iBaudRate = 1200;
break;
default:
iBaudRate = BAUDRATE115200;
break;
}
USART_Configuration();
SPI_Erase_Sector(UndefinedAddr);
SPI_Write_nBytes(UndefinedAddr,(uint8_t *)&EEPROM,sizeof(EEPROM_STRUCT));
}
}
}
void US_Updata_App(void){
app_enable_download();
soft_reset();
}
//***********************************************
//*ESCCommand
//*
//* ESC 指令
//*
void ESCCommand(unsigned char cParameter)
{
// MyPrintf("cParameter=%c\n",cParameter); // cParameter = '@'
switch(cParameter)
{
case ' ':
ESC_SP(); // ESC SP 1B 20
break;
case 'J':
ESC_J(); // ESC J 1B 4A
break;
case 'M':
ESC_M(); // ESC M 1B 4D
break;
case '3':
ESC_3(); // ESC 3 1B 33
break;
case '2':
ESC_2(); // ESC 2 1B 32
break;
case 'U':
ESC_U(); // ESC U 1B 55
break;
case 'V':
ESC_V(); // ESC V 1B 56
break;
case 'W':
ESC_W(); // ESC W 1B 57
break;
case 't':
ESC_t(); // ESC t 1B 74
break;
case 'R':
ESC_R(); // ESC R 1B 52
break;
case '!':
ESC_ExcalmatoryMark();// ESC ! 1B 21
break;
case '%':
ESC_mod(); // ESC % 1B 25
break;
case '&':
ESC_and(); // ESC & 1B 26
break;
case '*':
ESC_star(); // ESC * 1B 2A
break;
case 'c':
ESC_c(); // ESC c 1B 63
break;
case 'd':
ESC_dcmd(); // ESC d 1B 64
break;
case 'a':
ESC_acmd(); // ESC a 1B 61
break;
case 'e':
//ESC_ecmd(); // ESC e
break;
case '?':
ESC_interrogation(); // ESC ? 1B 3F
break;
case 'D':
ESC_D(); // ESC D 1b 44
break;
case '-':
ESC_subb(); // ESC - 1B 2D
break;
case '{':
ESC_Bigbrace(); // ESC { 1B 7B
break;
case '=':
//ESC_equal(); // ESC =
break;
case 'E':
ESC_E(); // ESC E 1B 45
break;
case 'G':
ESC_G(); // ESC G 1B 47
break;
case 'N':
ESC_N(); // ESC N 1B 4E
break;
case 'm':
//ESC_m(); // ESC m
break;
case 'u':
//ESC_ucmd(); // ESC u
break;
case 'v':
ESC_v(); // ESC v 1B 76
break;
case '@':
ESC_ATInit(); // ESC @ 1B 40
f_lable_printing = 0;
break;
case 'p':
ESC_p(); // ESC p 1B 70
break;
case 'q':
ESC_q(); // ESC q 1B 71
break;
case 'r':
ESC_r(); // ESC r 1B 72
break;
case '$':
ESC_$(); // ESC $ 1B 24
break;
case '\\'://反斜杠用法,反斜杠不能单独使用
ESC_backslash(); // ESC \ 1B 2F
break;
case 'B':
ESC_B(); // ESC B 1B 42
break;
case 'C':
// ESC_C(); // ESC B 1B 43
break;
default:
break;
}
}
//***********************************************
//*FSCommand
//*
//* FS 指令
//*
void FSCommand(unsigned char cParameter)
{
switch(cParameter)
{
case '.':
FS_dot(); // FS .
break;
case '&': //FS &
FS_and();
break;
case 'S': // FS S
FS_S();
break;
case '!': // FS !
FS_ExcalmatoryMark();
break;
case '-':
FS_subb(); // FS -
break;
case '2':
FS_2(); // FS 2
break;
case '?':
//FS_interrogation(); // FS ?
break;
case 'C':
//FS_C(); // FS C
break;
case 'W':
FS_W(); // FS W
break;
case 'p':
FS_p(); // FS p
break;
case 'q':
FS_q(); // FS q
break;
default:
break;
}
}
//***********************************************
//*GSCommand
//*
//* GS 指令
//*
void GSCommand(unsigned char cParameter)
{
// MyPrintf("cParameter=%d\n",cParameter);
switch(cParameter)
{
case 'L':
GS_L(); // GS L
break;
case 'I': //0X49
GS_I(); // GS I
break;
case 'W':
GS_W(); // GS W
break;
case 'v':
GS_v(); // GS v
break;
case '*':
GS_star(); // GS *
break;
case 'r':
//GS_r(); // GS r
break;
case '/':
GS_slash(); // GS /
break;
case 'E':
//GS_E(); // GS E
break;
case 'C':
//GS_C(); // GS C
break;
case '!':
GS_ExcalmatoryMark(); // GS !
break;
case 'B':
GS_B(); // GS B
break;
case 'H':
GS_H(); // GS H
break;
case 'f':
GS_f(); // GS f
break;
case 'k':
GS_k(); // GS k
break;
case 'h':
GS_h(); //GS h
break;
case 'w':
GS_w(); //GS w
break;
case '(': //GS ( //0x28
// MyPrintf("GS_1D28_\n");
GS_1D28();
break;
default:
break;
}
}
//***********************************************
//*
//*
//* US 指令
//*
void USCommand(unsigned char cParameter)
{
switch(cParameter)
{
case DC:
US_DC();
break;
case ESC:
US_ESC();
break;
case 0x0E:
break;
case 0x55:
US_Updata_App();
default:
break;
}
}
void PrinterRespond(u8 *cData,u8 leng){
if(Rcv_Port == RCV_TYPE_SPP){//1
BT_SendSppData(cData,leng);
}
else if(Rcv_Port == RCV_TYPE_BLE){//0
BT_SendBleData(cData,leng);
}
else if(Rcv_Port == RCV_TYPE_USB){//2
usb1_respond(cData,leng);
}
}
/**********************************END*****************************************/
// CmdSet.h
#ifndef _CMDSET_H_
#define _CMDSET_H_
//CmdSet.h
#include "type.h"
#define EOT 0x04
#define ENQ 0x05
#define ACK 0x06
#define GS 0x1d
#define HT 0x09
#define LF 0x0a
#define FF 0x0c
#define CR 0x0d
#define DLE 0x10
#define DC 0x11
#define NAK 0x15
#define SYN 0x16
#define ETB 0x17
#define CAN 0x18
#define ESC 0x1b
#define FS 0x1c
#define US 0x1f
#define END 0x64
#define LSB 1
#define BIT0 LSB
#define BIT1 2
#define BIT01 3
#define BIT2 4
#define BIT3 8
#define BIT23 12
#define BIT4 16
#define BIT5 32
#define BIT6 64
#define BIT56 96
#define BIT7 128
#define LINE_SPACE 6
/***************************************************************************************************/
void HTCmd(void);
void LFCmd(void);
void CRCmd(void);
void DLECmd(void);
void ESCCommand(unsigned char data);
void FSCommand(unsigned char data);
void GSCommand(unsigned char data);
void USCommand(unsigned char data);
void PrinterRespond(u8 *cData,u8 leng);
void usb1_respond(byte const *buff,byte size);
void save_databuffer(unsigned int data_len);
extern unsigned int ionedotlineFlag ; //每一点行标记
extern void ExecuteCmd(unsigned char data);
extern void ESC_ATInit(void);
extern void GS_k(void);
extern void GS_MoveToCut(unsigned char mode);
extern void Updata_finish_information_in_ble(unsigned char data);
#define data_receive_finish 0x09
extern volatile unsigned char SetTphDensitycounter;
extern unsigned char bBTPrintingFlag ;
extern unsigned char bIOSPrintingClearFlag;
extern uint8_t pape_current;
extern uint8_t page_tatal;
/**********************************END*****************************************/
#endif
YC3121_PT26\Source:第5个开始的文件
于 2024-04-17 15:48:05 首次发布