-
Notifications
You must be signed in to change notification settings - Fork 0
/
FDaq.pas
1750 lines (1508 loc) · 52.2 KB
/
FDaq.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Data Acquisition Task
// Date 19.06.22
//TODO//use Function for Unit conversion
unit FDaq;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Mask, Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons, ImgList, StrUtils, Math,
RzCommon, RzTabs, RzRadChk, RzEdit, RzSpnEdt, RzTrkBar, RzButton, RzBorder,
RzCmboBx, USystem, URegistry, SYS, ADC, SER, Global, Data, Flash, Deco, Texts,
Clock, Power, Sensor, Compass, Sonar, Tank, FLog, FInfo, UPidi,
System.ImageList;
type
TDaq = class(TForm)
DaqPageControl: TRzPageControl;
DaqStatus: TStatusBar;
DaqLoop: TTimer;
DaqIcons: TImageList; //10.04.07 nk add
TabControl: TRzTabSheet;
TabSettings: TRzTabSheet;
TabHelp: TRzTabSheet; //20.10.07 nk add
rbSaltWater: TRzRadioButton;
rbFreshWater: TRzRadioButton;
seScanMulti: TRzSpinEdit;
seSwimSpeed: TRzSpinEdit;
seAltitude: TRzSpinEdit;
seAirTemp: TRzSpinEdit;
seWaterTemp: TRzSpinEdit;
seSurfResp: TRzSpinEdit;
seFillPress: TRzSpinEdit;
edScanMulti: TRzNumericEdit;
edSwimSpeed: TRzNumericEdit;
edAltitude: TRzNumericEdit;
edWaterTemp: TRzNumericEdit;
edAirTemp: TRzNumericEdit;
edSurfResp: TRzNumericEdit;
edFillPress: TRzNumericEdit;
lbScanMulti: TLabel;
lbSwimSpeed: TLabel;
lbAltitude: TLabel;
lbAltitudeUnit: TLabel;
lbAirTemp: TLabel;
lbAirTempUnit: TLabel;
lbWaterTemp: TLabel;
lbWaterTempUnit: TLabel;
lbSurfResp: TLabel;
lbSurfRespUnit: TLabel;
lbFillPress: TLabel;
lbFillPressUnit: TLabel;
btUp: TRzBitBtn;
btDown: TRzBitBtn;
btLeft: TRzBitBtn;
btRight: TRzBitBtn;
btStop: TRzBitBtn;
btInfo: TRzButton;
pnCompass: TPanel;
pnPressure: TPanel;
tbCompass: TRzTrackBar;
tbPressure: TRzTrackBar;
cbTank: TRzCheckBox;
cbSonar: TRzCheckBox;
//DELHP dive control panel functions
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormMoving(var Msg: TwmMoving); message WM_MOVING;
procedure DaqLoopTimer(Sender: TObject);
procedure RunTask;
procedure btUpClick(Sender: TObject);
procedure btDownClick(Sender: TObject);
procedure btStopClick(Sender: TObject);
procedure btLeftClick(Sender: TObject);
procedure btRightClick(Sender: TObject);
procedure btInfoClick(Sender: TObject); //20.10.07 nk add
procedure rbWaterClick(Sender: TObject);
procedure seScanMultiChange(Sender: TObject);
procedure seSwimSpeedChange(Sender: TObject);
procedure seAltitudeChange(Sender: TObject);
procedure seWaterTempChange(Sender: TObject);
procedure seAirTempChange(Sender: TObject);
procedure seSurfRespChange(Sender: TObject);
procedure seFillPressChange(Sender: TObject);
procedure edScanMultiClick(Sender: TObject);
procedure edSwimSpeedClick(Sender: TObject);
procedure edAltitudeClick(Sender: TObject);
procedure edAirTempClick(Sender: TObject);
procedure edWaterTempClick(Sender: TObject);
procedure edFillPressClick(Sender: TObject);
procedure edSurfRespClick(Sender: TObject);
procedure cbTankClick(Sender: TObject);
procedure cbSonarClick(Sender: TObject);
private
//
public // Tiger DAQ functions (DAQ.INC)
procedure CalcDiveTime(Stime: Long; var DiveTime, SurfaceTime, IntervalTime, DiveDayNum: Long; var DivePhase: Byte);
procedure CalcDiveDepth(Apress: Long; var DiveDepth, MaxDepth: Long);
procedure CalcAscentRate(Stime, Ddepth: Long; var AscentTime, DiveSpeed: Long);
procedure CalcAltitude(Apress, Atemp: Long; var Altitude: Long);
procedure CalcAirPress(Aalti, Atemp: Long; var AirPress: Long);
procedure CalcBarometer(Apress: Long; var AirPress: Long);
procedure CalcWater(Wsalt: Word; Atemp: Long; var WaterDens, SoundSpeed: Word); //13.05.07 nk add TIGER
procedure CalcGasRate(Stime, AmbPress, TankPress, TotalDecoGas: Long; var BreathRate, GasTime: Long);
procedure CalcOxygenDose(Stime: Long; var OxPress, OxClock, OxUnits, OxDose: Long);
procedure CalcDiverScore(var DiverScore: Byte);
procedure CheckLimits(var StatusWord: Word; var SigNum: Long);
procedure InitEnvironment(DoClear: Boolean); //DELPHI only
end;
var
Daq: TDaq;
// Tiger declaration - must be global
//===================================
DaqBuff: string;
Ltime: Long;
Mtime: Long;
Htime: Long;
Ptime: Long;
implementation
uses FMain, FGui, FProfile, FTrack, FPlan;
{$R *.dfm}
procedure TDaq.FormCreate(Sender: TObject);
var
i: Long;
begin
HideMaxButton(Self); //hide maximize button
HideCloseButton(Self); //hide close button
DaqCtr := cCLEAR;
ScanPress := cCLEAR;
with Daq do begin
Tag := TASKDAQ;
HelpKeyword := IntToStr(PRIODAQ);
Left := MainRect.Right - MainRect.Left - Width - MAINMARGIN;
Top := MainRect.Bottom - MainRect.Top - Height - MAINMARGIN;
GetFormParameter(self);
Width := 248;
Height := 192 + TOPBORDER;
Enabled := False;
Show;
end;
with DaqPageControl do begin
ActivePageIndex := 0;
HotTrack := True;
end;
with DaqStatus do begin
for i := 0 to Panels.Count - 1 do
Panels[i].Text := sEMPTY;
end;
with DaqLoop do begin
Interval := DAQDELAY;
Enabled := True;
end;
with tbCompass do begin
Enabled := True;
ShowHint := False;
ShowTicks := True;
Transparent := True;
TabStop := False;
ThumbStyle := tsPointer;
TickStep := DAQTICKSTEP; // 45°
Min := 0;
Max := FULLCIRC; // 360°
Position := HALFCIRC; // 180° (North)
end;
with tbPressure do begin
Enabled := True;
ShowHint := False;
ShowTicks := True;
Transparent := True;
TabStop := False;
ThumbStyle := tsPointer;
TickStep := 10;
Min := -SPEEDMAX;
Max := SPEEDMAX; // 50cm/s
Position := cCLEAR;
end;
with pnCompass do begin
AutoSize := False;
Ctl3D := False;
BevelInner := bvNone;
BevelOuter := bvNone;
Caption := sEMPTY;
FullRepaint := True;
Enabled := False;
end;
with pnPressure do begin
AutoSize := False;
Ctl3D := False;
BevelInner := bvNone;
BevelOuter := bvNone;
Caption := sEMPTY;
FullRepaint := True;
Enabled := False;
end;
with seSwimSpeed do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := 1;
Min := 0;
Max := 20;
Value := Min;
end;
with edSwimSpeed do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seScanMulti do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := 1;
Min := 1;
Max := 15; //DO NOT CHANGE (ScanDelay)
Value := Min;
end;
with edScanMulti do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seAltitude do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := DAQALTSTEP; // 100m
Min := 0;
Max := ALTITUDEMAX;
end;
with edAltitude do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seAirTemp do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := CDEG; // 100cdeg = 1°C
Min := SENSTEMPMIN;
Max := SENSTEMPMAX;
end;
with edAirTemp do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seWaterTemp do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := CDEG; // 100cdeg = 1°C
Min := WATERTEMPMIN;
Max := WATERTEMPMAX;
end;
with edWaterTemp do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seSurfResp do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := 1;
Min := SURFRESPMIN; // surface RMV [l/min]
Max := SURFRESPMAX;
end;
with edSurfResp do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with seFillPress do begin
Alignment := taRightJustify;
AllowBlank := False;
AllowKeyEdit := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
Direction := sdUpDown;
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := False;
ShowHint := False;
TabStop := False;
Increment := 10;
Min := FILLPRESSMIN; // [bar]
Max := FILLPRESSMAX;
end;
with edFillPress do begin
Alignment := taRightJustify;
AllowBlank := False;
AutoSelect := False;
AutoSize := False;
CheckRange := False;
Ctl3D := True;
DisplayFormat := '0';
FrameVisible := True;
HideSelection := True;
IntegersOnly := True;
ReadOnly := True;
ShowHint := False;
TabStop := False;
end;
with cbTank do begin
AlignmentVertical := avCenter;
AllowGrayed := False;
Checked := False;
HotTrack := True;
ShowHint := False;
TabStop := False;
Transparent := False;
TabOnEnter := False;
end;
btDown.Hint := MakeHint(0); //DELPHI only
btUp.Hint := MakeHint(1);
btStop.Hint := MakeHint(2);
btLeft.Hint := MakeHint(3);
btRight.Hint := MakeHint(4);
//nk// 22.05.07 nk del - do not load environment
Application.ProcessMessages;
end;
procedure TDaq.FormClose(Sender: TObject; var Action: TCloseAction);
begin
DaqLoop.Enabled := False;
SetFormParameter(self);
//nk// 22.05.07 nk del - do not save environment
Action := caFree;
end;
procedure TDaq.FormMoving(var Msg: TwmMoving);
begin
LimitFormMove(MainRect, Msg);
end;
procedure TDaq.DaqLoopTimer(Sender: TObject);
var
enab: Boolean;
tnow: TDateTime;
begin
tnow := Now;
enab := (DivePhase < PHASEPREDIVE); //27.05.07 nk add
with DaqStatus, FormatSettings do begin //25.07.17 nk opt XE3
Panels[0].Text := FormatDateTime(ShortDateFormat, tnow);
Panels[1].Text := FormatDateTime(LongTimeFormat, tnow);
Panels[2].Text := sSPACE + PhaseName[DivePhase];
end;
cbTank.Enabled := enab;
cbSonar.Enabled := enab;
DaqPageControl.Pages[1].TabEnabled := enab;
Application.ProcessMessages;
end;
procedure TDaq.InitEnvironment(DoClear: Boolean);
var // DELPHI only
hour, nop: Long;
begin
if DoClear then begin //22.05.07 nk add
cbTank.Checked := False;
cbSonar.Checked := False;
tbPressure.Position := cCLEAR;
tbCompass.Position := HALFCIRC;
seAltitude.IntValue := DEF_ALTITUDE;
seAirTemp.IntValue := DEF_AIRTEMP;
seWaterTemp.IntValue := DEF_WATERTEMP;
seSurfResp.IntValue := DEF_SURFRESP;
seFillPress.IntValue := DEF_FILLPRESS;
seScanMulti.IntValue := DEF_SCANMULT;
seSwimSpeed.IntValue := DEF_SWIMSPEED;
SerPort := DEF_SERPORT;
ScanPress := cCLEAR;
SaltWater := (seAltitude.IntValue = 0);
ScanMulti := seScanMulti.IntValue;
ScanDelay := Round(seScanMulti.Max - seScanMulti.IntValue) + 1;
SwimSpeed := seSwimSpeed.IntValue;
end;
edScanMulti.IntValue := ScanMulti;
edSwimSpeed.IntValue := SwimSpeed;
rbFreshWater.Checked := not SaltWater;
rbSaltWater.Checked := SaltWater;
if cbTank.Checked then begin
TankFlag := cON;
end else begin
TankFlag := cOFF;
end;
if cbSonar.Checked then begin
SonarFlag := cON;
end else begin
SonarFlag := cOFF;
end;
with seAltitude do begin
if SaltWater then begin
Increment := cCLEAR; // locked
Value := cCLEAR;
end else begin
Increment := DAQALTSTEP; // 100m
end;
if UnitFlag = cOFF then begin // metrical unit system
edAltitude.Value := Value;
lbAltitudeUnit.Caption := DISTUNIT_EU;
end else begin // imperial unit system
edAltitude.Value := Value * 3; // 100m = 300ft
lbAltitudeUnit.Caption := DEPTHUNIT_US;
end;
end;
with seAirTemp do begin
if UnitFlag = cOFF then begin // metrical unit system
edAirTemp.Value := Value / CDEG; // [°C]
lbAirTempUnit.Caption := TEMPUNIT_EU;
end else begin // imperial unit system
edAirTemp.Value := (Value * CFACTOR + COFFSET) / 1000; // [°F]
lbAirTempUnit.Caption := TEMPUNIT_US;
end;
end;
with seWaterTemp do begin
if UnitFlag = cOFF then begin // metrical unit system
edWaterTemp.Value := Value / CDEG; // [cC]
lbWaterTempUnit.Caption := TEMPUNIT_EU;
end else begin // imperial unit system
edWaterTemp.Value := (Value * CFACTOR + COFFSET) / 1000; // [cF]
lbWaterTempUnit.Caption := TEMPUNIT_US;
end;
end;
with seSurfResp do begin
SurfResp := IntValue; // RMV at surface [l/min]
if UnitFlag = cOFF then begin // metrical unit system
edSurfResp.Value := Value; // [l/min]
lbSurfRespUnit.Caption := BREATHUNIT_EU;
end else begin // imperial unit system
edSurfResp.Value := Value * CUIN / 10; // [CuIn/min]
lbSurfRespUnit.Caption := BREATHUNIT_US;
end;
end;
with seFillPress do begin
FillPress := IntValue * MILLI; // tank fill pressure [mbar]
if UnitFlag = cOFF then begin // metrical unit system
edFillPress.Value := Value; // [bar]
lbFillPressUnit.Caption := TANKUNIT_EU;
end else begin // imperial unit system
edFillPress.Value := Value * PSI / 10; // [PSI]
lbFillPressUnit.Caption := TANKUNIT_US;
end;
end;
Altitude := seAltitude.IntValue; // altitude above sea level [m]
AirTemp := seAirTemp.IntValue; // air temperature [cdeg]
CalcAirPress(Altitude, AirTemp, AmbPress); // get ambient pressure [mbar]
CalcBarometer(AmbPress, AirPress); // at altitude = air pressure [hPa]
if SaltWater then begin
TempGrad := 10000000 div WATERGRADSEA;
end else begin
TempGrad := 10000000 div (WATERGRADSEA + Altitude * WATERGRADALT);
end;
// simulates real air pressure history [hPa]
if DoClear then begin
GetClock(nop, nop, nop, nop, hour, nop, nop, nop);
BaroPress[0] := hour; // pointer to actual hour (00..23)
BaroPress[1] := ISOPRESS - 15; // oldest air pressure -20h
BaroPress[2] := ISOPRESS - 14;
BaroPress[3] := ISOPRESS - 14;
BaroPress[4] := ISOPRESS - 12;
BaroPress[5] := ISOPRESS - 12;
BaroPress[6] := ISOPRESS - 8;
BaroPress[7] := ISOPRESS - 5;
BaroPress[8] := ISOPRESS;
BaroPress[9] := ISOPRESS;
BaroPress[10] := ISOPRESS - 5;
BaroPress[11] := ISOPRESS - 6;
BaroPress[12] := ISOPRESS - 7;
BaroPress[13] := ISOPRESS - 9;
BaroPress[14] := ISOPRESS - 9;
BaroPress[15] := ISOPRESS - 8;
BaroPress[16] := ISOPRESS - 8;
BaroPress[17] := ISOPRESS - 6;
BaroPress[18] := ISOPRESS - 6;
BaroPress[19] := ISOPRESS;
BaroPress[20] := ISOPRESS; // youngest air pressure -1h
BaroPress[21] := ISOPRESS; // actual air pressure
end;
Application.ProcessMessages;
end;
//DAQ application starts here
procedure TDaq.RunTask;
var
press: Long;
begin
if InitDaq <> cINIT then begin
InitDaq := cINIT; // DELPHI prevent multiple starts
DaqCtr := cCLEAR;
Ltime := cCLEAR;
Mtime := cCLEAR;
Htime := cCLEAR;
Ptime := cCLEAR;
LastPress := cCLEAR; // TIGER add in task
InitTime := cCLEAR;
TotalDecoTime := cCLEAR;
InitEnvironment(True); //22.05.07 nk add DELPHI
// initialize hardware modules
ReadAccu(cCLEAR, AccuPower, AccuTime);
InitSensor; // get initial pressure, temperature, and salinity
InitSaturation;
InitTank;
InitCompass;
InitSonar;
InitDaq := cINIT;
end else begin // while (InitFlag = cINIT) do begin (Tiger use a while loop)
if DaqCtr >= MAXLOOP then begin
DaqCtr := cCLEAR;
end;
// DELPHI get ambient values from dive plan or from control panel
if PlanFlag = cON then begin
if DaqCtr mod ScanDelay = 0 then begin
Plan.ReadDivePlan(AmbPress, AmbTemp, ScanTime);
end else begin
ScanTime := cCLEAR;
end;
end else begin
ReadPressure(AmbPress, AmbTemp, ScanTime);
end;
RunTime := RunTime + ScanTime; // 07.06.07 nk add TIGER [ms]
Ltime := Ltime + ScanTime; // low priority loop time counter [ms]
Mtime := Mtime + ScanTime; // medium priority loop time counter [ms]
Htime := Htime + ScanTime; // high priority loop time counter [ms]
Ptime := Ptime + ScanTime; // log point interval time [ms]
if DivePhase = PHASEREADY then begin
ReadSalinity(WaterSalt, WaterFlag); //TIGER add check if immersed
end;
CalcDiveDepth(AmbPress, DiveDepth, MaxDepth);
CalcDiveTime(ScanTime, DiveTime, SurfaceTime, IntervalTime, DiveDayNum, DivePhase);
CalcAscentRate(ScanTime, DiveDepth, AscentTime, DiveSpeed);
if (WinPos3 = WINNAVIGATION) or (DaqCtr mod 4 = 0) then begin
ReadCompass(Heading);
if SonarFlag = cON then begin
ReadSonar(HomeDist, Bearing, SonarSignal);
Track.AddDivePos(AUTOINC, HomeDist, Bearing); //nk//test
Track.DrawDivePos(HomeDist, Bearing, True);
Track.MoveDiver(SwimSpeed, Heading); // DELPHI diver tracking simulation
end;
end;
if DaqCtr mod HIGLOOP = 0 then begin // high priority actions every 7 loops TIGER opt
CalcOxygenDose(Htime, OxPress, OxClock, OxUnits, OxDose); //TIGER add
CalcSaturation(Htime, NullTime, DesatTime, FlightTime);
if (NullTime <= 0) or (TotalDecoTime > 0) then begin // deco situation - deco stop required
DecoFlag := cON;
NullTime := cCLEAR;
CalcDecoStop(DecoTime, DecoDepth); // calculate 1st (deepest) deco level [m] and time [s]
CalcDecoTime(TotalDecoTime, TotalDecoGas); // calculate total deco time [s] and gas consum [mbar]
end else begin
DecoFlag := cOFF;
DecoTime := cCLEAR;
DecoDepth := cCLEAR;
TotalDecoGas := cCLEAR;
end;
Htime := cCLEAR;
end;
if DaqCtr mod MEDLOOP = 0 then begin // medium priority actions every 11 loops TIGER add ff
if TankFlag = cON then begin //02.06.07 nk add TankFlag
ReadTank(Mtime, TankPress);
CalcGasRate(Mtime, AmbPress, TankPress, TotalDecoGas, BreathRate, GasTime);
end;
Mtime := cCLEAR;
end;
if DaqCtr mod LOWLOOP = 0 then begin // low priority actions every 39 loops
ReadAccu(Ltime, AccuPower, AccuTime); // 07.06.07 nk add Ltime TIGER
ReadSalinity(WaterSalt, WaterFlag); // TIGER add
if WaterFlag = cON then begin // TIGER add
CalcWater(WaterSalt, AmbTemp, WaterDens, SoundSpeed); //13.05.07 nk TIGER add
end else begin
CalcBarometer(AmbPress, press); //Tiger=AirPress
CalcAltitude(AmbPress, AmbTemp, Altitude);
end;
Ltime := cCLEAR;
end;
if DivePhase > PHASEPREDIVE then begin
if DivePhase < PHASEPOSTDIVE then begin
CheckLimits(StatusWord, SigNum); // check warning and alarm limits
end;
if (LogInterval > cOFF) and (Ptime >= LogInterval) then begin
if LogTime > cOFF then begin
LogDiveBlock; // log dive parameter and status while diving
end;
Ptime := cCLEAR;
StatusWord := cCLEAR; // clear all warning and alarm status bits
end;
end;
if RunMode = MODESTART then begin
LogEvent(TaskName[TASKDAQ], 'Switch task', 'OFF');
DaqLoop.Enabled := False; // stop task DAQ
end;
DaqCtr := DaqCtr + 1;
end; // while
end;
procedure TDaq.btInfoClick(Sender: TObject);
begin //20.10.07 nk add
Info.ShowLogo(10);
end;
//------------------------------------------------------------------------------
// CALCDIVETIME - Calculate the absolute start time [s], the current dive phase
// and dive number, and all dive, log and surface times [ms]
//------------------------------------------------------------------ 17.02.07 --
procedure TDaq.CalcDiveTime(Stime: Long; var DiveTime, SurfaceTime, IntervalTime, DiveDayNum: Long; var DivePhase: Byte);
var
nop: Long;
begin
//TIGER del PhaseFlag := cOFF;
if Stime <= 0 then begin
Exit;
end;
case DivePhase of
PHASEINITIAL: begin
InitTime := InitTime + Stime; // wait until initialized
//nk//InitTime := INITDELAY; //nk// test
if InitTime >= INITDELAY then begin
PhaseFlag := cON;
DivePhase := PHASEADAPTION; // initialized -> ADAPTION PHASE
Exit;
end;
end;
PHASEADAPTION: begin
SurfaceTime := SurfaceTime + Stime; // count surface time up [ms]
if DiveFlag = cON then begin // check if dived
PhaseFlag := cON;
DivePhase := PHASEREADY; // direct dive -> READY PHASE
Exit;
end;
if WaterFlag = cON then begin // check if inside water
PhaseFlag := cON;
DivePhase := PHASEREADY; // immersed -> READY PHASE
Exit;
end;
if DesatTime < SEC_MIN then begin // check if desaturated = adapted
PhaseFlag := cON;
DivePhase := PHASEREADY; // adapted -> READY PHASE
Exit;
end;
AirTemp := AmbTemp;
end;
PHASEREADY: begin
SurfaceTime := SurfaceTime + Stime; // count surface time up [ms]
//02.06.07 nk del TIGER FillPress := TankPress;
if DiveFlag = cON then begin // check if dived
PhaseFlag := cON;
DivePhase := PHASEPREDIVE; // direct dive -> PREDIVE PHASE
Exit;
end;
if WaterFlag = cON then begin // check if inside water
PhaseFlag := cON;
DivePhase := PHASEPREDIVE; // immersed -> PREDIVE PHASE
Exit;
end;
if DesatTime > SEC_HOUR then begin // check if in altitude
PhaseFlag := cON;
DivePhase := PHASEADAPTION; // unadapted -> ADAPTION PHASE
Exit;
end;
AirTemp := AmbTemp;
end;
PHASEPREDIVE: begin
SurfaceTime := SurfaceTime + Stime; // count surface time up [ms]
SigNum := SIGNONE; // clear all pending signals
if DiveFlag = cON then begin // check if dived
////// START OF DIVE //////
GetClock(StartTime, nop, nop, nop, nop, nop, nop, nop);
if DiveDayNum >= MAXDAYDIVE then begin
DiveDayNum := cCLEAR;
end;
DiveDayNum := DiveDayNum + 1; // count daily dives up (1..9)
StatusWord := cCLEAR;
DaqCtr := cCLEAR;
DiveTime := cCLEAR; // clear all timers and counters
LogTime := cCLEAR;
WaterTemp := AmbTemp;
InitDiveLog; // initialize a new dive log
SurfaceTime := cCLEAR;
IntervalTime := DiveRepTime;
PhaseFlag := cON;
DivePhase := PHASEDIVE; // dived -> DIVE PHASE
Exit;
end;
if WaterFlag = cOFF then begin // check if already inside water
PhaseFlag := cON;
DivePhase := PHASEREADY; // outside water -> READY PHASE
Exit;
end;
end;
PHASEDIVE: begin
LogTime := LogTime + Stime; // count log time up [ms]
DiveTime := DiveTime + Stime; // count dive time up [ms]
TotalDiveTime := TotalDiveTime + Stime; // count total dive time up [ms]
if AmbTemp < WaterTemp then begin // get min water temperature [cdeg]
WaterTemp := AmbTemp;
end;
if DiveFlag = cOFF then begin // check if alredy dived
PhaseFlag := cON;
DivePhase := PHASEPOSTDIVE; // dive paused -> POSTDIVE PHASE
Exit;
end;
end;
PHASEPOSTDIVE: begin
SurfaceTime := SurfaceTime + Stime; // count surface time up [ms]
IntervalTime := DiveRepTime - SurfaceTime + MSEC_MIN; // count interval time down [ms]
LogTime := LogTime + Stime; // count log time up [ms]
if DiveFlag = cON then begin // check if dived again
SurfaceTime := cCLEAR;
IntervalTime := DiveRepTime;
PhaseFlag := cON;
DivePhase := PHASEDIVE; // dive continue -> DIVE PHASE
Exit;
end;
if SurfaceTime > DiveRepTime then begin // check if dive timeouted
////// END OF DIVE //////
GetClock(EndTime, nop, nop, nop, nop, nop, nop, nop);
CloseDiveLog;
IntervalTime := DiveRepTime;
PhaseFlag := cON;
DivePhase := PHASEINTERVAL; // end of dive -> INTERVAL PHASE
DiveTime := cCLEAR; // clear old dive data
DiveDepth := cCLEAR;
MaxDepth := cCLEAR;
Exit;
end;
end;
PHASEINTERVAL: begin
SurfaceTime := SurfaceTime + Stime; // count surface time up [ms]
if DiveFlag = cON then begin // check if dived
PhaseFlag := cON;
DivePhase := PHASEREADY; // repetition dive -> READY PHASE
Exit;
end;
if DesatTime < SEC_MIN then begin // check if desaturated
OxUnits := cCLEAR; // clear oxygen units [mOTU]
OxClock := cCLEAR; // and CNS clock [ppm]
DiveDayNum := cCLEAR; // clear daily dive counter
TotalDiveTime := cCLEAR;
PhaseFlag := cON;
DivePhase := PHASEREADY; // desaturated -> READY PHASE
Exit;
end;
AirTemp := AmbTemp;
end;
else
DaqBuff := IntToStr(DivePhase);
LogError('CalcDiveTime', 'Invalid dive phase', DaqBuff, $90);
end;
end;
//------------------------------------------------------------------------------
// CALCDIVEDEPTH - Calculate the dive depth [cm] and the maximal dive depth [cm]
// and check if dived for the given ambient pressure [mbar]
//------------------------------------------------------------------ 17.02.07 --
procedure TDaq.CalcDiveDepth(Apress: Long; var DiveDepth, MaxDepth: Long);
var
depth: Long;
begin
depth := Apress - AirPress; // difference pressure at depth [mbar] rel surface
//nk// make true depth corrections here - using WaterDens