HandleFunctionQueue:TFunctionQueue;
unit AVRManager_U;
interface
uses
SerialNG, GTypes_U, GManager_U,SysUtils, StdCtrls, Dialogs, Vektor, math;
type
TAvrMan = class(TObject)
private
[COLOR="Red"] HandleFunctionQueue:TFunctionQueue;[/COLOR]
// HandleObjectQueue:TObjectQueue;
Connected:boolean;
SerialPort:TSerialPortNG;
GMan:TGMan;
ConnectionFlag:boolean;
public
constructor create(SerialPort0:TSerialPortNG; GMan0:TGMan);
function Connect:boolean;
procedure SetPort(b:boolean);
procedure SendString(s:string);
procedure HandleInputString(S:string);
procedure HandleCommandString(s:string; HandleFunction0:THandleFunction);
function GetConnected:boolean;
procedure ReadSensor(adr:Word;Edit1,Edit2:TEdit);
procedure HandleDefault(s:string);
procedure HandleRead(s:string);
procedure HandleWrite(s:string);
procedure HandleRange(s:string);
procedure HandleHallo(s:string);
procedure HandleOn(s:string);
end;
implementation
constructor TAvrMan.create(SerialPort0:TSerialPortNG; GMan0:TGMan);
begin
SerialPort:=SerialPort0;
[COLOR="Red"]HandleFunctionQueue:=TFunctionQueue.create;[/COLOR]
// HandleObjectQueue:=TObjectQueue.create;
GMan:=GMan0;
Connected:=SerialPort.Active;
connect;
ConnectionFlag:=false;
end;
procedure TAvrMan.SetPort(b:boolean);
begin
if b = true
then
begin
SerialPort.Active:=true;
connected:=true;
end
else
begin
SerialPort.Active:=false;
end;
end;
function TAvrMan.Connect:boolean;
begin
SetPort(true);
end;
function TAvrMan.GetConnected:boolean;
begin
result:=Connected;
end;
procedure TAvrMan.SendString(s:string);
var TempGMode:TGMode;
begin
if Connected = true
then
begin
if Length(s) > 0 then SerialPort.SendString(s);
if GMan.GetGMode.AddTx = true then GMan.AddCommandoTerminalLine('[Sended]: '+s);
end;
end;
procedure TAvrMan.ReadSensor(adr:Word;Edit1,Edit2:TEdit);
begin
end;
procedure TAvrMan.HandleDefault(s:string);
begin
GMan.AddCommandoTerminalLine('DefalutHandle: s='+s);
end;
procedure TAvrMan.HandleRead(s:string);
begin
end;
procedure TAvrMan.HandleWrite(s:string);
begin
end;
procedure TAvrMan.HandleOn(s:string);
begin
end;
procedure TAvrMan.HandleHallo(s:string);
begin
end;
procedure TAvrMan.HandleRange(s:string);
begin
end;
procedure TAvrMan.HandleCommandString(s:string; HandleFunction0:THandleFunction);
begin
HandleFunction0(s);
end;
procedure TAvrMan.HandleInputString(S : String);
var AddS,showS:String; values1: array[1..13] of integer; i,j,k:integer; values2: array[1..7] of integer; phi:single;
a,b:TVektor; [COLOR="Red"]NextHandleFunction:THandleFunction;[/COLOR]
begin
AddS := Copy(S,0,length(S));
i:=0;
while (i<=(length(S))) do
begin
if (Adds[i]='"') and (Adds[i+1] = '"')
then
begin // Anfang Command Erkennung
HandleFunctionQueue.enqueue(nextHandleFunction);
showS:=Copy(AddS,i+2,Length(AddS));
[COLOR="Blue"] NextHandleFunction:=HandleFunctionQueue.get;[/COLOR]
[COLOR="Red"]HandleCommandString(showS,NextHandleFunction);[/COLOR]
end; // Ende Command Erkennung
if (Adds[i]='!') and (Adds[i+14]='"')
then
begin // Anfang Value-Berechnung und GMan.Insert Value
showS:=Copy(AddS,i+1,13);
for j:=1 to 13 do
begin
values1[j]:=Ord(showS[j]);
end;
for j:=1 to 6 do
begin
values2[j]:=(((values1[2*j]*4))+((values1[2*j-1]) div 64));
if (values2[j] >= 513) then begin values2[j]:=-512+(values2[j]-512); end;
end;
values2[7]:=values1[13];
a:=VektorP(values2[1],values2[2],values2[3]);
b:=VektorP(values2[4],values2[5],values2[6]);
phi:=RadToDeg(ArcCos(Skalarprodukt(a,b)/(Betrag(a)*Betrag(b))));
Gman.InsertValue(CreateValue(values2[1],values2[2],values2[3],values2[4],values2[5],values2[6],values2[7],phi));
i:=i+14;
end; // Ende Value-Berechnung und GMan.Insert Value
i:=i+1;
end;
end;
end.