?? lb_xmit.c
字號:
/*
***********************************************************************************************************
Amos
The Real_Time Operation System
Multi Task
(c) Copyright 1998-2002, ShangYaoHui, Shenzhen
All Right Reserved
VERSION 6.01
" By : 商耀揮(ShangYaoHui)
create time: 2002-7-4 20:28:58
***********************************************************************************************************
*/
/************ head file list *************/
/* header include files -- defines (.h) */
#include "envopt.h" /* environment options */
#include "envdep.h" /* environment dependent */
#include "envind.h" /* environment independent */
#include "gen.h" /* general */
#include "cm5.h" /* common functions */
#include "ssi.h" /* system services */
/* header/extern include files (.x) */
#include "gen.x" /* general */
#include "cm5.x" /* common functions */
#include "ssi.x" /* system services */
#include "cm_llist.h"
#include "cm_llist.x"
#ifdef WIN32
#include "winbase.h"
#include "winsock2.h"
#endif
#include "rx.h"
#include "rx.x"
#include "rx_msg.h"
#include "rx_msg.x"
#include "lb_cm.h"
#include "lb_cm.x"
#include "lb_recv.h"
#include "lb_recv.x"
#include "lb_xmit.h"
#include "lb_xmit.x"
#include "lb_msg.h"
#include "lb_msg.x"
#include "lb_bdy1.h"
#include "lb_bdy1.x"
#include "lb_bdy2.h"
#include "lb_bdy2.x"
#include "lb_bdy4.h"
#include "lb_bdy3.h"
#include "lb_bdy3.x"
#include "lb_bdy4.h"
#include "lb_bdy4.x"
#include "lb_bdy5.h"
#include "lb_bdy5.x"
/************* const define **************/
/******** import variable declare ********/
/******* gloable variable declare ********/
/*********** function declare ************/
/********** function prototype ***********/
S16 lbXmitMsg(ScCommCb_s * scCommCb, Buffer * msg)
{
Bool writeStat;
Data * buf;
MsgLen writeLen, actualLen;
S32 err;
COMSTAT commStat;
if(msg == NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
if(ROK != SFndLenMsg(msg, &writeLen))
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(ROK);
}
if(!writeLen)
{
SPutMsg(msg);
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(ROK);
}
if(ROK != SGetSBuf(0, 0, &buf, writeLen + 2))
{
SPutMsg(msg);
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(ROK);
}
SCpyMsgFix(msg, 0, writeLen, buf, &writeLen);
lbFillCrc(buf, (MsgLen)(writeLen + 2));
#ifdef LO_DEBUG
lbCmPrntBuf("xmit msg:", buf, (MsgLen)(writeLen + 2));
LBLOG(scCommCb->commName, 0, 0);
LBLOG("Xmit msg", buf, writeLen + 2);
#endif
err = ClearCommError(scCommCb->comm, &err, &commStat );
if(err == 0)
{
err = GetLastError();
}
actualLen = commStat.cbInQue;
if(actualLen > 0)
{
Data recvBuf[2048];
ReadFile(scCommCb->comm, recvBuf, actualLen, &actualLen, NULLP);
}
writeStat = WriteFile(scCommCb->comm, buf, (U32)(writeLen + 2),
(U32*)&actualLen, NULLP);
SPutMsg(msg);
SPutSBuf(0, 0, buf, writeLen + 2);
RETVALUE(ROK);
}
S16 lbIndMsg(CmdMsg_s * cmd)
{
U32 i, len;
Data buf[512];
Data * ptr;
EquCfgEntry_s * equ;
buf[0] = cmd->msgCode;
ptr = buf;
switch(cmd->msgCode)
{
case 0x01:
buf[1] = cmd->rqstParam;
len = 2;
ptr = buf;
LBLOG("抬槍", ptr, len);
break;
case 0x02:
{
U32 volume;
U8 * temp;
GunDownIndMsg_s *msg = (GunDownIndMsg_s*)buf;
msg->gunId = cmd->gunId;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
volume = htonl(equ->crrntVolume);
temp = ((U8 *)&volume) + 1;
for(i = 0; i < 3; i++)
{
msg->volume[i] = *temp++;
}
len = 5;
ptr = buf;
LBLOG("掛槍", ptr, len);
break;
}
case 0x03:
{
OnWorkIndMsg_s * msg = (OnWorkIndMsg_s *)buf;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
memcpy(msg->workerCardNo, equ->workerCardNo, 10);
msg->gunId = cmd->rqstParam;
msg->totle = htonl(equ->totleVolume);
len = 16;
ptr = buf;
LBLOG("上崗", ptr, len);
break;
}
case 0x04:
{
UserInsCardIndMsg_s * msg = (UserInsCardIndMsg_s *)buf;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
memcpy(msg->cardNo, equ->crrntCardNo, 10);
msg->gunId = cmd->gunId;
len = sizeof(UserInsCardIndMsg_s);
ptr = buf;
LBLOG("用戶插卡", ptr, len);
break;
}
case 0x05:
{
UserOutCardIndMsg_s * msg = (UserOutCardIndMsg_s*)buf;
msg->cmdCode = 0x05;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
msg->ballencStat = equ->crrntCardInfo.cardBallencStat;
msg->cardValue = htonl(equ->crrntCardInfo.cardBallencValue);
msg->gunId = cmd->rqstParam;
len = 7;
ptr = &buf[2];;
LBLOG("用戶拔卡", ptr, len);
break;
}
case 0x06:
{
CrrntCardInfoIndMsg_s * msg = (CrrntCardInfoIndMsg_s*)buf;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
msg->cmdCode = 0x06;
msg->cardStat = equ->crrntCardInfo.cardStat;
msg->cardValue = htonl(equ->crrntCardInfo.cardValue);
msg->cardType = equ->crrntCardInfo.cardType;
msg->gunId = cmd->gunId;
len = 8;
ptr = &buf[2];
LBLOG("上傳卡信息", ptr, len);
break;
}
case 0x08:
{
equ = findEqu(cmd->rqstParam);
memcpy(&buf[1], &equ->record, 62);
len = 63;
ptr = buf;
LBLOG("上傳交易", ptr, len);
break;
}
case 0x09:
{
EquCfgEntry_s * equ;
U8 errCode = 0;
CHKHANDLESTAT(cmd);
equ = (EquCfgEntry_s *)cmLListFirst(&rxCb.pEquCfgList);
while(NULLP != equ)
{
if(equ->cmdProcErrCode)
{
errCode |= equ->cmdProcErrCode;
equ->cmdProcErrCode = 0;
}
equ = (EquCfgEntry_s *)cmLListNext(&rxCb.pEquCfgList);
}
if(errCode)
{
buf[1] = 0x11;
}
else
{
buf[1] = 0x10;
}
len = 2;
ptr = buf;
LBLOG("取黑名單回應", ptr, len);
lbCmDestroyCmdNode(cmd);
break;
}
case 0x0a:
{
U32 i, volume;
U8 * temp;
FillVolumeIndMsg_s * msg = (FillVolumeIndMsg_s *)buf;
msg->cmdCode = 0x0a;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
msg->gunId = cmd->rqstParam;
volume = htonl(equ->crrntVolume);
temp = ((U8 *)&volume) + 1;
for(i = 0; i < 3; i++)
{
msg->volume[i] = *temp++;
}
len = sizeof(FillVolumeIndMsg_s);
ptr = buf;;
LBLOG("加油量", ptr, len);
lbCmDestroyCmdNode(cmd);
break;
}
case 0x0b:
{
OutWorkIndMsg_s * msg = (OutWorkIndMsg_s *)buf;
equ = findEqu(cmd->gunId);
if(equ ==NULLP)
{
RXLOGERROR(0, 0, 0, "ERROR");
RETVALUE(RFAILED);
}
msg->cmdCode = 0x0b;
msg->gunId = cmd->rqstParam;
msg->totleVolume = htonl(equ->totleVolume);
len = 6;
ptr = &buf[2];
LBLOG("員工離崗", ptr, len);
break;
}
case 0x0c:
{
buf[1] = 0;
len = 2;
ptr = buf;
LBLOG("取站點代碼回應", ptr, len);
break;
}
case 0xd:
{
CHKHANDLESTAT(cmd);
buf[1] = 0x10;
len = 2;
ptr = buf;
LBLOG("取設備信息回應", ptr, len);
lbCmDestroyCmdNode(cmd);
break;
}
case 0x0e:
{
EquCfgEntry_s * equ;
U8 errCode = 0;
CHKHANDLESTAT(cmd);
equ = (EquCfgEntry_s *)cmLListFirst(&rxCb.pEquCfgList);
while(NULLP != equ)
{
if(equ->cmdProcErrCode)
{
errCode |= equ->cmdProcErrCode;
equ->cmdProcErrCode = 0;
}
equ = (EquCfgEntry_s *)cmLListNext(&rxCb.pEquCfgList);
}
if(errCode)
{
buf[1] = 0x11;
}
else
{
buf[1] = 0x10;
}
len = 2;
ptr = buf;
LBLOG("取定點回應", ptr, len);
lbCmDestroyCmdNode(cmd);
break;
}
case 0x0f:
{
EquCfgEntry_s * equ;
HistroyEntry_s * hisEntry, * temp;
Bool haveHis = FALSE;
CHKHANDLESTAT(cmd);
if(cmd->rqstParam == 0)
{
equ = (EquCfgEntry_s *)cmLListFirst(&rxCb.pEquCfgList);
while(NULLP != equ)
{
buf[0] = 0x08;
while(NULLP != (hisEntry = (HistroyEntry_s *)cmLListFirst(&equ->histroy)))
{
memcpy(&buf[1], &hisEntry->record , 62);
UP_DATA(0, 63, buf);
cmLListDelFrm(&equ->histroy, (CmLList *)hisEntry);
SPutSBuf(0, 0, (Data *)hisEntry, sizeof(HistroyEntry_s));
haveHis = TRUE;
}
equ = (EquCfgEntry_s *)cmLListNext(&rxCb.pEquCfgList);
}
}
else
{
equ = findEqu(cmd->rqstParam);
buf[0] = 0x08;
while(NULLP != (hisEntry = (HistroyEntry_s *)cmLListFirst(&equ->histroy)))
{
haveHis = TRUE;
memcpy(&buf[1], &hisEntry->record , 62);
LBLOG("取歷史交易回應", ptr, 63);
UP_DATA(0, 63, buf);
cmLListDelFrm(&equ->histroy, (CmLList *)hisEntry);
SPutSBuf(0, 0, (Data *)hisEntry, sizeof(HistroyEntry_s));
}
}
if(haveHis == FALSE)
{
buf[1] = 0x02;
LBLOG("取歷史交易回應", ptr, 2);
UP_DATA(0, 2, buf);
}
lbCmDestroyCmdNode(cmd);
RETVALUE(ROK);
}
case 0x10:
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -