-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.c
2306 lines (2025 loc) · 60.8 KB
/
database.c
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
/*
数据库 Database
Last update: 2012.5.4
*/
# include "9860g.h"
static jmp_buf env ;
int assume(int condition, int flag)
{
if (condition == EXIT_F) longjmp(env,1) ;
else return 0;
}
int Database(void)
{
unsigned int key ;
unsigned int page = 1 ;
do {
Bdisp_AllClr_DDVRAM() ; /* clear screen */
Print_zh(" 数据 ", 5, 2, VERT_REV) ;
PrintXY(113, 5, (unsigned char*)"\xE6\x9C ", 0) ;
PrintXY(113, 50, (unsigned char*)"\xE6\x9D ", 0) ;
if (page == 1 ) {
locatestr(28,2) ; printf("[1]平曲线F1") ;
locatestr(28,16) ; printf("[2]竖曲线F2") ;
locatestr(28,30) ; printf("[3]控制点F3") ;
locatestr(28,44) ; printf("[4]批量点F4") ;
}
else if (page == 2 ) {
locatestr(28,2) ; printf("[5]线元法F5") ;
locatestr(28,16) ; printf("[6]路幅库F6") ;
locatestr(28,30) ; printf("[7]隧道项N7") ;
locatestr(28,44) ; printf("[8]锁定表N8 ") ;
}
GetKey(&key) ;
switch (key) {
case KEY_CTRL_F1:case KEY_CHAR_1:
pqx_data() ;
break ;
case KEY_CTRL_F2:case KEY_CHAR_2:
sqx_data() ;
break ;
case KEY_CTRL_F3:case KEY_CHAR_3:
kzd_data();
break ;
case KEY_CTRL_F4:case KEY_CHAR_4:
pld_data() ;
break ;
case KEY_CTRL_F5:case KEY_CHAR_5:
xyf_data() ;
break ;
case KEY_CTRL_F6:case KEY_CHAR_6:
LF_data() ;
break ;
case KEY_CHAR_7:
SD_data() ;
break ;
case KEY_CHAR_8:
Checksum() ;
break ;
case KEY_CTRL_UP:
if (page == 2) page = 1;
break ;
case KEY_CTRL_DOWN:
if (page == 1) page = 2 ;
break ;
default:
break ;
}
}while (key != KEY_CTRL_EXIT) ;
return ;
}
int Lockfile(char* sht_name,BOOL update)
{
char flags_0 ; /* Used for main memory syscall */
int item_ptr ;
int data_length;
int result ;
int handle ;
int loghandle ;
unsigned char MDcp[16];
char hex_MDcp[16*2 + 1];
int di ;
unsigned char MD5result[16];
int ccret ;
result = MCS_SearchDirectoryItem( (unsigned char*)"@SSHEET", (unsigned char*)sht_name, &flags_0, &item_ptr, &handle, &data_length ) ;
if (result == 0) {
if (isLocked(sht_name)){
loghandle = OpenMD5log(sht_name) ;
if (loghandle >= 0){
Bfile_ReadFile(loghandle,MDcp,16,0) ;
Bfile_CloseFile(loghandle) ;
for (di = 0; di < 16; ++di)
sprintf(hex_MDcp + di * 2, "%02x", MDcp[di]);
ccret = MD5(handle,data_length,hex_MDcp,MD5result) ;
} else ccret = MD5(handle,data_length,"",MD5result) ;
} else ccret = MD5(handle,data_length,"",MD5result) ;
if (ccret == 0 ) ;//do nothing
else {
if (update == TRUE) {
if ( DebugS("是否锁定?\nF1-是 F6-否 ") == TRUE){
if (CreateMD5log(sht_name) == 0){
loghandle = OpenMD5log(sht_name) ;
if (loghandle >= 0){
Bfile_WriteFile(loghandle,MD5result,16) ;
Bfile_CloseFile(loghandle) ;
}
} else DebugS("写入校验失败 ") ;
}
} else DebugS("表格%s\n发生变化! ",sht_name) ;
}
} else {DebugS("打开%s失败 ", sht_name) ; return -1 ; }
return result ;
}
int isLocked(char* sht_name)
{
int test ;
BOOL flag = FALSE ;
test = OpenMD5log(sht_name) ;
if (test >= 0){
flag = TRUE ;
Bfile_CloseFile(test);
} else {
flag = FALSE ;
}
return flag ;
}
int OpenMD5log(char* sht_name)
{
BYTE char_p ;
FONTCHARACTER pfile[30] ;
char fname_buf[30] ;
memset(fname_buf,'\0', 30);
# ifdef PC_TEST
strcat(fname_buf, (char*)"\\\\crd0\\MD5\\") ; // Parent folder
# else
strcat(fname_buf, (char*)"\\\\fls0\\MD5\\") ; // Parent folder
# endif
strcat(fname_buf, sht_name) ;
strcat(fname_buf, (char*)".MD5") ;
for (char_p = 0 ; char_p <= strlen(fname_buf) ; ++char_p)
pfile[char_p] = (WORD)fname_buf[char_p] ;
return Bfile_OpenFile(pfile, _OPENMODE_READ) ;
}
int CreateMD5log(char* sht_name)
{
BYTE char_p ;
FONTCHARACTER pfile[30] ;
char fname_buf[30] ;
memset(fname_buf,'\0', 30);
# ifdef PC_TEST
strcat(fname_buf, (char*)"\\\\crd0\\MD5\\") ; // Parent folder
# else
strcat(fname_buf, (char*)"\\\\fls0\\MD5\\") ; // Parent folder
# endif
strcat(fname_buf, sht_name) ;
strcat(fname_buf, (char*)".MD5") ;
for (char_p = 0 ; char_p <= strlen(fname_buf) ; ++char_p)
pfile[char_p] = (WORD)fname_buf[char_p] ;
/* 重建文件 */
Bfile_DeleteFile(pfile) ;
return Bfile_CreateFile(pfile, 16) ;
}
/* S.H.I.E.L.D 表格文件完整性检查 */
int Checksum(void)
{
unsigned int key = 0 ;
do {
Bdisp_AllClr_DDVRAM() ; /* clear screen */
Print_zh("锁定", 2, 0, VERT_REV) ;
locatestr(25,1) ;
if (qxys_flag) {
if (isLocked(dbset.current_pq)) printf("F1-平曲线:%s*",dbset.current_pq);
else printf("F1-平曲线:%s",dbset.current_pq);
} else printf("F1-平曲线:空 ") ;
locatestr(25,14) ;
if (sqx_flag) {
if (isLocked(dbset.current_sq)) printf("F2-竖曲线:%s*",dbset.current_sq);
else printf("F2-竖曲线:%s",dbset.current_sq);
} else printf("F2-竖曲线:空 ") ;
locatestr(25,27) ;
if (xyf_flag) {
if (isLocked(dbset.current_ys)) printf("F3-线元表:%s*",dbset.current_ys);
else printf("F3-线元表:%s",dbset.current_ys);
} else printf("F3-线元表:空 ") ;
locatestr(25,40) ;
if (sd_flag) {
if (isLocked(dbset.current_sd)) printf("F4-隧道面:%s*",dbset.current_sd);
else printf("F4-隧道面:%s",dbset.current_sd);
} else printf("F4-隧道面:空 ") ;
// printf("F1-平曲线:%s%c\nF2-竖曲线:%s%c\nF3-线元表:%s%c\nF4-隧道面:%s%c ",
// qxys_flag?dbset.current_pq:"无 ",isLocked(dbset.current_pq) ? '*' : ' ',
// sqx_flag?dbset.current_sq:"无 ",isLocked(dbset.current_sq) ? '*' : ' ',
// xyf_flag?dbset.current_ys:"无 ",isLocked(dbset.current_ys) ? '*' : ' ',
// sd_flag?dbset.current_sd:"无 ",isLocked(dbset.current_sd) ? '*' : ' ') ;
PrintMini(2, 58, (unsigned char*)" F1 ", MINI_REV) ;
PrintMini(21, 58, (unsigned char*)" F2 ", MINI_REV) ;
PrintMini(40, 58, (unsigned char*)" F3 ", MINI_REV) ;
PrintMini(59, 58, (unsigned char*)" F4 ", MINI_REV) ;
PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ;
GetKey(&key) ;
switch (key)
{
case KEY_CTRL_F1:
if (qxys_flag == TRUE) Lockfile(dbset.current_pq,TRUE);
else Warning("无锁定目标 ",2) ;
break ;
case KEY_CTRL_F2:
if (sqx_flag == TRUE) Lockfile(dbset.current_sq,TRUE);
else Warning("无锁定目标 ",2) ;
break ;
case KEY_CTRL_F3:
if (xyf_flag == TRUE) Lockfile(dbset.current_ys,TRUE);
else Warning("无锁定目标 ",2) ;
break ;
case KEY_CTRL_F4:
if (sd_flag == TRUE) Lockfile(dbset.current_sd,TRUE);
else Warning("无锁定目标 ",2) ;
break ;
default:
break ;
}
} while (key != KEY_CTRL_EXIT) ;
return 0;
}
BYTE sd_flag = FALSE ;
int SD_data(void)
{
unsigned int key = 0 ;
do {
Bdisp_AllClr_DDVRAM() ; /* clear screen */
Print_zh(" 隧道 ", 2, 0, VERT_REV) ;
locatestr(22,22) ;
printf("F1-载入 F2-校验 \nF3-查看 F4-帮助 ") ;
PrintMini(112, 10, (unsigned char*)" AC", MINI_REV) ;
PrintMini(2, 58, (unsigned char*)" F1 ", MINI_REV) ;
PrintMini(21, 58, (unsigned char*)" F2 ", MINI_REV) ;
PrintMini(40, 58, (unsigned char*)" F3 ", MINI_REV) ;
PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ;
setjmp(env) ;
locatestr(22,5) ;
if (sd_flag == TRUE)
printf("使用中: %s",dbset.current_sd) ;
else printf("使用中: 空 ") ;
GetKey(&key) ;
switch (key)
{
case KEY_CTRL_F1:
sd_flag = load_SD_data(sd_flag) ;
break ;
case KEY_CTRL_F2:
if (sd_flag == TRUE) {
yanzheng() ;
}
else DebugS("未载入断面文件 ") ;
break ;
case KEY_CTRL_F3:
if (sd_flag == TRUE) show_SD_data() ;
else DebugS("未载入断面文件 ") ;
break ;
case KEY_CTRL_F4:
DatabaseHelp(7) ;
break ;
case KEY_CTRL_AC :
if (sd_flag == TRUE) {
sd_flag = FALSE ;
if ( Empty_SD() == 0) {FreeSD() ; Warning("重置成功!",1) ;}
else Warning("重置失败!",1) ;
}
break ;
default:
break ;
}
} while (key != KEY_CTRL_EXIT) ;
return 0;
}
int Empty_SD(void)
{
int confile_ptr = -1 ;
char temp_buffer[MAXLINE] ;
confile_ptr = Bfile_OpenFile(configfile, _OPENMODE_READ_SHARE) ;
if (confile_ptr < 0) return -1 ;
sprintf(temp_buffer,"Current_SD = EMP") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,NOW,TRUE) ;
Bfile_CloseFile(confile_ptr) ;
return 0 ;
}
#pragma inline (TestSD)
int TestSD(void)
{
return (SD_start_x == NULL || SD_start_y == NULL
|| SD_end_x == NULL || SD_end_y == NULL
|| SD_circle_x == NULL || SD_circle_y == NULL
|| SD_R == NULL) ? FALSE : TRUE ;
}
int FreeSD()
{
if (SD_start_x != NULL) { free(SD_start_x) ; SD_start_x = NULL ; }
if (SD_start_y != NULL) { free(SD_start_y) ; SD_start_y = NULL ; }
if (SD_end_x != NULL) { free(SD_end_x) ; SD_end_x = NULL ; }
if (SD_end_y != NULL) { free(SD_end_y) ; SD_end_y = NULL ; }
if (SD_circle_x != NULL) { free(SD_circle_x) ; SD_circle_x = NULL ; }
if (SD_circle_y != NULL) { free(SD_circle_y) ; SD_circle_y = NULL ; }
if (SD_R != NULL) { free(SD_R) ; SD_R = NULL ; }
return ;
}
/* 隧道要素 */
int SD_size = 0;
double* SD_start_x = NULL ; /*起点坐标X*/
double* SD_start_y = NULL ; /*起点坐标Y*/
double* SD_end_x = NULL ; /*终点坐标X*/
double* SD_end_y = NULL ; /*终点坐标Y*/
double* SD_circle_x = NULL ;/*圆心X*/
double* SD_circle_y = NULL ;/*圆心Y*/
double* SD_R = NULL ; /*半径*/
int LoadSD(BYTE flag)
{
unsigned int key ;
PopUpWin(3) ;
Print_zh("文件名: ", 20, 22, 0) ;
PrintXY(80, 25, (unsigned char *)dbset.current_sd, 0) ;
key = InputStr(80, 25) ;
if (key == KEY_CTRL_EXE) {
if (ipstr[0] == 0 && dbset.current_sd[0] != 0) strncpy(ipstr, dbset.current_sd, 5) ;
FreeSD() ;
SD_size = Init_Sht(7) ; /* 7列 */
if (SD_size == -1) return FALSE ;
/*
数据格式:
行1:线段的起点坐标X,Y,终点坐标X1,Y2,圆心的坐标X3,Y4,半径R
行N:同上
*/
SD_start_x = ReadFloat(1,7,SD_size) ;
SD_start_y = ReadFloat(2,7,SD_size) ;
SD_end_x = ReadFloat(3,7,SD_size) ;
SD_end_y = ReadFloat(4,7,SD_size) ;
SD_circle_x = ReadFloat(5,7,SD_size) ;
SD_circle_y = ReadFloat(6,7,SD_size) ;
SD_R = ReadFloat(7,7,SD_size) ;
if (TestSD() && yanzheng() == 0) { Warning("读取成功 ", 1) ; return TRUE ; }
else Warning("读取失败 ", 3) ;
}
else if (key == KEY_CTRL_EXIT) return EXIT_F ;
return FALSE ;
}
int autoload_SD(BYTE flag)
{
strncpy(ipstr, dbset.current_sd, 5) ;
FreeSD() ;
SD_size = Init_Sht(7) ; /* 7列 */
if (SD_size == -1) return FALSE ;
SD_start_x = ReadFloat(1,7,SD_size) ;
SD_start_y = ReadFloat(2,7,SD_size) ;
SD_end_x = ReadFloat(3,7,SD_size) ;
SD_end_y = ReadFloat(4,7,SD_size) ;
SD_circle_x = ReadFloat(5,7,SD_size) ;
SD_circle_y = ReadFloat(6,7,SD_size) ;
SD_R = ReadFloat(7,7,SD_size) ;
if (TestSD()) { sd_flag = TRUE ; return TRUE ; }
else rtfail() ;
return flag ;
}
int show_SD_data(void)
{
unsigned int step = 0 ;
assume(DebugS("数据行数: %d",SD_size), EXIT_F) ;
for (step = 0 ; step < SD_size ; ++step) {
assume(DebugS("起点X=%.3f\n起点Y=%.3f",SD_start_x[step], SD_start_y[step]), EXIT_F) ;
assume(DebugS("终点X=%.3f\n终点Y=%.3f",SD_end_x[step], SD_end_y[step]), EXIT_F) ;
assume(DebugS("圆心X=%.3f\n圆心Y=%.3f",SD_circle_x[step], SD_circle_y[step]), EXIT_F) ;
assume(DebugS("半径R=%.3f",SD_R[step]), EXIT_F) ;
}
return ;
}
int load_SD_data(BYTE fflag)
{
const DISPBOX clr = {20, 2, 120,54} ;
unsigned int key = 0 ;
BYTE flag = FALSE;
char* backup_cur = NULL;
Bdisp_AreaClr_DDVRAM(&clr) ;
DrawRect(20,2,54,100);
locatestr(22,2) ;
printf("1.%4s 2.%4s\n3.%4s 4.%4s\n5.%4s 6.%4s\n7.%4s 8.%4s",dbset.sd1,dbset.sd2,dbset.sd3,dbset.sd4,dbset.sd5,dbset.sd6,dbset.sd7,dbset.sd8) ;
GetKey(&key) ;
backup_cur = dbset.current_sd ;
switch (key)
{
case KEY_CHAR_1:
dbset.current_sd = dbset.sd1 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_2:
dbset.current_sd = dbset.sd2 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_3:
dbset.current_sd = dbset.sd3 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_4:
dbset.current_sd = dbset.sd4 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_5:
dbset.current_sd = dbset.sd5 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_6:
dbset.current_sd = dbset.sd6 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_7:
dbset.current_sd = dbset.sd7 ;
flag = LoadSD(flag) ;
break ;
case KEY_CHAR_8:
dbset.current_sd = dbset.sd8 ;
flag = LoadSD(flag) ;
break ;
case KEY_CTRL_EXIT:
dbset.current_sd = dbset.current_sd ;
flag = EXIT_F ;
default:
break ;
}
if (flag == TRUE) {
Save_SD_data(key) ;
return TRUE ;
}
else if (flag == EXIT_F) {
dbset.current_sd = backup_cur ;
return fflag ;
}
else return FALSE ;
}
int Save_SD_data(unsigned int key)
{
int confile_ptr = -1 ;
char temp_buffer[MAXLINE] ;
confile_ptr = Bfile_OpenFile(configfile, _OPENMODE_READ_SHARE) ;
if (confile_ptr < 0) return -1 ;
switch (key)
{
case KEY_CHAR_1:
strncpy(dbset.sd1,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD1") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD1 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd1, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_2:
strncpy(dbset.sd2,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD2") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD2 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd2, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_3:
strncpy(dbset.sd3,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD3") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD3 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd3, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_4:
strncpy(dbset.sd4,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD4") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD4 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd4, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_5:
strncpy(dbset.sd5,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD5") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD5 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd5, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_6:
strncpy(dbset.sd6,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD6") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD6 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd6, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_7:
strncpy(dbset.sd7,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD7") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD7 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd7, temp_buffer,NOW,FALSE) ;
break ;
case KEY_CHAR_8:
strncpy(dbset.sd8,ipstr, 5) ;
sprintf(temp_buffer,"Current_SD = SD8") ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.cusd, temp_buffer,LATER,TRUE) ;
sprintf(temp_buffer,"SD8 = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.sd_fpos.sd8, temp_buffer,NOW,FALSE) ;
break ;
default:
break ;
}
Bfile_CloseFile(confile_ptr) ;
return 0 ;
}
BYTE LF_flag = FALSE ;
int LF_data(void)
{
unsigned int key = 0 ;
do
{
Bdisp_AllClr_DDVRAM() ; /* clear screen */
Print_zh(" 路幅 ", 2, 0, VERT_REV) ;
locatestr(22,22) ;
printf("F1-载入 F2-校验 \nF3-查看 F4-帮助 ") ;
PrintMini(112, 10, (unsigned char*)" AC", MINI_REV) ;
PrintMini(2, 58, (unsigned char*)" F1 ", MINI_REV) ;
PrintMini(21, 58, (unsigned char*)" F2 ", MINI_REV) ;
PrintMini(40, 58, (unsigned char*)" F3 ", MINI_REV) ;
PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ;
locatestr(22,5) ;
if (LF_flag == TRUE)
printf("使用中: %s",dbset.current_hp) ;
else
printf("使用中: 空 ") ;
GetKey(&key) ;
switch (key)
{
case KEY_CTRL_F1:
LF_flag = load_lf_data(LF_flag) ;
break ;
case KEY_CTRL_F2:
if (LF_flag == TRUE) InputLFstake() ;
else DebugS("未载入数据 ") ;
break ;
case KEY_CTRL_F3:
if (LF_flag == TRUE) show_LF_data() ;
else DebugS("未载入数据 ") ;
break ;
case KEY_CTRL_F4:
DatabaseHelp(6) ;
break ;
case KEY_CTRL_AC :
if (LF_flag == TRUE) {
LF_flag = FALSE ;
strncpy(ipstr, " EMP\0", 5) ;
if ( Save_lf_data() == 0) { FreeLF() ; Warning("重置成功!",1) ;}
else Warning("重置失败!",1) ;
}
break ;
default:
break ;
}
}while (key != KEY_CTRL_EXIT) ;
return ;
}
int InputLFstake(void)
{
unsigned int key ;
BYTE exit_flag = FALSE ;
unsigned int check_HP ;
PopUpWin(3) ;
Print_zh("桩号 ", 18, 20, 0) ;
while (exit_flag != TRUE) {
key = InputValP(48, 22) ;
switch (key) {
case KEY_CTRL_EXE:
check_HP = LF_JS(number) ;
DebugS("左幅宽 %.3f\n左横坡 %.2f%%",LF_L_Width[check_HP], LF_L_HP[check_HP]) ;
DebugS("右幅宽 %.3f\n右横坡 %.2f%%",LF_R_Width[check_HP], LF_R_HP[check_HP]) ;
return TRUE ;
break ;
case KEY_CTRL_EXIT:
exit_flag = TRUE ;
break ;
default:
break ;
}
}
return FALSE ;
}
unsigned int LF_JS(double stake)
{
unsigned int step = 0 ;
for (step = 0 ; step < LF_size ; ++step) {
if (step == key_HP) continue ;
else {
if (stake >= LF_Start[step] && stake <= LF_End[step])
return step ;
}
}
return key_HP ;
}
int show_LF_data(void)
{
unsigned int step = 0 ;
BYTE key_set = FALSE ;
for (step = 0 ; step < LF_size ; ++step) {
if (LF_Start[step] < 0 && LF_End[step] < 0 && key_set == FALSE ) {
DebugS("通用设定 ") ;
key_set = TRUE ;
}
else DebugS("起始 %.3f\n结束 %.3f",LF_Start[step], LF_End[step]) ;
DebugS("左幅宽 %.3f\n左横坡 %.2f%%",LF_L_Width[step], LF_L_HP[step]) ;
DebugS("右幅宽 %.3f\n右横坡 %.2f%%",LF_R_Width[step], LF_R_HP[step]) ;
}
return ;
}
int LF_size = 0;
double* LF_L_Width = NULL ;
double* LF_L_HP = NULL ;
double* LF_R_Width = NULL ;
double* LF_R_HP = NULL ;
double* LF_Start = NULL ;
double* LF_End = NULL ;
unsigned int key_HP = 0 ;
int TestLF(void)
{
unsigned int step = 0 ;
if ( LF_L_Width != NULL && LF_L_HP != NULL && LF_R_Width != NULL && LF_R_HP != NULL
&& LF_Start != NULL && LF_End != NULL) {
for (step = 0 ; step < LF_size ; ++step) { //遍历得出通用路幅宽及横坡
if (LF_Start[step] < 0 && LF_End[step] < 0) {
key_HP = step ;
break ;
}
}
return TRUE ;
}
else return FALSE ;
}
int load_lf_data(BYTE fflag)
{
unsigned int key ;
PopUpWin(3) ;
Print_zh("文件名: ", 20, 22, 0) ;
PrintXY(80, 25, (unsigned char *)dbset.current_hp, 0) ;
key = InputStr(80, 25) ;
if (key == KEY_CTRL_EXE) {
if (ipstr[0] == 0 && dbset.current_hp[0] != 0) strncpy(ipstr, dbset.current_hp, 5) ;
FreeLF() ;
LF_size = Init_Sht(6) ; //A~F列
if (LF_size == -1) return FALSE ;
/* A~F列依次为 左宽,左横坡,右宽,右横坡,里程开始,里程结束(通用部分里程开始和结束输负数)*/
LF_L_Width = ReadFloat(1, 6, LF_size) ;
LF_L_HP = ReadFloat(2, 6, LF_size) ;
LF_R_Width = ReadFloat(3, 6, LF_size) ;
LF_R_HP = ReadFloat(4, 6, LF_size) ;
LF_Start = ReadFloat(5, 6, LF_size) ;
LF_End = ReadFloat(6, 6, LF_size) ;
if (TestLF()) {
if ( Save_lf_data() == 0) {
strncpy(dbset.current_hp, ipstr, 5) ;
Warning("读取成功 ", 1) ;
}
else Warning("请整理闪存 ", 1) ;
return TRUE ;
}
else Warning("读取失败 ", 3) ;
}
else if (key == KEY_CTRL_EXIT) return fflag ;
return FALSE ;
}
int autoload_LF(BYTE flag)
{
strncpy(ipstr, dbset.current_hp, 5) ;
FreeLF() ;
LF_size = Init_Sht(6) ; //A~F列
if (LF_size == -1) return FALSE ;
LF_L_Width = ReadFloat(1, 6, LF_size) ;
LF_L_HP = ReadFloat(2, 6, LF_size) ;
LF_R_Width = ReadFloat(3, 6, LF_size) ;
LF_R_HP = ReadFloat(4, 6, LF_size) ;
LF_Start = ReadFloat(5, 6, LF_size) ;
LF_End = ReadFloat(6, 6, LF_size) ;
if (TestLF()) { LF_flag = TRUE ;return TRUE ; }
else rtfail() ;
return flag ;
}
int Save_lf_data(void)
{
int confile_ptr = -1 ;
char temp_buffer[MAXLINE] ;
confile_ptr = Bfile_OpenFile(configfile, _OPENMODE_READ_SHARE) ;
if (confile_ptr < 0) return -1 ;
sprintf(temp_buffer,"Current_HP = %4s",ipstr) ;
confile_ptr = WriteINI(confile_ptr, dbset.hp_pos, temp_buffer,NOW,TRUE) ;
Bfile_CloseFile(confile_ptr) ;
return 0 ;
}
int FreeLF(void)
{
if (LF_L_Width != NULL) { free(LF_L_Width) ; LF_L_Width = NULL ; }
if (LF_L_HP != NULL) { free(LF_L_HP) ; LF_L_HP = NULL ; }
if (LF_R_Width != NULL) { free(LF_R_Width) ; LF_R_Width = NULL ; }
if (LF_R_HP != NULL) { free(LF_R_HP) ; LF_R_HP = NULL ; }
if (LF_Start != NULL) { free(LF_Start) ; LF_Start = NULL ; }
if (LF_End != NULL) { free(LF_End) ; LF_End = NULL ; }
return ;
}
BYTE pld_flag = FALSE ;
char name[FILENAMEMAX] ;
FONTCHARACTER pld_FileName[50];
BYTE SDcard_F = FALSE ;
BYTE Fls_F = FALSE ;
int pld_data(void)
{
char folder[FILENAMEMAX] = "";
char filename_buf[50] ;
unsigned int key = 0 ;
int csvFile ;
unsigned int csv_size = 0;
do
{
Bdisp_AllClr_DDVRAM() ; /* clear screen */
Print_zh(" 批量 ", 2, 0, VERT_REV) ;
locatestr(22,22) ;
printf("F1-载入 F2-校验 ") ;
PrintMini(114, 1, (unsigned char*)" AC", MINI_REV) ;
PrintMini(2, 58, (unsigned char*)" F1 ", MINI_REV) ;
PrintMini(21, 58, (unsigned char*)" F2 ", MINI_REV) ;
PrintMini(105, 58, (unsigned char*)" EXIT ", MINI_REV) ;
locatestr(22,5) ;
if (pld_flag == TRUE)
printf("使用中:%s",name) ;
else
printf("使用中: 空 ") ;
GetKey(&key) ;
switch (key){
case KEY_CTRL_F1 :
if (SelectRoot() == 0)
{
if(SelectFile( folder, name ) == 1){
if( strlen(folder) == 0 ) {
if (SDcard_F == TRUE)
{
sprintf( filename_buf, "\\\\crd0\\%s", name );
}
else if (Fls_F == TRUE)
{
sprintf( filename_buf, "\\\\fls0\\%s", name );
}
}
else {
if (SDcard_F == TRUE)
{
sprintf( filename_buf, "\\\\crd0\\%s\\%s", name );
}
else if (Fls_F == TRUE)
{
sprintf( filename_buf, "\\\\fls0\\%s\\%s", name );
}
}
CharToFont(filename_buf,pld_FileName);
csvFile = Bfile_OpenFile(pld_FileName,_OPENMODE_READ_SHARE);
if (csvFile >=0) {
PopUpWin(3) ;
Print_zh("索引建立中..", 28, 22, 0) ;
//csv_size = Bfile_GetFileSize (csvFile);
if (CreateIndex(csvFile) >=0){
//Reopen the csv file ;
Bfile_CloseFile(csvFile) ;
csvFile = Bfile_OpenFile(pld_FileName,_OPENMODE_READ);
if (BuildIndex(csvFile)==0) pld_flag = TRUE ;
}
else Warning("创建索引失败!",2) ;
Bfile_CloseFile(csvFile) ;
}
else {Warning("打开文件失败",2) ; pld_flag = FALSE ;}
}
}
break ;
case KEY_CTRL_F2 :
if (pld_flag == TRUE)
InputPT_num(Bfile_OpenFile(pld_FileName,_OPENMODE_READ_SHARE), FALSE) ;
else DebugS("未加载csv文件 ") ;
break ;
case KEY_CTRL_AC :
if (pld_flag == TRUE) {
pld_flag = FALSE ;
if ( Empty_pld() == 0) { Warning("重置成功!",1) ;}
else Warning("重置失败!",1) ;
}
break ;
default:
break ;
}
}while (key != KEY_CTRL_EXIT) ;
return ;
}
int Empty_pld(void)
{
int confile_ptr = -1 ;
confile_ptr = Bfile_OpenFile(configfile, _OPENMODE_READ_SHARE) ;
if (confile_ptr < 0) return -1 ;
WriteINI(confile_ptr, dbset.pld_pos, "Current_PLD = \\;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",NOW,TRUE) ;
Bfile_CloseFile(confile_ptr) ;
return 0 ;
}
unsigned int ptlist_count ;
int InputPT_num(int csvFile, BOOL usePT)
{
FONTCHARACTER indexfile[] = { '\\','\\','f','l','s','0','\\','I','N','D','E','X','.','d','a','t' ,'\0'} ;
FONTCHARACTER indexfile2[] = { '\\','\\','c','r','d','0','\\','I','N','D','E','X','.','d','a','t' ,'\0'} ;
unsigned int key ;
BYTE exit_flag = FALSE ;
unsigned int PT = 1;
int index_fptr = -1;
DWORD index_pos = 0;
PopUpWin(3) ;
Print_zh("点号 ", 18, 20, 0) ;
if (csvFile < 0) {
Warning("打开文件失败",2) ;
exit_flag = TRUE ;
}
while (exit_flag != TRUE) {
locatestr(100,20) ; printf("%d",PT) ;
key = InputValP(48, 22) ;
switch (key) {
case KEY_CTRL_EXE:
PT = number ? number : PT ;
if (PT < 1 || PT > ptlist_count) {
DebugS("点号范围1~%d",ptlist_count) ;
Bfile_CloseFile(csvFile) ;
return FALSE ;
}else {
/*首先尝试SD卡,其次内置闪存*/
index_fptr = Bfile_OpenFile(indexfile2, _OPENMODE_READWRITE_SHARE) ;
if (index_fptr < 0) index_fptr = Bfile_OpenFile(indexfile, _OPENMODE_READWRITE_SHARE) ;
if (index_fptr >=0){
Bfile_ReadFile(index_fptr, &index_pos, sizeof(DWORD), (PT - 1)*sizeof(DWORD)) ;
getPOSline(csvFile, index_pos) ;
parseCSVfile((char*)Linebuffer, usePT) ;
Bfile_CloseFile(index_fptr) ;
exit_flag = TRUE ; //Normal stop ;
}
else { DebugS("打开索引失败! ") ; exit_flag = TRUE ; }
}
exit_flag = TRUE ;
break ;
case KEY_CTRL_EXIT:
//exit_flag = TRUE ;
Bfile_CloseFile(csvFile) ;
return FALSE ;
break ;
default: break ;
}
}
Bfile_CloseFile(csvFile) ;
return TRUE ;
}
int parseCSVfile(char* string,BOOL usePT)
{
struct tkbox* info ;
unsigned int step_count = 1 ;
BOOL exit_flag = FALSE ;
double check_x = 0 ;
double check_y = 0 ;
double check_cmt = 0 ; //备注
begin = forward = string ; /* 指向缓冲区 */
while ((info = lexan_num()) && exit_flag != TRUE) {
if (info->token == TOKEN_NUM){
//数值大于10万切除大头
if (info->value >= 100000)
info->value -= floor(floor(info->value)/100000) * 100000 ;
switch(step_count){
case 1:
break ;
case 2:
if (usePT == TRUE) x = info->value ;
else check_x = info->value ;
break ;
case 3:
if (usePT == TRUE) y = info->value ;
else check_y = info->value ;
break ;
case 4:
break ;
case 5:
check_cmt = info->value ;