📄 sd_pei_tool_main.pas
字号:
CTS.Enabled := False;
MessageDlg('Timeout waiting for ready signal from radio.'#13#10+'Ensure that the radio is connected and turned on.'+#39+'', mtError, [mbAbort], 0);
end;
end; // End of procedure TForm1.Start_CTS_Timer
//*******************************************************
//
// PROCEDURE NAME : TForm1.Set_buttons_after_successful_connect
//
//
// PROCEDURE DESCRIPTION :-
// This procedure will enable and disable buttons on the
// form as required after a successful connection has been
// made to the radio.
//
//*******************************************************
procedure TForm1.Set_buttons_after_successful_connect;
begin
RegisterButton.Enabled := True;
SendButton.Enabled := True;
ProtocolIdentifierEdit.Enabled := True;
DisconnectButton.Enabled := True;
ConnectButton.Enabled := False;
ComPortComboBox.Enabled := False;
DeRegister.Enabled := True;
CheckBoxRec.Enabled := True;
CheckBoxCon.Enabled := True;
DestISSI_Edit.Enabled := True;
Message_Edit.Enabled := True;
DelayEdit.Enabled := True;
RepititionsEdit.Enabled := True;
end; // End of procedure TForm1.Set_buttons_after_successful_connect
//*******************************************************
//
// PROCEDURE NAME : TForm1.Get_Time
//
//
// PROCEDURE DESCRIPTION :-
// This function returns a string containing the current
// time of the PC the application is running on.
// The format of the text string is: HH:MM:SS:CCC
//
//*******************************************************
function TForm1.Get_Time: String;
var
Hour, Min, Sec, MSec : Word;
Present: TDateTime;
HH, MM, SS, CCC : String;
begin
// Pass Present Time To Working Variables
Present:= Now;
DecodeTime(Present, Hour, Min, Sec, MSec);
// Pass variables through for string conversion
HH := IntToStr(Hour);
MM := IntToStr(Min);
SS := IntToStr(Sec);
CCC := IntToStr(MSec);
// Add the necessary zero's to each time variable when required
If (Length(HH) = 0) then HH := '00' + HH;
If (Length(HH) = 1) then HH := '0' + HH;
If (Length(MM) = 0) then MM := '00' + MM;
If (Length(MM) = 1) then MM := '0' + MM;
If (Length(SS) = 0) then SS := '00' + SS;
If (Length(SS) = 1) then SS := '0' + SS;
If (Length(CCC) = 0) then CCC := '000' + CCC;
If (Length(CCC) = 1) then CCC := '00' + CCC;
If (Length(CCC) = 2) then CCC := '0' + CCC;
// Pass New Time back to fucntion call origin
Get_Time := (HH+':'+MM+':'+SS+'.'+CCC);
end;
//*******************************************************
//
// PROCEDURE NAME : TForm1.DataTimerTimer
//
//
// PROCEDURE DESCRIPTION :-
// This procedure is called when the Data timer expires.
// The procedure checks to see if data has arrived on the COM port.
// If data has arrived, this procedure will start to decode the data.
//
//*******************************************************
procedure TForm1.DataTimerTimer(Sender: TObject);
var
Buffer_Point: integer;
CR_LF_start_found: boolean;
// This procedure is event driven by a timer and every set number of MSecs
// recalls all of the listed number of procedures below. The list can be added
// to but care must be taken about the order in which new msg decryption
// proecedures are inserted. When the msg end is detected, the msg Flags are
// reset in order for a new msg to be decoded. This timer event polls the port
// for data every 100 Msecs. When data is detected, the Procedures are then called
begin
// Msg Decryption Start :
// The first step is to check the input buffer to see if any data exists on the
// que. If there is data, then pass it to a variable so called Buffer.
If (ComPort.InQue>0)then
begin
// Read the Data and assign to variable Buffer
ComPort.ReadString(Dumm_Buff,ComPort.InQue,true);
Buffer := Buffer + Dumm_Buff;
end
else
// Check to see if we have received the minimum number of bytes to start decoding
If (length(Buffer) >= 6) then
begin
// Something has been received on the PEI. First print the
// received data in the Log window and then try and decode it
CommandLogger_Memo.Lines.Add(Get_Time() + ' ms:' + buffer);
Buffer_Point := 1;
// Check for an +CMGS repsonse from the radio:
If ((Buffer[Buffer_Point] = #13)
and (Buffer[Buffer_Point+1] = #10)
and (Buffer[Buffer_Point+2] = '+')
and (Buffer[Buffer_Point+3] = 'C')
and (Buffer[Buffer_Point+4] = 'M')
and (Buffer[Buffer_Point+5] = 'G')) then
begin
// Insert code to process the +CMGS: repsonse
Decode_CMGS_response(buffer);
end
// Check for an OK response from the radio:
else
if ((Buffer[Buffer_Point] = #13)
and (Buffer[Buffer_Point+1] = #10)
and (Buffer[Buffer_Point+2] = 'O')
and (Buffer[Buffer_Point+3] = 'K') ) then
begin
// Insert code to process the OK repsonse
Decode_OK_response(Buffer);
end
// Check for an CME_ERROR response from the radio:
else
if ((Buffer[Buffer_Point] = #13)
and (Buffer[Buffer_Point+1] = #10)
and (Buffer[Buffer_Point+2] = '+')
and (Buffer[Buffer_Point+3] = 'C')
and (Buffer[Buffer_Point+4] = 'M')
and (Buffer[Buffer_Point+5] = 'E')) then
begin
// Insert code to process the +CME_ERROR repsonse
Decode_CME_ERROR_response(Buffer);
end
// Check for an +CMT message from the radio:
else
if ((Buffer[Buffer_Point] = #13)
and (Buffer[Buffer_Point+1] = #10)
and (Buffer[Buffer_Point+2] = '+')
and (Buffer[Buffer_Point+3] = 'C')
and (Buffer[Buffer_Point+4] = 'M')
and (Buffer[Buffer_Point+5] = 'T')) then
begin
// Insert code to process the +CMT message
Decode_CMT_message(Buffer);
end
else
begin
// We have received the minimum number of bytes to start decoding but the start of the data
// received from the radio is not one of the expected messages above.
// So simply throw the data away that can not be decoded.
// Check to see if the received data starts with a <CR><LF> pair
if ( (Buffer[Buffer_Point] = #13)
and (Buffer[Buffer_Point+1] = #10)) then
begin
Buffer_Point := Buffer_Point + 2;
CR_LF_start_found := True;
end
else
begin
CR_LF_start_found := False;
end;
// Find out if the first part of the data starts
// Start searching for a <CR><LF> pair since that it is used in the beginning of all
// the responses from the MS.
while ( (Buffer[Buffer_Point] <> #13)
and (Buffer[Buffer_Point+1] <> #10)
and ((Buffer_Point+1) <= length(Buffer)) ) do
begin
Buffer_Point := Buffer_Point + 1;
end;
// Find out whether a <CR><LF> pair was found or whether end of buffer was reached.
if (Buffer_Point = length(Buffer)) then
begin
// Delete all the data in the received buffer since there are no <CR><LF> pairs
if not(CR_LF_start_found) then
begin
Delete(Buffer, 1, length(Buffer))
end
end
else
begin
// Delete data in front of the <CR><LF> pair
Delete(Buffer, 1, (Buffer_Point-1));
end;
end;
end; // End of If (length(Buffer) > 6) then
end; // End of procedure TForm1.DataTimerTimer
//*******************************************************
//
// PROCEDURE NAME : TForm1.Decode_CMT_message
//
//
// PROCEDURE DESCRIPTION :-
// This procedure is called when an +CMT message has been
// received from the radio. The procedure decodes the +CMT message according
// to the syntax specified in the short data programmers guide. If a report
// has been requested, the procedure will return the requested report.
//*******************************************************
procedure TForm1.Decode_CMT_message(var msg_str: string);
Var
dummy, Time, ISSI, Dummy_Length, Dummy_PI, Dummy_PDU, Mes_Ref, Delivery_Status, Packet_Data, TotalPEIString, SDS_TL_TRANSFER_Str: string;
RequestedReport: TReportType;
Sent_OK: boolean;
Buf_Point, Data_Count, CRLF_count : integer;
begin
// CommandLogger_Memo.Lines.Add(Get_Time() + ' ms:' + buffer);
// Start out by checking that all the bytes for the +CMT message have been received
// This is checked by looking for 3 <CR><LF> pairs in the +CMT command buffer
CRLF_count := 0;
for Buf_Point := 1 to (length(msg_str)-1) do
begin
If ((msg_str[Buf_Point] = #13)
and (msg_str[Buf_Point+1] = #10)) then
CRLF_Count := CRLF_Count + 1;
end; // for Buf_Point := 1 to
if (CRLF_Count = 3) then
begin
// It seems that a complete +CMT message has been received so start decoding it
Buf_Point:= 7;
If ((msg_str[Buf_Point] = ':')
and (msg_str[Buf_Point+1] = ' ')) then
begin
// The first part of the +CMT message is OK
// Skip the ': '
Buf_Point := Buf_Point + 2;
// Collect the ISSI of the originating device
While (msg_str[Buf_Point] <> ',') do
begin
ISSI := ISSI + msg_str[Buf_Point];
Buf_Point := Buf_Point + 1;
end;
// Move Buf_Point to get pass the comma after <oa> originating device address
Buf_Point := Buf_Point + 1;
// Move Buf_Point to get pass <tooa>, since it is not considered relevant for this program
While (msg_str[Buf_Point] <> ',') do
begin
// Increase Buffer Pointer Count
Buf_Point := Buf_Point + 1;
end;
// Move Buf_Point to get passed the comma after <tooa> originating device address
Buf_Point := Buf_Point + 1;
// Retrieve the data Length.
while (msg_str[Buf_Point] <> #13) do
begin
Dummy_Length := Dummy_Length + msg_str[Buf_Point];
// Increase Buffer Pointer Count
Buf_Point := Buf_Point + 1;
end;
// Convert Length from Bytes to characters
Dummy_Length := IntToStr((StrToInt(Dummy_Length) div 8));
// Move Buf_Point to get passed '<CR><LF>'
Buf_Point := Buf_Point + 2;
// Get the 1'st byte from the SDS-TL layer = The Protocol Identifier PI
Dummy_PI := msg_str[Buf_Point] + msg_str[Buf_Point + 1];
Buf_Point := Buf_Point + 2;
// Get the 2'nd byte from the SDS-TL layer = Message type, Delivery report, SS, ST
Dummy_PDU := msg_str[Buf_Point] + msg_str[Buf_Point + 1];
Buf_Point := Buf_Point + 2;
// Check the message type (SDS-TL-TRANSFER or SDS-TL-REPORT)
If (Dummy_PDU[1] = '0') then
begin
// It is a SDS-TL-TRANSFER message
// Find out whether Received or/and Consumed report is requested
case Dummy_PDU[2] of
'0','1','2','3': RequestedReport := NoReport;
'4','5','6','7': RequestedReport := RecReport;
'8','9','A','B': RequestedReport := ConReport;
'C','D','E','F': RequestedReport := RecAndConReport;
else
// We should not end up here but let us keep it for completeness and assume no report requested
RequestedReport := NoReport;
end; // End of case Dummy_PDU[2] of
// Extract the Message reference number
Mes_Ref := msg_str[Buf_Point] + msg_str[Buf_Point + 1];
// Point to the data area after the message reference number
Buf_Point := Buf_Point + 2;
// Retrieve PayLoad Data and assume it is text
Data_Count := 1;
while (Data_Count <= (StrToInt(Dummy_Length) - 3)) do //length-3 to skip
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -