NEW VERSION FOR Z25:
Download here
Important!!!
Delphi 7 doesn't know TByte type as Adata in IdUDPServer1UDPRead
so i changed it to TStream, and it's work but compiler sometimes throw you this message:
Just click NO button
The Source Code:
I hope that it will be helpful for someone
Download here
Important!!!
Delphi 7 doesn't know TByte type as Adata in IdUDPServer1UDPRead
so i changed it to TStream, and it's work but compiler sometimes throw you this message:
Just click NO button
The Source Code:
{
******************************************************************************
In ENGLISH: (sorry for any mistakes;) )
Outgauge example for "Live for Speed" written by Radek Szewczyk
Contact: [email protected]
GG: 1480359
Myspace: myspace.com/deejayradzio
If you've got any problems with this code just contact me. I try to help you ;)
Thanks to 4programmers.net users for any help.
Important: This program uses Indy10 Components for Delphi 7.
******************************************************************************
******************************************************************************
Po POLSKU:
Przyklad Outgauge dla "Live for Speed" napisany przez Radka Szewczyka
Kontakt: [email protected]
GG: 1480359
Myspace: myspace.com/deejayradzio
Jezeli masz jakiekolwiek problemy z tym kodem poprostu sie ze mna skontaktuj.
Postaram sie Ci pomoc.
Podziekowania dla uzytkownikow 4programmers.net za wszelka pomoc.
Wazne: Ten program uzywa komponentow Indy10 dla Delphi 7.
******************************************************************************
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer,IdSocketHandle, StdCtrls,
ComCtrls, ExtCtrls, Gauges;
type
TPacket = record
Time: longint; // time in milliseconds (to check order)
Car: array[0..3] of char; // Car name
Flags: word; // OG_FLAGS
Gear: byte; // Reverse:0, Neutral:1, First:2...
SpareB: byte;
Speed: single; // M/S
RPM: single; // RPM
Turbo: single; // BAR
EngTemp: single; // C
Fuel: single; // 0 to 1
OilPress: single; // BAR
OilTemp: single; // C
DashLights: longint; // Dash lights available
ShowLights: longint; // Dash lights currently switched on
Throttle: single; // 0 to 1
Brake: single; // 0 to 1
Clutch: single; // 0 to 1
Display1: array[0..15] of char; // Usually Fuel
Display2: array[0..15] of char; // Usually Settings
ID: integer; // optional - only if GameID is specified
end;
TForm1 = class(TForm)
Label1: TLabel;
IdUDPServer1: TIdUDPServer;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label19: TLabel;
Image1: TImage;
Gauge1: TGauge;
Gauge2: TGauge;
Gauge3: TGauge;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
CheckBox10: TCheckBox;
CheckBox11: TCheckBox;
CheckBox12: TCheckBox;
CheckBox13: TCheckBox;
CheckBox14: TCheckBox;
CheckBox15: TCheckBox;
CheckBox16: TCheckBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Memo1: TMemo;
Memo2: TMemo;
Label18: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
paczka: Tpacket;
gear_tmp:string;
const
// values for each light
DL_SHIFT = 1 ; // bit 0 - shift light
DL_FULLBEAM = 2 ; // bit 1 - full beam
DL_HANDBRAKE = 4 ; // bit 2 - handbrake
DL_PITSPEED = 8 ; // bit 3 - pit speed limiter
DL_TC = 16 ; // bit 4 - TC active or switched off
DL_SIGNAL_L = 32 ; // bit 5 - left turn signal
DL_SIGNAL_R = 64 ; // bit 6 - right turn signal
DL_SIGNAL_ANY = 128 ; // bit 7 - shared turn signal
DL_OILWARN = 256 ; // bit 8 - oil pressure warning
DL_BATTERY = 512 ; // bit 9 - battery warning
DL_ABS = 1024 ; // bit 10 - ABS active or switched off
DL_SPARE = 2048 ; // bit 11
DL_NUM = 4096 ; //noinfo
OG_TURBO = 8192 ; // show turbo gauge
OG_KM = 16384 ; // if 0 set - user prefers MILES
OG_BAR = 32768 ; // if 0 set - user prefers PSI
implementation
{$R *.dfm}
procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
begin
Adata.Read(paczka, sizeof(paczka));
label6.Caption :=paczka.Car;
gear_tmp:=intToStr(paczka.gear-1); //
if paczka.gear=1 then gear_tmp:= 'N'; // change gear values 0 and 1 to R and N
if paczka.gear=0 then gear_tmp:= 'R'; //
label12.Caption:=gear_tmp;
label7.Caption := FloatToStr(trunc(paczka.Speed / 0.27777778)) + ' Km/h';
label8.Caption := FloatToStr(trunc(paczka.RPM));
label9.Caption := FloatToStr(trunc(paczka.Turbo*100)) + ' BAR';
label10.Caption := FloatToStr(trunc(paczka.Fuel*100))+'.'+FloatToStr(trunc(paczka.Fuel*10000) - trunc(paczka.Fuel*100)*100 ) + ' %';
Gauge1.Progress:= trunc(paczka.Clutch*100);
Gauge2.Progress:= trunc(paczka.Brake*100);
Gauge3.Progress:= trunc(paczka.Throttle*100);
Label20.Caption:= FloatToStr(paczka.EngTemp) +' °C';
Label23.Caption:= FloatToStr(paczka.OilPress) +' BAR';
Label24.Caption:= FloatToStr(paczka.OilTemp) +' °C';
//////Flags//////
//-----------------------------------------------------//
//if shift light is switched on//
if (paczka.ShowLights AND DL_SHIFT) <> 0 then
CheckBox1.Checked:= True
else
CheckBox1.Checked:= False;
//if shift light is available on dash//
if (paczka.DashLights AND DL_SHIFT) <> 0 then
CheckBox1.Enabled:= True
else
CheckBox1.Enabled:= False;
//-----------------------------------------------------//
//if fullbeam is switched on//
if (paczka.ShowLights AND DL_FULLBEAM) <> 0 then
CheckBox2.Checked:= True
else
CheckBox2.Checked:= False;
//if fullbeam is available on dash//
if (paczka.DashLights AND DL_FULLBEAM) <> 0 then
CheckBox2.Enabled:= True
else
CheckBox2.Enabled:= False;
//-----------------------------------------------------//
//if handbrake is switched on//
if (paczka.ShowLights AND DL_HANDBRAKE) <> 0 then
CheckBox3.Checked:= True
else
CheckBox3.Checked:= False;
//if handbrake is available on dash//
if (paczka.DashLights AND DL_HANDBRAKE) <> 0 then
CheckBox3.Enabled:= True
else
CheckBox3.Enabled:= False;
//-----------------------------------------------------//
//if pit speed limiter is switched on//
if (paczka.ShowLights AND DL_PITSPEED) <> 0 then
CheckBox4.Checked:= True
else
CheckBox4.Checked:= False;
//if pit speed limiter is available on dash//
if (paczka.DashLights AND DL_PITSPEED) <> 0 then
CheckBox4.Enabled:= True
else
CheckBox4.Enabled:= False;
//-----------------------------------------------------//
//if Traction Control is switched on//
if (paczka.ShowLights AND DL_TC) <> 0 then
CheckBox5.Checked:= True
else
CheckBox5.Checked:= False;
//if Traction Control is available on dash//
if (paczka.DashLights AND DL_TC) <> 0 then
CheckBox5.Enabled:= True
else
CheckBox5.Enabled:= False;
//-----------------------------------------------------//
//if left turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_L) <> 0 then
CheckBox6.Checked:= True
else
CheckBox6.Checked:= False;
//if left turn signal is available on dash//
if (paczka.DashLights AND DL_SIGNAL_L) <> 0 then
CheckBox6.Enabled:= True
else
CheckBox6.Enabled:= False;
//-----------------------------------------------------//
//if right turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_R) <> 0 then
CheckBox7.Checked:= True
else
CheckBox7.Checked:= False;
//if right turn signal is available on dash//
if (paczka.DashLights AND DL_SIGNAL_R) <> 0 then
CheckBox7.Enabled:= True
else
CheckBox7.Enabled:= False;
//-----------------------------------------------------//
//if any turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_ANY) <> 0 then
CheckBox8.Checked:= True
else
CheckBox8.Checked:= False;
//if any turn signal is available on dash//
// if (paczka.DashLights AND DL_SIGNAL_ANY) <> 0 then
// CheckBox8.Enabled:= True
// else
// CheckBox8.Enabled:= False;
//-----------------------------------------------------//
//if oil pressure warning is switched on//
if (paczka.ShowLights AND DL_OILWARN) <> 0 then
CheckBox9.Checked:= True
else
CheckBox9.Checked:= False;
//if oil pressure warning is available on dash//
if (paczka.DashLights AND DL_OILWARN) <> 0 then
CheckBox9.Enabled:= True
else
CheckBox9.Enabled:= False;
//-----------------------------------------------------//
//if battery warning is switched on//
if (paczka.ShowLights AND DL_BATTERY) <> 0 then
CheckBox10.Checked:= True
else
CheckBox10.Checked:= False;
//if battery warning is available on dash//
if (paczka.DashLights AND DL_BATTERY) <> 0 then
CheckBox10.Enabled:= True
else
CheckBox10.Enabled:= False;
//-----------------------------------------------------//
//if ABS is switched on//
if (paczka.ShowLights AND DL_ABS) <> 0 then
CheckBox11.Checked:= True
else
CheckBox11.Checked:= False;
//if ABS is available on dash//
if (paczka.DashLights AND DL_ABS) <> 0 then
CheckBox11.Enabled:= True
else
CheckBox11.Enabled:= False;
//-----------------------------------------------------//
//if Turbo Gauge is available//
if (paczka.Flags AND 8192) <> 0 then //show Turbo Gauge
CheckBox14.Checked:= True
else
CheckBox14.Checked:= False;
//-----------------------------------------------------//
//if KM is set//
if (paczka.Flags AND 16384) <> 0 then //users prefers km
CheckBox15.Checked:= True
else
CheckBox15.Checked:= False;
//-----------------------------------------------------//
//if BAR is set//
if (paczka.Flags AND 32768) <> 0 then //users prefers bar
CheckBox16.Checked:= True
else
CheckBox16.Checked:= False;
memo1.Text:=paczka.Display1;
memo2.Text:=paczka.Display2;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
IdUDPServer1.DefaultPort := 11111;
IdUDPServer1.Active := true;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdUDPServer1.Active:=False;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
IdUDPServer1.DefaultPort := 11111;
IdUDPServer1.Active := true;
end;
end.
I hope that it will be helpful for someone