📄 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 + -