-
Notifications
You must be signed in to change notification settings - Fork 0
/
heathui.cpp
22755 lines (20920 loc) · 793 KB
/
heathui.cpp
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
#define EXTERN extern
#include "heather.ch"
// Thunderbolt TSIP monitor
//
// Copyright (C) 2008-2018 Mark S. Sims - all rights reserved
// Win32 port by John Miles, KE5FX (john@miles.io)
//
//
// This file contains most of the user interface stuff.
// Abandon all hope, ye mortals who dain to understand it...
// It makes my noggin throb, and I wrote it...
//
int all_plots;
extern char *dst_list[];
extern char szAppName[];
extern DATA_SIZE k6, k7, k8, integrator;
extern double osc_k6, osc_k7, osc_k8, osc_integrator;
extern int first_request;
#define DEFAULT_DEGLITCH_SIGMA 3.0 // standard deviation sigma to use when deglitching plots
extern char degc[]; // degrees symbols
extern char degk[];
extern char degs[];
#define GRAPH_LLA 1 // if 1, make graphs 1,2,3 lat/lon/alt if rcvr is in 3D mode
#define NEED_NEW_QUEUES 2 // return values for string_param()
#define NEED_SCREEN_REDRAW 1
// text editing stuff
u08 first_edit;
u08 insert_mode;
u08 edit_cursor;
u08 no_auto_erase;
int edit_err_flag;
int e_row;
char mode_string[SLEN+1]; // the last driver mode change string used
int getting_plot;
u08 old_show_plots[NUM_PLOTS+DERIVED_PLOTS]; // used to save/restore plot enables when toggling jitter measurement mode
u08 old_plot_azel;
u08 old_plot_watch;
DATA_SIZE scale_step;
DATA_SIZE center_step;
int cal_adjust; // used to adjust calendar by user specified "x" months or years
void set_steps(void);
// codes for identifiing edit strings (i.e. the getting_string variable)
#define ADEV_CMD 'a'
#define OSCPID_CMD 'b'
#define DACV_CMD 'c'
#define SCALE_CMD 'd'
#define ELEV_CMD 'e'
#define FILTER_CMD 'f'
#define COLOR_CMD 'g'
#define CHIME_CMD 'h'
#define QUEUE_INT_CMD 'i'
#define LOG_INT_CMD 'j'
#define TEMP_PID_CMD 'k'
#define SET_LLA_CMD 'l'
#define SET_SIGMASK_CMD 'm'
#define LOG_CMD 'n'
#define FOLIAGE_CMD 'o'
#define SET_PDOP_CMD 'p'
#define READ_CMD 'r'
#define SURVEY_CMD 's'
#define MIN_RANGE_CMD 't'
#define DYNAMICS_CMD 'u'
#define VIEW_CMD 'v'
#define WRITE_CMD 'w'
#define SINGLE_SAT_CMD 'x'
#define ABORT_SURV_CMD 'A' // capital letters used to be reserved for ignore_blank_line() commands
#define CENTER_CMD 'C'
#define TITLE_CMD 'H'
#define ABORT_LLA_CMD 'L'
#define SIGNAL_CMD 'Q'
#define MAX_RANGE_CMD 'T'
#define SET_TZ_CMD 'Z'
#define DRIFT_CMD '='
#define SCREEN_CMD '$'
#define STAT_CMD '~'
#define EXIT_CMD '/'
#define ALARM_CMD ':'
#define OPTION_CMD ','
#define SWITCH_CMD '-'
#define SCREEN_DUMP_CMD '!'
#define LOG_DUMP_CMD '('
#define TEMP_SET_CMD '*'
#define WRITE_SIGS_CMD '%'
#define PRECISE_SURV_CMD '^'
#define TC_CMD '1' // 1 .. 8 are oscillator disciplining parameters
#define DAMP_CMD '2'
#define GAIN_CMD '3'
#define MINV_CMD '4'
#define MAXV_CMD '5'
#define JAMSYNC_CMD '6'
#define MAX_FOSC_CMD '7'
#define INITV_CMD '8'
#define CABLE_CMD '9'
// extended codes for identifiing edit strings (getting_string variable)
#define DRVR_CMD 0x0100 // luxor driver mode change
#define PC_CMD 0x0101 // load protection overcurrent
#define PH_CMD 0x0102 // battery HVC
#define PL_CMD 0x0103 // battery LVC
#define PM_CMD 0x0104 // message watchdog timeout
#define PO_CMD 0x0105 // battery overcurrent
#define PP_CMD 0x0106 // load overwatts
#define PR_CMD 0x0107 // protection fault reset
#define PS_CMD 0x0108 // temp2 overtemp
#define PT_CMD 0x0109 // temp1 overtemp
#define PU_CMD 0x010A // load undervoltage
#define PV_CMD 0x010B // load overvoltage
#define PX_CMD 0x010C // auxv overvoltage
#define PW_CMD 0x010D // battery overwatts
#define PZ_CMD 0x010E // auxv undervoltage
#define WC_CMD 0x010F // write config data to file
#define S_CMD 0x0110 // set luxor lat, lon, alt
#define SCRIPT_RUN_CMD 0x0111 // run keyboard script on a schedule
#define EXEC_PGM_CMD 0x0112 // run keyboard script on a schedule
#define AMPL_CMD 0x0120 // lux sensitivity
#define AMPU_CMD 0x0121 // lumen sensitivity
#define AMPE_CMD 0x0122 // IR1 emissivity
#define AMPI_CMD 0x0123 // IR2 emissivity
#define AMPS_CMD 0x0124 // serial number
#define AMPV_CMD 0x0125 // reference voltage
#define BC_CMD 0x0130 // constant current load mode
#define BF_CMD 0x0131 // 3.60V LiFePO4 charge mode
#define BH_CMD 0x0132 // high voltage lipo charge mode
#define BL_CMD 0x0133 // 4.20V lipo charge mode
#define BP_CMD 0x0134 // battery PWM resolution (8/9/10 bit)
#define BR_CMD 0x0135 // pwm sweep rate
#define BS_CMD 0x0136 // pwm sweep
#define BV_CMD 0x0137 // constant load voltage mode
#define BW_CMD 0x0138 // constant load wattage mode
#define CAL_CMD 0x0140 // calibration constants
#define DEBUG_LOG_CMD 0x0150 // open debug log (debug_file)
#define RAW_LOG_CMD 0x0151 // open raw receiver data log (raw_file)
#define TICC_LOG_CMD 0x0152 // open raw TICC data log (ticc_file)
#define RUN_PGM_CMD 0x0153 // run a program
#define MONITOR_CMD 0x0154 // monitor port command
#define TERM_CMD 0x0155 // terminal mode command
#define VECTOR_FONT_CMD 0x0156 // enable scaled vector fonts
#define STOP_SURVEY_CMD 0x0157 // stop standard survey
#define KBD_TIMEOUT_CMD 0x0158 // keyboard idle timeout
#define SET_BAUD_CMD 0x0159 // set receiver com port baud rate
#define SET_RAW_CMD 0x015C // set satellite raw observation rate
#define LOG_CLOSE_CMD 0x015D // close log file
#define PRN_LOG_CMD 0x015E // open/close sat PRN info log
#define PALETTE_CMD 0x0160 // edit color palette
#define DEGLITCH_CMD 0x0161 // set plot deglitch sigma value
#define DEGLITCH_ALL_CMD 0x0162 // set plot deglitch sigma value
#define ADEV_BIN_CMD 0x0170 // adev bin sequence
#define ADEV_HIDE_CMD 0x0171 // hide adev plots
#define ADEV_RECALC_CMD 0x0172 // recalc adev plots
#define TRIM_QUEUE_CMD 0x0173 // remove data from plot queue
#define CALC_CMD 0x0180 // MUST match value in heather.ch
#define EDIT_DEFINE_CMD 0x0181
#define SHOW_CALENDAR_CMD 0x0182
#define PROP_DELAY_CMD 0x0190 // calculate propogation delay
#define TRAIM_CMD 0x0200 // traim threshold
#define PPS_OFS_CMD 0x0201 // simple pps offset
#define ZODIAC_RESTART 0x0202 // reset Zodiac receiver into Motorola mode
#define USER_CMD 0x0203 // send user command to receiver
#define TSX_CMD 0x0204 // set time_sync_offset
#define PPS_OFS1_CMD 0x0210 // PPS1 offset delay
#define PPS_OFS2_CMD 0x0211 // PPS2 offset delay
#define PPS1_CFG_CMD 0x0212
#define PPS2_CFG_CMD 0x0213
#define REF_CMD 0x0214 // GPSDO reference source
#define ATTEN_CMD 0x0215 // attenuator
#define ANTENNA_CMD 0x0216 // antenna monitoring
#define SAT_IGN_CMD 0x0220 // ignore satellite command
#define GNSS_CMD 0x0230 // GNSS system select command
#define SI_CMD 0x0240 // sat info display count
#define PLOT_PRN_CMD 0x0241 // plot sat prn az/el/sig level
#define TRACK_PORT_CMD 0x0242 // select data to send out the TRACK_PORT
#define SORT_CMD 0x0250 // sort sat info display
#define TIDE_CMD 0x0251 // control tide/gravity plots
#define SAT_PLOT_CMD 0x0252 // control sat count plot
#define BAUD_CMD 0x0260 // set serial com port params
#define NVS_FILTER_CMD 0x0270 // NVS_RCVR solution filtration factor
#define NAV_RATE_CMD 0x0280 // navigation update rate
#define SUN_CMD 0x0290 // sunrise/sunset calculation type
#define DELTA_T_CMD 0x02A0 // set TT-UT1 delta T
#define MARINE_CMD 0x02B0 // Motorola marine velocity filter
#define PULLIN_CMD 0x02C0 // UCCM pullin-range
#define EDITOR_CMD 0x02D0 // spawn text editor program
#define SET_LLA_REF_CMD 0x02E0 // set lla scattergram reference point
#define TIME_CODE_CMD 0x02F0 // set time code format
#define UTC_OFS_CMD 0x02F1 // set default utc offset
#define REVERT_SEG_CMD 0x02F2 // revert EEPROM segment(s)
#define TRIMBLE_LLA_CMD 0x02F3 // save position on Trimble receivers using multiple single point surveys
#define BLINK_PRN_CMD 0x02F8 // select a sat to blink in the sat map
#define TICC_MODE_CMD 0x0300 // TICC mode
#define TICC_EDGE_CMD 0x0301 // TICC trigger edges
#define TICC_FUDGE_CMD 0x0302 // TICC fudge factors
#define TICC_TIME2_CMD 0x0303 // TICC time2 factors
#define TICC_SYNC_CMD 0x0304 // TICC sync mode
#define TICC_CAL_CMD 0x0305 // TICC cal periods
#define TICC_DILAT_CMD 0x0306 // TICC dilation factors
#define TICC_SPEED_CMD 0x0307 // TICC ref clock speed
#define TICC_COARSE_CMD 0x0308 // TICC coarse clock speed
#define TICC_TIMEOUT_CMD 0x0309 // TICC coarse clock speed
#define TICC_TUNE_CMD 0x030A // TICC autotune command
#define TICC_FREQ_CMD 0x030B // TICC input nominal freq
#define TRUE_TUNE_CMD 0x030C // Trueposition autotune command
#define PHASE_WRAP_CMD 0x0310 // set phase wrap interval
#define TS_WRAP_CMD 0x0311 // set timestamp wrap interval
#define CS_DISP_CMD 0x0320 // set HP5071A display
#define CS_REMOTE_CMD 0x0321 // set HP5071A remote mode
#define CS_STANDBY_CMD 0x0322 // set HP5071A standby mode
#define CS_SYNC_CMD 0x0323 // set HP5071A sync mode
#define CS_TIMESET_CMD 0x0324 // set HP5071A time
#define CS_LEAP_CMD 0x0326 // set HP5071A leapsecond
#define CS_STER_CMD 0x0327 // set HP5071A frequency steering
#define CS_SLEW_CMD 0x0328 // set HP5071A clock slew
#define PRS_SAVE_CMD 0x0340 // save PRS-10 param(s) into eeprom
#define PRS_MO_CMD 0x0341 // PRS-10 magnetic offset
#define PRS_MS_CMD 0x0342 // PRS-10 magnetic switching
#define PRS_SF_CMD 0x0343 // PRS-10 freq offset
#define PRS_SP_CMD 0x0344 // PRS-10 synthesizer command
#define PRS_TO_CMD 0x0345 // PRS-10 time tag offset
#define X72_FXO_CMD 0x0380 // X72 FXO output enable
#define X72_ACMOS_ENAB_CMD 0x0381 // X72 ACMOS output enable
#define X72_SINE_CMD 0x0382 // X72 Sine output enable
#define X72_EFC_CMD 0x0383 // X72 EFC input enable
#define X72_TIC_CMD 0x0384 // X72 set TIC value
#define X72_FREQ_CMD 0x0385 // X72 set ACMOS freq divider value
#define X72_DDS_CMD 0x0386 // X72 set DDS freq tune value
#define X72_TSAVE_CMD 0x0387 // X72 save tune value in EEPROM
#define X72_TUNE_CMD 0x0388 // auto-tune X72
#define X72_HOLDOVER_CMD 0x0389 // set holdover analysis time
#define X72_OSC_CMD 0x038A // X72 master oscillator freq
#define SRO_WIDTH_CMD 0x03A0 // PPS output pulse width
#define SRO_DELAY_CMD 0x03A1 // PPS output pulse delay
#define SRO_ALARM_CMD 0x03A2 // alarm window width
#define SRO_WINDOW_CMD 0x03A3 // tracking window width
#define SRO_RAW_CMD 0x03A4 // raw phase adjust
#define SRO_FC_CMD 0x03A5 // frequency correction
#define SRO_SY_CMD 0x03A6 // sync mode
#define SRO_TR_CMD 0x03A7 // track mode
#define SRO_FS_CMD 0x03A8 // freq save mode
#define SRO_CO_CMD 0x03A9 // fine phase comparator offset
#define SRO_GF_CMD 0x03AA // gofast mode (only for later firmware)
#define LPFRS_FREQ_CMD 0x03B0 // frequency adjustment
#define TM4_PPS_CMD 0x03B8 // TM4 pps source
#define RT17_OFS_CMD 0x03B8 // RT17 clock offset enable
#define STAR_SET_WTR_CMD 0x03C0 // wait-to-restore time
#define STAR_CLEAR_WTR_CMD 0x03C1 // wait-to-restore time
#define STAR_SET_HBSQ_CMD 0x03C2 // hbsq time in minutes
#define STAR_TS_CMD 0x03D2 // fixup timestamp errors
#define SMOOTHING_CMD 0x03D0 // Furuno smoothing filter
#define RINEX_SITE_CMD 0x0400
#define RINEX_FORMAT_CMD 0x0401
#define RINEX_ANT_TYPE_CMD 0x0402
#define RINEX_ANT_NUM_CMD 0x0403
#define RINEX_HEIGHT_CMD 0x0404
#define MARKER_NAME_CMD 0x0405
#define MARKER_NUM_CMD 0x0406
#define RINEX_LIST_CMD 0x0407
#define RINEX_FIX_CMD 0x0408
#define RINEX_FILE_CMD 0x0410 // open RINEX file
#define RINEX_CLOSE_CMD 0x0411 // close RINEX file
#define RINEX_CPPR_CMD 0x0412 // derive L1 pseduorange from carrier phase data
#define RTK_MODE_CMD 0x0420
#define SA35_FREQ_CMD 0x0430 // frequency adjustment
void edit_plot(int id, int c);
int rpn_calc(void);
int rinex_list;
//
//
// RPN calculator stuff
//
//
void rpn_help();
#define ITYPE u64 // logical operations data type
#define ISIZE 64 // logical operation bits (actually 54 valid bits)
#define RPN_MEM 100 // number of memory registers
#define MAX_RPN_SIZE 16 // max stack size
int RPN_SIZE = 6; // current stack size
double rpn[MAX_RPN_SIZE+1]; // value stack
double rpn_mem[RPN_MEM+1]; // memory registers
double last_x;
int last_was_clx;
double last_rpn0;
double deg_mode = (180.0/PI);
int hex_mode;
int rpn_format = 8;
int comma_fmt;
int eng_mode;
int skip_next_rpn;
int rpn_break;
#define MAX_RPN_DEFS 100 // max number of user defined operations
char *rpn_defs[MAX_RPN_DEFS+1]; // user defined operation strings
int num_rpn_defs; // how many user operations have been defined
#define RPN_EXEC_DEPTH 10 // max nesting depth of user defined operations
struct RPN_EXEC_STACK { // user operations nesting stack
char msg[NMEA_MSG_SIZE+1]; // commands
int col; // where we last processed
int skip; // skip operation flag
} rpn_exec_stack[RPN_EXEC_DEPTH+1];
int rpn_exec_level; // how deep DEFINE execution is currently nested
void start_calc_zoom(int why)
{
// start calculator in zoom display mode
add_kbd('z');
add_kbd('`');
}
void show_rpn_defines(int row, int col)
{
int i;
// display user defined operations (limited by screen height)
strcpy(out, "User DEFINEd operations: define edit savedefs saveall showdefs run");
vidstr(row++, 0, WHITE, out);
if(num_rpn_defs) {
for(i=0; i<num_rpn_defs; i++) { // show the DEFINEs
if(rpn_defs[i]) {
sprintf(out, "(%s)", rpn_defs[i]);
vidstr(row++,col, WHITE, out);
if(row >= (TEXT_ROWS-1)) break; // !!!!could use PLOT_ROW or MOUSE_ROW
}
}
}
}
void rpn_help()
{
int row,col;
// display calculator help
col = 0;
row = 0;
vidstr(row++, col, WHITE, "Math: + - * / chs inv mod abs int frac max min");
vidstr(row++, col, WHITE, " ctof ftoc (temperature conversion)");
vidstr(row++, col, WHITE, " mtof ftom (meters / feet conversion)");
vidstr(row++, col, WHITE, " rn (resistor noise nV/sqrt(Hz) - Y=degrees C X=ohms)");
vidstr(row++, col, WHITE, "Trig: sin cos tan asin acos atan atan2 deg rad");
vidstr(row++, col, WHITE, " dtor rtod rtop ptor diag dist gcd bearing dms dec");
vidstr(row++, col, WHITE, "Powers: sqrt sqr exp powe pow10 pow ** ln log");
vidstr(row++, col, WHITE, "Logic: ~ & | ^ >># <<# (#=shift count)");
vidstr(row++, col, WHITE, "Values: lastx pi e c k h t0 lat lon alt lla dac temp pps osc");
vidstr(row++, col, WHITE, " dop pdop hdop vdop gdop tdop edop xdop ydop");
vidstr(row++, col, WHITE, " tfom ffom cable elmask amu tc damp gain initv");
vidstr(row++, col, WHITE, "Times: date time utc local gps mjd gtime utime greg secs spd spw dow ti");
vidstr(row++, col, WHITE, " tz tzjd leap week tow epoch rise noon set");
vidstr(row++, col, WHITE, "Sats: az# el# sig# doppler# range# phase# prn# (#=sat PRN)");
vidstr(row++, col, WHITE, "Stack: ex enter clx cls swap# stack# roll# down# up# drop# size# (#=count)");
vidstr(row++, col, WHITE, "Memory: rcl# rcl@# rcl+# rcl-# rcl*# rcl/# (#=register num)");
vidstr(row++, col, WHITE, " sto# sto@# sto+# sto-# sto*# sto/# clm clear");
vidstr(row++, col, WHITE, "Compare: x=y x<>y x<y x<=y x>y x>=y x=# x<># x<# x<=# x># x>=#");
vidstr(row++, col, WHITE, " isz dsz nop break again (#=value)");
vidstr(row++, col, WHITE, "Format: fix# sci# exp# hex# oct# bin# comma# zoom help ? (#=decimals)");
show_rpn_defines(row, 9);
}
int rpn_err_flag; // flag set if an error occurs on calculator line execution
void rpn_error(char *s)
{
// flash calculator error message on the srceen
if(s == 0) return;
erase_screen();
vidstr(0,0, YELLOW, s);
refresh_page();
BEEP(7834);
Sleep(1000);
edit_buffer[0] = ' ';
edit_buffer[1] = 0;
rpn_err_flag = 1;
start_calc(1234);
}
void rpn_clear(int flag)
{
int i;
// clear stack and/or memory
if(flag & 0x01) { // clear stack
for(i=0; i<RPN_SIZE; i++) {
rpn[i] = 0.0;
}
}
if(flag & 0x02) { // clear memory
for(i=0; i<RPN_MEM; i++) {
rpn_mem[i] = 0.0;
}
}
last_x = 0.0;
last_rpn0 = 0.0;
last_was_clx = 0;
}
void rpn_down()
{
int i;
int count;
double val;
// rotate stack down
last_was_clx = 0;
count = 1;
if(isdigit(msg_field[4])) count = atoi(&msg_field[4]);
if(count < 0) count = 0-count;
count %= RPN_SIZE;
while(count--) {
val = rpn[0];
for(i=0; i<RPN_SIZE-1; i++) {
rpn[i] = rpn[i+1];
}
rpn[RPN_SIZE-1] = val;
}
}
void rpn_up()
{
int i;
int count;
double val;
// rotate stack up
last_was_clx = 0;
count = 1;
if(isdigit(msg_field[2])) count = atoi(&msg_field[2]);
if(count < 0) count = 0-count;
count %= RPN_SIZE;
while(count--) {
val = rpn[RPN_SIZE-1];
for(i=RPN_SIZE-1; i; i--) {
rpn[i] = rpn[i-1];
}
rpn[0] = val;
last_rpn0 = val;
}
}
double rpn_top()
{
double val;
int i;
// get stack top into last_x and drop the stack one level
// (used to prepare for a two operand command)
last_was_clx = 0;
val = rpn[0];
last_x = last_rpn0 = val;
for(i=0; i<RPN_SIZE-1; i++) {
rpn[i] = rpn[i+1];
}
return val;
}
void rpn_drop()
{
int count;
double last;
// drop stack down
last_was_clx = 0;
count = 1;
if(isdigit(msg_field[4])) count = atoi(&msg_field[4]);
if(count < 0) count = 0-count;
count %= RPN_SIZE;
last = rpn[0];
while(count--) {
rpn_top();
}
last_x = last;
}
void rpn_push(double val)
{
int i;
// push val onto stack
if(last_was_clx == 0) {
for(i=RPN_SIZE-1; i; i--) {
rpn[i] = rpn[i-1];
}
}
rpn[0] = val;
last_was_clx = 0;
}
void rpn_inc(double val)
{
double last;
// does ISZ and DSZ commands
last = rpn[0];
rpn[0] += val;
if(rpn[0] == 0) skip_next_rpn = 1;
last_x = last;
last_was_clx = 0;
}
void rpn_stack()
{
int count;
double val;
double last;
// push the value at a specified stack location onto the stack
count = 1;
if(isdigit(msg_field[5])) count = atoi(&msg_field[5]);
if(count < 0) count = 0-count;
count %= RPN_SIZE;
val = rpn[count];
last = rpn[0];
rpn_push(val);
last_x = last;
last_was_clx = 0;
}
void rpn_swap()
{
int count;
double val;
double last;
// swap X and a value on the stack
count = 1;
if(isdigit(msg_field[4])) count = atoi(&msg_field[4]);
if(count < 0) count = 0-count;
count %= RPN_SIZE;
last = rpn[0];
val = rpn[0];
rpn[0] = rpn[count];
rpn[count] = val;
last_x = last;
last_was_clx = 0;
}
void rpn_new(double val)
{
// replace top of stack and lastx with new value
last_x = rpn[0];
last_rpn0 = val;
rpn[0] = val;
last_was_clx = 0;
}
void rpn_set(double val)
{
// replace top of stack with new value
// last_x = rpn[0];
last_rpn0 = val;
rpn[0] = val;
last_was_clx = 0;
}
void rpn_store()
{
int i;
int sign;
// save top of stack into a memory location
sign = msg_field[3];
i = 0;
if(isdigit(sign)) i = atoi(&msg_field[3]);
else if(sign) i = atoi(&msg_field[4]);
if(i < 0) i = 0 - i;
sprintf(out, "Memory index out of range 0..%d", RPN_MEM);
if(i >= RPN_MEM) rpn_error(out);
else if(sign == '+') rpn_mem[i] += rpn[0];
else if(sign == '-') rpn_mem[i] -= rpn[0];
else if(sign == '*') rpn_mem[i] *= rpn[0];
else if(sign == '/') rpn_mem[i] /= rpn[0];
else if(sign == '@') { // indirect
i = (int) rpn_mem[i];
i = i % RPN_MEM;
rpn_mem[i] = rpn[0];
}
else rpn_mem[i] = rpn[0];
last_was_clx = 0;
}
void rpn_recall()
{
int i;
int sign;
// push memory location onto stack
sign = msg_field[3];
i = 0;
if(isdigit(sign)) i = atoi(&msg_field[3]);
else if(sign) i = atoi(&msg_field[4]);
if(i < 0) i = 0 - i;
sprintf(out, "Memory index out of range 0..%d", RPN_MEM);
if(i >= RPN_MEM) rpn_error(out);
else if(sign == '+') rpn_push(rpn[0]+rpn_mem[i]);
else if(sign == '-') rpn_push(rpn[0]-rpn_mem[i]);
else if(sign == '*') rpn_push(rpn[0]*rpn_mem[i]);
else if(sign == '/') rpn_push(rpn[0]/rpn_mem[i]);
else if(sign == '@') { // indirect
i = (int) rpn_mem[i];
i = i % RPN_MEM;
rpn_push(rpn_mem[i]);
}
else rpn_push(rpn_mem[i]);
last_was_clx = 0;
}
void rpn_max()
{
double last;
double x0,y0;
double val;
// maximum of x and y
last = rpn[0];
x0 = rpn_top();
y0 = rpn_top();
if(x0 > y0) val = x0;
else val = y0;
rpn_push(val);
last_x = last;
last_was_clx = 0;
}
void rpn_min()
{
double last;
double x0,y0;
double val;
// minimum of x and y
last = rpn[0];
x0 = rpn_top();
y0 = rpn_top();
if(x0 < y0) val = x0;
else val = y0;
rpn_push(val);
last_x = last;
last_was_clx = 0;
}
void rpn_rtop()
{
double x, y;
// rectangular to polar
last_x = rpn[0];
x = rpn[0];
y = rpn[1];
rpn[0] = sqrt(x*x + y*y);
rpn[1] = atan2(y,x) * deg_mode;
last_rpn0 = rpn[0];
last_was_clx = 0;
}
void rpn_ptor()
{
double r, theta;
// polar to rectangular
last_x = rpn[0];
r = rpn[0];
theta = rpn[1];
rpn[0] = r * cos(theta/deg_mode);
rpn[1] = r * sin(theta/deg_mode);
last_rpn0 = rpn[0];
last_was_clx = 0;
}
void rpn_rn()
{
double temp, ohms;
double val;
// resistor noise (in nV/sqrt(Hz))
ohms = rpn_top();
temp = rpn[0] - ABS_ZERO;
val = sqrt(4.0 * KB * temp * ohms);
rpn_set(val*1.0E9);
last_was_clx = 0;
}
void rpn_az(int i)
{
double val;
// push sat azimuth
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[2])) {
i = atoi(&msg_field[2]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else {
val = sat[i].azimuth;
if(deg_mode == 1.0) val = val * PI / 180.0;
rpn_push(val);
}
last_was_clx = 0;
}
void rpn_el(int i)
{
double val;
// push sat elevation
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[2])) {
i = atoi(&msg_field[2]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else {
val = sat[i].elevation;
if(deg_mode == 1.0) val = val * PI / 180.0;
rpn_push(val);
}
last_was_clx = 0;
}
void rpn_sig(int i)
{
// push sat sig level
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[3])) {
i = atoi(&msg_field[3]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else rpn_push(sat[i].sig_level);
last_was_clx = 0;
}
void rpn_doppler(int i)
{
// push sat doppler
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[7])) {
i = atoi(&msg_field[7]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else rpn_push(sat[i].doppler);
last_was_clx = 0;
}
void rpn_range(int i)
{
// push sat pseudorange
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[5])) {
i = atoi(&msg_field[5]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else rpn_push(sat[i].range);
last_was_clx = 0;
}
void rpn_phase(int i)
{
// push sat code or carrier phase
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[5])) {
i = atoi(&msg_field[5]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 1..%d", SUN_MOON_PRN);
if(i > SUN_MOON_PRN) rpn_error(out);
else if(i <= 0) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else rpn_push(sat[i].code_phase);
last_was_clx = 0;
}
void rpn_prn(int i)
{
// push all info for a sat prn onto the stack
if(i == 0) {
i = highest_sat();
if(isdigit(msg_field[3])) {
i = atoi(&msg_field[3]);
}
}
if(i < 0) i = 0 - i;
sprintf(out, "PRN out of range 0..%d", SUN_MOON_PRN);
if((i == 0) || (i > SUN_MOON_PRN)) rpn_error(out);
else if(NO_SATS || (sat[i].level_msg == 0)) {
rpn_error("Satellite info not available");
}
else {
rpn_phase(i);
rpn_range(i);
rpn_doppler(i);
rpn_sig(i);
rpn_el(i);
rpn_az(i);
}
last_was_clx = 0;
}
void rpn_dist()
{
double last;
double x0,y0;
double x1,y1;
double val;
// linear distance between two points
last = rpn[0];
x0 = rpn_top();
y0 = rpn_top();
x1 = rpn_top();
y1 = rpn_top();
x0 -= x1;
y0 -= y1;
val = sqrt(x0*x0 + y0*y0);
rpn_new(val);
last_x = last;
last_was_clx = 0;
}
void rpn_gcd()
{
double last;
double x0,y0;
double x1,y1;
double val;
double az;
// great circle distance between two locations (lat,lon = R,Z and Y,X)
// also calculate azimuth angle
last = rpn[0];
x0 = rpn_top() / deg_mode;
y0 = rpn_top() / deg_mode;
x1 = rpn_top() / deg_mode;
y1 = rpn_top() / deg_mode;
val = greatcircle(y0,x0, y1,x1) * 1000.0;
az = az_angle(y1,x1, y0,x0);
if(deg_mode == 1.0) az = az * PI / 180.0;
rpn_push(az);
rpn_push(val);
last_x = last;
last_was_clx = 0;
}
void rpn_bearing()
{
double last;
double x0,y0;
double x1,y1;