⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transmit.pas

📁 电信网关平台(V3.0)
💻 PAS
📖 第 1 页 / 共 3 页
字号:
begin
  if SMGPGateWay.MeMO1.Lines.count > 500 then SMGPGateWay.MeMO1.Clear;
  if SMGPGateWay.N3.Checked then
    SMGPGateWay.MeMO1.Lines.Add(Statustr + #13#10);
  SMGPGateWay.StatusBar1.Panels[1].Text := 'T: ' + inttostr(CTD_cou);
  SMGPGateWay.StatusBar1.Refresh;
end;

procedure TTransmit.showError;
begin
  if SMGPGateWay.MeMO1.Lines.count > 500 then SMGPGateWay.MeMO1.Clear;
  if SMGPGateWay.N2.Checked then
    SMGPGateWay.MeMO1.Lines.Add(StatustrE + #13#10);
end;
procedure TTransmit.showstatu;
begin
  if SMGPGateWay.MeMO3.Lines.count > 1000 then SMGPGateWay.MeMO3.Clear;
  SMGPGateWay.MeMO3.Lines.Add(StatuTxt);
end;

procedure TTransmit.AddCou;
begin
  if CTD_cou > 2147483600 then CTD_cou := 1;
  inc(CTD_cou);
end;

procedure TTransmit.AddsSeq;
begin
  if sSequence >= 4294967200 then sSequence := 1;
  sSequence := sSequence + 1;
end;

procedure TTransmit.WriteReport(const Msgid: array of char; const Source: array of char);
var
  CTReport: PReport;
  buff: array[0..19] of char;
  temp: string;
begin
  FillChar(buff, sizeof(buff), 0);
  new(CTReport);
  move(Source[3], buff, 10);
  CTReport^.id := BCDToHex(buff, 10); // 状态报告对应原短消息回馈报告中的MsgID
  FillChar(buff, sizeof(buff), 0);
  move(Source[18], buff, 3);
  CTReport^.sub := buff; //   sub
  FillChar(buff, sizeof(buff), 0);
  move(Source[28], buff, 3);
  CTReport^.dlvrd := buff; //   dlvrd
  FillChar(buff, sizeof(buff), 0);
  move(Source[44], buff, 10);
  CTReport^.Submit_date := buff; //   Submit_date
  FillChar(buff, sizeof(buff), 0);
  move(Source[65], buff, 10);
  CTReport^.done_date := buff; //   done_date
  FillChar(buff, sizeof(buff), 0);
  move(Source[81], buff, 7);
  CTReport^.Stat := buff; //    Stat
  FillChar(buff, sizeof(buff), 0);
  move(Source[93], buff, 3);
  CTReport^.Err := buff; //    Err
  FillChar(buff, sizeof(buff), 0);
  move(Source[101], buff, 3); // Txt前3个byte
  temp := buff;
  FillChar(buff, sizeof(buff), 0);
  move(Source[108], buff, 12); //后12个BYTE
  temp := temp + buff;
  CTReport^.Txt := temp;
  ReportList.Add(CTReport);
  Statustr := '[' + datetimetostr(now) + ']Report:';
  Statustr := Statustr +'<MsgID>'+CTReport^.id + #32;
  Statustr := Statustr +'<Submit_date>'+CTReport^.Submit_date + #32;
  Statustr := Statustr +'<done_date>'+ CTReport^.done_date + #32;
  Statustr := Statustr +'<Stat>'+ CTReport^.Stat + #32;
  Statustr := Statustr +'<Err>'+ CTReport^.Err;
  LogList.AddLog('04' + Statustr);
  upmemo;
end;

procedure TTransmit.ShowDeliver(aDeliver: TCTDeliver; const LinkID:string);
begin
  Statustr := '[' + datetimetostr(now) + ']Deliver:';
  Statustr := Statustr +'<Msgid>' +BCDToHex(aDeliver.Msgid, sizeof(aDeliver.Msgid)) + #32;
  //Statustr := Statustr + inttostr(aDeliver.IsReport) + #32;
  Statustr := Statustr +'<SrcTermID>' + aDeliver.SrcTermID + #32;
  Statustr := Statustr +'<DestTermID>' +aDeliver.DestTermID + #32;
  Statustr := Statustr +'<MsgFormat>' + inttostr(aDeliver.MsgFormat) + #13#10;
  Statustr := Statustr +'<LinkID>' +LinkID + #32;
  Statustr := Statustr +'<MsgContent>' + aDeliver.MsgContent;
  LogList.AddLog('00' + Statustr);
  upmemo;
end;

procedure TTransmit.SaveToDeliverList(aDeliver: TCTDeliver;const LinkID:string); //短信
var
  pDeliver: PCTDeliver;
begin
  new(pDeliver);
  pDeliver^.Msgid := BCDToHex(aDeliver.Msgid, sizeof(aDeliver.Msgid));
  pDeliver^.IsReport := aDeliver.IsReport;
  pDeliver^.MsgFormat := aDeliver.MsgFormat;
  pDeliver^.RecvTime := aDeliver.RecvTime;
  pDeliver^.SrcTermID := aDeliver.SrcTermID;
  pDeliver^.DestTermID := aDeliver.DestTermID;
  pDeliver^.MsgLength := aDeliver.MsgLength;
  if aDeliver.MsgFormat = 8 then {Unicode}
    pDeliver.MsgContent := Ucs2ToString(aDeliver.MsgContent)
  else if aDeliver.MsgFormat = 15 then
    pDeliver^.MsgContent := aDeliver.MsgContent
  else if aDeliver.IsReport = 9 then
  begin {用户拆机、停机消息}
    pDeliver^.MsgContent := copy(aDeliver.MsgContent, 1, 12);
    pDeliver^.MsgContent := pDeliver^.MsgContent + aDeliver.MsgContent[17];
  end;
  pDeliver^.LinkID := LinkID;
  DeliverList.Add(pDeliver); //放入DELIVER队列中
end;
procedure TTransmit.SP_Deliver_Resp(Msg_id: array of char; SequenceID: Longword);
var
  SPDeliver_Resp: TDeliver_Resp; // 上行回馈
  Msgid: string;
begin
  FillChar(SPDeliver_Resp, sizeof(TDeliver_Resp), 0);
  SPDeliver_Resp.Head.PacketLength := HostToNet(sizeof(TDeliver_Resp));
  SPDeliver_Resp.Head.RequestID := HostToNet(Deliver_resp);
  SPDeliver_Resp.Head.SequenceID := HostToNet(SequenceID);
  move(Msg_id, SPDeliver_Resp.body.Msgid, 10);
  Msgid := BCDToHex(Msg_id, 10);
  SPDeliver_Resp.body.Status := HostToNet(0);
  if CTDeliver.Connected then
    if sizeof(TDeliver_Resp) = CTDeliver.SendBuf(SPDeliver_Resp, sizeof(TDeliver_Resp)) then
    begin
      Statustr := '[' + datetimetostr(now()) + ']Deliver_Resp:' + Msgid;
      upmemo;
    end;
end;
function TTransmit.SP_Submit: boolean;
var
  xList: TList;
  SubmitLen: integer;
  Empty: boolean;
  xTCSubmit: PxSubmit; //系统内部数据消息包指针
  rSubmit: xSubmit; //系统内部数据消息包
  SubmitSequence: Longword;
begin
  Result := True;
  Empty := False;
  xTCSubmit := nil;
  FillChar(rSubmit, sizeof(xSubmit), 0);
  if CTDeliver.Connected then
  begin
    xList := SubmitList.LockList;
    try
      if xList.count > 0 then
      begin
        try
          xTCSubmit := PxSubmit(xList.First); //强制类型转换
          rSubmit := xTCSubmit^; //转换记录
          try
            dispose(xTCSubmit); //释放指针
            xList.Delete(0); //删除列表
            xTCSubmit := nil;
          except
          end;
        except
        end;
      end
      else
        Empty := True;
    finally
      SubmitList.UnlockList;
    end;
    if Empty then
    begin
      Result := False;
      exit;
    end;
    //设置socket传输消息包体
    SubmitSequence := MakeSockBuff(SubmitLen, rSubmit);
    //=============================================================================
    try
      if (SubmitLen) = CTDeliver.SendBuf(SocketBuff[0], SubmitLen) then
      begin
        AddsSeq;
        inc(rSubmit.Resend); //发送次数加1
        rSubmit.SequenceID := SubmitSequence; //HostToNet(SMGPSubmit2011.Head.SequenceID);
        rSubmit.Then_DateTime := now; //设置当前发送时间
        new(xTCSubmit);
        xTCSubmit^ := rSubmit;
        SaveSubmitList.Add(xTCSubmit); //SAVE SM
       Statustr := '[' + datetimetostr(now) + ']Submit:';
        Statustr := Statustr +'<SequenceID>'+inttostr(xTCSubmit^.SequenceID) + #32;
        Statustr := Statustr +'<Mid>'+ xTCSubmit^.sSubmit.Mid + #32;
        Statustr := Statustr +'<MsgType>'+ inttostr(xTCSubmit^.sSubmit.MsgType) + #32;
        //Statustr := Statustr +'<NeedReport>'+ inttostr(xTCSubmit^.sSubmit.NeedReport) + #32;
        Statustr := Statustr +'<ServiceID>'+ xTCSubmit^.sSubmit.ServiceID + #32;
        Statustr := Statustr +'<FeeCode>'+ xTCSubmit^.sSubmit.FeeCode + #32;
        Statustr := Statustr +'<FixedFee>'+ xTCSubmit^.sSubmit.FixedFee + #32;
        Statustr := Statustr +'<ChargeTermID>'+ xTCSubmit^.sSubmit.ChargeTermID + #32;
        Statustr := Statustr +'<DestTermID>'+ xTCSubmit^.sSubmit.DestTermID + #13#10;
        Statustr := Statustr +'<SrcTermID>'+ xTCSubmit^.sSubmit.SrcTermID + #32;
        Statustr := Statustr +'<SubmitMsgType>'+ inttostr(xTCSubmit^.sSubmit.SubmitMsgType) + #32;
        Statustr := Statustr +'<LinkID>'+ xTCSubmit^.sSubmit.LinkID + #32;
        Statustr := Statustr +'<MsgContent>'+ xTCSubmit^.sSubmit.MsgContent + #32;
        LogList.AddLog('07' + Statustr);
        AddCou;
        upmemo;
      end
      else
      begin {发送不成功}
        new(xTCSubmit);
        xTCSubmit^ := rSubmit;
        SubmitList.Add(xTCSubmit);
      end;
    except
    end;
    SocketBuff := nil;
  end;
end;

procedure TTransmit.ReSubmit(SequenceID, statu: Longword);
var
  i: integer;
  cSubmit: PxSubmit;
  aList: TList;
  Mid: string;
begin
  aList := SaveSubmitList.LockList;
  try
    for i := 0 to aList.count - 1 do
    begin
      cSubmit := PxSubmit(aList.Items[i]);
      if SequenceID = cSubmit^.SequenceID then
        if cSubmit^.Resend >= sendtimes then
        begin //重发4次失败,不再重发
          Mid := cSubmit^.sSubmit.Mid;
          dispose(cSubmit);
          aList.Delete(i);
          StatustrE := '【' + datetimetostr(now()) + '】Submit_Resp MID=' + Mid + ' 电信网关返回状态=' + inttostr(statu) + '序列号=' + inttostr(SequenceID) + ',第4发送次失败,短消息已被删除';
          LogList.AddLog('09' + StatustrE);
          synchronize(showError);
          break;
        end
        else
        begin
          SubmitList.Add(cSubmit);
          aList.Delete(i);
          Mid := cSubmit^.sSubmit.Mid;
          StatustrE := '【' + datetimetostr(now()) + '】Submit_Resp MID=' + Mid + ' 电信网关返回状态=' + inttostr(statu) + '发送失败,等待再发...';
          synchronize(showError);
          break;
        end;
    end;
  finally
    SaveSubmitList.UnlockList;
  end;
end;
function TTransmit.DeleteMT(SequenceID: Longword; var aMid: string): boolean; //回馈报告
var
  i, FirstCount: integer;
  cSubmit: PxSubmit;
  aList: TList;
begin
  Result := False; //返回MID
  aList := SaveSubmitList.LockList;
  FirstCount := aList.count - 1; //列表初始元素个数
  try
    for i := FirstCount downto 0 do //扫描保存区列表一遍
    begin
      cSubmit := PxSubmit(aList.Items[i]);
      if SequenceID = cSubmit^.SequenceID then
      begin
        aMid := cSubmit^.sSubmit.Mid; //返回MID
        dispose(cSubmit);
        aList.Delete(i);
        Result := True;
      end
      else
      begin {SaveSubmitList中有还没有回馈报告回来的短信}
        if minutesBetween(now, cSubmit^.Then_DateTime) > resptime then {大于10分钟没有回回馈报告重发}
        begin
          SubmitList.Add(cSubmit);
          aList.Delete(i);
          Statustr := '【' + datetimetostr(now()) + '】MID=' + #32 + cSubmit^.sSubmit.Mid + #32 + '在' + inttostr(resptime) + '分钟后没有接收到电信回馈报告,网关作重发处理';
          synchronize(upmemo);
          LogList.AddLog('07' + Statustr);
        end;
      end;
    end;
  finally
    SaveSubmitList.UnlockList;
  end;
end;
procedure TTransmit.NoResponse_Resubmit;
var
  i, FirstCount: integer;
  cSubmit: PxSubmit;
  aList: TList;
begin
  aList := SaveSubmitList.LockList;
  FirstCount := aList.count - 1; //列表初始元素个数
  try
    for i := FirstCount downto 0 do //扫描保存区列表一遍
    begin
      cSubmit := PxSubmit(aList.Items[i]);
      {SaveSubmitList中有还没有回馈报告回来的短信}
      if minutesBetween(now, cSubmit^.Then_DateTime) > resptime then {大于10分钟没有回回馈报告重发}
      begin
        SubmitList.Add(cSubmit);
        aList.Delete(i);
        Statustr := '【' + datetimetostr(now()) + '】MID=' + #32 + cSubmit^.sSubmit.Mid + #32 + '在' + inttostr(resptime) + '分钟后没有接收到电信回馈报告,网关作重发处理';
        synchronize(upmemo);
        LogList.AddLog('07' + Statustr);
      end;
    end;
  finally
    SaveSubmitList.UnlockList;
  end;
end;

function TTransmit.MakeSockBuff(var SubmitLen: integer;
  rSubmit: xSubmit): Longword;
var
  i, count: integer;
  onenumber, Source: string;
  tmpBuf: array[0..20] of char;
  {2.0协议后}
  SMGPSubmit2011: TSMGPSubmit2011; //包头+包体1
  SMGPSubmit203: TSMGPSubmit203; //包体3
  SMGPTLV_tag:TSMGPTLV_tag;
  SMGPTLVLinkID_tag:TSMGPTLVLinkID_tag;
begin
  Result := 0;
  FillChar(SMGPSubmit2011, sizeof(TSMGPSubmit2011), 0);
  FillChar(SMGPSubmit203, sizeof(TSMGPSubmit203), 0);
  with SMGPSubmit203 do //包体3
  begin
    count := rSubmit.sSubmit.DestTermIDCount; //号码数
    Source := rSubmit.sSubmit.DestTermID; //号码列表
    if count > 1 then
    begin
      for i := 0 to count - 1 do
      begin
        FillChar(tmpBuf, sizeof(tmpBuf), 0);
        Source := ChtchOne(Source, onenumber); //获取单个号码
        strpcopy(tmpBuf, onenumber);
        move(tmpBuf, DestTermID[i * 21], 21);
      end;
    end
    else
      strpcopy(DestTermID, Source);
    DestTermIDCount := count;
    strpcopy(SrcTermID, rSubmit.sSubmit.SrcTermID);
    strpcopy(ChargeTermID, rSubmit.sSubmit.ChargeTermID);
    MsgLength := rSubmit.sSubmit.MsgLength;
    strpcopy(MsgContent, rSubmit.sSubmit.MsgContent);    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -