Home > Back-end >  Deiphi converted to C or C code
Deiphi converted to C or C code

Time:11-15

My hand have a written in Delphi source code, as if is used to generate a DLL file,
I want to put it inside the function of content into written in C or C + +, don't know anyone who can help me have a look, appreciate ~
The library PSIdll;
Const
Pkg8400Len=4120;
Pkg8400ChNum=1024;
Type
Byte69=array [0.. 68] of Byte;
Single16=array [0.. 15] of Single;
Byte8400=array [0..] Pkg8400Len - 1 Byte,
Single8400=array [0.. Pkg8400ChNum - 1] of Single;
DataPkgType=the packed record
St: Byte;
SN: integer;
ChData: Single16;
end;

//below is the PSI scanner packet decoding function
//a single format 7-4 bytes & gt; Single precision floating point number
The Function ToSingle (s1, s2, s3, s4: byte) : Single; stdcall;
Var SPT: ^ single;
Sary, array [0.. 3] of byte;
The begin
Sary [0] :=s4;
Sary [1] :=s3;
Sary [2] :=s2;
Sary [3] : s1=;
SPT:=@ sary;

ToSingle: SPT=^.
end;

//a single 4 byte format 8 - & gt; Single precision floating point number
The Function ToSingle8 (s1, s2, s3, s4: byte) : Single; stdcall;
Var SPT: ^ single;
Sary, array [0.. 3] of byte;
The begin
Sary [0] : s1=;
Sary [1] :=s2;
Sary [2] :=s3;
Sary [3] :=s4;
SPT:=@ sary;

ToSingle8: SPT=^.
end;


//a single 69 - byte packets - & gt; 16 single-precision floating-point number
The Function Decode9000 (var rBuff: Byte69; PsiFormat: integer; Var SN: Longint; Var ChData: Single16) : integer; stdcall;
Var
MyData: ^ DataPkgType;
ByteAry: Byte69;
I: integer;

The Begin
If (rBuff [0] & gt; 3) or (rBuff [0] <1) then
The begin
Decode9000:=1;
For I:=0 to 15 do
The begin
ChData: [I]=0.0;
end;

SN:=0;
The exit;

end;

Case psiFormat of
7:
The begin
ByteAry [0] :=rBuff [0].
For I:=0 to 16 do
The begin//exchange of byte order, form 7 - & gt; Format 8
ByteAry: [I * 4 + 1]=rBuff [I * 4 + 4];
ByteAry: [I * 4 + 2]=rBuff [I * 4 + 3];
ByteAry [I * 4 + 3] :=rBuff [I * 4 + 2];
ByteAry: [I * 4 + 4]=rBuff [I * 4 + 1];
end;
MyData:=@ byteAry;
end;

8:
MyData:=@ rBuff;

The else
Decode9000:=1;
The exit;
end;
Decode9000:=0;
ChData: myData=^. ChData;
SN:=myData ^. SN;
The End;

//==============================
//Decode DTCInitium and 8400 packets
The Function DecodeDTC8400 (var rBuff: Byte8400; Var SN: Longint; Var ChData: Single8400) : integer; stdcall;
Var SPT: ^ single;
Sary, array [0.. 3] of byte;
DataNum: integer;
I: integer;

The Begin
DecodeDTC8400:=1;
Analytic://header reply packet
Case rBuff [1] of
4,8,9,128://simple reply packet
The begin
DecodeDTC8400:=1;
For I:=0 to 63 do
The begin
ChData: [I]=0.0;
end;

SN:=0;
end;

19://data flow package
If rBuff [0]=250 then
The begin
DecodeDTC8400:=0;
SN:=rBuff [4].
SN:=SN * 256 + rBuff [5].
DataNum:=rBuff [6].
DataNum:=DataNum * 256 + rBuff [7].//get data points

//byte order, always use the format 7, 8400 big head format
For I:=0 to do//DataNum DataNum - 1-1
The begin//exchange of byte order, form 7 - & gt; Format 8
Sary [0] :=rBuff [I * 4 + 24 + 3);
Sary [01] :=rBuff [I * 4 + 24 + 2];
Sary [02] :=rBuff [I * 4 + 24 + 1];
Sary [03] :=rBuff * 4 + 24 [I];
SPT:=@ sary;
ChData [I] : SPT=^.
end;
end;

The else//other not decoding
The begin
DecodeDTC8400:=1;
For I:=0 to 63 do
The begin
ChData: [I]=0.0;
end;

SN:=0;
end;
end;

The End;

Exports

ToSingle,
ToSingle name 'ToSingle',
ToSingle name 'ToSingle7',
ToSingle8,
DecodeDTC8400,
Decode9000;
The begin

End.

CodePudding user response:

If the method is feasible and pay, thank you thank you

CodePudding user response:

Compile a direct use can
Don't want to translation, it is easy to
 
//PSIdll. CPP

#include

Const int Pkg8400Len=4120;
Const int Pkg8400ChNum=1024;

Typedef unsigned char byte;
Typedef byte Byte69 [69].
Typedef float Single16 [16].
Typedef byte Byte8400 [Pkg8400Len];
Typedef float Single8400 [Pkg8400ChNum];
# pragma pack (push, 1)
Typedef struct tagDataPkgType
{
Byte st.
Int SN;
Single16 ChData;
} DataPkgType;
# pragma pack (pop)

__declspec (dllexport) __stdcall float ToSingle (byte byte byte s1, s2, s3, byte s4)
{
Int result=(int) s4 + ((int) s3 & lt; <8) + ((int) s2 & lt; <16) + ((int) s1 & lt; <24);

Return * (float *) & amp; The result;
}

//the rest of you turn yourself

BOOL APIENTRY DllMain (HANDLE hModule, dwords dwReason, void * lpReserved)
{
The switch (dwReason)
{
Case DLL_PROCESS_ATTACH:
//...
break;

Case DLL_PROCESS_DETACH:
//...
break;
}

return true;
}

CodePudding user response:

refer to the second floor early play big play nuclear response:
compile a direct use can
Don't want to translation, it is easy to
 
//PSIdll. CPP

#include

Const int Pkg8400Len=4120;
Const int Pkg8400ChNum=1024;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related