?? comm.c
字號:
///////////////////////////////////////////////////////////////////////////////
// Comm.c
//
// Copyright (c) 2004, WeiHua Technology Co., Ltd.
// All rights reserved.
//
// Created by: Chen hh 2004-09-20
//
// Desription:
///////////////////////////////////////////////////////////////////////////////
#include "ecrsys.h"
#include "ftype.h"
#include "data.h"
#include "string.h"
#include "sysdata.h"
///////////////////////////////////////////////////////////////////////////////
// 修改步驟
// 1. 在項目中加入本文件 Comm.c
//
// 2. main.c, sale.c, program.c, xzreport.c, timmer.c, ftype.h
// 查找 comm.c 中的相關函數,然后拷貝修改部分.
//
// 3. tool.c: GetKey() GetIn()
// 查找 KD_PCLINK 相關部分.
//
// 4. keydef.h 加入
// #define KD_PCLINK 250
//
// 5. serial.c
// 比較后替換. 更改為全雙工發送接收,以支持中斷中發送.
//
// 6. ecrsys.h 中相應修改以下宏定義:
// #define RSBUFLEN 0x3FF
// #define WRBUFLEN 0x3FF
//
///////////////////////////////////////////////////////////////////////////////
// public function
void Comm_AutoChkLinkCmd(byte port, byte uartData);
void Comm_SetStatus(byte status);
void Comm_ChkTimeOut(void);
void Comm_LinkCmdReply(byte port, byte status);
void KB_InsKey(word keyValue);
static byte ecrStatus = STATUS_INIT; // 機器(系統)當前狀態.
static byte linkCmdTimeOut = 0; // PC聯機命令字符間隔時間計數器.
static byte tmpStatus; // 臨時變量.
// PC聯機命令字符數組(HOST -> ECR).
//static const byte linkCmd[] = {0x1b, 0x10, 0, 5, 0x1b+0x10+0+5};
//static const byte linkCmd[] = {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x23, 0x00, 0x00};
static const byte linkCmd[] = {0x00, 0x00, 0x23, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
// PC聯機命令應答,返回當前狀態的命令字符數組(ECR -> HOST).
//static const byte linkCmdReply[] = {'O', 'K', 0, sizeof(linkCmdReply), 0, 'O'+'K'+0+6+0};
static const byte linkCmdReply[] = {0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x23, 0x01, STATUS_IDLE, STATUS_IDLE};
static byte linkCmdIdx = sizeof(linkCmd); // PC聯機命令已匹配字節數.
///////////////////////////////////////////////////////////////////////////////
// Descript: ECR空閑時,實時檢測PC命令.檢測到聯機命令時,發出虛擬按鍵以進入通訊模式.
// 帶超時檢測功能. (連續數據間隔時間不得超過500ms)
// In Param: uartData --- 最新收到的串口數據.
// Out Param: void
// Return: void
///////////////////////////////////////////////////////////////////////////////
void Comm_AutoChkLinkCmd(byte port, byte uartData)
{
// 通訊狀態下,不再檢測聯機命令.
if ((ecrStatus != STATUS_COMM) && (linkCmd[linkCmdIdx-1] == uartData))
{
// linkCmdIdx++;
linkCmdIdx--;
if (linkCmdIdx == 0) // 檢測到有效命令.
{
linkCmdIdx = sizeof(linkCmd);
if(COMM_PORT == port)
tmpStatus = ecrStatus;
else
tmpStatus = STATUS_NOT_PC_COMM;
Comm_LinkCmdReply(port, tmpStatus);
if (tmpStatus == STATUS_IDLE)
{
if (bellcnt != 0xFF)
{
bellcnt = 30;
}
g_LCDBLCnt = sysflag->LCD_BL_Time; // set the LCD backlight time again.
KB_InsKey(KD_PCLINK); // 發出聯機按鍵.
}
}
else
{
linkCmdTimeOut = RSTIMEOUT / 5; // 每5ms減一次.
}
}
else
{
linkCmdIdx = sizeof(linkCmd); // 命令數據需連續送入.
}
}
///////////////////////////////////////////////////////////////////////////////
// Descript: 每隔5ms檢查一次字符發送超時. 用于系統定時回調處理.
// In Param: void
// Out Param: void
// Return: void
///////////////////////////////////////////////////////////////////////////////
void Comm_ChkTimeOut(void)
{
if (linkCmdTimeOut)
{
linkCmdTimeOut--;
if (linkCmdTimeOut == 0)
{
linkCmdIdx = sizeof(linkCmd); // 包字符間隔時間過長.
}
}
}
///////////////////////////////////////////////////////////////////////////////
// Descript: 設置系統當前狀態.
// In Param: status --- 銷售 / 報表 / 報表打印 / 編程 /...
// Out Param: void
// Return: void
///////////////////////////////////////////////////////////////////////////////
void Comm_SetStatus(byte status)
{
ecrStatus = status;
}
///////////////////////////////////////////////////////////////////////////////
// Descript: 應答PC聯機命令,返回當前狀態.
// In Param: status
// Out Param: void
// Return: void
///////////////////////////////////////////////////////////////////////////////
void Comm_LinkCmdReply(byte port, byte status)
{
byte replyCmd[sizeof(linkCmdReply)];
memcpy(replyCmd, linkCmdReply, sizeof(linkCmdReply));
replyCmd[8] = status;
replyCmd[9] += status;
Wr_Str_Uart(port, replyCmd, sizeof(linkCmdReply));
}
///////////////////////////////////////////////////////////////////////////////
// Descriptor: Insert one key into Key Buffer.
// In Param: keyValue
// Out Param: void
// Return: void
///////////////////////////////////////////////////////////////////////////////
void KB_InsKey(word keyValue)
{
if (((Khead + 1) % KEY_BUFF_SIZE) != Ktail) // Key buffer not full
{
KeyBuffer[Khead] = keyValue;
Khead = (Khead + 1) % KEY_BUFF_SIZE;
}
if (bellcnt != 0xFF) // Not the long bell
{
bellcnt = 30;
}
g_LCDBLCnt = sysflag->LCD_BL_Time; // set the LCD backlight time.
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -