• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 26, 2024, 01:01:24 pm

News:

SMF - Just Installed!


Detecting Data packets

Started by sbeaulie, May 15, 2012, 10:24:14 am

Previous topic - Next topic

sbeaulie

Is there any way to detect variable length data coming in with a $1B as the start of the packet but no specific end character?

Roman Novgorodov

Hello

Yes of course, it's possible.
For example our kermit implementation waits start char and calculates necessary packet length at run time on every detected packet.

You need add data packet definition with PacketBegin := #$1b; and add handler OnPacketLength that changes data packet length.
See kermit implementation below:

procedure TnrKermit.HandlePacketLength(Packet: TnrDataPacket; chData: byte;
  var IsHandled: Boolean);
begin
  // detect variable datapacket length and set it into needed property ...
  Packet.PacketLength := byte(chData) - 32 + Packet.DataLength;
  IsHandled := True;
end;


Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sbeaulie

I looked a the Kermit demo and I don’t see the on packet handler  and unfortunately I’m not a professional  programmer and I don’t know how to add a handler for OnPacketLength. Could you give me an example

This is all I see in the Kermit demo


    procedure Button2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure nrKermit1FileStart(Sender: TObject);
    procedure nrKermit1ChangeState(Sender: TObject);
    procedure nrKermit1FileEnd(Sender: TObject);
    procedure nrKermit1Error(Sender: TObject);
    procedure nrKermit1FatalError(Sender: TObject; ErrorCode,
      Detail: Cardinal; ErrorMsg: String; var RaiseException: Boolean);
    procedure nrKermit1Progress(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }                           
  public
    { Public declarations }       
  end;

var
  Form1: TForm1;

implementation

Roman Novgorodov

Hello

There are small misunderstanding between us :-).

I mean Kermit sources, you look at Kermit Demo.

You can open DataProc demo, select  nrDataProcessor1 component and click DataPackets property in Object Inspector.
You will see DataPacket list. Select any datapacket and you will find OnPacketLength event in object inspector.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sbeaulie


sbeaulie

Hi It’s me again (the pain in the butt) I tried using the event handle

procedure TForm1.nrDataProcessor1DataPackets0PacketLength(Packet: TnrDataPacket;
  chData: Byte; var IsHandled: Boolean);
begin
// detect variable datapacket length and set it into needed property ...
  Packet.PacketLength := byte(chData) - 32 + Packet.DataLength;
  IsHandled := true
end;

with a PacketStart of #$1B expecting to see the the packets below

1B[=2l
1B.0
1B=)-
1Br1232
1B=)_YES
1Bq
1B=*-
1Br1237
1B=*_YES
1Bq
1B=+-
1Br1230
1B=+_Y
Etc…

But what I got was several long packets like the one below

1B[=2l1B.01B=)-1Br12321B=)_YES1Bq1B=*-1Br12371B=*_YES1Bq1B=+-1Br12301B=+_Y
ETC….

I’m very confused

Roman Novgorodov

Hello

You initially asked:
Is there any way to detect variable length data coming in with a $1B as the start of the packet but no specific end character?

Do you understand how to detect length of variable part of packet after $1b char?
Do you have protocol description?

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sbeaulie

I am trying to figure out how to detect the variable length part of the packet so I can send the commands to the terminal (Memo) . I am trying to emulate a TelaVideo 995 dumb terminal.  The packets start 1B (ESC) and can have any number of hex codes following depending on what the commands are.

Roman Novgorodov

Hello

If you do not understand how your protocol works, nrComm Lib will not help you :-)
Sorry.


Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sbeaulie

we have a misunderstanding I know the protocol and all of the ESC sequences and how to implement them I just can’t detect them because the length of the packet is variable and there is no end of packet.

Example

Packet Begin  =  $1B
Packet End  =  none
Packet Length = Variable

Roman Novgorodov

Hello

Good  :-)

Please understand that If packet has variable length it should provide info about this length.
If you do not see length info in packet after 1b char, computer can not see it too. Miracles do not happen.
I explain obvious things.

It seems like your protocol is something like VT100/ANSI ESC-sequence protocol.
You need find and download its specification.
When you investigate it you will learn that all packets have fixed length. For example:

1Br1237
1Br1230

are Packet with
PacketBegin := $#1B'r';
PacketLength := 6;

1Bq
1Bq
are Packet with
PacketBegin := $#1B'q';

and so on ...

You need declare many packet definition for correct detection them.

For example look at here
http://www.braun-home.net/michael/info/misc/VT100_commands.htm

Better if you will find good skill programmer and he will resolve this task easy.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

sbeaulie

Hi Roman,

You are correct  :)

The only command that was giving me trouble is $#1Br******* insert text  at cursor position. The text can be any length. I was hoping for an easy way of detecting the data but I guess life isn’t that simple !
I’ll write a parsing function and get the info that way.  Thank you for the help I appreciate your time and effort.

Steve B.