PT606668DC\Src:第1~7

//                       DeviceDB.c



/****************************************************************************
 * File Name: DeviceDB.c
 *
 * Description:
 *					DeviceDB
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2019/12/05		Original
 *
 *****************************************************************************/
#include "hal.h"
#include <string.h>
#include "DeviceDB.h"
#include "Version.h"
#include "Structures.h"
#include "Language.h"
#include "Printer.h"
const ST_DEVICE_DATABASE DeviceDB_Default = {
    .ValidCheck1    = VALID_CHECK_VALUE,
    .TableVersion   = DEVICE_DB_TABLE_VERSION,
    .PrintConfig    = { 
        .Depth      = PRINT_DEPTH_6,
        .Speed      = PRINT_SPEED_3,
#if defined(MODEL_PT68DC) || defined(MODEL_PT60DC)
        .PaperType  = PAPER_TYPE_RFID,
#else
        .PaperType  = PAPER_TYPE_GAP,
#endif
        .PrintMode  = PRINT_MODE_NORMAL,
		.Distance   = 10,
        .TxPower    = 15,
        .LabelSize  = {0, 0},
    },
#if defined(BRAND_ORVED)
    .Language       = LANGUAGE_ITALIANO,
#elif defined(BRAND_RU)
    .Language       = LANGUAGE_RU,
#else
    .Language       = LANGUAGE_CHINESE,
#endif    
    .ShutMode       = SHUT_MODE_NEVER,
    .ValidCheck2    = VALID_CHECK_VALUE,
};
ST_DEVICE_DATABASE DeviceDB = {
    .ValidCheck1    = VALID_CHECK_VALUE,
    .TableVersion   = DEVICE_DB_TABLE_VERSION,
    .PrintConfig    = { 
        .Depth      = PRINT_DEPTH_6,
        .Speed      = PRINT_SPEED_3,
#if defined(MODEL_PT68DC) || defined(MODEL_PT60DC)
        .PaperType  = PAPER_TYPE_RFID,
#else
        .PaperType  = PAPER_TYPE_GAP,
#endif
        .PrintMode  = PRINT_MODE_NORMAL,
		.Distance   = 10,
        .TxPower    = 15,
        .LabelSize  = {0, 0},
    },
#if defined(BRAND_ORVED)
    .Language       = LANGUAGE_ITALIANO,
#elif defined(BRAND_RU)
    .Language       = LANGUAGE_RU,
#else
    .Language       = LANGUAGE_CHINESE,
#endif   
    .ShutMode       = SHUT_MODE_NEVER,
    .GapVoltageThreshold = 0,
    .ValidCheck2    = VALID_CHECK_VALUE,
};
BOOL DeviceDBChangeFlag = 0;

void DeviceDB_FactoryDefault(void)
{
    ENUM_LANGUAGE lang = DeviceDB.Language;
    
    DeviceDB = DeviceDB_Default;
    DeviceDB.Language = lang;
    DeviceDB.GapVoltageThreshold = 0;
    DeviceDB_Save();
}
void DeviceDB_Load(void)
{
    ExtFlash_Read(FLASH_ADDRESS_DEVICE_DB, (BYTE *)&DeviceDB, sizeof(ST_DEVICE_DATABASE));
    #if defined(BRAND_ORVED)   //ITALIANO  
        if((DeviceDB.Language != LANGUAGE_ITALIANO) && (DeviceDB.Language != LANGUAGE_ENGLISH))
        {
            DeviceDB.Language = LANGUAGE_CHINESE;
        }
    #elif defined(BRAND_RU)     // RU
        if((DeviceDB.Language != LANGUAGE_RU) && (DeviceDB.Language != LANGUAGE_ENGLISH))
        {
            DeviceDB.Language = LANGUAGE_CHINESE;
        }
    #else   // Chinese
        if((DeviceDB.Language != LANGUAGE_CHINESE) && (DeviceDB.Language != LANGUAGE_ENGLISH))
        {
            DeviceDB.Language = LANGUAGE_CHINESE;
        }
    #endif
    if((DeviceDB.ValidCheck1 != VALID_CHECK_VALUE) || (DeviceDB.ValidCheck2 != VALID_CHECK_VALUE) || (DeviceDB.TableVersion != DEVICE_DB_TABLE_VERSION))
    {
        DeviceDB = DeviceDB_Default;
        DeviceDB_Save();
    }
    if(DeviceDB.GapVoltageThreshold > 0)
    {
        Printer_SetPaperGapVoltageThreshold(DeviceDB.GapVoltageThreshold);
    }
    
    LanguageSwitch(DeviceDB.Language);
#ifdef MODEL_PT68DC
    UHF_SetTxPower(MIN(25, DeviceDB.PrintConfig.TxPower) * 100, DeviceDB.PrintConfig.TxPower * 100, 1, 0);
#endif
}
void DeviceDB_Save(void)
{
    ExtFlash_Erase4K(FLASH_ADDRESS_DEVICE_DB);
    ExtFlash_Write(FLASH_ADDRESS_DEVICE_DB,(BYTE *)&DeviceDB, sizeof(ST_DEVICE_DATABASE));
    DeviceDBChangeFlag = 0;
}























//                           DeviceDB.h  



/****************************************************************************
 * File Name: DeviceDB.h
 *
 * Description:
 *					DeviceDB
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2019/12/05		Original
 *
 *****************************************************************************/
#ifndef __DEVICE_DB_H__
#define __DEVICE_DB_H__
#include "hal.h"

extern ST_DEVICE_DATABASE DeviceDB;
extern BOOL DeviceDBChangeFlag;
void DeviceDB_FactoryDefault(void);
void DeviceDB_Load(void);
void DeviceDB_Save(void);

#endif

























//                            EscCommand.c   



/****************************************************************************
 * File Name: EscCommand.c
 *
 * Description:
 *					EscCommand
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2019/02/19		Original
 *
 *****************************************************************************/
#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "hal.h"
#include "EscCommand.h"
#include "Printer.h"
#include "Version.h"
#include "CRC16.h"
#include "usbd_cdc_if.h"
#include "MFG.h"
#include "UI.h"
#define ESC_CMD_BUFFER_SIZE     1030
#define CMD_TIMEOUT             (5000)


enum
{
    YMODEM_DATA_128 = 0x01,
    YMODEM_DATA_1K  = 0x02,
    YMODEM_END      = 0x04,
    YMODEM_CANCEL   = 0x18,
    YMODEM_ACK      = 0x06,
    YMODEM_NACK     = 0x15,
    YMODEM_BEGIN    = 0x43,
};
enum
{
    ESC_EXECUTION_SET_PRINT_DENSITY,
    ESC_EXECUTION_SET_PRINT_SPEED,
    ESC_EXECUTION_SET_PAPER_TYPE,
    ESC_EXECUTION_SET_PRINT_MODE,
    ESC_EXECUTION_SET_LABEL_SIZE,
    ESC_EXECUTION_SET_BOOT_LOGO,
    ESC_EXECUTION_CLEAR_BOOT_LOGO,
    ESC_EXECUTION_SET_NFC_PASSWORD,
    ESC_EXECUTION_SET_RIBBONS_LENGTH,
    ESC_EXECUTION_ENTER_UPGRADE_MODE,
    ESC_EXECUTION_GET_PRINTER_INFO,
    ESC_EXECUTION_GET_TAPE_STATE,
    ESC_EXECUTION_GET_TAPE_STATUS,
    ESC_EXECUTION_GET_BATTERY_STATUS,
    ESC_EXECUTION_GET_WIRELESS_STATUS,
    ESC_EXECUTION_GET_PRINTER_MAX_WIDTH,
//    ESC_EXECUTION_DOWNLOAD_BITMAP,    
    ESC_EXECUTION_GET_PRINTER_STATUS,
    ESC_EXECUTION_SET_LABEL_INFO,
    ESC_EXECUTION_PRINT_ROW,
    ESC_EXECUTION_PRINT_RLE_ROW,
    ESC_EXECUTION_FEEDPAPER,
    ESC_EXECUTION_FEEDPAPER_TO_GAP,    
    ESC_EXECUTION_WRITE_HF_RFID,
    ESC_EXECUTION_WRITE_UHF_RFID,    
    ESC_EXECUTION_FW_UPGRADE_CONFIRM,
    
    ESC_EXECUTION_HORIZONTAL_MOVE,
    ESC_EXECUTION_PRINT_MOVE_LINE,
    ESC_EXECUTION_PRINT_AND_ENTER,
    ESC_EXECUTION_STATE_TRANSMIT,
    ESC_EXECUTION_SET_RIGHT_INTERVAL,
    ESC_EXECUTION_SELECT_PRINT_MODE,
    ESC_EXECUTION_SET_PRINT_POSITION,
    ESC_EXECUTION_SEL_CANCEL_USER_CHAR,
    ESC_EXECUTION_USER_DEFINE_CHAR,
    ESC_EXECUTION_SELECT_BITMAP_MODE,
    ESC_EXECUTION_SEL_CANCEL_UNDERLINE_MODE,
    ESC_EXECUTION_SET_DEFAULT_RAW_HIGHT,
    ESC_EXECUTION_SET_RAW_HIGHT,
    ESC_EXECUTION_SELECT_EXTERNAL_EQUIPMENT,
    ESC_EXECUTION_CANCEL_USER_CHAR,
    ESC_EXECUTION_INIT_PRINTER,
    ESC_EXECUTION_SET_HORI_MOVE_POSITION,
    ESC_EXECUTION_SEL_CANCEL_BOLD_MODE,
    ESC_EXECUTION_SEL_CANCEL_DOUBLE_PRINTING,
    ESC_EXECUTION_PRINT_MOVE_PAPER,
    ESC_EXECUTION_SELECT_FONT,
    ESC_EXECUTION_SEL_INTERNATIONAL_CHAR_SET,
    ESC_EXECUTION_HORIZONTAL_AMPLIFY,
    ESC_EXECUTION_VERTICAL_AMPLIFY,
    ESC_EXECUTION_HORI_VERTI_AMPLIFY,
    ESC_EXECUTION_SET_RELATIVE_HORI_PRINT_POSITION,
    ESC_EXECUTION_SEL_CHAR_ALIGN_MODE,
    ESC_EXECUTION_EN_DISABLE_REVERSE_PRINTING,
    ESC_EXECUTION_EN_DISABLE_BUTTON,
    ESC_EXECUTION_PRINT_MOVE_N_LINE,
    ESC_EXECUTION_EN_DISABLE_INVERSE_PRINTING,
    ESC_EXECUTION_SELECT_CHRAR_CODE_PAGE,
    ESC_EXECUTION_SEL_CANCEL_INVERTED_PRINTING,
    ESC_EXECUTION_FS_CONTROL,
    ESC_EXECUTION_SEL_CANCEL_ROTATE_90_DEGREES,
    ESC_EXECUTION_PRINT_PRE_STORED_BITMAP,
    ESC_EXECUTION_SELECT_CHAR_SIZE,
    ESC_EXECUTION_EXECUTE_TEST_PRINT,
    ESC_EXECUTION_EN_DISABLE_REALTIME_CMD,
    ESC_EXECUTION_DEFINE_DOWNLOAD_BITMAP,
    ESC_EXECUTION_PRINT_DOWNLOAD_BITMAP,
    ESC_EXECUTION_SEL_CANCEL_WHITE_BLACK_REVERSE,
    ESC_EXECUTION_QUERY_PRINTER_ID,
    ESC_EXECUTION_SET_LEFT_MARGIN,
    ESC_EXECUTION_SET_HORI_VERTI_MOVE_UNIT,
    ESC_EXECUTION_SET_PRINT_AREA_WIDTH,
    ESC_EXECUTION_SET_AUTO_STATE_RETURN,
    ESC_EXECUTION_SEL_QRCODE_TYPE,
    ESC_EXECUTION_ESC_PRINT_QRCODE,
    ESC_EXECUTION_PRINT_QRCODE,
    
//    ESC_EXECUTION_ENTER_SETUP_MODE,
//    ESC_EXECUTION_EXIT_SETUP_MODE,
//    ESC_EXECUTION_SET_BLUETOOTH_PASSWORD,
//    ESC_EXECUTION_SET_BLUETOOTH_MASTER_SLAVE_MODE,
//    ESC_EXECUTION_SET_BLUETOOTH_NAME,
//    ESC_EXECUTION_SET_BLUETOOTH_TYPE,
//    ESC_EXECUTION_SET_BLUETOOTH_PASSWORD_ENABLE,
//    ESC_EXECUTION_SET_LANGUAGE,
//    ESC_EXECUTION_SET_BLACK_MARK_POSITION,
//    ESC_EXECUTION_SET_PRINT_CMD_SET,
//    ESC_EXECUTION_SET_MANUFACTURER_NAME,
//    ESC_EXECUTION_SET_PRINTER_MODEL,
//    ESC_EXECUTION_SET_PRINT_FONT,
//    ESC_EXECUTION_SET_BLACK_MARK_MODE,
//    ESC_EXECUTION_SET_SERIAL_PORT_PARS,
//    ESC_EXECUTION_SET_STANDBY_TIME,
//    ESC_EXECUTION_SET_PAPER_SENSOR_SENSITIVITY,
//    ESC_EXECUTION_SET_PRINTER_SERIAL_NUMBER,
//    ESC_EXECUTION_SET_PRINT_DIRECTION,
//    ESC_EXECUTION_SET_DEFAULT_CODE_PAGE,
//    ESC_EXECUTION_SET_WIFI_AP_PARS,
};
typedef UINT16 ENUM_ESC_EXECUTION_ID;
enum
{
    ESC_CMDID_STATUS_GET      		= 0x10,
    ESC_CMDID_PARAM_CONFIG    		= 0x1D,
    ESC_CMDID_LABEL_SET           = 0x17,
    ESC_CMDID_PRINT_BLANK         = 0x15,
    ESC_CMDID_PRINT_ROW           = 0x16,
    ESC_CMDID_PRINT_RLE_ROW       = 0x18,
    ESC_CMDID_PRINT_TO_END        = 0x0C,
    ESC_CMDID_CONTROL             = 0x1B,
	ESC_CMDID_FS_CONTROL          = 0x1C,
	                                
    ESC_CMDID_HORIZONTAL_MOVE     = 0x09,
		ESC_CMDID_PRINT_MOVE_LINE     = 0x0A,
		ESC_CMDID_PRINT_AND_ENTER	    = 0x0D,
		ESC_CMDID_STATE_TRANSMIT	    = 0x04,
		ESC_CMDID_SET_RIGHT_INTERVAL	= 0x20,
		ESC_CMDID_SELECT_PRINT_MODE		= 0x21,
		ESC_CMDID_SET_PRINT_POSITION	= 0x24,
		ESC_CMDID_SEL_CANCEL_USER_CHAR       = 0x25,
		ESC_CMDID_USER_DEFINE_CHAR	  = 0x26,
		ESC_CMDID_SELECT_BITMAP_MODE  = 0x2A,
		ESC_CMDID_SEL_CANCEL_UNDERLINE_MODE  = 0x2D,
		ESC_CMDID_SET_DEFAULT_RAW_HIGHT      = 0x32,
		ESC_CMDID_SET_RAW_HIGHT  			= 0x33,
		ESC_CMDID_SELECT_EXTERNAL_EQUIPMENT	 = 0x3D,
		ESC_CMDID_CANCEL_USER_CHAR		= 0x3F,
		ESC_CMDID_INIT_PRINTER				= 0x40,
		ESC_CMDID_SET_HORI_MOVE_POSITION		 = 0x44,
		ESC_CMDID_SEL_CANCEL_BOLD_MODE		   = 0x45,
		ESC_CMDID_SEL_CANCEL_DOUBLE_PRINTING = 0x47,
		ESC_CMDID_PRINT_MOVE_PAPER 		= 0x4A,
		ESC_CMDID_SELECT_FONT 				= 0x4D,
		ESC_CMDID_SEL_INTERNATIONAL_CHAR_SET = 0x52,
		ESC_CMDID_HORIZONTAL_AMPLIFY	= 0x55,
		ESC_CMDID_VERTICAL_AMPLIFY		= 0x56,
		ESC_CMDID_HORI_VERTI_AMPLIFY	= 0x57,
		ESC_CMDID_SET_RELATIVE_HORI_PRINT_POSITION	= 0x5C,
		ESC_CMDID_SEL_CHAR_ALIGN_MODE	= 0x61,
		ESC_CMDID_EN_DISABLE_REVERSE_PRINTING	= 0x63,
		ESC_CMDID_EN_DISABLE_BUTTON		= 0x35,
		ESC_CMDID_PRINT_MOVE_N_LINE		= 0x64,
		ESC_CMDID_EN_DISABLE_INVERSE_PRINTING	= 0x69,
		ESC_CMDID_SELECT_CHRAR_CODE_PAGE	= 0x74,
		ESC_CMDID_SEL_CANCEL_INVERTED_PRINTING	= 0x7B,		
		ESC_CMDID_SEL_CANCEL_ROTATE_90_DEGREES  = 0x49,
		ESC_CMDID_PRINT_PRE_STORED_BITMAP  = 0x50,
		ESC_CMDID_SELECT_CHAR_SIZE  	= 0x21,
		ESC_CMDID_EXECUTE_TEST_PRINT  = 0x41,
		ESC_CMDID_EN_DISABLE_REALTIME_CMD  = 0x44,
		ESC_CMDID_DEFINE_DOWNLOAD_BITMAP  = 0x2A,
		ESC_CMDID_PRINT_DOWNLOAD_BITMAP  = 0x2F,
		ESC_CMDID_SEL_CANCEL_WHITE_BLACK_REVERSE  = 0x42,
		ESC_CMDID_QUERY_PRINTER_ID  	= 0x49,
		ESC_CMDID_SET_LEFT_MARGIN  		= 0x4C,
		ESC_CMDID_SET_HORI_VERTI_MOVE_UNIT  		= 0x50,
		ESC_CMDID_SET_PRINT_AREA_WIDTH 		= 0x57,
		ESC_CMDID_SET_AUTO_STATE_RETURN		= 0x61,
		ESC_CMDID_SEL_QRCODE_TYPE			= 0x5A,
		ESC_CMDID_ESC_PRINT_QRCODE			= 0x5A,
		ESC_CMDID_PRINT_QRCODE			= 0x6B,
//		ESC_CMDID_ENTER_SETUP_MODE	= 0x09,
//		ESC_CMDID_EXIT_SETUP_MODE		= 0x15,
//		ESC_CMDID_SET_BLUETOOTH_PASSWORD		= 0x10,
//		ESC_CMDID_SET_BLUETOOTH_MASTER_SLAVE_MODE		= 0x11,
//		ESC_CMDID_SET_BLUETOOTH_NAME		= 0x13,
//		ESC_CMDID_SET_BLUETOOTH_TYPE		= 0x14,
//		ESC_CMDID_SET_BLUETOOTH_PASSWORD_ENABLE		= 0x27,
//		ESC_CMDID_SET_LANGUAGE					= 0x16,
//		ESC_CMDID_SET_BLACK_MARK_POSITION					= 0x17,
//		ESC_CMDID_SET_PRINT_CMD_SET			= 0x18,
//		ESC_CMDID_SET_MANUFACTURER_NAME	= 0x1B,
//		ESC_CMDID_SET_PRINTER_MODEL			= 0x1C,
//		ESC_CMDID_SET_PRINT_SPEED				= 0x1E,
//		ESC_CMDID_SET_PRINT_FONT				= 0x21,
//		ESC_CMDID_SET_BLACK_MARK_MODE		= 0x22,
//		ESC_CMDID_SET_SERIAL_PORT_PARS	= 0x23,
//		ESC_CMDID_SET_STANDBY_TIME			= 0x26,
//		ESC_CMDID_SET_PAPER_SENSOR_SENSITIVITY		= 0x28,
//		ESC_CMDID_SET_PRINTER_SERIAL_NUMBER				= 0x1D,
//		ESC_CMDID_SET_PRINT_DIRECTION		= 0x63,
//		ESC_CMDID_SET_DEFAULT_CODE_PAGE	= 0x74,
//		ESC_CMDID_SET_PRINT_DENSITY			= 0xFD,
//		ESC_CMDID_DOWNLOAD_BITMAP				= 0xFE,
//		ESC_CMDID_SET_WIFI_AP_PARS			= 0x30,
		
		
    // 0x13 RFID?
};
typedef BYTE ENUM_ESC_CMDID;

enum
{
    ESC_SUB_CMDID_PARAM_GET = 0x49,
    ESC_SUB_CMDID_PARAM_SET = 0x28,
};
typedef BYTE ENUM_ESC_SUB_CMD;
enum
{
    ESC_STATE_IDLE,
	
    ESC_STATE_SUB_FRAME_IN,    
    ESC_STATE_RECV_STATUS_GET,
    ESC_STATE_RECV_PARAM_CONFIG,		
    ESC_STATE_RECV_LABEL_SET,
    ESC_STATE_RECV_PRINT_BLANK,
    ESC_STATE_RECV_PRINT_ROW,
    ESC_STATE_RECV_PRINT_RLE_ROW,
    ESC_STATE_RECV_CONTROL,
    ESC_STATE_RECV_STATUS_FS,
	
    OTA_STATE_WAIT_START,
    OTA_STATE_WAIT_SELECT,
    OTA_STATE_YMODEM_HEAD,
    OTA_STATE_YMODEM_DATA_128,
    OTA_STATE_YMODEM_DATA_1K,
};
typedef BYTE ENUM_ESC_STATE;
enum
{
    CMD_MODE_ESC,
    CMD_MODE_OTA,
};
typedef BYTE ENUM_CMD_MODE;
enum
{
    INTERFACE_NONE,
    INTERFACE_USB,
    INTERFACE_BT,
};
typedef BYTE ENUM_INTERFACE;
typedef struct
{
    ENUM_INTERFACE  Interface;
    ENUM_CMD_MODE   Mode;
    ENUM_ESC_STATE  State;
    ENUM_ESC_CMDID  CmdID;
    BYTE            DataBuffer[ESC_CMD_BUFFER_SIZE];
    UINT16          DataLength;
    BYTE            SubDataIndex;
    UINT16          SubDataLength;
    
    UINT32          OtaAddrIndex;
    char            OtaFilename[100];
    char            OtaFilesize[10];
    UINT32          IdleTime;
    BOOL            SetupModeEn;
}ST_CMD_DB;

 ST_CMD_DB CmdDB = {
    .Interface  = INTERFACE_NONE,
    .Mode       = CMD_MODE_ESC,
    .State      = ESC_STATE_IDLE,
    .CmdID      = 0,
    .DataBuffer = {0},
    .DataLength = 0,
    .SubDataIndex   = 0,
    .SubDataLength  = 0,
    .SetupModeEn    = 0,
};
#ifdef MODEL_PT68DC
static ST_ISO18K6C_FILTER_INFO TagFilterStatus = {0};
#endif


typedef struct
{
    BYTE Len;
    BYTE Data[CDC_DATA_FS_MAX_PACKET_SIZE];
}ST_USBCMD_PACKET;

//ST_PRINTER_CONFIG g_PrinterConfig = {
		"11101806666",
//		.MAC_Add  = {0xA0,0xBB,0x00,0xDD,0x0E,0xFF},
//};
//static const BYTE BitReverseTable256[256] = 
//{
//  0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 
//  0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 
//  0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 
//  0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 
//  0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 
//  0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
//  0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 
//  0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
//  0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
//  0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 
//  0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
//  0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
//  0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 
//  0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
//  0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 
//  0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
//};
static QueueHandle_t     UsbQueueHandle = NULL;
void TIM5_IRQHandler(void)
{
    // Internal 100ms
    if(__HAL_TIM_GET_FLAG(&htimCMD, TIM_FLAG_UPDATE) != RESET)  
    {   
        __HAL_TIM_CLEAR_IT(&htimCMD, TIM_IT_UPDATE);
        if(CmdDB.IdleTime >= (CMD_TIMEOUT / 100))
        {
            HAL_TIM_Base_Stop_IT(&htimCMD);
            CmdDB.IdleTime = 0;
            if(CmdDB.Interface != INTERFACE_NONE)
            {
                CmdDB.Interface = INTERFACE_NONE;
                CmdDB.State     = ESC_STATE_IDLE;
            }
        }
        CmdDB.IdleTime++;
    }
}
static void IdleTimerStart(void)
{
    CmdDB.IdleTime = 0;
    __HAL_TIM_SET_COUNTER(&htimCMD, 0);
    HAL_TIM_Base_Start_IT(&htimCMD);
}
//static void IdleTimerStop(void)
//{
//    CmdDB.IdleTime = 0;
//    HAL_TIM_Base_Stop_IT(&htimCMD);
//}

static void DataResponse(BYTE *pData, UINT16 len)
{
    switch(CmdDB.Interface)
    {
        case INTERFACE_BT: 
            BT_WriteBuffer(pData, len, 100);
            break;
        case INTERFACE_USB:
            USB_Send(pData, len);
            break;
    }
}
static void CmdResponse(BYTE cmdID, ENUM_ERROR_CODE status, BYTE *pData, UINT16 length)
{
    BYTE head[8] = {0x1D, 0x28, 0x4C, (BYTE)(length + 3), (BYTE)((length + 3) >> 8),0x55, cmdID, status};
    switch(CmdDB.Interface)
    {
        case INTERFACE_BT:                
            BT_WriteBuffer(head, 8, 100);
            if(length > 0)
            {
                BT_WriteBuffer(pData, length, 100);
            }
            break;
        case INTERFACE_USB:
        {
//            USB_Send(head, 8);
//            if(length > 0)
//            {
//                USB_Send(pData, length);
//            }
            BYTE *ptr = pvPortMalloc(8 + length);
            memcpy(ptr, head, 8);
            memcpy(&ptr[8], pData, length);
            USB_Send(ptr, 8 + length);
            vPortFree(ptr);
            break;
        }
    }
}
static void StringResponse(char *str)
{
    switch(CmdDB.Interface)
    {
        case INTERFACE_BT:                
            BT_WriteString(str);
            break;
        case INTERFACE_USB:
            USB_Send((BYTE *)str, strlen(str));
            break;
    }
}
static void IdleTimerClear(void)
{
    CmdDB.IdleTime = 0;
}
static ENUM_ERROR_CODE EscCmdExecute(ENUM_ESC_EXECUTION_ID exeID, BYTE *pData, UINT16 dataLength)
{
    switch(exeID)
    {
				case ESC_EXECUTION_HORIZONTAL_MOVE:
					break;
				case ESC_EXECUTION_PRINT_MOVE_LINE:
					break;
				case ESC_EXECUTION_PRINT_AND_ENTER:
					break;
				case ESC_EXECUTION_STATE_TRANSMIT:
					break;
				case ESC_EXECUTION_SET_RIGHT_INTERVAL:
					break;
				case ESC_EXECUTION_SELECT_PRINT_MODE:
					break;
				case ESC_EXECUTION_SET_PRINT_POSITION:
					break;
				case ESC_EXECUTION_SEL_CANCEL_USER_CHAR:
					break;
				case ESC_EXECUTION_USER_DEFINE_CHAR:
					break;
				case ESC_EXECUTION_SELECT_BITMAP_MODE:
					break;
				case ESC_EXECUTION_SEL_CANCEL_UNDERLINE_MODE:
					break;
				case ESC_EXECUTION_SET_DEFAULT_RAW_HIGHT:
					break;
				case ESC_EXECUTION_SET_RAW_HIGHT:
					break;
				case ESC_EXECUTION_SELECT_EXTERNAL_EQUIPMENT:
					break;
				case ESC_EXECUTION_CANCEL_USER_CHAR:
					break;
				case ESC_EXECUTION_INIT_PRINTER:
					break;
				case ESC_EXECUTION_SET_HORI_MOVE_POSITION:
					break;
				case ESC_EXECUTION_SEL_CANCEL_BOLD_MODE:
					break;
				case ESC_EXECUTION_SEL_CANCEL_DOUBLE_PRINTING:
					break;
				case ESC_EXECUTION_PRINT_MOVE_PAPER:
					break;
				case ESC_EXECUTION_SELECT_FONT:
					break;
				case ESC_EXECUTION_SEL_INTERNATIONAL_CHAR_SET:
					break;
				case ESC_EXECUTION_HORIZONTAL_AMPLIFY:
					break;
				case ESC_EXECUTION_VERTICAL_AMPLIFY:
					break;
				case ESC_EXECUTION_HORI_VERTI_AMPLIFY:
					break;
				case ESC_EXECUTION_SET_RELATIVE_HORI_PRINT_POSITION:
					break;
				case ESC_EXECUTION_SEL_CHAR_ALIGN_MODE:
					break;
				case ESC_EXECUTION_EN_DISABLE_REVERSE_PRINTING:
					break;
				case ESC_EXECUTION_EN_DISABLE_BUTTON:
					break;
				case ESC_EXECUTION_PRINT_MOVE_N_LINE:
					break;
				case ESC_EXECUTION_EN_DISABLE_INVERSE_PRINTING:
					break;
				case ESC_EXECUTION_SELECT_CHRAR_CODE_PAGE:
					break;
				case ESC_EXECUTION_SEL_CANCEL_INVERTED_PRINTING:
					break;
				case ESC_EXECUTION_SEL_CANCEL_ROTATE_90_DEGREES:
					break;
				case ESC_EXECUTION_PRINT_PRE_STORED_BITMAP:
					break;
				case ESC_EXECUTION_SELECT_CHAR_SIZE:
					break;
				case ESC_EXECUTION_EXECUTE_TEST_PRINT:
					break;
				case ESC_EXECUTION_EN_DISABLE_REALTIME_CMD:
					break;
				case ESC_EXECUTION_DEFINE_DOWNLOAD_BITMAP:
					break;
				case ESC_EXECUTION_PRINT_DOWNLOAD_BITMAP:
					break;
				case ESC_EXECUTION_SEL_CANCEL_WHITE_BLACK_REVERSE:
					break;
				case ESC_EXECUTION_QUERY_PRINTER_ID:
					break;
				case ESC_EXECUTION_SET_LEFT_MARGIN:
					break;
				case ESC_EXECUTION_SET_HORI_VERTI_MOVE_UNIT:
					break;
				case ESC_EXECUTION_SET_PRINT_AREA_WIDTH:
					break;
				case ESC_EXECUTION_SET_AUTO_STATE_RETURN:
					break;
				case ESC_EXECUTION_SEL_QRCODE_TYPE:
					break;
				case ESC_EXECUTION_ESC_PRINT_QRCODE:
					break;
				case ESC_EXECUTION_PRINT_QRCODE:
					break;				
//				case ESC_EXECUTION_ENTER_SETUP_MODE:
//					break;
//				case ESC_EXECUTION_EXIT_SETUP_MODE:
//					break;
//				case ESC_EXECUTION_SET_BLUETOOTH_PASSWORD:
//					break;
//				case ESC_EXECUTION_SET_BLUETOOTH_MASTER_SLAVE_MODE:
//					break;
//				case ESC_EXECUTION_SET_BLUETOOTH_NAME:
//					break;
//				case ESC_EXECUTION_SET_BLUETOOTH_TYPE:
//					break;
//				case ESC_EXECUTION_SET_BLUETOOTH_PASSWORD_ENABLE:
//					break;
//				case ESC_EXECUTION_SET_LANGUAGE:
//					break;
//				case ESC_EXECUTION_SET_BLACK_MARK_POSITION:
//					break;
//				case ESC_EXECUTION_SET_PRINT_CMD_SET:
//					break;
//				case ESC_EXECUTION_SET_MANUFACTURER_NAME:
//					break;
//				case ESC_EXECUTION_SET_PRINTER_MODEL:
//					break;
//				case ESC_EXECUTION_SET_PRINT_FONT:
//					break;
//				case ESC_EXECUTION_SET_BLACK_MARK_MODE:
//					break;
//				case ESC_EXECUTION_SET_SERIAL_PORT_PARS:
//					break;
//				case ESC_EXECUTION_SET_STANDBY_TIME:
//					break;
//				case ESC_EXECUTION_SET_PAPER_SENSOR_SENSITIVITY:
//					break;
//				case ESC_EXECUTION_SET_PRINTER_SERIAL_NUMBER:
//					break;
//				case ESC_EXECUTION_SET_PRINT_DIRECTION:
//					break;
//				case ESC_EXECUTION_SET_DEFAULT_CODE_PAGE:
//					break;
//				case ESC_EXECUTION_SET_WIFI_AP_PARS:
//					break;
				
        case ESC_EXECUTION_SET_PRINT_DENSITY:
//        #ifndef __DEBUG__
            DeviceDB.PrintConfig.Depth = MIN(14, pData[6]);
#if defined(MODEL_PT66DC)
            StringResponse("OK");
#endif
//        #endif
            break;
        case ESC_EXECUTION_SET_PRINT_SPEED:
            DeviceDB.PrintConfig.Speed = MIN(4, pData[6]);
#if defined(MODEL_PT66DC)
            StringResponse("OK");
#endif
            break;
        case ESC_EXECUTION_SET_PAPER_TYPE:
            DeviceDB.PrintConfig.PaperType = MIN(ENUM_PAPER_TYPE_COUNT - 1, pData[6]);
#if defined(MODEL_PT66DC)
            StringResponse("OK");
#endif
            break;
        case ESC_EXECUTION_SET_PRINT_MODE:
            DeviceDB.PrintConfig.PrintMode = MIN(ENUM_PRINT_MODE_COUNT - 1, pData[6]);
            break;
        case ESC_EXECUTION_SET_LABEL_SIZE:
            DeviceDB.PrintConfig.LabelSize.Width  = pData[6] | (pData[7] << 8);
            DeviceDB.PrintConfig.LabelSize.Height = pData[8] | (pData[9] << 8);
            break;
        case ESC_EXECUTION_SET_BOOT_LOGO:
            break;
        case ESC_EXECUTION_CLEAR_BOOT_LOGO:
            break;
        case ESC_EXECUTION_SET_NFC_PASSWORD:
            break;
        case ESC_EXECUTION_SET_RIBBONS_LENGTH:
            break;
        case ESC_EXECUTION_GET_PRINTER_INFO:
            switch(CmdDB.DataBuffer[1])
            {
//                case 0x65:    // get firmware version
//                    break;
                case 0x42:    // get vendor
                    DataResponse((BYTE *)"puty", 5);
                    break;
                case 0x43:    // get printer name
                    DataResponse((BYTE *)MODEL_NO, strlen(MODEL_NO) + 1);
                    break;
                case 0x44:    // get printer serial number
                    break;
                case 0x45:    // get supported chinese character 
                    break;
                case 0x46:    // get bluetooth MAC address
                    break;
                case 0x40:    // get FW version
                    DataResponse((BYTE *)pBL_INFO->Version, strlen(pBL_INFO->Version) + 1);
                    break;
                case 0x41:    // get BL version
                {
                    char buf[32] = "_";//"_02.001.BJ0930";
                    MFG_GetFWVersion(&buf[1]);
                    DataResponse((BYTE *)buf, strlen(buf) + 1);
                    break;
                }
            }
            break;            
        case ESC_EXECUTION_GET_TAPE_STATUS:
            break;
        case ESC_EXECUTION_GET_BATTERY_STATUS:
            break;
        case ESC_EXECUTION_GET_WIRELESS_STATUS:
            break;
        case ESC_EXECUTION_GET_PRINTER_MAX_WIDTH:
            break;
//        case ESC_EXECUTION_DOWNLOAD_BITMAP:
//            break;
        case ESC_EXECUTION_GET_PRINTER_STATUS:                            
            if(pData[1] == 1)     // get printer status
            {
                g_DeviceStatus.RealStatusFlag.Bits.Pause    = SystemStatus.PauseFlag;
                g_DeviceStatus.RealStatusFlag.Bits.HasError = (SystemStatus.NoPaper || SystemStatus.PHOpen || SystemStatus.NoDetectGap || SystemStatus.RibbonRunout || SystemStatus.RibbonNoDetect);
                DataResponse(&g_DeviceStatus.RealStatusFlag.Value, 1);
            }
            else if(pData[1] == 2) // get error status
            {
                g_DeviceStatus.ErorFlag.Bits.Fix1               = 1;
                g_DeviceStatus.ErorFlag.Bits.Fix0               = 0;
                g_DeviceStatus.ErorFlag.Bits.NoPaper            = SystemStatus.NoPaper || SystemStatus.NoDetectGap;
                g_DeviceStatus.ErorFlag.Bits.CoverOpen          = SystemStatus.PHOpen;
                g_DeviceStatus.ErorFlag.Bits.MotorError         = 0;
                g_DeviceStatus.ErorFlag.Bits.PrintHeadTempError = 0;
                g_DeviceStatus.ErorFlag.Bits.InvalidTape        = (SystemStatus.RibbonNoDetect);
#ifdef MODEL_PT66DC
                g_DeviceStatus.ErorFlag.Bits.TapeExhausted      = (SystemStatus.RibbonRunout);
#else
                g_DeviceStatus.ErorFlag.Bits.TapeExhausted      = (SystemStatus.RibbonNoDetect);
#endif
                DataResponse(&g_DeviceStatus.ErorFlag.Value, 1);
            }
            break;
        case ESC_EXECUTION_SET_LABEL_INFO:
        {
            ST_PRINT_LABEL_CONFIG config;
            config.PrintLength      = (UINT16)((pData[1] << 8) | pData[0]);
            config.PrintOffset      = (UINT16)((pData[3] << 8) | pData[2]);
            config.TapeWidth        = pData[4];
            config.DeviceType       = pData[5];
            config.LabelCount       = pData[6];
            config.LabelIndex       = pData[7];
            config.TotalDataCount   = (UINT32)((pData[11] << 24) | (pData[10] << 16) | (pData[9] << 8) | pData[8]);
            Printer_SetLabelConfig(config);
            g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 0;
            g_DeviceStatus.RealStatusFlag.Bits.PrintDone    = 0;
            g_DeviceStatus.RealStatusFlag.Bits.PrintCancel  = 0;
            break;
        }
        case ESC_EXECUTION_PRINT_ROW:
        {
            BYTE printData[48] = {0};
            //memset(printData, 0, 48);
            memcpy(printData, &pData[1], MIN(48, pData[0]));
            if(g_DeviceStatus.RealStatusFlag.Bits.DataReceived == 0)
            {
                g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 1;
            }
            Printer_PrintRow(printData);
            break;
        }
        case ESC_EXECUTION_PRINT_RLE_ROW:
        {
            if(g_DeviceStatus.RealStatusFlag.Bits.DataReceived == 0)
            {
                g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 1;
            }
            Printer_PrintRleRow(pData, dataLength);
            break;
        }
        case ESC_EXECUTION_FEEDPAPER:
            Printer_Feedpaper(CmdDB.DataBuffer[0]);
            break;
        case ESC_EXECUTION_FEEDPAPER_TO_GAP:
            Printer_FeedpaperToEnd();
            break;
        case ESC_EXECUTION_WRITE_HF_RFID:
        {
//            UINT16 totalLen = pData[2] | (pData[3] << 8);
//            UINT16 offset = 0;
//            Printer_RFIDInfoClear();
//            while((offset + 2) < totalLen)
//            {
//                BYTE blockNo = pData[6 + offset];
//                BYTE dataLen = pData[7 + offset];
//                Printer_RFIDInfoInsert(blockNo, &pData[8 + offset], dataLen);
//                offset = offset + 2 + dataLen;
//            }
            break;
        }
        case ESC_EXECUTION_WRITE_UHF_RFID:
            break;
        case ESC_EXECUTION_FW_UPGRADE_CONFIRM:
            UI_SendEvent(UIEVENT_UPGRADING, NULL);
            BT_WriteBuffer((BYTE *)"OK", 2, 1000);
            break;
        default:
            break;
    }
    return NO_ERROR;
}

