📄 main.pas
字号:
for j := 0 to high(Protocol) do
begin
if (Protocol[j].GateCode = ServiceCode[i].GateCode) and (Mt.Mt.MtMsgType = Protocol[j].MsgType) then
begin
mtbuffer.UpdatePrePrced(Seqid, j);
preprced := True;
break;
end;
end;
end;
end;
if preprced = false then
begin
//业务代码校验和转换失内败
//预处理无对应类型的业务代码
mtbuffer.UpdateFailPrePrced(Seqid, 1);
end;
end;
end;
end;
procedure TMtPrePrcThreadObj.ThAddMsgToMemo;
begin
if MainForm <> nil then
begin
MainForm.ShowToMemo(ErrMsg, MainForm.MonitorMemo);
end;
end;
{ TMonitorThreadObj }
procedure TMonitorThreadObj.AddMsgToMemo(const Msg: string);
begin
ErrMsg := Msg;
Synchronize(ThAddMsgToMemo);
end;
constructor TMonitorThreadObj.Create(CreateSuspended: boolean);
begin
inherited;
InMonitorBuffer := TMonitorInBufferObj.Create;
OutMonitorBuffer := TMonitorOutBufferObj.Create;
OutMonitorcmppBuffer := TMonitorOutcmppBufferObj.Create;
end;
destructor TMonitorThreadObj.destroy;
begin
OutMonitorBuffer.Free;
InMonitorBuffer.Free;
inherited;
end;
procedure TMonitorThreadObj.Execute;
var
i: integer;
begin
FreeOnTerminate := True;
while not Terminated do
begin
try
try
for i := 0 to high(OutMonitorBuffer.Buffers) do
begin
if OutMonitorBuffer.Buffers[i].IsUsed = 1 then
begin
ShowOutPac(OutMonitorBuffer.Buffers[i].pac);
OutMonitorBuffer.Delete(i);
break;
end;
end;
for i := 0 to high(OutMonitorcmppBuffer.Buffers) do
begin
if OutMonitorcmppBuffer.Buffers[i].IsUsed = 1 then
begin
ShowOutcmppPac(OutMonitorcmppBuffer.Buffers[i].pac);
OutMonitorcmppBuffer.Delete(i);
break;
end;
end;
//每2分钟,删除过期数据
if now - LastPrcExpireTime > 2 / 60 / 24 then
begin
if mobuffer <> nil then
begin
mobuffer.DelExpired;
mobuffer.BakBuffer;
end;
if mocmppbuffer <> nil then
begin
mocmppbuffer.DelExpired;
mocmppbuffer.BakBuffer;
end;
if mtbuffer <> nil then
begin
mtbuffer.DelExpired;
mtbuffer.BakBuffer;
end;
if mtcmppbuffer <> nil then
begin
mtcmppbuffer.DelExpired;
mtcmppbuffer.BakBuffer;
end;
if rptbuffer <> nil then
begin
rptbuffer.DelExpired;
rptbuffer.BakBuffer;
end;
if rptcmppbuffer <> nil then
begin
rptcmppbuffer.DelExpired;
rptcmppbuffer.BakBuffer;
end;
LastPrcExpireTime := now;
end;
except
on e: exception do
begin
AddMsgToMemo('数据包监控线程:' + e.Message);
end;
end;
finally
LastActiveTime := now;
sleep(10);
end;
end;
end;
procedure TMonitorThreadObj.ShowOutPac(pac: TSMGP13_PACKET);
var
li: TListItem;
p: TOutPacket;
begin
if (pac.MsgHead.RequestID <> SMGP13_ACTIVE_TEST) and (pac.MsgHead.RequestID <> SMGP13_ACTIVE_TEST_RESP) then
begin
if OutListview = nil then exit;
if OutListview.Items.Count > 100 then
begin
OutListview.Items.BeginUpdate;
TOutPacket(OutListview.Items[OutListview.Items.Count - 1].Data).Free;
OutListview.Items[OutListview.Items.Count - 1].Data := nil;
OutListview.Items.Delete(OutListview.Items.Count - 1);
OutListview.Items.EndUpdate;
end;
if OutListview.Items.Count > 0 then
begin
li := OutListview.Items.Insert(0);
end
else
begin
li := OutListview.Items.Add;
end;
li.SubItems.Add(inttostr(pac.MsgHead.SequenceID));
li.SubItems.Add(FormatDatetime('yyyy-mm-dd hh:nn:ss', now()));
p := TOutPacket.Create(pac);
li.Data := p;
case pac.MsgHead.RequestID of
SMGP13_LOGIN:
begin
li.Caption := '登录';
end;
SMGP13_LOGIN_RESP:
begin
li.Caption := '登录应答';
end;
SMGP13_DELIVER:
begin
if pac.MsgBody.DELIVER.IsReport = 0 then
li.Caption := '上行'
else li.Caption := '报告';
end;
SMGP13_DELIVER_RESP:
begin
if pac.MsgBody.DELIVER_RESP.MsgID = '' then
li.Caption := '报告应答'
else li.Caption := '上行应答';
end;
SMGP13_SUBMIT:
begin
li.Caption := '下行';
end;
SMGP13_SUBMIT_RESP:
begin
li.Caption := '下行应答';
end;
end;
end;
end;
procedure TMonitorThreadObj.ShowOutcmppPac(pac: TCMPP20_PACKET);
var
li: TListItem;
p: TOutcmppPacket;
begin
if (pac.MsgHead.Command_ID <> CMPP_ACTIVE_TEST) and (pac.MsgHead.Command_ID <> CMPP_ACTIVE_TEST_RESP) then
begin
if OutListview = nil then exit;
if OutListview.Items.Count > 100 then
begin
OutListview.Items.BeginUpdate;
TOutcmppPacket(OutListview.Items[OutListview.Items.Count - 1].Data).Free;
OutListview.Items[OutListview.Items.Count - 1].Data := nil;
OutListview.Items.Delete(OutListview.Items.Count - 1);
OutListview.Items.EndUpdate;
end;
if OutListview.Items.Count > 0 then
begin
li := OutListview.Items.Insert(0);
end
else
begin
li := OutListview.Items.Add;
end;
li.SubItems.Add(inttostr(pac.MsgHead.Sequence_ID));
li.SubItems.Add(FormatDatetime('yyyy-mm-dd hh:nn:ss', now()));
p := TOutcmppPacket.Create(pac);
li.Data := p;
case pac.MsgHead.Command_ID of
CMPP_CONNECT:
begin
li.Caption := '登录';
end;
CMPP_CONNECT_RESP:
begin
li.Caption := '登录应答';
end;
CMPP_DELIVER:
begin
if pac.MsgBody.CMPP_DELIVER.Registered_Delivery = 0 then
li.Caption := '上行'
else li.Caption := '报告';
end;
CMPP_DELIVER_RESP:
begin
if pac.MsgBody.CMPP_DELIVER_RESP.Msg_Id = 0 then
li.Caption := '报告应答'
else li.Caption := '上行应答';
end;
CMPP_SUBMIT:
begin
li.Caption := '下行';
end;
CMPP_SUBMIT_RESP:
begin
li.Caption := '下行应答';
end;
end;
end;
end;
procedure TMonitorThreadObj.ShowOutSgipPac(pac: TSGIP12_PACKET);
var
li: TListItem;
p: TOutcmppPacket;
begin
{ if (pac.MsgHead.Command_ID <> CMPP_ACTIVE_TEST) and (pac.MsgHead.Command_ID <> CMPP_ACTIVE_TEST_RESP) then
begin
if OutListview = nil then exit;
if OutListview.Items.Count > 100 then
begin
OutListview.Items.BeginUpdate;
TOutcmppPacket(OutListview.Items[OutListview.Items.Count - 1].Data).Free;
OutListview.Items[OutListview.Items.Count - 1].Data := nil;
OutListview.Items.Delete(OutListview.Items.Count - 1);
OutListview.Items.EndUpdate;
end;
if OutListview.Items.Count > 0 then
begin
li := OutListview.Items.Insert(0);
end
else
begin
li := OutListview.Items.Add;
end;
li.SubItems.Add(inttostr(pac.MsgHead.Sequence_ID));
li.SubItems.Add(FormatDatetime('yyyy-mm-dd hh:nn:ss', now()));
p := TOutcmppPacket.Create(pac);
li.Data := p;
case pac.MsgHead.Command_ID of
CMPP_CONNECT:
begin
li.Caption := '登录';
end;
CMPP_CONNECT_RESP:
begin
li.Caption := '登录应答';
end;
CMPP_DELIVER:
begin
if pac.MsgBody.CMPP_DELIVER.Registered_Delivery = 0 then
li.Caption := '上行'
else li.Caption := '报告';
end;
CMPP_DELIVER_RESP:
begin
if pac.MsgBody.CMPP_DELIVER_RESP.Msg_Id = 0 then
li.Caption := '报告应答'
else li.Caption := '上行应答';
end;
CMPP_SUBMIT:
begin
li.Caption := '下行';
end;
CMPP_SUBMIT_RESP:
begin
li.Caption := '下行应答';
end;
end;
end; }
end;
procedure TMonitorThreadObj.ThAddMsgToMemo;
begin
if MainForm <> nil then
begin
MainForm.ShowToMemo(ErrMsg, MainForm.MonitorMemo);
end;
end;
{ TOutPacket }
constructor TOutPacket.Create(p: TSMGP13_PACKET);
begin
pac := p;
end;
destructor TOutPacket.destroy;
begin
inherited;
end;
{ TOutcmppPacket }
constructor TOutcmppPacket.Create(p: TCMPP20_PACKET);
begin
pac := p;
end;
destructor TOutcmppPacket.destroy;
begin
inherited;
end;
{ TOutSgipPacket }
constructor TOutSgipPacket.Create(p: TSGIP12_PACKET);
begin
pac := p;
end;
destructor TOutSgipPacket.destroy;
begin
inherited;
end;
procedure TMainForm.ShowToMemo(s: string; m: TMemo);
begin
if m <> nil then
begin
m.Lines.Add('[' + FormatDatetime('yyyy-mm-dd hh:nn:ss', now) + ']' + s);
end;
end;
procedure TMainForm.SMGPTCPClientConnected(Sender: TObject);
begin
try
ShowToMemo('外部网关SMGP已连接', MonitorMemo);
if MtSendThread <> nil then
begin
MtSendThread.Terminate;
MtSendThread := nil;
end;
if OutReadThread <> nil then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -