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

📄 sd_pei_tool_main.pas

📁 Motorola 集群通信系统中SDTS车载台PEI端测试程序
💻 PAS
📖 第 1 页 / 共 4 页
字号:
             begin
               // Increase Buffer Pointer Count
                Packet_Data := Packet_Data + msg_str[Buf_Point] + msg_str[Buf_Point+1];
                Buf_Point := Buf_Point + 2;
                Data_Count := data_count + 1;
             end;

             Buf_Point := Buf_Point + 1;
             Time := Get_Time;
             MessagesPad_Memo.Lines.Append(Time + ': Message received from: ' + ISSI + ' mes. ref.: ' + Mes_Ref + ' PI: ' + Dummy_PI + ' Text: ' + HexStringToByteString(Packet_Data));

            // Message has been processed. Now it is time to check whether a report has been requested
             Case RequestedReport of
                RecReport: begin
                             // Received report has been requested, so return a received report to the originator.
                              SDS_TL_TRANSFER_Str:=Dummy_PI + '1000' + Mes_Ref;
                              dummy:= HexStringToByteString(SDS_TL_TRANSFER_Str);
                              TotalPEIString := ('AT+CMGS=' + ISSI + ',1,0,' + IntToStr(Length(dummy)*8) + #13 + SDS_TL_TRANSFER_Str + #26);
                              MessagesPad_Memo.Lines.Append(Get_Time() + ': Sending received report to ' + ISSI + ' mes. ref. ' + Mes_Ref);
                              Sent_OK := Send_PEI_Msg(TotalPEIString);
                           end;

                ConReport: begin
                             // Consumed report has been requested, so return a consumed report to the originator.
                              SDS_TL_TRANSFER_Str:=Dummy_PI + '1002' + Mes_Ref;
                              dummy:= HexStringToByteString(SDS_TL_TRANSFER_Str);
                              TotalPEIString := ('AT+CMGS=' + ISSI + ',1,0,' + IntToStr(Length(dummy)*8) + #13 + SDS_TL_TRANSFER_Str + #26);
                              MessagesPad_Memo.Lines.Append(Get_Time() + ': Sending consumed report to ' + ISSI + ' mes. ref. ' + Mes_Ref);
                              Sent_OK := Send_PEI_Msg(TotalPEIString);
                           end;

                RecAndConReport:
                           begin
                             // Received and consumed reports have been requested, so return a received and a consumed report to the originator.
                              SDS_TL_TRANSFER_Str:=Dummy_PI + '1000' + Mes_Ref;
                              dummy:= HexStringToByteString(SDS_TL_TRANSFER_Str);
                              TotalPEIString := ('AT+CMGS=' + ISSI + ',1,0,' + IntToStr(Length(dummy)*8) + #13 + SDS_TL_TRANSFER_Str + #26);
                              MessagesPad_Memo.Lines.Append(Get_Time() + ': Sending received report to ' + ISSI + ' mes. ref. ' + Mes_Ref);
                              Sent_OK := Send_PEI_Msg(TotalPEIString);
                             // Wait 1 second before sending the consumed report to reduce load on the system.
                              sleep(1000);
                              SDS_TL_TRANSFER_Str:=Dummy_PI + '1002' + Mes_Ref;
                              dummy:= HexStringToByteString(SDS_TL_TRANSFER_Str);
                              TotalPEIString := ('AT+CMGS=' + ISSI + ',1,0,' + IntToStr(Length(dummy)*8) + #13 + SDS_TL_TRANSFER_Str + #26);
                              MessagesPad_Memo.Lines.Append(Get_Time() + ': Sending consumed report to ' + ISSI + ' mes. ref. ' + Mes_Ref);
                              Sent_OK := Send_PEI_Msg(TotalPEIString);
                           end;
             else
               // Do nothing since no report was requested
             end; // End of Case RequestedReport of

          end
          else
          If (Dummy_PDU = '10') then
          begin
            // It is a STS-TL-REPORT since "Message type = 1"

            // Retrieve the delivery status byte
             Delivery_Status := msg_str[Buf_Point] + msg_str[Buf_Point + 1];
             Buf_Point := Buf_Point + 2;  // to pass Delivery status
            // Retrieve the message reference status byte
             Mes_Ref := msg_str[Buf_Point] + msg_str[Buf_Point + 1];
            // Move Buf_Point to the end of the +CMT command pointing at <LF> as preparation
            // for the deleting of the +CMT command in the receive buffer
             Buf_point := Buf_Point + 3;

             MessagesPad_Memo.Lines.Append(Get_Time() + ': Report received from ' + ISSI + ': ' + 'Delivery status : ' +  Delivery_Status + ' for mes. ref.: ' +  Mes_Ref);
          end; // End If (Dummy_PDU =
      end;
     // Delete the received message
      Delete(msg_str, 1, Buf_Point);
   end; // End if (CRLF_Count = 3)
end; // End of procedure TForm1.Decode_CMT_message


//*******************************************************
//
// PROCEDURE NAME : TForm1.Decode_CMGS_response
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when an +CMGS response has been
// received from the radio. The procedure decodes the+CMGS response
//
//*******************************************************

procedure TForm1.Decode_CMGS_response(var msg_str: string);
Var
   Buf_Point: integer;
begin
  // Check to see if the entire string has been received or whether any bytes are missing
   if (Length(msg_str) >= Length(CommandSuccessfulResponse)) then
   begin
     // The received buffer contains enough bytes to start checking for a CMGS response
     // Check to see the remaining part of the response is OK
      Buf_Point := 8;
      If    (  (msg_str[Buf_Point-1] = 'S')
          and (msg_str[Buf_Point]   = ':')
          and (msg_str[Buf_Point+1] = ' ')
          and (msg_str[Buf_Point+2] = '0')
          and (msg_str[Buf_Point+3] = #13)
          and (msg_str[Buf_Point+4] = #10)
          and (msg_str[Buf_Point+5] = #13)
          and (msg_str[Buf_Point+6] = #10)
          and (msg_str[Buf_Point+7] = 'O')
          and (msg_str[Buf_Point+8] = 'K')
          and (msg_str[Buf_Point+9] = #13)
          and (msg_str[Buf_Point+10] = #10)) then
      begin
        // The message received is OK
        // Check if it was a response to a registration command
         if (CTSPendingOperation = REGISTERAPP) then
         begin
           // It is a response to a registration command
            MessagesPad_Memo.Lines.Append(Get_Time() + ': (De-)Registration successful.');
            Set_buttons_after_successful_registration();
            CTSPendingOperation := REGISTERED;
         end
         else
         begin
           // It is a response to a send command
            MessagesPad_Memo.Lines.Append(Get_Time() + ': Message sent successfully.');
         end;
        // Delete the +CMGS response from the receive buffer
         Delete(msg_str, 1, Length(CommandSuccessfulResponse));
      end
      else
      begin
        // A message has been received that is is not compliant with the CMGS response syntax
        // so delete the non compliant stuff
         Delete_Str_Until_2nd_CR_LF(msg_str);
      end;
   end; // if (Length(msg_str) >= Length(CommandSuccessfulResponse))
end; // End of procedure TForm1.Decode_CMGS_response


//*******************************************************
//
// PROCEDURE NAME : TForm1.Delete_Str_Until_2nd_CR_LF
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when the message received is not fully compliant with the syntax
// for that message. Delete the non-compliant message by deleting all characters until the
// 2nd <CR><LF> pair
//*******************************************************

procedure TForm1.Delete_Str_Until_2nd_CR_LF(var msg_str: string);
var
   Buffer_Pointer : integer;
begin
  // Get past the first <CR><LF> pair
   Buffer_Pointer := 2;
   Repeat
      Buffer_Pointer := Buffer_Pointer + 1;
   Until ((msg_str[Buffer_Pointer] = #13) and (msg_str[Buffer_Pointer+1] = #10));
   Delete(msg_str, 1, Buffer_Pointer);
end; // End of procedure TForm1.Delete_Str_Until_2nd_CR_LF

//*******************************************************
//
// PROCEDURE NAME : TForm1.Decode_OK_response
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when an OK response has been
// received from the radio. The procedure decodes the OK response
//
//*******************************************************

procedure TForm1.Decode_OK_response(var msg_str: string);
var
   Buf_Point: integer;
begin
   Buf_Point := 1;
  // Check to see if the entire string has been received or whether any bytes are missing
   if (Length(msg_str) >= Length(AT_OK_Response)) then
   begin
     // Check to see the remaining part of the response is OK
      if    (     (msg_str[Buf_Point+4] = #13)
              and (msg_str[Buf_Point+5] = #10)) then
      begin
        // The message received is OK
        MessagesPad_Memo.Lines.Append(Get_Time() + ': Connection to radio successful. Radio supports AT commands.');
        Set_buttons_after_successful_connect();
        CTSPendingOperation := CONNECTED;
       // Delete the +CMGS response from the receive buffer
        Delete(msg_str, 1, Length(AT_OK_Response));
      end
      else
      begin
        // A message has been received that is is not compliant with the CMGS response syntax
        // so delete the non compliant stuff
         Delete_Str_Until_2nd_CR_LF(msg_str);
      end;
   end; // if (Length(msg_str) >= Length(AT_OK_Response)) then
end; // End of procedure TForm1.Decode_CMGS_response


//*******************************************************
//
// PROCEDURE NAME : TForm1.Decode_CME_ERROR_response
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when an CME_ERROR response has been
// received from the radio. The procedure decodes the CME_ERROR response
//
//*******************************************************

procedure TForm1.Decode_CME_ERROR_response(var msg_str: string);
const
   ERROR_CODE_START = 15;
var
   Buffer_Pointer: integer;
   Error_code_str : string;
begin

   if (Length(msg_str) >= Length(ATCME_Error)) then

   Buffer_Pointer := 7;
   If    ((msg_str[Buffer_Pointer]    = ' ')
       and (msg_str[Buffer_Pointer+1] = 'E')
       and (msg_str[Buffer_Pointer+2] = 'R')
       and (msg_str[Buffer_Pointer+3] = 'R')
       and (msg_str[Buffer_Pointer+4] = 'O')
       and (msg_str[Buffer_Pointer+5] = 'R')
       and (msg_str[Buffer_Pointer+6] = ':')
       and (msg_str[Buffer_Pointer+7] = ' ')) then
   begin
     // Search for the error code located between the CME ERROR:<space-character> and <CR><LF>

      Buffer_Pointer := ERROR_CODE_START - 1 ;
     // Move Buffer_Pointer to the end of the CME ERROR: response
      Repeat
         Buffer_Pointer := Buffer_Pointer + 1;
      Until (msg_str[Buffer_Pointer] = #13);

      Error_code_str := Copy(msg_str, ERROR_CODE_START, (Buffer_Pointer - ERROR_CODE_START));
      MessagesPad_Memo.Lines.Append(Get_Time() + ': CME ERROR received from MS with error code: ' + Error_code_str);
     // Delete the received CME ERROR response
      Delete(msg_str, 1, Buffer_Pointer);
   end
   else
   begin
     // A message has been received that is is not compliant with the CME ERROR response syntax
     // so delete the non compliant stuff
      Delete_Str_Until_2nd_CR_LF(msg_str);
   end; // End else if msg_str=CME_ERROR

end; // End of procedure TForm1.Decode_CMGS_response


//*******************************************************
//
// PROCEDURE NAME : TForm1.RegisterButtonClick
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when the user clicks on
// the Register button. It sends the AT registration command
// to the radio using the protocol identifier specified by the user.
//
//*******************************************************

procedure TForm1.RegisterButtonClick(Sender: TObject);
var
   Sent_OK: Bool;
   ATRegisterCommand: string;
begin
   MessagesPad_Memo.Lines.Append(Get_Time() + ': Registering using protocol identifier: ' + ProtocolIdentifierEdit.Text);
   ATRegisterCommand := ATRegisterCommandFirstPart + IntToHex(StrToInt(ProtocolIdentifierEdit.Text),2) + ATRegisterCommandLastPart;
   Sent_OK := Send_PEI_Msg(ATRegisterCommand);
   CTSPendingOperation := REGISTERAPP;
   if not(Sent_OK) then
   begin
      Unsent_PEI_msg := ATRegisterCommand;
     // Start CTS timer waiting to check if the radio becomes ready to receive data
      Start_CTS_Timer(REGISTERAPP);
   end;
end; // End of procedure TForm1.RegisterButtonClick


//*******************************************************
//
// PROCEDURE NAME : TForm1.DeregisterButtonClick
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure is called when the user clicks on
// the De-register button. It sends the AT de-registration command
// to the radio using the protocol identifier specified by the user.
//
//*******************************************************

procedure TForm1.DeregisterClick(Sender: TObject);
var
   Sent_OK: Bool;
   ATRegisterCommand: string;
begin
   MessagesPad_Memo.Lines.Append(Get_Time() + ': De-registering using protocol identifier: ' + ProtocolIdentifierEdit.Text);
   ATRegisterCommand := ATDeRegisterCommandFirstPart + IntToHex(StrToInt(ProtocolIdentifierEdit.Text),2) + ATRegisterCommandLastPart;
   Sent_OK := Send_PEI_Msg(ATRegisterCommand);
   CTSPendingOperation := REGISTERAPP;
   if not(Sent_OK) then
   begin
      Unsent_PEI_msg := ATRegisterCommand;
     // Start CTS timer waiting to check if the radio becomes ready to receive data
      Start_CTS_Timer(REGISTERAPP);
   end;
end; // End of procedure TForm1.DeregisterClick



//*******************************************************
//
// PROCEDURE NAME : TForm1.Set_buttons_after_successful_registration
//
//
// PROCEDURE DESCRIPTION :-
//   This procedure enables/diables the appropriate buttons
// after successful registration.
//
//
//*******************************************************

procedure TForm1.Set_buttons_after_successful_registration;

⌨️ 快捷键说明

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