void JumpToUpgradeApp(void)
{
#define BL_UPTRAGE_FUN_ADDRESS   (0x08000000)
    typedef void (*FUNC)(void);
    FUNC jump2app;
    __disable_irq();
//    HAL_UART_DeInit(&huart1);
//    HAL_UART_DeInit(&huart2);
    HAL_NVIC_DisableIRQ(USART1_IRQn);
    HAL_NVIC_DisableIRQ(USART2_IRQn);
    HAL_NVIC_DisableIRQ(USB_LP_CAN1_RX0_IRQn);
    HAL_NVIC_DisableIRQ(TIM2_IRQn);
    HAL_NVIC_DisableIRQ(TIM3_IRQn);
    HAL_NVIC_DisableIRQ(TIM4_IRQn);
    HAL_NVIC_DisableIRQ(TIM5_IRQn);
    HAL_NVIC_DisableIRQ(TIM6_IRQn);
    HAL_NVIC_DisableIRQ(TIM7_IRQn);
    HAL_NVIC_DisableIRQ(EXTI15_10_IRQn);
    HAL_NVIC_DisableIRQ(EXTI2_IRQn);
    HAL_NVIC_DisableIRQ(DMA1_Channel1_IRQn);
   // HAL_DeInit();
     SCB->VTOR = 0x08000000;
    jump2app=(FUNC)(*(__IO UINT32 *)(BL_UPTRAGE_FUN_ADDRESS + 4));
    __set_MSP(*(__IO UINT32 *)BL_UPTRAGE_FUN_ADDRESS);             // Initialize APP stack 
    jump2app();
}
static void OtaStateMachine(BYTE dataIn)
{
    switch(CmdDB.State)
    {
        case OTA_STATE_WAIT_START:
            if(dataIn == 0x55)
            {
                BT_WriteByte(0xAA, 1000);
                BT_WriteString("Waiting forthe file to be sent ...\r\n");
                CmdDB.State = OTA_STATE_WAIT_SELECT;
            }
            break;
        case OTA_STATE_WAIT_SELECT:
            if(dataIn == '1')
            {
                BT_WriteByte(YMODEM_BEGIN, portMAX_DELAY);
                CmdDB.State = OTA_STATE_YMODEM_HEAD;
            }
            else if(dataIn == '2')
            {
                CmdDB.DataLength = 0;
                CmdDB.Mode       = CMD_MODE_ESC;
                CmdDB.State      = ESC_STATE_IDLE;
            }
            break;
        case OTA_STATE_YMODEM_HEAD:
            if(dataIn == YMODEM_DATA_128)
            {
                CmdDB.DataBuffer[0]  = dataIn;
                CmdDB.DataBuffer[1]  = 0;
                CmdDB.DataLength     = 1;
                CmdDB.State       = OTA_STATE_YMODEM_DATA_128;
            }
            else if(dataIn == YMODEM_DATA_1K)
            {
                CmdDB.DataBuffer[0]  = dataIn;
                CmdDB.DataBuffer[1]  = 0;
                CmdDB.DataLength     = 1;
                CmdDB.State       = OTA_STATE_YMODEM_DATA_1K;
            }
            else if(dataIn == YMODEM_END)
            {
                BT_WriteByte(YMODEM_ACK, 1000);
            }
            else if(dataIn == YMODEM_CANCEL)
            {
                CmdDB.DataLength = 0;
                CmdDB.State      = ESC_STATE_IDLE;
                CmdDB.Mode       = CMD_MODE_ESC;
                BT_WriteByte(YMODEM_ACK, 1000);
            }
            break;
        case OTA_STATE_YMODEM_DATA_128:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = dataIn;
            }
            if(CmdDB.DataLength == 133)
            {
                UINT16 crc = (UINT16)((CmdDB.DataBuffer[131] << 8) | CmdDB.DataBuffer[132]);
                if((CmdDB.DataBuffer[1] == (BYTE)(~CmdDB.DataBuffer[2])) && (crc == CRC16(0, &CmdDB.DataBuffer[3], 128)))
                {
                    if(CmdDB.DataBuffer[3] == '\0')
                    {
                        BT_WriteByte(YMODEM_ACK, 1000);
                        BT_WriteString("\n\n\r Programming Completed Successfully!\n\r");
                        BT_WriteString(" -----------------------------------\n\r");
                        BT_WriteString(" Name: %s\r\n", CmdDB.OtaFilename);
                        BT_WriteString(" Size: %s\r\n", CmdDB.OtaFilesize);
                        BT_WriteString(" -----------------------------------\n");
                        
                        WriteFirmwareUpgrateFlag();
                        CmdDB.DataLength = 0;
                        CmdDB.State      = ESC_STATE_IDLE;
                        CmdDB.Mode       = CMD_MODE_ESC;
                        //HAL_NVIC_SystemReset();
                        JumpToUpgradeApp();
                        // show press "OK" to load new firmware
                        //UI_UpgradeModeConfirm(); 
                    }
                    else
                    {
                        BYTE i, j;
                        for(i = 0; i < 99; i++)
                        {
                            CmdDB.OtaFilename[i] = CmdDB.DataBuffer[i + 3];
                            if(CmdDB.DataBuffer[i + 3] == '\0')
                            {
                                break;
                            }
                        }
                        CmdDB.OtaFilename[i] = '\0';
                        for(j = 0; j < 9; j++)
                        {
                            CmdDB.OtaFilesize[j] = CmdDB.DataBuffer[i + 4 + j];
                            if(CmdDB.DataBuffer[i + 4 + j] == '\0')
                            {
                                break;
                            }
                        }
                        CmdDB.OtaFilesize[i] = '\0';
                        BT_WriteByte(YMODEM_ACK, 1000);
                        BT_WriteByte(YMODEM_BEGIN, 1000);
                    }
                }
                else
                {
                    BT_WriteByte(YMODEM_NACK, 1000);
                }
                CmdDB.State      = OTA_STATE_YMODEM_HEAD;
            }
            break;
        case OTA_STATE_YMODEM_DATA_1K:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = dataIn; 
            }          
            if(CmdDB.DataLength >= 1029)
            {
                UINT16 crc = (UINT16)((CmdDB.DataBuffer[1027] << 8) | CmdDB.DataBuffer[1028]);
                if((CmdDB.DataBuffer[1] == (BYTE)(~CmdDB.DataBuffer[2])) && (crc == CRC16(0, &CmdDB.DataBuffer[3], 1024)))
                {
                    UINT32 addr = FLASH_ADDRESS_DFU_BANK0 + CmdDB.OtaAddrIndex;
                    if((addr % 4096) == 0)
                    {
                        ExtFlash_Erase4K(addr);
                    }
                    ExtFlash_Write(addr, &CmdDB.DataBuffer[3], 1024);
                    CmdDB.OtaAddrIndex += 1024;
                    BT_WriteByte(YMODEM_ACK, 1000);
                }
                else
                {
                    BT_WriteByte(YMODEM_NACK, 1000);
                }
                CmdDB.State      = OTA_STATE_YMODEM_HEAD;
            }
            break;
        default:
            CmdDB.State = OTA_STATE_YMODEM_HEAD;
            break;
    }
}
static void EscStateMachine(BYTE data)
{
    switch(CmdDB.State)
    {
        case ESC_STATE_IDLE:
            CmdDB.CmdID = data;
            switch(CmdDB.CmdID)
            {
                case ESC_CMDID_HORIZONTAL_MOVE:
                    EscCmdExecute(ESC_EXECUTION_HORIZONTAL_MOVE, CmdDB.DataBuffer, CmdDB.DataLength);
                    break;
                case ESC_CMDID_PRINT_MOVE_LINE:
                    EscCmdExecute(ESC_EXECUTION_PRINT_MOVE_LINE, CmdDB.DataBuffer, CmdDB.DataLength);
                    break;
                case ESC_CMDID_PRINT_AND_ENTER:
                    EscCmdExecute(ESC_EXECUTION_PRINT_AND_ENTER, CmdDB.DataBuffer, CmdDB.DataLength);
                    break;
                case ESC_CMDID_FS_CONTROL:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_STATUS_FS;
                    break;
                case ESC_CMDID_PRINT_TO_END:
                    EscCmdExecute(ESC_EXECUTION_FEEDPAPER_TO_GAP, CmdDB.DataBuffer, CmdDB.DataLength);
                    break;
                case ESC_CMDID_STATUS_GET:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_STATUS_GET;
                    break;
                case ESC_CMDID_PARAM_CONFIG:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_PARAM_CONFIG;
                    break;
                case ESC_CMDID_LABEL_SET:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_LABEL_SET;
                    break;
                case ESC_CMDID_PRINT_BLANK:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_PRINT_BLANK;
                    break;
                case ESC_CMDID_PRINT_ROW:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_PRINT_ROW;
                    break;
                case ESC_CMDID_PRINT_RLE_ROW:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_PRINT_RLE_ROW;
                    break;
                case ESC_CMDID_CONTROL:
                    CmdDB.DataLength     = 0;
                    CmdDB.SubDataLength  = 0;
                    CmdDB.SubDataIndex   = 0;
                    CmdDB.State          = ESC_STATE_RECV_CONTROL;
                    break;
                default:
                    break;
            }
            break;
        case ESC_STATE_RECV_STATUS_GET:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(CmdDB.DataLength >= 2)
            {
                if(CmdDB.DataBuffer[0] == 0x06)      // real status
                {
                    EscCmdExecute(ESC_EXECUTION_GET_PRINTER_STATUS, CmdDB.DataBuffer, CmdDB.DataLength);
                }
                else if(CmdDB.DataBuffer[0] == 0x04)     
                {
                    EscCmdExecute(ESC_EXECUTION_GET_PRINTER_STATUS, CmdDB.DataBuffer, CmdDB.DataLength);
                }
                CmdDB.DataLength = 0;
                CmdDB.State = ESC_STATE_IDLE;
            }
            break;
        case ESC_STATE_RECV_PARAM_CONFIG:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(CmdDB.DataLength >= 1)
            {
                if(CmdDB.DataBuffer[0]       == 0x49) // get printer ID
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        EscCmdExecute(ESC_EXECUTION_GET_PRINTER_INFO, CmdDB.DataBuffer, CmdDB.DataLength);
                        CmdDB.DataLength = 0;
                        CmdDB.State = ESC_STATE_IDLE;
                    }
                }
                else if(CmdDB.DataBuffer[0]  == 0x28)
                {
                    if(CmdDB.DataLength == 4)
                    {
                        CmdDB.SubDataLength = CmdDB.DataBuffer[2] | (CmdDB.DataBuffer[3] << 8);
                        CmdDB.SubDataIndex = 0;
                    }
                    else if(CmdDB.DataLength > 4)
                    {
                        if(CmdDB.DataLength >= (CmdDB.SubDataLength + 4))
                        {
                            BYTE fn = CmdDB.DataBuffer[4];
                            BYTE m  = CmdDB.DataBuffer[5];
                            if(CmdDB.DataBuffer[1] == 0x4B)
                            {
                                switch(fn)
                                {
                                    case 48:    // set depth
                                        EscCmdExecute(ESC_EXECUTION_SET_PRINT_DENSITY, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 49:    // set speed
                                        EscCmdExecute(ESC_EXECUTION_SET_PRINT_SPEED, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 51:  // set paper type
                                        EscCmdExecute(ESC_EXECUTION_SET_PAPER_TYPE, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 53:    // set label size
                                        EscCmdExecute(ESC_EXECUTION_SET_LABEL_SIZE, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 52:    // set print mode
                                        EscCmdExecute(ESC_EXECUTION_SET_PRINT_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                }
                            }
                            else if(CmdDB.DataBuffer[1] == 0x4C)
                            {
                                switch(CmdDB.DataBuffer[4])
                                {
                                    case 48:    // set boot logo
                                        EscCmdExecute(ESC_EXECUTION_SET_BOOT_LOGO, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 49:    // clear boot logo
                                        EscCmdExecute(ESC_EXECUTION_CLEAR_BOOT_LOGO, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 50:    // set NFC password
                                        EscCmdExecute(ESC_EXECUTION_SET_NFC_PASSWORD, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 51:    // set ribbons length
                                        EscCmdExecute(ESC_EXECUTION_SET_RIBBONS_LENGTH, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
//                                    case 52:    // Enter upgrade mode
//                                        EscCmdExecute(ESC_EXECUTION_ENTER_UPGRADE_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                                        break;
                                    case 0x34:
                                    {// firmware Upgrade Confirm
                                        EscCmdExecute(ESC_EXECUTION_FW_UPGRADE_CONFIRM, CmdDB.DataBuffer, CmdDB.DataLength);
                                        CmdDB.DataLength = 0;
                                        CmdDB.Mode       = CMD_MODE_OTA;
                                        CmdDB.State      = OTA_STATE_WAIT_START;
                                        return;
                                    }
                                    case 0x55:  
                                        switch(m)
                                        {
                                            case 0x48:
                                                EscCmdExecute(ESC_EXECUTION_WRITE_HF_RFID, CmdDB.DataBuffer, CmdDB.DataLength);
                                                break;                                            
                                            case 0x49:
                                                EscCmdExecute(ESC_EXECUTION_WRITE_UHF_RFID, CmdDB.DataBuffer, CmdDB.DataLength);
                                                break;
                                            case 0x00: // GetStatus
                                            {
                                                typedef union
                                                {
                                                    BYTE val;
                                                    struct
                                                    {
                                                        BOOL Busy:1;
                                                        BOOL Pause:1;
                                                        BOOL NoPaper:1;
                                                        BOOL MotorError:1;
                                                        BOOL PHOpen:1;
                                                        BOOL Charging:1;
                                                        BOOL BTConn:1;
                                                        BOOL USBConn:1;
                                                    }bits;
                                                }ST_PRINTER_STATUS_1;
                                                typedef union
                                                {
                                                    BYTE val;
                                                    struct
                                                    {
                                                        BYTE BatLevel:3;
                                                        BOOL NoRibbon:1;
                                                        BOOL PrintCancel:1;
                                                        BOOL RFIDFail:1;
                                                        BOOL RFIDWriteBufFull:1;
                                                        BOOL Reserve:1;
                                                    }bits;
                                                }ST_PRINTER_STATUS_2;
                                                BYTE rsp[4];
                                                extern BYTE RFIDWriteFailRecordCount;
                                                ST_PRINTER_STATUS_1 printerStatus1;
                                                ST_PRINTER_STATUS_2 printerStatus2;
                                                printerStatus1.bits.USBConn     = SystemStatus.USBConn;
                                                printerStatus1.bits.BTConn      = SystemStatus.BTConn;
                                                printerStatus1.bits.Charging    = SystemStatus.Charging;
                                                printerStatus1.bits.PHOpen      = SystemStatus.PHOpen;
                                                printerStatus1.bits.MotorError  = 0;
                                                printerStatus1.bits.NoPaper     = SystemStatus.NoPaper || SystemStatus.NoDetectGap;;
                                                printerStatus1.bits.Pause       = SystemStatus.PauseFlag;
                                                printerStatus1.bits.Busy        = Printer_IsBusy();
                                                printerStatus2.bits.BatLevel    = SystemStatus.BatLevel;
#ifdef MODEL_PT66DC
                                                printerStatus2.bits.NoRibbon    = (SystemStatus.RibbonNoDetect) || (SystemStatus.RibbonRunout);
#else
                                                printerStatus2.bits.NoRibbon    = SystemStatus.RibbonNoDetect;
#endif
                                                printerStatus2.bits.PrintCancel = SystemStatus.AbortFlag;
                                                printerStatus2.bits.RFIDFail    = (RFIDWriteFailRecordCount > 0);
                                                printerStatus2.bits.RFIDWriteBufFull = Printer_RFIDWriteBufFullStatus();
                                                printerStatus2.bits.Reserve     = 0;
                                                SystemStatus.AbortFlag = 0;
                                                
                                                rsp[0] = printerStatus1.val;
                                                rsp[1] = printerStatus2.val;
                                                rsp[2] = Printer_GetBufferCount();
                                                rsp[3] = Printer_GetLastPrintLabelIndex();
                                                CmdResponse(m, NO_ERROR, rsp, 4);
                                                break;
                                            }
                                            case 0x01: // Move to Antenna
                                                Printer_MoveToAntenna();
                                                CmdResponse(m, NO_ERROR, NULL, 0);
                                                break;
                                            case 0x02: // Fallback to start position
//                                                WriteFirmwareUpgrateFlag();
//                                                JumpToUpgradeApp();
                                                Printer_FallbackToStart();
                                                CmdResponse(m, NO_ERROR, NULL, 0);
                                                break;
                                           
                                            case 0x03: 
                                            {
                                                ENUM_ERROR_CODE status = NO_ERROR;
                                                switch(CmdDB.DataBuffer[6])
                                                {
                                                    case 0x00:
                                                        if(SystemStatus.PauseFlag)
                                                        {
                                                            // resume
                                                            Printer_PrintResume();
                                                            SystemStatus.PauseFlag = 0;
                                                            UI_SendEvent(UIEVENT_PRINT_RESUME, NULL);   
                                                        }
                                                        break;
                                                    case 0x01:
                                                        // abort
                                                        SystemStatus.AbortFlag = 0;
                                                        SystemStatus.PauseFlag = 0;
                                                        Printer_PrintAbort();
                                                        UI_SendEvent(UIEVENT_PRINT_ABORT, NULL); 
                                                        break;
                                                    default:
                                                        status = ERROR_NO_SUPPORTED;
                                                        break;
                                                }
                                                CmdResponse(m, status, NULL, 0);
                                                break;
                                            }
                                            case 0x04: // Read RFID Write fail record
                                            {
                                                ENUM_ERROR_CODE status = NO_ERROR;
                                                BYTE rsp[101];
                                                rsp[0] = Printer_GetRFIDWriteFailRecord(&rsp[1]);
                                                CmdResponse(m, status, rsp, rsp[0] + 1);
                                                break;
                                            }
                                            case 0x38: // ISO14443A Read Tag Info
                                            {
                                            #ifdef MODEL_PT60DC
                                                BYTE rsp[10] = {0};
                                                ENUM_ERROR_CODE status = ISO14443A_Get_CardType_ID(&rsp[0], &rsp[2]);
                                                if(status == NO_ERROR)
                                                {
                                                    CmdResponse(m, NO_ERROR, rsp, 9);
                                                }
                                                else
                                                {
//                                                    Printer_StatusInit();
                                                    CmdResponse(m, status, NULL, 0);
                                                }
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x39: // ISO14443A Read Block Data
                                            {
                                            #if defined(MODEL_PT60DC) || defined(MODEL_PT66DC)
                                                BYTE rsp[16] = {0};
                                                //if(ISO14443A_Read_Block(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7], CmdDB.DataBuffer[13], &rsp[1]))
                                                ENUM_ERROR_CODE status = ISO14443A_Read_Block(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7], CmdDB.DataBuffer[13], rsp);
                                                if(status == NO_ERROR)
                                                {
                                                    CmdResponse(m, NO_ERROR, rsp, 16);
                                                }
                                                else
                                                {
//                                                    Printer_StatusInit();
                                                    CmdResponse(m, status, NULL, 0);
                                                }      
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x3A: // ISO14443A Write Block Data
                                            {
                                            #ifdef MODEL_PT60DC
                                                ENUM_ERROR_CODE status = ISO14443A_Write_Block(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7], CmdDB.DataBuffer[13], &CmdDB.DataBuffer[14]);
                                                if(status != NO_ERROR)
                                                {
//                                                    Printer_StatusInit();
                                                }
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x3B: // ISO14443A Write Block Data while printing
                                            {
                                            #ifdef MODEL_PT60DC
                                                Printer_HFWriteWhilePrinting(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7]);
                                            //    CmdResponse(m, NO_ERROR, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x60: // ISO18K6C Inventory once
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE rsp[66] = {0};
                                                ENUM_ERROR_CODE status = ISO18K6C_InventoryOnce(3000, (UINT16 *)&rsp[2], &rsp[4], (INT16 *)&rsp[0]);
                                                if(status == NO_ERROR)
                                                {
                                                    UINT16 pc = (rsp[3] << 8) | rsp[2];
                                                    //BYTE len = (pc >> 11) * 2 + 2;
                                                    BYTE len = ((pc >> 11) & 0x1F) * 2 + 4;
                                                    CmdResponse(m, NO_ERROR, rsp, len);
                                                }
                                                else
                                                {
                                                    CmdResponse(m, status, NULL, 0);
                                                    
                                                }                                                
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x61: // ISO18K6C Read
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE rsp[128] = {0};
                                                UINT16 addr = (CmdDB.DataBuffer[12] << 8) | CmdDB.DataBuffer[11];
                                                UINT16 readLen = CmdDB.DataBuffer[13]; //(CmdDB.DataBuffer[14] << 8) | CmdDB.DataBuffer[13];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagRead(&CmdDB.DataBuffer[6], NULL, CmdDB.DataBuffer[10], addr, readLen, rsp);
                                                if(status == NO_ERROR)
                                                {
                                                    CmdResponse(m, NO_ERROR, rsp, readLen * 2);
                                                }
                                                else
                                                {
                                                    CmdResponse(m, status, NULL, 0);
                                                }                                                
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x62: // ISO18K6C Write
                                            {
                                            #ifdef MODEL_PT68DC
                                                UINT16 addr = (CmdDB.DataBuffer[12] << 8) | CmdDB.DataBuffer[11];
                                                UINT16 writeLen = CmdDB.DataBuffer[13]; //(CmdDB.DataBuffer[14] << 8) | CmdDB.DataBuffer[13];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagWrite(&CmdDB.DataBuffer[6], NULL, CmdDB.DataBuffer[10], addr, writeLen, &CmdDB.DataBuffer[15]);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x63: // ISO18K6C Lock
                                            {
                                            #ifdef MODEL_PT68DC
                                                UINT32 mask = (CmdDB.DataBuffer[12] << 16) | (CmdDB.DataBuffer[11] << 8) | CmdDB.DataBuffer[10];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagLock(&CmdDB.DataBuffer[6], NULL, mask);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x64: // ISO18K6C Kill
                                            {
                                            #ifdef MODEL_PT68DC
                                                ENUM_ERROR_CODE status = ISO18K6C_TagKill(&CmdDB.DataBuffer[6], NULL);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x65: // ISO18K6C SetTxPower
                                            {
                                            #ifdef MODEL_PT68DC
                                                ENUM_ERROR_CODE status = UHF_SetTxPower(*(INT16 *)&CmdDB.DataBuffer[6], *(INT16 *)&CmdDB.DataBuffer[8], 1, 1);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x66: // ISO18K6C SetFilter
                                            {
                                            #ifdef MODEL_PT68DC
                                                
                                                TagFilterStatus.BankNo = CmdDB.DataBuffer[6];
                                                TagFilterStatus.StartBit = CmdDB.DataBuffer[7] | (CmdDB.DataBuffer[8] << 8);
                                                TagFilterStatus.BitCount = CmdDB.DataBuffer[9] | (CmdDB.DataBuffer[10] << 8);
                                                memset(TagFilterStatus.Data, 0, 32);
                                                memcpy(TagFilterStatus.Data, &CmdDB.DataBuffer[11], MIN(32, ((TagFilterStatus.BitCount + 7) / 8)));
                                                CmdResponse(m, NO_ERROR, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x67: // ISO18K6C Read
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE rsp[128] = {0};
                                                UINT16 addr = (CmdDB.DataBuffer[12] << 8) | CmdDB.DataBuffer[11];
                                                UINT16 readLen = CmdDB.DataBuffer[13]; //(CmdDB.DataBuffer[14] << 8) | CmdDB.DataBuffer[13];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagRead(&CmdDB.DataBuffer[6], &TagFilterStatus, CmdDB.DataBuffer[10], addr, readLen, rsp);
                                                if(status == NO_ERROR)
                                                {
                                                    CmdResponse(m, NO_ERROR, rsp, readLen * 2);
                                                }
                                                else
                                                {
                                                    CmdResponse(m, status, NULL, 0);
                                                }                                                
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x68: // ISO18K6C Write
                                            {
                                            #ifdef MODEL_PT68DC
                                                UINT16 addr = (CmdDB.DataBuffer[12] << 8) | CmdDB.DataBuffer[11];
                                                UINT16 writeLen = CmdDB.DataBuffer[13]; //(CmdDB.DataBuffer[14] << 8) | CmdDB.DataBuffer[13];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagWrite(&CmdDB.DataBuffer[6], &TagFilterStatus, CmdDB.DataBuffer[10], addr, writeLen, &CmdDB.DataBuffer[15]);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x69: // ISO18K6C Lock
                                            {
                                            #ifdef MODEL_PT68DC
                                                UINT32 mask = (CmdDB.DataBuffer[12] << 16) | (CmdDB.DataBuffer[11] << 8) | CmdDB.DataBuffer[10];
                                                ENUM_ERROR_CODE status = ISO18K6C_TagLock(&CmdDB.DataBuffer[6], &TagFilterStatus, mask);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x6A: // ISO18K6C Kill
                                            {
                                            #ifdef MODEL_PT68DC
                                                ENUM_ERROR_CODE status = ISO18K6C_TagKill(&CmdDB.DataBuffer[6], &TagFilterStatus);
                                                CmdResponse(m, status, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x6B: // ISO18K6C Tag Write while printing
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE bank = CmdDB.DataBuffer[6];
                                                UINT16 addr = (CmdDB.DataBuffer[8] << 8) | CmdDB.DataBuffer[7];
                                                UINT16 writeLen = CmdDB.DataBuffer[9];
                                                Printer_UHFWriteWhilePrinting(bank, addr, &CmdDB.DataBuffer[11], writeLen);
                                            //    CmdResponse(m, NO_ERROR, NULL, 0);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x6C: // ISO18K6C Tag Write while printing
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE rsp[256] = {0};
                                                UINT16 rspLen = 0;
                                                INT16 RSSIs[3] = {0};
                                                BYTE tagCount = 0;
                                                ENUM_ERROR_CODE status =  ISO18K6C_CountInventory(CmdDB.DataBuffer[6], rsp, &rspLen, &tagCount, RSSIs);                                                
                                                CmdResponse(m, status, (BYTE *)rsp, rspLen);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
                                            case 0x6F:
                                            {
                                            #ifdef MODEL_PT68DC
                                                BYTE rsp[256] = {0};
                                                UINT16 rsplen;
                                                ENUM_ERROR_CODE UHF_SendCmd(BYTE CmdID, BYTE *pTxParam, UINT16 TxParamLen, BYTE *pRxParam, UINT16 *pRxParamLen);
                                                ENUM_ERROR_CODE status = UHF_SendCmd(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7], CmdDB.DataBuffer[2] - 3, rsp, &rsplen);
                                                CmdResponse(m, status, rsp, rsplen);
                                            #else
                                                CmdResponse(m, ERROR_NO_SUPPORTED, NULL, 0);
                                            #endif
                                                break;
                                            }
//                                            case 0xEF:
//                                            {
//                                                UINT16 rubbonLength = 0;
//                                                ENUM_ERROR_CODE status = Printer_ReadRibbon(&rubbonLength);
//                                                //ISO14443A_Write_Block(CmdDB.DataBuffer[6], &CmdDB.DataBuffer[7], CmdDB.DataBuffer[13], &CmdDB.DataBuffer[14]);
//                                                if(status != NO_ERROR)
//                                                {
                                                    Printer_StatusInit();
//                                                }
//                                                CmdResponse(m, status, (BYTE *)&rubbonLength, 2);
//                                                break;
//                                            }
                                        }
                                        break;
                                }
                            }
                            else if(CmdDB.DataBuffer[1] == 0x48)
                            {
                                switch(fn)
                                {
                                    case 49:    // get tape use status
                                        EscCmdExecute(ESC_EXECUTION_GET_TAPE_STATUS, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 50:    // get battery level
                                        EscCmdExecute(ESC_EXECUTION_GET_BATTERY_STATUS, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 51:    // get bluetooth/wifi connection status
                                        EscCmdExecute(ESC_EXECUTION_GET_WIRELESS_STATUS, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                    case 53:    // get printer max width
                                        EscCmdExecute(ESC_EXECUTION_GET_PRINTER_MAX_WIDTH, CmdDB.DataBuffer, CmdDB.DataLength);
                                        break;
                                }
                            }
                            CmdDB.DataLength = 0;
                            CmdDB.State = ESC_STATE_IDLE;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_CHAR_SIZE)
                {
                    EscCmdExecute(ESC_EXECUTION_SELECT_CHAR_SIZE, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
                    CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == 0x28)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataBuffer[1] == ESC_CMDID_EXECUTE_TEST_PRINT)
                        {
                            EscCmdExecute(ESC_EXECUTION_EXECUTE_TEST_PRINT, CmdDB.DataBuffer, CmdDB.DataLength);
                        }
                        else if(CmdDB.DataBuffer[1] == ESC_CMDID_EN_DISABLE_REALTIME_CMD)
                        {
                            EscCmdExecute(ESC_EXECUTION_EN_DISABLE_REALTIME_CMD, CmdDB.DataBuffer, CmdDB.DataLength);
                        }
                        CmdDB.DataLength = 0;
                        CmdDB.State = ESC_STATE_IDLE;
                    }
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_DEFINE_DOWNLOAD_BITMAP)
                {
                    EscCmdExecute(ESC_EXECUTION_DEFINE_DOWNLOAD_BITMAP, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
                  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_PRINT_DOWNLOAD_BITMAP)
                {
                    EscCmdExecute(ESC_EXECUTION_PRINT_DOWNLOAD_BITMAP, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
                  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_WHITE_BLACK_REVERSE)
                {
                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_WHITE_BLACK_REVERSE, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_QUERY_PRINTER_ID)
                {
                    EscCmdExecute(ESC_EXECUTION_QUERY_PRINTER_ID, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_LEFT_MARGIN)
                {
                    EscCmdExecute(ESC_EXECUTION_SET_LEFT_MARGIN, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_HORI_VERTI_MOVE_UNIT)
                {
                    EscCmdExecute(ESC_EXECUTION_SET_HORI_VERTI_MOVE_UNIT, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_PRINT_AREA_WIDTH)
                {
                    EscCmdExecute(ESC_EXECUTION_SET_PRINT_AREA_WIDTH, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_AUTO_STATE_RETURN)
                {
                    EscCmdExecute(ESC_EXECUTION_SET_AUTO_STATE_RETURN, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_QRCODE_TYPE)
                {
                    EscCmdExecute(ESC_EXECUTION_SEL_QRCODE_TYPE, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }
                else if(CmdDB.DataBuffer[0] == ESC_CMDID_PRINT_QRCODE)
                {
                    EscCmdExecute(ESC_EXECUTION_PRINT_QRCODE, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
  CmdDB.State = ESC_STATE_IDLE;
                }								
                else
                {
                    CmdDB.DataLength = 0;
                    CmdDB.State = ESC_STATE_IDLE;
                }
            }
            break;
						
        case ESC_STATE_RECV_LABEL_SET:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(CmdDB.DataLength >= 12)
            {
                EscCmdExecute(ESC_EXECUTION_SET_LABEL_INFO, CmdDB.DataBuffer, CmdDB.DataLength);                        
                CmdDB.DataLength = 0;
                CmdDB.State = ESC_STATE_IDLE;
            }
            break;
        case ESC_STATE_RECV_PRINT_BLANK:
            CmdDB.DataBuffer[CmdDB.DataLength++] = data;  
            EscCmdExecute(ESC_EXECUTION_FEEDPAPER, CmdDB.DataBuffer, CmdDB.DataLength);
            CmdDB.DataLength = 0;
            CmdDB.State = ESC_STATE_IDLE;
            break;
        case ESC_STATE_RECV_PRINT_ROW:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(CmdDB.DataLength == 1)
            {
                CmdDB.SubDataLength = data;
                CmdDB.SubDataIndex = 0;
            }
            else
            {
                CmdDB.SubDataIndex++;
                if(CmdDB.SubDataIndex >= CmdDB.SubDataLength)
                {
                    EscCmdExecute(ESC_EXECUTION_PRINT_ROW, CmdDB.DataBuffer, CmdDB.DataLength);
                    CmdDB.DataLength = 0;
                    CmdDB.State = ESC_STATE_IDLE;
                }
            }
            break;
        case ESC_STATE_RECV_PRINT_RLE_ROW:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(data == 0x00)
            {
                EscCmdExecute(ESC_EXECUTION_PRINT_RLE_ROW, CmdDB.DataBuffer, CmdDB.DataLength);
                CmdDB.DataLength = 0;
                CmdDB.State = ESC_STATE_IDLE;
                break;
            }
            CmdDB.SubDataLength = ((data & 0x80) == 0x80)?(1):(data);
            CmdDB.SubDataIndex = 0;
            CmdDB.State = ESC_STATE_SUB_FRAME_IN;
            break;
        case ESC_STATE_RECV_CONTROL:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data; 
            }                
            if(CmdDB.DataLength >= 1)
            {
                if(CmdDB.DataBuffer[0] == 0x09) // ENTER_SETUP_MODE
                {
                    CmdDB.SetupModeEn = 1;
                    StringResponse("OK");
                    CmdDB.State = ESC_STATE_IDLE;
                    CmdDB.DataLength = 0;
                }
                else if(CmdDB.DataBuffer[0] == 0x15) // EXIT_SETUP_MODE
                {
                    CmdDB.SetupModeEn = 0;
                    StringResponse("OK");
                    CmdDB.State = ESC_STATE_IDLE;
                    CmdDB.DataLength = 0;
                }
                else if(CmdDB.DataBuffer[0] == 0x01) // Read/Write MFG Info
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataBuffer[1] == 0x00) // read
                        {
                            if(CmdDB.SetupModeEn) 
                            {
                                ST_MFG_WRITE_INFO *ptr = (ST_MFG_WRITE_INFO *)&CmdDB.DataBuffer[4];
                                memset(ptr, 0, sizeof(ST_MFG_WRITE_INFO));
                                strncpy(ptr->BTName,    MfgInfo.BT.Name, 17);
                                strncpy(ptr->BTPin,     MfgInfo.BT.Pin, 9);
                                strncpy(ptr->SerialNo,  MfgInfo.SerialNo, 17);
                                strncpy(ptr->ModelName, MfgInfo.ModelNo, 17);
                                CmdDB.DataBuffer[2] = 'O';
                                CmdDB.DataBuffer[3] = 'K';
                                DataResponse(&CmdDB.DataBuffer[2], sizeof(ST_MFG_WRITE_INFO) + 2);
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;                       
                        }
                        else if(CmdDB.DataBuffer[1] == 0x01) // write
                        {
                            if(CmdDB.DataLength >= (sizeof(ST_MFG_WRITE_INFO) + 2))
                            {
                                if(CmdDB.SetupModeEn) 
                                {
                                    BOOL status = MFG_WriteInfo((ST_MFG_WRITE_INFO *)&CmdDB.DataBuffer[2]);
                                    StringResponse(status?"OK":"ERROR");
                                }
                                CmdDB.State = ESC_STATE_IDLE;
                                CmdDB.DataLength = 0;
                            }     
                        }
                        else
                        {
                            StringResponse("ERROR");
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                        
                }
                else if(CmdDB.DataBuffer[0] == 0x10) // SET_BLUETOOTH_PASSWORD
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] < 4) || (CmdDB.DataBuffer[1] > 8))
                            {
                                StringResponse("1ERROR");
                            }
                            else
                            {
                                CmdDB.DataBuffer[CmdDB.DataBuffer[1] + 2] = '\0';
                                BOOL status = MFG_BTPinSet((char *)&CmdDB.DataBuffer[2]);
                                StringResponse(status?"OK":"2ERROR");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x11) // SET_BLUETOOTH_MASTER_SLAVE_MODE
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("3ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x13) // SET_BLUETOOTH_NAME
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] < 1) || (CmdDB.DataBuffer[1] > 32))
                            {
                                StringResponse("4ERROR");
                            }
                            else
                            {
                                // SetBTNAME
                                CmdDB.DataBuffer[CmdDB.DataBuffer[1] + 2] = '\0';
                                BOOL status = MFG_BTNameSet((char *)&CmdDB.DataBuffer[2]);
                                StringResponse(status?"OK":"5ERROR");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x14) // SET_BLUETOOTH_TYPE
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] != 6))
                            {
                                StringResponse("6ERROR");
                            }
                            else
                            {
                                // SetBTTYPE
                                StringResponse("7ERROR");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x27) // SET_BLUETOOTH_PASSWORD_ENABLE
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("8ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x16) // SET_LANGUAGE
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        //SetLanguage CmdDB.DataBuffer[1]
                        StringResponse("OK");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x17) // SET_BLACK_MARK_POSITION
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("9ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x18) // SET_PRINT_CMD_SET
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        //SetCommandMode CmdDB.DataBuffer[1]
                        StringResponse("OK");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x1B) // ESC_CMDID_SET_MANUFACTURER_NAME
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] < 1) || (CmdDB.DataBuffer[1] > 32))
                            {
                                StringResponse("10ERROR");
                            }
                            else
                            {
                                // SetMFGName
                                StringResponse("OK");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x1C) // ESC_CMDID_SET_PRINTER_MODEL
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] < 1) || (CmdDB.DataBuffer[1] > 16))
                            {
                                StringResponse("11ERROR");
                            }
                            else
                            {
                                // SetModelName
                                CmdDB.DataBuffer[CmdDB.DataBuffer[1] + 2] = '\0';
                                BOOL status = MFG_ModelNameSet((char *)&CmdDB.DataBuffer[2]);
                                StringResponse(status?"OK":"12ERROR");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x1E) // ESC_CMDID_SET_PRINT_SPEED
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("13ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x21) // ESC_CMDID_SET_PRINT_FONT
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("14ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x22) // ESC_CMDID_SET_BLACK_MARK_MODE
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("15ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x23) // ESC_CMDID_SET_SERIAL_PORT_PARS)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("16ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x26) // ESC_CMDID_SET_STANDBY_TIME)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("17ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x28) // ESC_CMDID_SET_PAPER_SENSOR_SENSITIVITY)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("18ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x1D) // ESC_CMDID_SET_PRINTER_SERIAL_NUMBER)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        if(CmdDB.DataLength >= (CmdDB.DataBuffer[1] + 2))
                        {
                            if((!CmdDB.SetupModeEn) || (CmdDB.DataBuffer[1] < 1) || (CmdDB.DataBuffer[1] > 16))
                            {
                                StringResponse("19ERROR");
                            }
                            else
                            {
                                // SetSN
                                CmdDB.DataBuffer[CmdDB.DataBuffer[1] + 2] = '\0';
                                BOOL status = MFG_SerialNoSet((char *)&CmdDB.DataBuffer[2]);
                                StringResponse(status?"OK":"20ERROR");
                            }
                            CmdDB.State = ESC_STATE_IDLE;
                            CmdDB.DataLength = 0;
                        }
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x63) // ESC_CMDID_SET_PRINT_DIRECTION)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("21ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x74) // ESC_CMDID_SET_DEFAULT_CODE_PAGE)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("22ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0xFD) // ESC_CMDID_SET_PRINT_DENSITY)
                {
                    if(CmdDB.DataLength >= 2)
                    {
                        StringResponse("23ERROR");
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0xFE) // download  bitmap
                {
                    if(CmdDB.DataLength >= 7)
                    {
                        //BYTE m = CmdDB.DataBuffer[2];
                        UINT16 x = (UINT16)(CmdDB.DataBuffer[4] << 8) | CmdDB.DataBuffer[3];
                        UINT16 y = (UINT16)(CmdDB.DataBuffer[6] << 8) | CmdDB.DataBuffer[5];
                        UINT16 k = x * y;
                        if(CmdDB.DataLength >= (7 + k))
                        {
//                            EscCmdExecute(ESC_EXECUTION_DOWNLOAD_BITMAP, CmdDB.DataBuffer, CmdDB.DataLength);
                        }
                        CmdDB.State = ESC_STATE_IDLE;
                        CmdDB.DataLength = 0;
                    }
                }
                else if(CmdDB.DataBuffer[0] == 0x30) // ESC_CMDID_SET_WIFI_AP_PARS)
                {
                    StringResponse("24ERROR");
                    CmdDB.State = ESC_STATE_IDLE;
                    CmdDB.DataLength = 0;
                }
                else
                {
                    CmdDB.State = ESC_STATE_IDLE;
                    CmdDB.DataLength = 0;
                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_RIGHT_INTERVAL)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_RIGHT_INTERVAL, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_PRINT_MODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SELECT_PRINT_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_PRINT_POSITION)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_PRINT_POSITION, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_USER_CHAR)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_USER_CHAR, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_USER_DEFINE_CHAR)
//                {
//                    EscCmdExecute(ESC_EXECUTION_USER_DEFINE_CHAR, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_BITMAP_MODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SELECT_BITMAP_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_UNDERLINE_MODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_UNDERLINE_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_DEFAULT_RAW_HIGHT)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_DEFAULT_RAW_HIGHT, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_RAW_HIGHT)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_RAW_HIGHT, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_EXTERNAL_EQUIPMENT)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SELECT_EXTERNAL_EQUIPMENT, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_CANCEL_USER_CHAR)
//                {
//                    EscCmdExecute(ESC_EXECUTION_CANCEL_USER_CHAR, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_INIT_PRINTER)
//                {
//                    EscCmdExecute(ESC_EXECUTION_INIT_PRINTER, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_HORI_MOVE_POSITION)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_HORI_MOVE_POSITION, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_BOLD_MODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_BOLD_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_DOUBLE_PRINTING)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_DOUBLE_PRINTING, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_PRINT_MOVE_PAPER)
//                {
//                    EscCmdExecute(ESC_EXECUTION_PRINT_MOVE_PAPER, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_FONT)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SELECT_FONT, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_INTERNATIONAL_CHAR_SET)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_INTERNATIONAL_CHAR_SET, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_HORIZONTAL_AMPLIFY)
//                {
//                    EscCmdExecute(ESC_EXECUTION_HORIZONTAL_AMPLIFY, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_VERTICAL_AMPLIFY)
//                {
//                    EscCmdExecute(ESC_EXECUTION_VERTICAL_AMPLIFY, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_HORI_VERTI_AMPLIFY)
//                {
//                    EscCmdExecute(ESC_EXECUTION_HORI_VERTI_AMPLIFY, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SET_RELATIVE_HORI_PRINT_POSITION)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SET_RELATIVE_HORI_PRINT_POSITION, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CHAR_ALIGN_MODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CHAR_ALIGN_MODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_EN_DISABLE_REVERSE_PRINTING)
//                {
//                    if(CmdDB.DataLength == 2)
//                    {
//                        if(CmdDB.DataBuffer[1] == ESC_CMDID_EN_DISABLE_BUTTON)
//                        {
//                            EscCmdExecute(ESC_EXECUTION_EN_DISABLE_BUTTON, CmdDB.DataBuffer, CmdDB.DataLength);
//                        }
//                        else
//                        {
//                            EscCmdExecute(ESC_EXECUTION_EN_DISABLE_REVERSE_PRINTING, CmdDB.DataBuffer, CmdDB.DataLength);
//                        }
//                    }
//                    else
//                    {
//                        break;
//                    }
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_PRINT_MOVE_N_LINE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_PRINT_MOVE_N_LINE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_EN_DISABLE_INVERSE_PRINTING)
//                {
//                    EscCmdExecute(ESC_EXECUTION_EN_DISABLE_INVERSE_PRINTING, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SELECT_CHRAR_CODE_PAGE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SELECT_CHRAR_CODE_PAGE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_INVERTED_PRINTING)
//                {
//                    EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_INVERTED_PRINTING, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
//                else if(CmdDB.DataBuffer[0] == ESC_CMDID_ESC_PRINT_QRCODE)
//                {
//                    EscCmdExecute(ESC_EXECUTION_ESC_PRINT_QRCODE, CmdDB.DataBuffer, CmdDB.DataLength);
//                }
            }
            break;
        case ESC_STATE_RECV_STATUS_FS:
        {
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            if(CmdDB.DataBuffer[0] == ESC_CMDID_SEL_CANCEL_ROTATE_90_DEGREES)
            {
                EscCmdExecute(ESC_EXECUTION_SEL_CANCEL_ROTATE_90_DEGREES, CmdDB.DataBuffer, CmdDB.DataLength);
            }
            else if(CmdDB.DataBuffer[0] == ESC_CMDID_PRINT_PRE_STORED_BITMAP)
            {
                EscCmdExecute(ESC_EXECUTION_PRINT_PRE_STORED_BITMAP, CmdDB.DataBuffer, CmdDB.DataLength);
            }
                
            CmdDB.State = ESC_STATE_IDLE;
            CmdDB.DataLength = 0;
        }
        case ESC_STATE_SUB_FRAME_IN:
            if(CmdDB.DataLength < ESC_CMD_BUFFER_SIZE)
            {
                CmdDB.DataBuffer[CmdDB.DataLength++] = data;
            }
            CmdDB.SubDataIndex++;
            if(CmdDB.SubDataIndex >= CmdDB.SubDataLength)
            {
                switch(CmdDB.CmdID)
                {
                    case ESC_CMDID_STATUS_GET:
                        CmdDB.State          = ESC_STATE_RECV_STATUS_GET;
                        break;
                    case ESC_CMDID_PARAM_CONFIG:
                        CmdDB.State          = ESC_STATE_RECV_PARAM_CONFIG;
                        break;
                    case ESC_CMDID_LABEL_SET:
                        CmdDB.State          = ESC_STATE_RECV_LABEL_SET;
                        break;
                    case ESC_CMDID_PRINT_BLANK:
                        CmdDB.State          = ESC_STATE_RECV_PRINT_BLANK;
                        break;
                    case ESC_CMDID_PRINT_ROW:
                        CmdDB.State          = ESC_STATE_RECV_PRINT_ROW;
                        break;
                    case ESC_CMDID_PRINT_RLE_ROW:
                        CmdDB.State          = ESC_STATE_RECV_PRINT_RLE_ROW;
                        break;
                    case ESC_CMDID_CONTROL:
                        CmdDB.State          = ESC_STATE_RECV_CONTROL;
                        break;
                    default:
                        CmdDB.State          = ESC_STATE_IDLE;
                        break;
                }
            }
            break;
        default:
            CmdDB.State = ESC_STATE_IDLE;
            CmdDB.DataLength = 0;
            break;
    }
}

void USB_ReceiveISR(BYTE *pBuf, UINT16 len)
{
    portBASE_TYPE taskWoken = pdFALSE;
    ST_USBCMD_PACKET bufUsb;
    
    bufUsb.Len = len;
    memcpy(bufUsb.Data, pBuf, MIN(CDC_DATA_FS_MAX_PACKET_SIZE, len));
    xQueueSendFromISR(UsbQueueHandle, &bufUsb, &taskWoken);
    if(taskWoken)
    {
        portYIELD_FROM_ISR(taskWoken);
    }
}
static void CmdDataIn(BYTE data)
{
    UI_ClearIdle();
    
    switch(CmdDB.Mode)
    {
        default:
        case CMD_MODE_ESC:
            EscStateMachine(data);
            break;
        case CMD_MODE_OTA:
            OtaStateMachine(data);
            break;
    }
}
static void CmdPacketTask(void const *param)
{ 
    BYTE    data = 0;    
    ST_USBCMD_PACKET bufUsb;
    while(1)
    {
        switch(CmdDB.Interface)
        {
            default:
            case INTERFACE_NONE:
                if(BT_ReadBuffer(&data, 1, 1) != 0)
                {
                    CmdDB.Interface = INTERFACE_BT;
                    CmdDataIn(data);
                    IdleTimerStart();
                }
                else if(xQueueReceive(UsbQueueHandle, &bufUsb, 1) == pdTRUE)
                {
                    CmdDB.Interface = INTERFACE_USB;
                    for(BYTE i = 0; i < bufUsb.Len; i++)
                    {
                        CmdDataIn(bufUsb.Data[i]);
                    }
                    USB_EndReceive();
                    IdleTimerStart();
                }
                break;
            case INTERFACE_BT:
                if(BT_ReadBuffer(&data, 1, 1) != 0)
                {
                    IdleTimerClear();
                    CmdDataIn(data);
                }
                break;
            case INTERFACE_USB:
                if(xQueueReceive(UsbQueueHandle, &bufUsb, 1) == pdTRUE)
                {
                    IdleTimerClear();
                    for(BYTE i = 0; i < bufUsb.Len; i++)
                    {
                        CmdDataIn(bufUsb.Data[i]);
                    }
                    USB_EndReceive();
                }
                break;
        }
       
    }
}

void ESC_Init(void)
{
    UsbQueueHandle  = xQueueCreate(1, sizeof(ST_USBCMD_PACKET));
    osThreadDef(EscUartProcess, CmdPacketTask, osPriorityAboveNormal, 0, 256);
    osThreadCreate(osThread(EscUartProcess), NULL);
 //   CITimerHandle   = xTimerCreate( "CIIdle50ms", 50, pdTRUE, ( void * ) NULL, CITimerCallback );
    HAL_NVIC_SetPriority(TIM5_IRQn, 6, 1);
    HAL_NVIC_EnableIRQ(TIM5_IRQn);
}





















//                                           EscCommand.h


/****************************************************************************
 * File Name: EscCommand.h
 *
 * Description:
 *					EscCommand
 *
 * --------------------------------------------------------------------
 * Revision	Author		Date		Comment
 * --------------------------------------------------------------------
 * 1.0          Junrong         2019/02/19		Original
 *
 *****************************************************************************/
#ifndef __ESC_COMMAND_H__
#define __ESC_COMMAND_H__
#include "stm32f1xx_hal.h"
#include "Types.h"

//打印机状态位域
typedef struct 
{
	uint8_t Default_BitField_0:1;						//固定位1bit
	uint8_t Default_BitField_1:1;						//固定位1bit
	uint8_t CashDrawerSignel_Field_2:1;			//钱箱开/关信号位1bit
	uint8_t Online_OR_FFline_Field_3:1;			//脱机或联机位1bit
	uint8_t Default_BitField_4:1;						//固定位1bit
	uint8_t Undefined_BitField_5:1;					//未定义位1bit
	uint8_t Undefined_BitField_6:1;					//未定义位1bit
	uint8_t Default_BitField_7:1;						//固定为位1bit
}PRINTER_STATUS_FIELD;



//打印机脱机状态位域
typedef struct 
{
	uint8_t Default_BitField_0:1;						//固定位1bit 
	uint8_t Default_BitField_1:1;						//固定位1bit
	uint8_t UpperCover_Status_Field_2:1; 		//上盖开关状态位1bit
	uint8_t FeedPaper_Mode_Field_3:1;		  	//有无按下走纸键位1bit
	uint8_t Default_BitField_4:1;						//固定位1bit	
	uint8_t PaperOutStop_BitField_5:1;			//打印机缺纸停止或其他  1bit
	uint8_t ErrorStatus_BitField_6:1;				//有无出现错误位1bit
	uint8_t Default_BitField_7:1;						//固定位1bit
}OFFline_STATUS_FIELD;



//打印机错误状态位域
typedef struct 
{
	uint8_t Default_BitField_0:1;					  //固定位1bit 
	uint8_t Default_BitField_1:1;					  //固定位1bit
	uint8_t Undefined_BitField_2:1; 			  //未定义位1bit
	uint8_t CutterIsWrong_Field_3:1;		    //切刀有无错误位1bit
	uint8_t Default_BitField_4:1;					  //固定位1bit	
	uint8_t UnrecoverableError_Field_5:1;		//有无不可恢复错误位1bit
	uint8_t Default_BitField_6:1;						//未定义位1bit
	uint8_t Default_BitField_7:1;					  //未定义位1bit
}ERROR_STATUS_FIELD;

//纸传感器状态位域
typedef struct 
{
	uint8_t Default_BitField_0:1;					  //固定位1bit 
	uint8_t Default_BitField_1:1;					  //固定位1bit
	uint8_t Default_BitField_2:1; 			  	//固定位1bit
	uint8_t Default_BitField_3:1;		    		//固定位1bit
	uint8_t Default_BitField_4:1;					  //固定位1bit	
	uint8_t HAVEPAPER_BitField_5:1;				  //缺纸传感器:有纸位1bit
	uint8_t NOPAPER_BitField_6:1;						//缺纸传感器:缺纸位1bit
	uint8_t Default_BitField_7:1;					  //固定位1bit
}PAPER_SENSOR_STATUS_FIELD;

//GS I n 查询打印机ID号打印类型ID
typedef struct 
{
	uint8_t Bouble_Byte_encoding_0:1; //是否支持双字节字符编码
	uint8_t Cutter_1:1;								//是否有切刀
	uint8_t Reserved_2:1;							//预留
	uint8_t Reserved_3:1;							//预留
	uint8_t Default_4:1;							//固定为0
	uint8_t Reserved_5:1;							//预留
	uint8_t Reserved_6:1;							//预留
	uint8_t Default_7:1;							//固定为0
	
} Printer_Type_ID;

void ESC_Init(void);
void DataResponse(BYTE *pData, UINT16 len);
#endif
























//                             ESCPOS.c   




/****************************************************************************
 * File Name: ESCPOS.c
 *
 * Description:
 *					ESC/POS command
 *
 * --------------------------------------------------------------------
 * Revision	    Author		      Date		     Comment
 * --------------------------------------------------------------------
 * 1.0          LiuYB         2020/12/01		Original
 *
 *****************************************************************************/

#include "ESCPOS.h"
#include "hal_keypad.h"

static QueueHandle_t Uart1ReceiveQueueHandle = NULL;
static QueueHandle_t Uart2ReceiveQueueHandle = NULL;

extern BOOL KeyFeedPaperFlag; //按下SETUP键进纸标志位


#define ESC_CMD_BUFFER_SIZE1     1030   

enum
{
    
    ESC_POSID_HORIZONTAL_MOVE     = 0x09,  //横向跳格 HT
	  ESC_POSID_STATUS_GET      		= 0x10,  //实时状态获取 DLE EOT n
		ESC_POSID_PRINT_MOVE_LINE     = 0x0A,  //打印并走纸一行 LF
		ESC_POSID_PRINT_AND_ENTER	    = 0x0D,  //打印并回车 CR
	  ESC_POSID_CONTROL             = 0x1B,  //ESC控制 
	  ESC_POSID_FS_CONTROL          = 0x1C,	 //FS控制
	  ESC_POSID_PARAM_CONFIG    		= 0x1D,  //GS设置
	
    ESC_POSID_LABEL_SET           = 0x17,
    ESC_POSID_PRINT_BLANK         = 0x15,
    ESC_POSID_PRINT_ROW           = 0x16,
    ESC_POSID_PRINT_RLE_ROW       = 0x18,
    ESC_POSID_PRINT_TO_END        = 0x0C, //打印一个间隙纸
       
		ESC_POSID_STATE_TRANSMIT	    = 0x04,
		ESC_POSID_SET_RIGHT_INTERVAL	= 0x20,
		ESC_POSID_SELECT_PRINT_MODE		= 0x21, //选择打印模式
		ESC_POSID_SET_PRINT_POSITION	= 0x24,
		ESC_POSID_SEL_CANCEL_USER_CHAR       	= 0x25,
		ESC_POSID_USER_DEFINE_CHAR	  				= 0x26,
		ESC_POSID_SELECT_BITMAP_MODE  				= 0x2A,
		ESC_POSID_SEL_CANCEL_UNDERLINE_MODE  	= 0x2D,
		ESC_POSID_SET_DEFAULT_RAW_HIGHT      	= 0x32,
		ESC_POSID_SET_RAW_HIGHT  							= 0x33,
		ESC_POSID_SELECT_EXTERNAL_EQUIPMENT	 	= 0x3D,
		ESC_POSID_CANCEL_USER_CHAR						= 0x3F,
		ESC_POSID_INIT_PRINTER								= 0x40,
		ESC_POSID_SET_HORI_MOVE_POSITION		 	= 0x44,
		ESC_POSID_SEL_CANCEL_BOLD_MODE		   	= 0x45,
		ESC_POSID_SEL_CANCEL_DOUBLE_PRINTING 	= 0x47,
		ESC_POSID_PRINT_MOVE_PAPER 						= 0x4A,
		ESC_POSID_SELECT_FONT 								= 0x4D,
		ESC_POSID_SEL_INTERNATIONAL_CHAR_SET 	= 0x52,
		ESC_POSID_HORIZONTAL_AMPLIFY					= 0x55,
		ESC_POSID_VERTICAL_AMPLIFY						= 0x56,
		ESC_POSID_HORI_VERTI_AMPLIFY					= 0x57,
		ESC_POSID_SET_RELATIVE_HORI_PRINT_POSITION	= 0x5C,
		ESC_POSID_SEL_CHAR_ALIGN_MODE								= 0x61,
		ESC_POSID_EN_DISABLE_REVERSE_PRINTING				= 0x63,
		ESC_POSID_EN_DISABLE_BUTTON									= 0x35,
		ESC_POSID_PRINT_MOVE_N_LINE									= 0x64,
		ESC_POSID_EN_DISABLE_INVERSE_PRINTING				= 0x69,
		ESC_POSID_SELECT_CHRAR_CODE_PAGE						= 0x74,
		ESC_POSID_SEL_CANCEL_INVERTED_PRINTING			= 0x7B,		
		ESC_POSID_SEL_CANCEL_ROTATE_90_DEGREES  		= 0x49,
		ESC_POSID_PRINT_PRE_STORED_BITMAP  					= 0x50,
//		ESC_POSID_SELECT_CHAR_SIZE  								= 0x21,
		ESC_POSID_EXECUTE_TEST_PRINT  							= 0x41,
		ESC_POSID_EN_DISABLE_REALTIME_CMD 		 			= 0x44,
		ESC_POSID_DEFINE_DOWNLOAD_BITMAP  					= 0x2A,
		ESC_POSID_PRINT_DOWNLOAD_BITMAP  						= 0x2F,
		ESC_POSID_SEL_CANCEL_WHITE_BLACK_REVERSE  	= 0x42,
		ESC_POSID_QUERY_PRINTER_ID  								= 0x49,
		ESC_POSID_SET_LEFT_MARGIN  									= 0x4C,
		ESC_POSID_SET_HORI_VERTI_MOVE_UNIT  				= 0x50,
		ESC_POSID_SET_PRINT_AREA_WIDTH 							= 0x57,
		ESC_POSID_SET_AUTO_STATE_RETURN							= 0x61,
		ESC_POSID_SEL_QRCODE_TYPE										= 0x5A,
		ESC_POSID_ESC_PRINT_QRCODE									= 0x5A,
		ESC_POSID_PRINT_QRCODE											= 0x6B,
};

enum
{
    EXECUTION_SET_PRINT_DENSITY,           //设置打印密度  0
    EXECUTION_SET_PRINT_SPEED,						 //设置打印速度	 1
    EXECUTION_SET_PAPER_TYPE,							 //设置纸张类型  2
    EXECUTION_SET_PRINT_MODE,							 //设置打印模式  3
    EXECUTION_SET_LABEL_SIZE,							 //设置标签大小  4
    EXECUTION_SET_BOOT_LOGO,				       //设置logo标签			 
    EXECUTION_CLEAR_BOOT_LOGO,
    EXECUTION_SET_NFC_PASSWORD,            //设置NFC密码
    EXECUTION_SET_RIBBONS_LENGTH,					 //设置色带长度
    EXECUTION_ENTER_UPGRADE_MODE,					 //输入升级模式
    EXECUTION_GET_PRINTER_INFO,						 //获取打印信息
    EXECUTION_GET_TAPE_STATE,							 //获取磁带状态
    EXECUTION_GET_TAPE_STATUS,						 //获取磁带状态
    EXECUTION_GET_BATTERY_STATUS,          //获取电池状态
    EXECUTION_GET_WIRELESS_STATUS,				 //获取无线状态
    EXECUTION_GET_PRINTER_MAX_WIDTH,			 //获取打印机最大宽度
//    EXECUTION_DOWNLOAD_BITMAP,    
	  EXECUTION_GET_PRINTER_STATUS,			     //指令的获取打印机状态
    EXECUTION_SET_LABEL_INFO,							 //设置便签信息
    EXECUTION_PRINT_ROW,									 //打印行
    EXECUTION_PRINT_RLE_ROW,							 //RLE 算法打印行
    EXECUTION_FEEDPAPER,									 //走纸
    EXECUTION_FEEDPAPER_TO_GAP,    				 //走纸到间隙
    EXECUTION_WRITE_HF_RFID,							 //写高频RFID
    EXECUTION_WRITE_UHF_RFID,    					 //写超高频RFID
    EXECUTION_FW_UPGRADE_CONFIRM,					 //固件升级确认
    
    EXECUTION_HORIZONTAL_MOVE,             //水平移动
		EXECUTION_SET_HORIZONTAL_POS,					 //设置水平跳格位置
    EXECUTION_PRINT_MOVE_LINE,						 //打印移动线
    EXECUTION_PRINT_AND_ENTER,             //打印并输入
		
    EXECUTION_STATE_TRANSMIT,						
    EXECUTION_SET_RIGHT_INTERVAL,
    EXECUTION_SELECT_PRINT_MODE,           //选择打印模式
    EXECUTION_SET_PRINT_POSITION,
    EXECUTION_SEL_CANCEL_USER_CHAR,
    EXECUTION_USER_DEFINE_CHAR,
    EXECUTION_SELECT_BITMAP_MODE,
    EXECUTION_SEL_CANCEL_UNDERLINE_MODE,
    EXECUTION_SET_DEFAULT_RAW_HIGHT,
    EXECUTION_SET_RAW_HIGHT,
    EXECUTION_SELECT_EXTERNAL_EQUIPMENT,
    EXECUTION_CANCEL_USER_CHAR,
    EXECUTION_INIT_PRINTER,
    EXECUTION_SET_HORI_MOVE_POSITION,
    EXECUTION_SEL_CANCEL_BOLD_MODE,
    EXECUTION_SEL_CANCEL_DOUBLE_PRINTING,
    EXECUTION_PRINT_MOVE_PAPER,
    EXECUTION_SELECT_FONT,
    EXECUTION_SEL_INTERNATIONAL_CHAR_SET,
    EXECUTION_HORIZONTAL_AMPLIFY,
    EXECUTION_VERTICAL_AMPLIFY,
    EXECUTION_HORI_VERTI_AMPLIFY,
    EXECUTION_SET_RELATIVE_HORI_PRINT_POSITION,
    EXECUTION_SEL_CHAR_ALIGN_MODE,
    EXECUTION_EN_DISABLE_REVERSE_PRINTING,
    EXECUTION_EN_DISABLE_BUTTON,
    EXECUTION_PRINT_MOVE_N_LINE,
    EXECUTION_EN_DISABLE_INVERSE_PRINTING,
    EXECUTION_SELECT_CHRAR_CODE_PAGE,
    EXECUTION_SEL_CANCEL_INVERTED_PRINTING,
    EXECUTION_FS_CONTROL,
    EXECUTION_SEL_CANCEL_ROTATE_90_DEGREES,
    EXECUTION_PRINT_PRE_STORED_BITMAP,
    EXECUTION_SELECT_CHAR_SIZE,
    EXECUTION_EXECUTE_TEST_PRINT,
    EXECUTION_EN_DISABLE_REALTIME_CMD,
    EXECUTION_DEFINE_DOWNLOAD_BITMAP,
    EXECUTION_PRINT_DOWNLOAD_BITMAP,
    EXECUTION_SEL_CANCEL_WHITE_BLACK_REVERSE,
    EXECUTION_QUERY_PRINTER_ID,
    EXECUTION_SET_LEFT_MARGIN,
    EXECUTION_SET_HORI_VERTI_MOVE_UNIT,
    EXECUTION_SET_PRINT_AREA_WIDTH,
    EXECUTION_SET_AUTO_STATE_RETURN,
    EXECUTION_SEL_QRCODE_TYPE,
    EXECUTION_ESC_PRINT_QRCODE,
    EXECUTION_PRINT_QRCODE, 
};

enum
{
    ESCPOS_STATE_IDLE,               //空闲状态  
	     
    ESCPOS_STATE_RECV_STATUS_GET,   //实时状态条件 (实时状态获取 DLE EOT n)
    ESCPOS_STATE_RECV_PARAM_CONFIG,	//GS 控制系列
    ESCPOS_STATE_RECV_LABEL_SET,
    ESCPOS_STATE_RECV_PRINT_BLANK,  
    ESCPOS_STATE_RECV_PRINT_ROW,   
    ESCPOS_STATE_RECV_PRINT_RLE_ROW,
    ESCPOS_STATE_RECV_CONTROL,       //ESC 控制系列
    ESCPOS_STATE_RECV_STATUS_FS,		 //FS  控制系列
	  
};
//接收数据的结构体
typedef struct
{
	  uint8_t       Interface;      
    uint8_t       Mode;
    uint8_t       State;
	  uint8_t       POSID;
    uint8_t       DataBuffer[ESC_CMD_BUFFER_SIZE1];
    uint16_t      DataLength;
    uint8_t       SubDataIndex;
    uint16_t      SubDataLength;
    
    uint32_t      IdleTime;
    BOOL          SetupModeEn;
}ST_CMD_DB1;
//结构体初始化
static ST_CMD_DB1 EscCmd =
{
	.Interface  =0,
	.State      = ESCPOS_STATE_IDLE,
	.POSID      = 0,
	.DataBuffer = {0},
	.DataLength = 0,
	.SubDataIndex   = 0,
	.SubDataLength  = 0,
	.SetupModeEn    = 0,
};
//Liu 20201218 状态初始化
//打印机状态
//PRINTER_STATUS_FIELD PRINTER_STATUS=
//{
//	.Default_BitField_0 =0,         				//固定为0
//	.Default_BitField_1 =1,	        				//固定为1
//	.CashDrawerSignel_Field_2 =0,   				//固定为0
//	.Online_OR_FFline_Field_3 =0,						//脱机为0,联机为1
//	.Default_BitField_4 =1,         				//固定为1
//	.Undefined_BitField_5 =0,       				//未定义
//	.Undefined_BitField_6 =0,								//未定义
//	.Default_BitField_7=0,									//固定为0
//};
脱机状态
//OFFline_STATUS_FIELD OFFline_STATUS=
//{
//	.Default_BitField_0 =0,         				//固定为0
//	.Default_BitField_1 =1,	        				//固定为1
//	.UpperCover_Status_Field_2 =0,  				//固定为0
//	.FeedPaper_Mode_Field_3 =0,							//未按键走纸键 0 或 按下走纸键 1
//	.Default_BitField_4 =1,         				//固定为1
//	.PaperOutStop_BitField_5 =0,    				//打印机缺纸停止 1 或其他为0
//	.ErrorStatus_BitField_6 =0,							//没有出错情况 0 ,有错误情况为1
//	.Default_BitField_7=0,									//固定为0
//};
错误状态
//ERROR_STATUS_FIELD ERROR_STATUS=
//{
//	.Default_BitField_0 =0,         				//固定为0
//	.Default_BitField_1 =1,	        				//固定为1
//	.Undefined_BitField_2 =0,  							//未定义
//	.CutterIsWrong_Field_3 =0,							//切刀无错误 0 或 切刀有错误 1
//	.Default_BitField_4 =1,          				//固定为1
//	.UnrecoverableError_Field_5 =0,  				//有无不可恢复错误
//	.Default_BitField_6 =0,									//未定义
//	.Default_BitField_7=0,					  			//未定义
//};
纸张传感器状态
//PAPER_SENSOR_STATUS_FIELD PAPER_SENSOR_STATUS=
//{
//	.Default_BitField_0 =0,									//固定为0
//	.Default_BitField_1 =1,	        				//固定为1
//	.Default_BitField_2 =0,  								//固定为0
//	.Default_BitField_3 =0,									//固定为0
//	.Default_BitField_4 =1,          				//固定为1
//	.HAVEPAPER_BitField_5 =0,  							//缺纸传感器:有纸为1
//	.NOPAPER_BitField_6 =0,									//缺纸传感器:缺纸为1
//	.Default_BitField_7=0,					  			//固定为0

//};
//

//ST_PRINT_LABEL_CONFIG HT_Config=
//{
//	.PrintLength  	=0,
//  .PrintOffset  	=0,
//  .TapeWidth    	=50,  // unit: mm
//  .DeviceType			=0,
//  .LabelCount 		=0,
//  .LabelIndex			=0,
//  .TotalDataCount	=0,
//	
//};  //设置标签参数结构体

/*************************************************
*名称:CmdExecute
*描述: 对应指令的功能执行,如打印数据,状态回复等
*输入参数:exeID-执行对应功能的条件
*      		pData-接收到的数据
*			 		dataLength-接收到数据的长度
**************************************************/
static unsigned char CmdExecute(uint16_t exeID, BYTE *pData, UINT16 dataLength)
{
		switch(exeID)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
    {
				case EXECUTION_HORIZONTAL_MOVE:// HT 0x09 水平移动
				{	
//					if(HT_Config.PrintOffset >=HT_Config.TapeWidth) //偏移量大于至纸张宽度移至下一行开头
//					{
//						HT_Config.PrintOffset =0;
//						Printer_Feedpaper(3);
//						break;
//					}
//					HT_Config.PrintOffset =HT_Config.PrintOffset+8;	//设置字符偏移量
//					Printer_SetLabelConfig(HT_Config); 
//					DataResponse((uint8_t*)&"9", 1);   
					break;
				}
				case EXECUTION_PRINT_MOVE_LINE://LF 0A打印一行
//					Printer_PrintRow(pData);
						Printer_Feedpaper(3);
//						Printer_FeedpaperRow();
					break;
				case EXECUTION_PRINT_AND_ENTER: //
					
					break;
				case EXECUTION_STATE_TRANSMIT:
					break;
				 case EXECUTION_GET_PRINTER_STATUS://DLE EOT n 获取打印机状态               
            
//						if(pData[1] == 1)// 获取打印状态
//            {
//							if(IORead(GPIO_BT_CONN_STATE))
//							{
//								 
//								PRINTER_STATUS.Online_OR_FFline_Field_3 =0; //蓝牙已连接设备
//							}
//							else
//								PRINTER_STATUS.Online_OR_FFline_Field_3 =1; //蓝牙未连接设备
//								      
//							  DataResponse((uint8_t*)&PRINTER_STATUS, 1); //发送给串口  
//            }
//            else if(pData[1] == 2)// 传输脱机状态
//            {
//							//按下SETUP走纸
//							if(KeyFeedPaperFlag==1)
//							{
//								KeyFeedPaperFlag =0;
//								OFFline_STATUS.FeedPaper_Mode_Field_3 =1;  
//							}
//							else 
//							{
//								OFFline_STATUS.FeedPaper_Mode_Field_3 =0;  
//							}
//							//缺纸
//							if(SystemStatus.NoPaper)
//							{
//								OFFline_STATUS.PaperOutStop_BitField_5 =1;
//							}
//							else 
//							{
//								OFFline_STATUS.PaperOutStop_BitField_5 =0;
//							}
//                DataResponse((uint8_t*)&OFFline_STATUS, 1);
//            }
//						else if(pData[1] == 3)//传输错误状态
//						{
//							
//							DataResponse((uint8_t*)&ERROR_STATUS, 1);
//						}
//						else if(pData[1] == 4)//传输纸传感器状态
//						{
//							if(SystemStatus.NoPaper)
//							{
//								PAPER_SENSOR_STATUS.HAVEPAPER_BitField_5 =0;
//								PAPER_SENSOR_STATUS.NOPAPER_BitField_6 =1;
//							}
//							else
//							{
//								PAPER_SENSOR_STATUS.HAVEPAPER_BitField_5 =1;
//								PAPER_SENSOR_STATUS.NOPAPER_BitField_6 =0;
//							}
//							DataResponse((uint8_t*)&PAPER_SENSOR_STATUS, 1);
//						}
          break;
				case EXECUTION_SELECT_PRINT_MODE: //选择打印模式
					if((pData[1]&0x01)==0x01)  //1byte第1bit
					{
						DeviceDB.PrintConfig.LabelSize.Width  = 0x0012;
            DeviceDB.PrintConfig.LabelSize.Height = 0x0024;
					}
					else if((pData[1]&0x01)==0x00)
					{
						DeviceDB.PrintConfig.LabelSize.Width  = 0x0008;
            DeviceDB.PrintConfig.LabelSize.Height = 0x0016;
					}
					if((pData[1]&0x08)==0x08)//1byte第4bit
					{
						BT_WriteByte(0x04,100);
					}
					if((pData[1]&0x10)==0x10)//1byte第5bit
					{
						BT_WriteByte(0x05,100);
					}
					if((pData[1]&0x20)==0x20)//1byte第6bit
					{
						BT_WriteByte(0x06,100);
					}
					if((pData[1]&0x40)==0x40)//1byte第7bit
					{
						BT_WriteByte(0x07,100);
					}
					if((pData[1]&0x80)==0x80)//1byte第8bit
					{
						BT_WriteByte(0x08,100);
					}
//					BYTE printData[48] = {0};
// 
//					Printer_PrintRow(printData);  //打印行
					break;
				case EXECUTION_SET_HORIZONTAL_POS:
				{
						
						if(pData[1])
				
					break;
				}
				case EXECUTION_SET_RIGHT_INTERVAL:
					break;
				

				case EXECUTION_SET_PRINT_POSITION:
					break;
				case EXECUTION_SEL_CANCEL_USER_CHAR:
					break;
				case EXECUTION_USER_DEFINE_CHAR:
					break;
				case EXECUTION_SELECT_BITMAP_MODE:
					break;
				case EXECUTION_SEL_CANCEL_UNDERLINE_MODE:
					break;
				case EXECUTION_SET_DEFAULT_RAW_HIGHT:
					break;
				case EXECUTION_SET_RAW_HIGHT:
					break;
				case EXECUTION_SELECT_EXTERNAL_EQUIPMENT:
					break;
				case EXECUTION_CANCEL_USER_CHAR:
					break;
				case EXECUTION_INIT_PRINTER:
					break;
				case EXECUTION_SET_HORI_MOVE_POSITION:
					break;
				case EXECUTION_SEL_CANCEL_BOLD_MODE:
					break;
				case EXECUTION_SEL_CANCEL_DOUBLE_PRINTING:
					break;
				case EXECUTION_PRINT_MOVE_PAPER:
					break;
				case EXECUTION_SELECT_FONT:
					break;
				case EXECUTION_SEL_INTERNATIONAL_CHAR_SET:
					break;
				case EXECUTION_HORIZONTAL_AMPLIFY:
					break;
				case EXECUTION_VERTICAL_AMPLIFY:
					break;
				case EXECUTION_HORI_VERTI_AMPLIFY:
					break;
				case EXECUTION_SET_RELATIVE_HORI_PRINT_POSITION:
					break;
				case EXECUTION_SEL_CHAR_ALIGN_MODE:
					break;
				case EXECUTION_EN_DISABLE_REVERSE_PRINTING:
					break;
				case EXECUTION_EN_DISABLE_BUTTON:
					break;
				case EXECUTION_PRINT_MOVE_N_LINE:
					break;
				case EXECUTION_EN_DISABLE_INVERSE_PRINTING:
					break;
				case EXECUTION_SELECT_CHRAR_CODE_PAGE:
					break;
				case EXECUTION_SEL_CANCEL_INVERTED_PRINTING:
					break;
				case EXECUTION_SEL_CANCEL_ROTATE_90_DEGREES:
					break;
				case EXECUTION_PRINT_PRE_STORED_BITMAP:
					break;
				case EXECUTION_SELECT_CHAR_SIZE:
					break;
				case EXECUTION_EXECUTE_TEST_PRINT:
					break;
				case EXECUTION_EN_DISABLE_REALTIME_CMD:
					break;
				case EXECUTION_DEFINE_DOWNLOAD_BITMAP:
					break;
				case EXECUTION_PRINT_DOWNLOAD_BITMAP:
					break;
				case EXECUTION_SEL_CANCEL_WHITE_BLACK_REVERSE:
					break;
				case EXECUTION_QUERY_PRINTER_ID:
					break;
				case EXECUTION_SET_LEFT_MARGIN:
					break;
				case EXECUTION_SET_HORI_VERTI_MOVE_UNIT:
					break;
				case EXECUTION_SET_PRINT_AREA_WIDTH:
					break;
				case EXECUTION_SET_AUTO_STATE_RETURN:
					break;
				case EXECUTION_SEL_QRCODE_TYPE:
					break;
				case EXECUTION_ESC_PRINT_QRCODE:
					break;
				case EXECUTION_PRINT_QRCODE:
					break;
			case EXECUTION_SET_PRINT_DENSITY: //设置打印密度
//        #ifndef __DEBUG__
            DeviceDB.PrintConfig.Depth = MIN(14, pData[6]);
//        #endif
            break;
        case EXECUTION_SET_PRINT_SPEED:   //设置打印速度
            DeviceDB.PrintConfig.Speed = MIN(4, pData[6]); //打印速度
            break;
        case EXECUTION_SET_PAPER_TYPE:    //设置纸张类型
            DeviceDB.PrintConfig.PaperType = MIN(ENUM_PAPER_TYPE_COUNT - 1, pData[6]);
            break;
        case EXECUTION_SET_PRINT_MODE:    //设置打印模式
            DeviceDB.PrintConfig.PrintMode = MIN(ENUM_PRINT_MODE_COUNT - 1, pData[6]);
            break;
        case EXECUTION_SET_LABEL_SIZE:   //设置标签大小
            DeviceDB.PrintConfig.LabelSize.Width  = pData[6] | (pData[7] << 8);
            DeviceDB.PrintConfig.LabelSize.Height = pData[8] | (pData[9] << 8);
            break;
        case EXECUTION_SET_BOOT_LOGO:
            break;
        case EXECUTION_CLEAR_BOOT_LOGO:
            break;
        case EXECUTION_SET_NFC_PASSWORD:
            break;
        case EXECUTION_SET_RIBBONS_LENGTH:
            break;
        case EXECUTION_GET_PRINTER_INFO:  //获取打印机信息
            switch(EscCmd.DataBuffer[1])
            {
                case 0x65:    // get firmware version
                    break;
                case 0x66:    // get vendor
                    break;
                case 0x67:    // get printer name
                    break;
                case 0x68:    // get printer serial number
                    break;
                case 0x69:    // get supported chinese character 
                    break;
                case 0x70:    // get bluetooth MAC address
                    break;
                case 0x40:    // get FW version
                    DataResponse((BYTE *)pBL_INFO->Version, strlen(pBL_INFO->Version) + 1);
                    break;
                case 0x41:    // get BL version
                {
//                    char buf[32] = "_";//"_02.001.BJ0930";
//                    MFG_GetFWVersion(&buf[1]);
//                    DataResponse((BYTE *)buf, strlen(buf) + 1);
                    break;
                }
            }
            break;            
        case EXECUTION_GET_TAPE_STATUS:
            break;
        case EXECUTION_GET_BATTERY_STATUS:
            break;
        case EXECUTION_GET_WIRELESS_STATUS:
            break;
        case EXECUTION_GET_PRINTER_MAX_WIDTH:
            break;
        case EXECUTION_SET_LABEL_INFO:    //设置标签信息
        {
            ST_PRINT_LABEL_CONFIG config;
            config.PrintLength      = (UINT16)((pData[1] << 8) | pData[0]);
            config.PrintOffset      = (UINT16)((pData[3] << 8) | pData[2]);
            config.TapeWidth        = pData[4];
            config.DeviceType       = pData[5];
            config.LabelCount       = pData[6];
            config.LabelIndex       = pData[7];
            config.TotalDataCount   = (UINT32)((pData[11] << 24) | (pData[10] << 16) | (pData[9] << 8) | pData[8]);
            Printer_SetLabelConfig(config);
            g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 0;
            g_DeviceStatus.RealStatusFlag.Bits.PrintDone    = 0;
            g_DeviceStatus.RealStatusFlag.Bits.PrintCancel  = 0;
            break;
        }
        case EXECUTION_PRINT_ROW:     //执行打印行操作
        {
            BYTE printData[48] = {0};
            //memset(printData, 0, 48);
            memcpy(printData, &pData[1], MIN(48, pData[0]));
            if(g_DeviceStatus.RealStatusFlag.Bits.DataReceived == 0)
            {
                g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 1;
            }
            Printer_PrintRow(printData);  //打印行
            break;
        }
        case EXECUTION_PRINT_RLE_ROW: //执行打印RLE算法行操作
        {
            if(g_DeviceStatus.RealStatusFlag.Bits.DataReceived == 0)
            {
                g_DeviceStatus.RealStatusFlag.Bits.DataReceived = 1;
            }
            Printer_PrintRleRow(pData, dataLength);
            break;
        }
        case EXECUTION_FEEDPAPER: //执行正向进纸
            Printer_Feedpaper(EscCmd.DataBuffer[0]);
            break;
        case EXECUTION_FEEDPAPER_TO_GAP:
            Printer_FeedpaperToEnd();
            break;
        case EXECUTION_WRITE_HF_RFID: //执行写高频RFID
        {
//            UINT16 totalLen = pData[2] | (pData[3] << 8);
//            UINT16 offset = 0;
//            Printer_RFIDInfoClear();
//            while((offset + 2) < totalLen)
//            {
//                BYTE blockNo = pData[6 + offset];
//                BYTE dataLen = pData[7 + offset];
//                Printer_RFIDInfoInsert(blockNo, &pData[8 + offset], dataLen);
//                offset = offset + 2 + dataLen;
//            }
            break;
        }
        case EXECUTION_WRITE_UHF_RFID:  //执行写超高频RFID
            break;
        case EXECUTION_FW_UPGRADE_CONFIRM:  //执行固件升级确认
            BT_WriteBuffer((BYTE *)"OK", 2, 1000);
            break;
        default:
            break;
    }
    return 0;
}


/*************************************************
*函数名称:ESCPOSCmd
*描述: 接收到BT和USB的指令数据进行判断
*
*参数:Data-接收到的数据
*      		 
**************************************************/
void ESCPOSCmd(BYTE data)
{
	switch(EscCmd.State)
	{
		case ESCPOS_STATE_IDLE:
					EscCmd.POSID =data;
//					BT_WriteByte(data,100);
					switch(EscCmd.POSID)
					{
						case ESC_POSID_HORIZONTAL_MOVE:   //0x09 水平移动 HT
								KeyFeedPaperFlag =0;
								CmdExecute(EXECUTION_HORIZONTAL_MOVE, EscCmd.DataBuffer, EscCmd.DataLength);
								break;
						case ESC_POSID_PRINT_MOVE_LINE:  //0x0A 打印并走纸一行 LF
								KeyFeedPaperFlag =0;
								CmdExecute(EXECUTION_PRINT_MOVE_LINE, EscCmd.DataBuffer, EscCmd.DataLength);
								break;
//						case ESC_POSID_PRINT_TO_END:    //0x0C 打印并走纸到下页首 FF
//									KeyFeedPaperFlag =0;
//									CmdExecute(EXECUTION_FEEDPAPER_TO_GAP, EscCmd.DataBuffer, EscCmd.DataLength);
//									break;
						case ESC_POSID_PRINT_AND_ENTER:  //0x0D 打印并输入 CR
								KeyFeedPaperFlag =0;
//								CmdExecute(EXECUTION_FEEDPAPER_TO_GAP, EscCmd.DataBuffer, EscCmd.DataLength);
								CmdExecute(EXECUTION_PRINT_MOVE_LINE, EscCmd.DataBuffer, EscCmd.DataLength);
//								CmdExecute(EXECUTION_PRINT_AND_ENTER, EscCmd.DataBuffer, EscCmd.DataLength);
								break;
						case ESC_POSID_FS_CONTROL:      //0x1C  控制(FS)
								EscCmd.DataLength     = 0;
								EscCmd.SubDataLength  = 0;
								EscCmd.SubDataIndex   = 0;
								EscCmd.State          = ESCPOS_STATE_RECV_STATUS_FS;
								break;
						case ESC_POSID_STATUS_GET:  //0x10 实时状态传输 DLE EOT n (一级)
								EscCmd.DataLength     = 0;
								EscCmd.SubDataLength  = 0;
								EscCmd.SubDataIndex   = 0;
								EscCmd.State          = ESCPOS_STATE_RECV_STATUS_GET;
								break;
						case ESC_POSID_PARAM_CONFIG: //0x1D 参数配置(GS)
								EscCmd.DataLength     = 0;
								EscCmd.SubDataLength  = 0;
								EscCmd.SubDataIndex   = 0;
								EscCmd.State          = ESCPOS_STATE_RECV_PARAM_CONFIG;
								break;
						case ESC_POSID_CONTROL:      //0x1B 接收控制(ESC)
								EscCmd.DataLength     = 0;
								EscCmd.SubDataLength  = 0;
								EscCmd.SubDataIndex   = 0;
								EscCmd.State          = ESCPOS_STATE_RECV_CONTROL;
								break;
						default:
								break;
					}
				break;
			case ESCPOS_STATE_RECV_STATUS_GET:           //实时状态传输 DLE EOT n(二级数据)
				if(EscCmd.DataLength < ESC_CMD_BUFFER_SIZE1)
				{ 
						EscCmd.DataBuffer[EscCmd.DataLength++] =data;
				}
				if(EscCmd.DataLength>=2)
				{
					if(EscCmd.DataBuffer[0]==0x04) //(二级数据)
					{
						CmdExecute(EXECUTION_GET_PRINTER_STATUS, EscCmd.DataBuffer, EscCmd.DataLength);
					}
					EscCmd.DataLength=0;
					EscCmd.State =ESCPOS_STATE_IDLE;
				}
				break;
			case ESCPOS_STATE_RECV_CONTROL:     //ESC 控制系列
			{
				if(EscCmd.DataLength < ESC_CMD_BUFFER_SIZE1)
				{
					EscCmd.DataBuffer[EscCmd.DataLength++] =data;
				}
				if(EscCmd.DataLength >=1)
				{
					if(EscCmd.DataBuffer[0] == 0x20)  //ESC SP n设置字符右间距
				  {
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x21) // ESC ! n 选择打印模式
					{
//							 BT_WriteByte(EscCmd.DataBuffer[1],100);
//							 BT_WriteByte(EscCmd.DataLength,100);
							if((EscCmd.DataLength >= 2))
							{
										
										CmdExecute(EXECUTION_SELECT_PRINT_MODE, EscCmd.DataBuffer, EscCmd.DataLength);
										EscCmd.DataLength = 0;
										EscCmd.State = ESCPOS_STATE_IDLE;
							}
							
					}
					else if(EscCmd.DataBuffer[0] == 0x24) //ESC $ nL nH 设置绝对打印位置
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x25) //ESC % n 选择/取消用户自定义字符
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x26) //ESC & y .. 定义用户自定义字符
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x2A) //ESC * m nL nH d1... dk 选择位图模式
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x2D) //ESC - n 选择/取消下划线模式
					{
					}
					else if(EscCmd.DataBuffer[0] == 0x32) //ESC 2 设置默认行高
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x33) //ESC 3 n 设置行高
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x3D) //ESC 3 n 选择外部设备
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x3F) //ESC ? n 取消用户自定义字符
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] ==0x40)  //ESC @ 打印机初始化 清除打印缓冲区数据)  
					{
//						uint8_t temp =0x40;
//						DataResponse(&temp, 1);
//						BT_WriteString("40");
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x44)  //ESC D nl....nK NUL设置横向跳格位置
					{
						if(EscCmd.DataLength >=2)
						{
							if(data ==0x00)
							{
									CmdExecute(EXECUTION_SET_HORIZONTAL_POS, EscCmd.DataBuffer, EscCmd.DataLength); 
									EscCmd.DataLength=0;
									EscCmd.State =ESCPOS_STATE_IDLE;
							}
						}
					}
					else if(EscCmd.DataBuffer[0] == 0x45) //ESC E n 选择/取消加粗模式
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x47) //ESC E n 选择/取消双重打印模式
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] ==0x4A)  //ESC J N 打印并走纸
					{
							uint8_t temp =0x4A;
						 DataResponse(&temp, 1);
						
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x4D) //ESC M n 选择字体
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x52) //ESC R n 选择国际字符集
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x55) //ESC U n 横向放大
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x56) //ESC V n 纵向放大
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x57) //ESC W n 横向纵向放大
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x5C) //ESC \ nL nH 设置相对横向打印位置
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x61) //ESC a n 选择字符对齐模式
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x63) 
					{
						 if(EscCmd.DataLength >=2)
						 {
							 if(EscCmd.DataBuffer[1]==0x35) //ESC c 5 n  允许/禁止按键
							 {
										EscCmd.DataLength = 0;
										EscCmd.State = ESCPOS_STATE_IDLE;
							 }
							 else 													//ESC c n 允许/禁止反向打印
							 {
								 
								EscCmd.DataLength = 0;
								EscCmd.State = ESCPOS_STATE_IDLE;
							 }
						 
						 }
						 
					}
					else if(EscCmd.DataBuffer[0] == 0x64) //ESC d n 打印并向前走纸n行
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x69) //ESC I n 允许/禁止反白打印
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x74) //ESC t n 选择字符代码页
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0] == 0x7B) //ESC { n 选择/取消倒置打印模式
					{
							EscCmd.DataLength = 0;
							EscCmd.State = ESCPOS_STATE_IDLE;
					}
					else
					{
							EscCmd.State = ESCPOS_STATE_IDLE;
							EscCmd.DataLength = 0;
					}
					
				}
				break;
			}	
			case ESCPOS_STATE_RECV_PARAM_CONFIG:  //GS 配置系列
			{
				if(EscCmd.DataLength < ESC_CMD_BUFFER_SIZE1)
				{
					EscCmd.DataBuffer[EscCmd.DataLength++] =data;
				}
				if(EscCmd.DataLength >=1)
				{
					if(EscCmd.DataBuffer[0]==0x21) //GS ! n选择字符大小
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x28) //GS ( A pL pH n m 执行测试打印
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x2A) //GS * x y d1...d(x *y*8) 定义下载位图
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x2F) //GS / m 打印下载位图
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x42) //GS B n 选择/取消黑白打印模式
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x49) //GS I n 查询打印机型号
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x4C) //GS L nL nH 设置左边距
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x50) //GS P x y 设置横向和纵向移动单位
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x57) //GS W nL nH 设置打印区域宽度
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
					else if(EscCmd.DataBuffer[0]==0x5A) //GS Z n 选择二维码类型
					{
						EscCmd.DataLength=0;
						EscCmd.State =ESCPOS_STATE_IDLE;
					}
				}
				
				break;
			}
			default:
				EscCmd.DataLength=0;
				EscCmd.State =ESCPOS_STATE_IDLE;
				break;
	}
}























