Skip to content

Commit a0fab10

Browse files
committed
ADD: check if tnc still not in hostmode
1 parent 8ad8ea3 commit a0fab10

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

src/flexpacket.lpi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<UseVersionInfo Value="True"/>
2424
<AutoIncrementBuild Value="True"/>
2525
<MinorVersionNr Value="8"/>
26-
<BuildNr Value="2628"/>
26+
<BuildNr Value="2631"/>
2727
<Language Value="0C0C"/>
2828
<StringTable InternalName="flexpacket" ProductName="flexpacket" ProductVersion="0.8.0"/>
2929
</VersionInfo>

src/flexpacket.lps

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<IsPartOfProject Value="True"/>
3232
<IsVisibleTab Value="True"/>
3333
<EditorIndex Value="9"/>
34-
<TopLine Value="88"/>
35-
<CursorPos X="12" Y="105"/>
34+
<TopLine Value="120"/>
35+
<CursorPos X="6" Y="130"/>
3636
<UsageCount Value="214"/>
3737
<Loaded Value="True"/>
3838
</Unit>
@@ -267,26 +267,10 @@
267267
<EditorIndex Value="-1"/>
268268
<TopLine Value="375"/>
269269
<CursorPos Y="387"/>
270-
<UsageCount Value="4"/>
270+
<UsageCount Value="3"/>
271271
</Unit>
272272
</Units>
273273
<JumpHistory HistoryIndex="29">
274-
<Position>
275-
<Filename Value="umain.pas"/>
276-
<Caret Line="1136" Column="24" TopLine="1109"/>
277-
</Position>
278-
<Position>
279-
<Filename Value="umain.pas"/>
280-
<Caret Line="1306" TopLine="1300"/>
281-
</Position>
282-
<Position>
283-
<Filename Value="umain.pas"/>
284-
<Caret Line="190" Column="31" TopLine="187"/>
285-
</Position>
286-
<Position>
287-
<Filename Value="umain.pas"/>
288-
<Caret Line="1314" Column="38" TopLine="1292"/>
289-
</Position>
290274
<Position>
291275
<Filename Value="uinfo.pas"/>
292276
<Caret Line="50" TopLine="36"/>
@@ -391,6 +375,22 @@
391375
<Filename Value="uhostmode.pas"/>
392376
<Caret Line="47" Column="27" TopLine="21"/>
393377
</Position>
378+
<Position>
379+
<Filename Value="uhostmode.pas"/>
380+
<Caret Line="136" TopLine="113"/>
381+
</Position>
382+
<Position>
383+
<Filename Value="uhostmode.pas"/>
384+
<Caret Line="170" Column="20" TopLine="157"/>
385+
</Position>
386+
<Position>
387+
<Filename Value="uhostmode.pas"/>
388+
<Caret Line="127" Column="34" TopLine="105"/>
389+
</Position>
390+
<Position>
391+
<Filename Value="uhostmode.pas"/>
392+
<Caret Line="131" Column="17" TopLine="121"/>
393+
</Position>
394394
</JumpHistory>
395395
<RunParams>
396396
<FormatVersion Value="2"/>

src/flexpacket.res

0 Bytes
Binary file not shown.

src/uhostmode.pas

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ THostmode = class(TThread)
2525
function ReceiveDataUntilZero: AnsiString;
2626
function ReceiveStringData: AnsiString;
2727
function ReceiveByteData:TBytes;
28+
function ReadWithTimeout(Ser: TBlockSerial; TimeoutMS: Integer): String;
2829
protected
2930
procedure Execute; override;
3031
public
@@ -90,17 +91,17 @@ function THostmode.ComPortExists(const APort: String): Boolean;
9091
end;
9192

9293
procedure THostmode.Execute;
93-
var
94-
LastSendTimeG, LastSendTimeL: Cardinal;
94+
var LastSendTimeG, LastSendTimeL: Cardinal;
95+
resp: String;
9596
begin
9697
repeat
97-
SetTNCStatusMessage('TNC Init Comport');
98+
SetTNCStatusMessage('TNC Init COM Port');
9899
if FPConfig^.ComPort <> '' then
99100
begin
100101
try
101102
if not ComPortExists(FPConfig^.ComPort) then
102103
begin
103-
SetTNCStatusMessage('COM does not exist');
104+
SetTNCStatusMessage('COM Port does not exist');
104105
Terminate;
105106
Exit;
106107
end;
@@ -121,10 +122,18 @@ procedure THostmode.Execute;
121122

122123
// Init TNC
123124
SetTNCStatusMessage('TNC Set Hostmode');
124-
repeat
125-
Sleep(200)
126-
until FSerial.CanWrite(100);
125+
127126
FSerial.SendString(#17#24#13#27'JHOST1'#13);
127+
sleep(200);
128+
129+
resp := ReadWithTimeout(FSerial, 500);
130+
if Pos('*', resp) > 0 then
131+
begin
132+
SetTNCStatusMessage('TNC could''t set Hostmode');
133+
Terminate;
134+
Exit;
135+
end;
136+
128137
Sleep(200);
129138

130139
Connected := True;
@@ -167,6 +176,23 @@ procedure THostmode.Execute;
167176
WaitFor;
168177
end;
169178

179+
function THostmode.ReadWithTimeout(Ser: TBlockSerial; TimeoutMS: Integer): String;
180+
var T0: QWord;
181+
begin
182+
Result := '';
183+
T0 := GetTickCount64;
184+
185+
repeat
186+
if Ser.CanRead(50) then
187+
Result := Result + Ser.RecvString(50);
188+
189+
if Result <> '' then
190+
Exit;
191+
192+
Sleep(10);
193+
until (GetTickCount64 - T0) > QWord(TimeoutMS);
194+
end;
195+
170196
procedure THostmode.SendG;
171197
var i: Integer;
172198
begin

0 commit comments

Comments
 (0)