//                                       ESCPOS.h  


#ifndef __USER_H_
#define __USER_H_

#include "stm32f1xx_hal.h"
#include "cmsis_os.h"
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "Structures.h"
//#include "hal.h"
#include "EscCommand.h"
#include "Printer.h"
#include "hal_bluetooth.h"
//#include "Version.h"
//#include "CRC16.h"
//#include "usbd_cdc_if.h"
//#include "MFG.h"
//#include "UI.h"
//#include "hal_uhf_module.h"



void ESCPOSCmd(BYTE data);


打印机状态位域
//typedef struct 
//{
//	uint8_t Default_BitField_0:1;						//固定位1bit
//	uint8_t Default_BitField_1:1;						//固定位1bit
//	uint8_t CashDrawerSignel_Field_2:1;			//钱箱开/关信号位1bit
//	uint8_t Online_OR_FFline_Field_3:1;			//脱机或联机位1bit
//	uint8_t Default_BitField_4:1;						//固定位1bit
//	uint8_t Undefined_BitField_5:1;					//未定义位1bit
//	uint8_t Undefined_BitField_6:1;					//未定义位1bit
//	uint8_t Default_BitField_7:1;						//固定为位1bit
//}PRINTER_STATUS_FIELD;



打印机脱机状态位域
//typedef struct 
//{
//	uint8_t Default_BitField_0:1;						//固定位1bit 
//	uint8_t Default_BitField_1:1;						//固定位1bit
//	uint8_t UpperCover_Status_Field_2:1; 		//上盖开关状态位1bit
//	uint8_t FeedPaper_Mode_Field_3:1;		  	//有无按下走纸键位1bit
//	uint8_t Default_BitField_4:1;						//固定位1bit	
//	uint8_t PaperOutStop_BitField_5:1;			//打印机缺纸停止或其他  1bitss
//	uint8_t ErrorStatus_BitField_6:1;				//有无出现错误位1bit
//	uint8_t Default_BitField_7:1;						//固定位1bit
//}OFFline_STATUS_FIELD;



打印机错误状态位域
//typedef struct 
//{
//	uint8_t Default_BitField_0:1;					  //固定位1bit 
//	uint8_t Default_BitField_1:1;					  //固定位1bit
//	uint8_t Undefined_BitField_2:1; 			  //未定义位1bit
//	uint8_t CutterIsWrong_Field_3:1;		    //切刀有无错误位1bit
//	uint8_t Default_BitField_4:1;					  //固定位1bit	
//	uint8_t UnrecoverableError_Field_5:1;		//有无不可恢复错误位1bit
//	uint8_t Default_BitField_6:1;						//未定义位1bit
//	uint8_t Default_BitField_7:1;					  //未定义位1bit
//}ERROR_STATUS_FIELD;

纸传感器状态位域
//typedef struct 
//{
//	uint8_t Default_BitField_0:1;					  //固定位1bit 
//	uint8_t Default_BitField_1:1;					  //固定位1bit
//	uint8_t Default_BitField_2:1; 			  	//固定位1bit
//	uint8_t Default_BitField_3:1;		    		//固定位1bit
//	uint8_t Default_BitField_4:1;					  //固定位1bit	
//	uint8_t HAVEPAPER_BitField_5:1;				  //缺纸传感器:有纸位1bit
//	uint8_t NOPAPER_BitField_6:1;						//缺纸传感器:缺纸位1bit
//	uint8_t Default_BitField_7:1;					  //固定位1bit
//}PAPER_SENSOR_STATUS_FIELD;

#endif 






























//                                freertos.c  


/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * This notice applies to any and all portions of this file
  * that are not between comment pairs USER CODE BEGIN and
  * USER CODE END. Other portions of this file, whether 
  * inserted by the user or by software development tools
  * are owned by their respective copyright owners.
  *
  * Copyright (c) 2019 STMicroelectronics International N.V. 
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without 
  * modification, are permitted, provided that the following conditions are met:
  *
  * 1. Redistribution of source code must retain the above copyright notice, 
  *    this list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
  * 3. Neither the name of STMicroelectronics nor the names of other 
  *    contributors to this software may be used to endorse or promote products 
  *    derived from this software without specific written permission.
  * 4. This software, including modifications and/or derivative works of this 
  *    software, must execute solely and exclusively on microcontroller or
  *    microprocessor devices manufactured by or for STMicroelectronics.
  * 5. Redistribution and use of this software other than as permitted under 
  *    this license is void and will automatically terminate your rights under 
  *    this license. 
  *
  * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS" 
  * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT 
  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
  * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT 
  * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */     

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
   
/* USER CODE END FunctionPrototypes */

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
     
/* USER CODE END Application */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值