-
Notifications
You must be signed in to change notification settings - Fork 1
/
Control_Kaist_main.ino
1956 lines (1702 loc) · 61.1 KB
/
Control_Kaist_main.ino
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
#include <Arduino.h>
#include <EEPROM.h>
#include <Servo.h>
#define BT_NEED_INIT 1
#include <SPI.h>
#include <SD.h>
File csLogFile ;
#define GS_0_PL_1 // if defined GS = UART_PORT_0 , PL = UART_PORT_1 VERSION 2014
//#define GS_1_PL_0 // if defined GS = UART_PORT_0 , PL = UART_PORT_1 VERSION 2012,3
const unsigned char MASK_BIT_OR [8] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 };
const unsigned char MASK_BIT_AND[8] = { 0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE };
unsigned char time_tick=0 ;
unsigned short time_servo_tick=0;
unsigned short time_msec=0 ; // use millis() % 1000 ;
unsigned long time_run =0 ; // use millis() / 1000 ;
unsigned long time_sec =0 ; // use gps + time_run
// PORT 0 is Camera
// PORT 1 is GS
#define MAX_PL_RX_QUEUE 128
#define MAX_GS_RX_QUEUE 32
#define MAX_PL_TX_QUEUE 32
#define MAX_GS_TX_QUEUE 256
#define PL_RX_QUEUE_IDX_MASK 0x7F
#define GS_RX_QUEUE_IDX_MASK 0x1F
#define PL_TX_QUEUE_IDX_MASK 0x1F
#define GS_TX_QUEUE_IDX_MASK 0xFF
#define TX_SPEED_9600 9600
#define TX_SPEED_38400 38400
#define TX_SPEED_115200 115200
// baud_setting = (F_CPU / 8 / baud - 1) / 2;
#define PL_TX_SPEED 115200
#define GS_TX_SPEED 115200
#ifdef GS_0_PL_1
#define GS_PORT Serial
#define PL_PORT Serial1
#else
#define PL_PORT Serial
#define GS_PORT Serial1
#endif
///////////////////////////////////////////////////////////////////////////////////
// USE ARDUINO's begin function.. OK
// baud_setting = (F_CPU / 8 / baud - 1) / 2;
#define GS_PORT_SPEED_SET(macSpeed) GS_PORT.begin(macSpeed)
#define PL_PORT_SPEED_SET(macSpeed) PL_PORT.begin(macSpeed)
///////////////////////////////////////////////////////////////////////////////////
void PL_UART_INIT() { PL_PORT.begin(PL_TX_SPEED); }
void GS_UART_INIT() { GS_PORT.begin(GS_TX_SPEED); }
///////////////////////////////////////////////////////////////////////////////////
unsigned char Pl_Rx_QueueInIdx = 0 ;
unsigned char Pl_Rx_QueueOutIdx = 0 ;
unsigned char Pl_Rx_Queue[MAX_PL_RX_QUEUE]; // for packet data
unsigned char Gs_Rx_QueueInIdx = 0 ;
unsigned char Gs_Rx_QueueOutIdx = 0 ;
unsigned char Gs_Rx_Queue[MAX_GS_RX_QUEUE]; // for packet data
unsigned char Pl_Tx_QueueInIdx = 0 ;
unsigned char Pl_Tx_QueueOutIdx = 0 ;
unsigned char Pl_Tx_Queue[MAX_PL_TX_QUEUE]; // for packet data
unsigned char Gs_Tx_QueueInIdx = 0 ;
unsigned char Gs_Tx_QueueOutIdx = 0 ;
unsigned char Gs_Tx_Queue[MAX_GS_TX_QUEUE]; // for packet data
#define Pl_Rx_QueueIn(macData) { Pl_Rx_QueueInIdx &= PL_RX_QUEUE_IDX_MASK; Pl_Rx_Queue[Pl_Rx_QueueInIdx] = (macData) ; Pl_Rx_QueueInIdx++ ; }
#define Pl_Rx_QueueOut(macData) { Pl_Rx_QueueOutIdx &= PL_RX_QUEUE_IDX_MASK; (macData) = Pl_Rx_Queue[Pl_Rx_QueueOutIdx]; Pl_Rx_QueueOutIdx++ ; }
#define Pl_Rx_QueueFlush() { Pl_Rx_QueueInIdx = Pl_Rx_QueueOutIdx; }
#define Gs_Rx_QueueIn(macData) { Gs_Rx_QueueInIdx &= GS_RX_QUEUE_IDX_MASK; Gs_Rx_Queue[Gs_Rx_QueueInIdx] = (macData) ; Gs_Rx_QueueInIdx++ ; }
#define Gs_Rx_QueueOut(macData) { Gs_Rx_QueueOutIdx &= GS_RX_QUEUE_IDX_MASK; (macData) = Gs_Rx_Queue[Gs_Rx_QueueOutIdx]; Gs_Rx_QueueOutIdx++ ; }
#define Gs_Rx_QueueFlush() { Gs_Rx_QueueInIdx = Gs_Rx_QueueOutIdx; }
#define Pl_Tx_QueueIn(macData) { Pl_Tx_QueueInIdx &= PL_TX_QUEUE_IDX_MASK; Pl_Tx_Queue[Pl_Tx_QueueInIdx] = (macData) ; Pl_Tx_QueueInIdx++ ; }
#define Pl_Tx_QueueOut(macData) { Pl_Tx_QueueOutIdx &= PL_TX_QUEUE_IDX_MASK; (macData) = Pl_Tx_Queue[Pl_Tx_QueueOutIdx]; Pl_Tx_QueueOutIdx++ ; }
#define Pl_Tx_QueueFlush() { Pl_Tx_QueueInIdx = Pl_Tx_QueueOutIdx; }
#define Gs_Tx_QueueIn(macData) { Gs_Tx_QueueInIdx &= GS_TX_QUEUE_IDX_MASK; Gs_Tx_Queue[Gs_Tx_QueueInIdx] = (macData) ; Gs_Tx_QueueInIdx++ ; }
#define Gs_Tx_QueueOut(macData) { Gs_Tx_QueueOutIdx &= GS_TX_QUEUE_IDX_MASK; (macData) = Gs_Tx_Queue[Gs_Tx_QueueOutIdx]; Gs_Tx_QueueOutIdx++ ; }
#define Gs_Tx_QueueFlush() { Gs_Tx_QueueInIdx = Gs_Tx_QueueOutIdx; }
#define Pl_Rx_QueueIsEmpty() ( Pl_Rx_QueueInIdx == Pl_Rx_QueueOutIdx )
#define Gs_Rx_QueueIsEmpty() ( Gs_Rx_QueueInIdx == Gs_Rx_QueueOutIdx )
#define Pl_Tx_QueueIsEmpty() ( Pl_Tx_QueueInIdx == Pl_Tx_QueueOutIdx )
#define Gs_Tx_QueueIsEmpty() ( Gs_Tx_QueueInIdx == Gs_Tx_QueueOutIdx )
#define Pl_Rx_QueueIsNotEmpty() ( Pl_Rx_QueueInIdx != Pl_Rx_QueueOutIdx )
#define Gs_Rx_QueueIsNotEmpty() ( Gs_Rx_QueueInIdx != Gs_Rx_QueueOutIdx )
#define Pl_Tx_QueueIsNotEmpty() ( Pl_Tx_QueueInIdx != Pl_Tx_QueueOutIdx )
#define Gs_Tx_QueueIsNotEmpty() ( Gs_Tx_QueueInIdx != Gs_Tx_QueueOutIdx )
#define RxMode_DEFAULT 0
#define RxMode_CAMERA 1
#define RxMode_CAMERA_SIZE 2
#define RxMode_CAMERA_IMAGE 3
#define RxMode_GPS 4
#define RxMode_IMU 5
#define RxMode_ATLM 6
#define RxMode_DTLM 7
#define RxMode_M4 0x14
#define RxMode_M5 0x15
#define RxMode_M6 0x16
#define RxMode_M7 0x17
unsigned char hyRxMode = RxMode_CAMERA ; // when 0
#define RxMode_CAMERA_PORT 0x00
#define RxMode_GPS_PORT 0x01
#define RxMode_IMU_PORT 0x02
#define RxMode_M4_PORT 0x04
#define RxMode_M5_PORT 0x05
#define RxMode_M6_PORT 0x06
#define RxMode_M7_PORT 0x07
// need direction is 0
void hyRxMode_PortSet( unsigned char iMode)
{
unsigned char b = PINC ;
b &= 0xF0 ; // direction is 0
b |= iMode ;
PORTC = b ;
}
// 각 단계별 필요한 수행 횟수 정의 ( 기준 11.0592 Mhz Clock 사용시 )
#define WAIT_CNT_SEND 0x000100
#define WAIT_CNT_GPS 0x020000
#define WAIT_CNT_IMU 0x010000
#define WAIT_CNT_MSG 0x020000
#define WAIT_CNT_ATLM 0x000080
//#define WAIT_CNT_CAMERA_STEP 0x002000
#define WAIT_CNT_CAMERA_STEP 0x001000
#define WAIT_CNT_CAMERA_INIT_STEP 0x007000
#define WAIT_CNT_CAMERA_IMAGE_160 0x010000
#define WAIT_CNT_CAMERA_IMAGE_320 0x020000
#define WAIT_CNT_CAMERA_IMAGE_640 0x080000
unsigned long WAIT_CNT_CAMERA_IMAGE = WAIT_CNT_CAMERA_IMAGE_640 ;
//#define WAIT_CNT_CAMERA_IMAGE WAIT_CNT_CAMERA_IMAGE_640
#define WAIT_CNT_BT_STEP 0x010000
// Payload 데이터를 얻기 위해 UART 포트의 수신 속도 및 MUX를 설정한다.
void hyRxMode_Set(unsigned char iMode)
{
switch(iMode)
{
case RxMode_CAMERA :
case RxMode_CAMERA_SIZE :
case RxMode_CAMERA_IMAGE: PL_PORT_SPEED_SET(115200) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_CAMERA_PORT) ; break;
case RxMode_IMU : PL_PORT_SPEED_SET(115200) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_IMU_PORT) ; break;
case RxMode_GPS : PL_PORT_SPEED_SET(9600) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_GPS_PORT) ; break;
case RxMode_ATLM : PL_PORT_SPEED_SET(115200) ; hyRxMode = iMode ; break;
case RxMode_DTLM : PL_PORT_SPEED_SET(115200) ; hyRxMode = iMode ; break;
case RxMode_M4 : PL_PORT_SPEED_SET(9600) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_M4_PORT) ; break;
case RxMode_M5 : PL_PORT_SPEED_SET(9600) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_M5_PORT) ; break;
case RxMode_M6 : PL_PORT_SPEED_SET(9600) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_M6_PORT) ; break;
case RxMode_M7 : PL_PORT_SPEED_SET(9600) ; hyRxMode = iMode ; hyRxMode_PortSet(RxMode_M7_PORT) ; break;
}
}
void hyCANSAT_USER_OPERATION();
void hyTransUartWait(unsigned long cnt);
/////////////////////////
// 한 바이트 송신 함수 //
#define hyPlTxByte(data) PL_PORT.write(data)
#define hyGsTxByte(data) GS_PORT.write(data)
#define hyGsSetTxByte(data) hyGsTxByte(data)
//#define hyGsSetTxByte(data) GS_PORT.write(data)
// read one byte processing //
// 각 포트로부터 한바이트 데이터를 받았을 경우 처리한다.
void hyGs_RecvByte(unsigned char b);
void hyCamera_RecvByte(unsigned char b);
void hyImu_RecvByte(unsigned char b);
void hyGps_RecvByte(unsigned char b);
///////////////////////////////////////////////////
// Analog Inputs :: ADC Conver 할 갯수를 설정한다.
#define ADC_TLMS 8
#define ADC_MASK 0x07
///////////////////////////////////////////////////
// LED output
unsigned char cansat_led = 0xFF ;
///////////////////////////////////////////////////
// COMMANDS 4 바이트 32개의 명령을 다룬다.
// cansat_dcmd[4] 처럼 array 로 다루어도 되지만,
// 각각의 처리 시간을 아끼기 위해서 그냥 변수로 사용하였다.
// DTLM & CMD & iCMD
unsigned char cansat_dcmd_0 = 0xFF ; // operation flag 1111 1111
unsigned char cansat_dcmd_1 = 0x00 ; // dcmd_1 for use Digital Port
unsigned char cansat_dcmd_2 = 0x00 ; // dcmd_2 for use sub command
unsigned char cansat_dcmd_3 = 0x00 ; // dcmd_3 for use Analog Port
unsigned char cansat_byte_cmd[8] = { 0,0,0,0,0,0,0,0 } ;
// 2012.6.29 : Append OP_MASK_USER for USER Defined Operation
// cansat_dcmd_0 를 다룬다.
#define OP_MASK_GPS 0x80
#define OP_MASK_IMU 0x40
#define OP_MASK_CAMERA 0x20
#define OP_MASK_ATLM 0x10
#define OP_MASK_DTLM 0x08
#define OP_MASK_USER 0x04
#define OP_MASK_CAMERA_160 0x02 // default 320 when 1 0 then 160
#define OP_MASK_CAMERA_640 0x01 // default 320 when 0 1 then 640
#define IS_NEED_OP(macMask) (( cansat_dcmd_0 & (macMask) ) ? 1 : 0 )
#define TOGGLE_OP(macMask) {cansat_dcmd_0 ^= (macMask) ; }
#define SET_OP(macMask) {cansat_dcmd_0 |= (macMask) ; }
#define CLEAR_OP(macMask) {cansat_dcmd_0 &= ~(macMask) ; }
// cansat_dcmd_2 를 다룬다.
#define ICMD_MASK_RESET 0x80 // reset cansat
#define ICMD_MASK_CAMERA_RESET 0x40 // reset camera command
#define ICMD_MASK_ATLM_TO_DIGITAL 0x20 // when user operation
#define ICMD_MASK_ATLM_TO_LED 0x10 // when user operation
#define ICMD_MASK_PWM_0_L 0x20 // when not user/pwm operation
#define ICMD_MASK_PWM_0_R 0x10 // when not user/pwm operation
#define ICMD_MASK_PWM_1_L 0x08 // when not user/pwm operation
#define ICMD_MASK_PWM_1_R 0x04 // when not user/pwm operation
#define ICMD_MASK_GS 0x02
#define ICMD_MASK_SIGN 0x01
#define IS_NEED_ICMD(macMask) (( cansat_dcmd_2 & (macMask) ) ? 1 : 0 )
#define TOGGLE_ICMD(macMask) {cansat_dcmd_2 ^= (macMask) ; }
#define SET_ICMD(macMask) {cansat_dcmd_2 |= (macMask) ; }
#define CLEAR_ICMD(macMask) {cansat_dcmd_2 &= ~(macMask) ; }
//////////////////////////////////////////////////////////////////////////////
// eeprom 을 다룬다.
#define OP_EEPROM_ADDR 0x10
#define OP_TO_EEPROM() { EEPROM.write(OP_EEPROM_ADDR, cansat_dcmd_0); }
#define OP_FROM_EEPROM() { cansat_dcmd_0 = EEPROM.read(OP_EEPROM_ADDR); }
//////////////////////////////////////////////////////////////////////////////
// 3개의 LED 를 다룬다.
#define LED_MASK_SIGN 0x40 // Led 포트 설정에 따라 Toggling 한다.
#define LED_MASK_GS 0x80 // 지상국에서 명령을 수신했을 경우
#define LED_MASK_PL 0x20 // When Recv Data Port
#define LED_MASK_LOG 0x01 //
//////////////////////////////////////////////////////////////////////////////
void CLEAR_LED (unsigned char mask){ unsigned char b = PINC ; b |= (mask & 0xE0) ; PORTC = b ; }
void SET_LED (unsigned char mask){ unsigned char b = PINC ; b &= ~(mask & 0xE0) ; PORTC = b ; }
void TOGGLE_LED(unsigned char mask){ unsigned char b = PINC ; b ^= (mask & 0xE0) ; PORTC = b ; }
// LED 값을 쓴다.
void hyLed_PortSet()
{
TOGGLE_LED( LED_MASK_SIGN) ;
CLEAR_LED ( LED_MASK_GS ) ;
CLEAR_LED ( LED_MASK_PL ) ;
// CLEAR_LED ( LED_MASK_USER) ;
// if( IS_NEED_OP(OP_MASK_USER) ) CLEAR_LED(LED_MASK_USER); else SET_LED(LED_MASK_USER);
CLEAR_LED ( LED_MASK_LOG ) ;
}
// AD convertor 를 다룬다.
unsigned char adc_mux = 0 ;
unsigned char ad_data[ADC_TLMS];// AD Converting 한 값을 저장한다.
unsigned char FILTER_MID_3(unsigned char b0, unsigned char b1, unsigned char b2 )
{
if( b0 < b1 )
{
if( b1 < b2 ) return b1 ;
else if ( b0 < b2 ) return b2 ;
else return b0 ;
}
else
{
if( b0 < b2 ) return b0 ;
else if ( b1 < b2 ) return b2 ;
else return b1 ;
}
}
// ATLM 획득 함수
// Analog Telemetry GET : Interrupt Setting //
void hyATlm_Get(void)
{
unsigned char b0, b1, b2, b3, b4;
int sensor_value ;
sensor_value = analogRead(adc_mux) ; // remove
sensor_value = analogRead(adc_mux) ; // remove
sensor_value = analogRead(adc_mux) ; b0 = ( sensor_value >> 2 ) & 0xFF ;
sensor_value = analogRead(adc_mux) ; b1 = ( sensor_value >> 2 ) & 0xFF ;
sensor_value = analogRead(adc_mux) ; b2 = ( sensor_value >> 2 ) & 0xFF ;
// ARLM Extra Sensor Start (아날로그)
sensor_value = analogRead(adc_mux) ; b3 = ( sensor_value >> 2 ) & 0xFF ;
sensor_value = analogRead(adc_mux) ; b4 = ( sensor_value >> 2 ) & 0xFF ;
// Extra Sensor End
ad_data[adc_mux] = FILTER_MID_3(b0,b1,b2,b3);
adc_mux = (adc_mux+1) & 0x07 ;
}
void hyATlm_Send()
{
unsigned char cs_atlm=0;
Gs_Tx_QueueIn(0x76);
Gs_Tx_QueueIn(0x00);
Gs_Tx_QueueIn(0x40);
Gs_Tx_QueueIn(0x10);
Gs_Tx_QueueIn(ad_data[0]); cs_atlm+= ad_data[0];
Gs_Tx_QueueIn(ad_data[1]); cs_atlm+= ad_data[1];
Gs_Tx_QueueIn(ad_data[2]); cs_atlm+= ad_data[2];
Gs_Tx_QueueIn(ad_data[3]); cs_atlm+= ad_data[3];
Gs_Tx_QueueIn(ad_data[4]); cs_atlm+= ad_data[4];
Gs_Tx_QueueIn(ad_data[5]); cs_atlm+= ad_data[5];
Gs_Tx_QueueIn(ad_data[6]); cs_atlm+= ad_data[6];
Gs_Tx_QueueIn(ad_data[7]); cs_atlm+= ad_data[7];
Gs_Tx_QueueIn(cs_atlm) ;
}
////////////////////////////////////////////////////////////////////////////////
// for 10 ms
// 16000000/1024 ==> 15625 // 15625==125*125==> 125 ==> 0x7D
// 11059200/1024 ==> 10800 // 10800/100 ==> 108 ==> 0x6C
// 9830400/1024 ==> 9600 // 9600/100 ==> 96 ==> 0x60 ==> 0x90
// TIMER SERVO 제어
// 20 msec 주기를 갖는다.
// 1.0 msec 왼쪽
// 1.5 msec 중간
// 2.0 msec 오른쪽
unsigned char pwm_0_cnt = 0 ;
unsigned char pwm_1_cnt = 0 ;
/////////////////////////////////////////////////////////////////////////////////////////////
#if 0 // when 0.25msec ticks
#define PWM_20_MSEC_CNT 80 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_LEFT 5 // 1 msec // over 4 + 1
#define PWM_CNT_CENTER 6 // 1.5 msec
#define PWM_CNT_RIGHT 7 // 2 msec // under 8 - 1
#elif 0 // when 0.1 msec ticks
#define PWM_20_MSEC_CNT 200 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_LEFT 11 // 1 msec // over 10 + 1
#define PWM_CNT_CENTER 15 // 1.5 msec //
#define PWM_CNT_RIGHT 19 // 2 msec // under 20 - 1
#elif 0 // when 0.05 msec ticks
#define PWM_20_MSEC_CNT 400 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_START 15
#define PWM_CNT_LEFT 20 // 1 msec // over 10 + 1
#define PWM_CNT_CENTER 30 // 1.5 msec //
#define PWM_CNT_RIGHT 40 // 2 msec // under 20 - 1
#define PWM_CNT_END 55
#elif 0 // when 0.25 msec ticks
#define PWM_20_MSEC_CNT 800 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_START 30
#define PWM_CNT_LEFT 41 // 1 msec // over 10 + 1
#define PWM_CNT_CENTER 60 // 1.5 msec //
#define PWM_CNT_RIGHT 79 // 2 msec // under 20 - 1
#define PWM_CNT_END 140
#elif 0 // when 0.02 msec ticks ( 20 us )
#define PWM_20_MSEC_CNT 1000 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_LEFT 51 // 1 msec // over + 1
#define PWM_CNT_CENTER 75 // 1.5 msec //
#define PWM_CNT_RIGHT 99 // 2 msec // under - 1
#else // when arduino's count == degree
#define PWM_20_MSEC_CNT 800 // 20 msec
#define PWM_CNT_NULL 0 // no control
#define PWM_CNT_START 0
#define PWM_CNT_LEFT 0 // 0 deg
#define PWM_CNT_CENTER 90 // 90 deg
#define PWM_CNT_RIGHT 180 // 180 deg
#define PWM_CNT_END 180
#endif
// 다음과 같이 작동하도록 하였다.
// 00 : NULL : 아무 작업 안한다.
// 01 : LEFT
// 11 : CENTER
// 10 : RIGHT
inline void hyCANSAT_PWM_OPERATION() // 0.1 msec 단위로 처리한다.
{
// pwm processing 20 msec processing
time_servo_tick++ ;
if ( PWM_20_MSEC_CNT <= time_servo_tick ) time_servo_tick = 0 ;
// 0 == 0.5ms , 1 == 1ms , 2 == 1.5ms, 3 == 2 ms
// PWM_0 COUNT 계산
if( IS_NEED_ICMD(ICMD_MASK_PWM_0_L) ) { pwm_0_cnt = ( IS_NEED_ICMD(ICMD_MASK_PWM_0_R) ) ? PWM_CNT_CENTER : PWM_CNT_LEFT ;}
else { pwm_0_cnt = ( IS_NEED_ICMD(ICMD_MASK_PWM_0_R) ) ? PWM_CNT_RIGHT : cansat_byte_cmd[0] ;}
if( IS_NEED_ICMD(ICMD_MASK_PWM_1_L) ) { pwm_1_cnt = ( IS_NEED_ICMD(ICMD_MASK_PWM_1_R) ) ? PWM_CNT_CENTER : PWM_CNT_LEFT ;}
else { pwm_1_cnt = ( IS_NEED_ICMD(ICMD_MASK_PWM_1_R) ) ? PWM_CNT_RIGHT : cansat_byte_cmd[1] ;}
if( PWM_CNT_START <= pwm_0_cnt && time_servo_tick <= pwm_0_cnt && time_servo_tick <= PWM_CNT_END ) { cansat_dcmd_1 |= 0x80 ; } else { cansat_dcmd_1 &= 0x7F;}
if( PWM_CNT_START <= pwm_1_cnt && time_servo_tick <= pwm_1_cnt && time_servo_tick <= PWM_CNT_END ) { cansat_dcmd_1 |= 0x40 ; } else { cansat_dcmd_1 &= 0xBF;}
PORTA = cansat_dcmd_1 ;
}
//// 1ms 단위 처리를 수행한다.
//inline void hyCANSAT_MSEC_OPERATION() // 1 msec 단위로 처리한다.
//{
// // msec 단위로 시간을 증가한다.
// time_msec++ ;
//
// // wait ms processing
// if( 0 < time_wait_msec ) time_wait_msec-- ;
//
// // 1000ms 즉 1초 단위의 Operation 을 수행한다.
//// if( 1000 < time_msec ) // 1 SEC // 약 80개가 더 많네..
// if( 1080 < time_msec ) // 1 SEC // 약 80개가 더 많네..
// {
// time_msec = 0 ;
// time_run++ ;
// time_sec++ ; // 1 sec
// }
//}
// 1 msec : 0xAA
// 0.5 msec : 0xD5
// 0.25 msec : 0xEC
// 0.20 msec : 0xEF
// 0.10 msec : 0xF8 : when TCCR0 == 5 // 100 us
// 0.05 msec : 0xF? : when TCCR0 == 5 // 50 us
// 0.02 msec : 0xF9 : when TCCR0 == 3 // 20 us
// 0.01 msec : 0x?? : when TCCR0 == 3 // 10 us
//SIGNAL(TIMER0_OVF_vect)
//{
//// TCNT0 = 0xAA ; // 클럭에 따른 변경 필요 : 1ms 를 생성해 보자.
//// TCNT0 = 0xD5 ; // 클럭에 따른 변경 필요 : 0.5ms 를 생성해 보자
//// TCNT0 = 0xEC ; // 클럭에 따른 변경 필요 : 0.25ms 를 생성해 보자
//// TCNT0 = 0xEF ; // 클럭에 따른 변경 필요 : 0.2ms 를 생성해 보자
//// TCNT0 = 0xF8 ; // 클럭에 따른 변경 필요 : 0.1ms 를 생성해 보자 , TCCR0 == 5
// TCNT0 = 0xFC ; // 클럭에 따른 변경 필요 : 0.05ms 를 생성해 보자 , TCCR0 == 5
//// TCNT0 = 0xFE ; // 클럭에 따른 변경 필요 : 0.025ms를 생성해 보자 , TCCR0 == 5 .. image 오류발생하고 있음.
//// TCNT0 = 0xF9 ; // 클럭에 따른 변경 필요 : 0.02ms 를 생성해 보자 , TCCR0 == 3
//
// // increase time_msec
// time_tick++ ; // 초기값이 0 이면, 1 ==> 0 ==> 1 // 1과 0을 반복한다.
// if( 20 <= time_tick ) { time_tick = 0 ; hyCANSAT_MSEC_OPERATION() ; } // 1msec 에 한번씩 수행
// if( !IS_NEED_OP(OP_MASK_USER ) ) hyCANSAT_PWM_OPERATION() ; // NOT USER DEFINED ==> PWM OPERATION
//// cansat_dcmd_1 ^= 0x80 ; PORTA = cansat_dcmd_1 ;
//}
// DTLM 처리 함수
// 1. Flag Toggle
// 2. PORT 에 데이터 설정
void hyDTlm_OP()
{
TOGGLE_ICMD(ICMD_MASK_SIGN);
// 아래 부분은 사용자가 바꾸어도 괜찮을 것이다.
unsigned char pf = PINF ; // analog data status get
cansat_dcmd_3 = 0 ;
if( pf & 0x01 ) cansat_dcmd_3 |= 0x80 ;
if( pf & 0x02 ) cansat_dcmd_3 |= 0x40 ;
if( pf & 0x04 ) cansat_dcmd_3 |= 0x20 ;
if( pf & 0x08 ) cansat_dcmd_3 |= 0x10 ;
if( pf & 0x10 ) cansat_dcmd_3 |= 0x08 ;
if( pf & 0x20 ) cansat_dcmd_3 |= 0x04 ;
if( pf & 0x40 ) cansat_dcmd_3 |= 0x02 ;
if( pf & 0x80 ) cansat_dcmd_3 |= 0x01 ;
PORTA = cansat_dcmd_1 ; // digital setting
}
// DTLM 지상 전송 함수
#if 0 // OLD VERSION
// 76 00 48 02 DTLM(2) CS(1) //
void hyDTlm_Send()
{
Gs_Tx_QueueIn(0x76);
Gs_Tx_QueueIn(0x00);
Gs_Tx_QueueIn(0x48);
Gs_Tx_QueueIn(0x02);
Gs_Tx_QueueIn(cansat_dcmd_0);
Gs_Tx_QueueIn(cansat_dcmd_1);
Gs_Tx_QueueIn((cansat_dcmd_0 ^ cansat_dcmd_1));
}
#else // new version
// 76 00 48 04 DTLM(4) CS(1) //
void hyDTlm_Send()
{
Gs_Tx_QueueIn(0x76);
Gs_Tx_QueueIn(0x00);
Gs_Tx_QueueIn(0x48);
Gs_Tx_QueueIn(0x04);
Gs_Tx_QueueIn(cansat_dcmd_0);
Gs_Tx_QueueIn(cansat_dcmd_1);
Gs_Tx_QueueIn(cansat_dcmd_2);
Gs_Tx_QueueIn(cansat_dcmd_3);
Gs_Tx_QueueIn((cansat_dcmd_0 ^ cansat_dcmd_1 ^ cansat_dcmd_2 ^ cansat_dcmd_3));
}
#endif
////////////////////////////////////////////////////////////////////////
// read one byte processing //
void hyGps_RecvByte(unsigned char b);
void hyCamera_Receive_Size(unsigned char rx);
void hyCamera_Receive_Image(unsigned char rx);
void hyMsg_RecvByte(unsigned char b);
// UART 통신 처리 메인 함수
// 1. Pl_Rx_Queue 처리 (모드별 처리 수행)
// 2. Gs_Rx_Queue 처리 (지상 명령 처리 수행 )
// 3. Gs_Tx_Queue 처리 (지상 전송 명령 처리 )
// 4. Pl_Tx_Queue 처리 (내부 명령 전송 처리 )
unsigned char hyTransUart()
{
unsigned char b ;
unsigned char worked =0;
// Pl_Rx ==> Gs_Tx
if( PL_PORT.available() ) { Pl_Rx_QueueIn(PL_PORT.read()); } // When no interrupt processing ...
if( Pl_Rx_QueueIsNotEmpty() )
{
worked = 1 ;
Pl_Rx_QueueOut(b);
switch( hyRxMode )
{
case RxMode_CAMERA : Gs_Tx_QueueIn(b); break;
case RxMode_CAMERA_SIZE : Gs_Tx_QueueIn(b); hyCamera_Receive_Size(b) ; break;
case RxMode_CAMERA_IMAGE : Gs_Tx_QueueIn(b); hyCamera_Receive_Image(b); break;
case RxMode_GPS : hyGps_RecvByte(b); break;
case RxMode_IMU : hyImu_RecvByte(b); break;
case RxMode_M4 : hyMsg_RecvByte(b); break;
case RxMode_M5 : hyMsg_RecvByte(b); break;
case RxMode_M6 : hyMsg_RecvByte(b); break;
case RxMode_M7 : hyMsg_RecvByte(b); break;
default : Gs_Tx_QueueIn(b) ; break;
}
}
// if( GS_PORT.available() ) { Gs_Rx_QueueIn(PL_PORT.read()); } // When no interrupt processing ... // use interrupt OK ..
// Gs_Rx ==> Pl_Tx
if( Gs_Rx_QueueIsNotEmpty() )
{
worked = 1 ;
Gs_Rx_QueueOut(b) ;
hyGs_RecvByte(b);
}
// Gs_Tx ==> Gs_Tx PORT
if( Gs_Tx_QueueIsNotEmpty() )
{
worked = 1 ;
Gs_Tx_QueueOut(b);
hyGsTxByte(b);
}
// Pl_Tx ==> Pl_Tx PORT
if( Pl_Tx_QueueIsNotEmpty() )
{
worked = 1 ;
Pl_Tx_QueueOut(b);
hyPlTxByte(b);
}
return worked ; // 0 means do nothing //
}
// 블루투스 초기화 함수
// 1. UART1 초기화 : 9600
// 2. BT 통신 속도 초기화 : AT+UARTCONFIG,115200,N,1
// 3. BT MODE 초기화 : AT+BTMODE,3
// 4. BT 재 설정 : ATZ
void hyBT_STOP()
{
hyGsSetTxByte('+');
hyGsSetTxByte('+');
hyGsSetTxByte('+');
hyGsSetTxByte(0x0D);
hyGsSetTxByte(0x0A);
}
void hyBT_115200()
{
hyGsSetTxByte('a');
hyGsSetTxByte('t');
hyGsSetTxByte('+');
hyGsSetTxByte('u');
hyGsSetTxByte('a');
hyGsSetTxByte('r');
hyGsSetTxByte('t');
hyGsSetTxByte('c');
hyGsSetTxByte('o');
hyGsSetTxByte('n');
hyGsSetTxByte('f');
hyGsSetTxByte('i');
hyGsSetTxByte('g');
hyGsSetTxByte(',');
hyGsSetTxByte('1');
hyGsSetTxByte('1');
hyGsSetTxByte('5');
hyGsSetTxByte('2');
hyGsSetTxByte('0');
hyGsSetTxByte('0');
hyGsSetTxByte(',');
hyGsSetTxByte('N');
hyGsSetTxByte(',');
hyGsSetTxByte('1');
hyGsSetTxByte(',');
hyGsSetTxByte('0');
hyGsSetTxByte(0x0D);
hyGsSetTxByte(0x0A);
}
void hyBT_MODE()
{
hyGsSetTxByte('a');
hyGsSetTxByte('t');
hyGsSetTxByte('+');
hyGsSetTxByte('b');
hyGsSetTxByte('t');
hyGsSetTxByte('m');
hyGsSetTxByte('o');
hyGsSetTxByte('d');
hyGsSetTxByte('e');
hyGsSetTxByte(',');
hyGsSetTxByte('3');
hyGsSetTxByte(0x0D);
hyGsSetTxByte(0x0A);
}
void hyBT_ATS()
{
hyGsSetTxByte('a');
hyGsSetTxByte('t');
hyGsSetTxByte('s');
hyGsSetTxByte('1');
hyGsSetTxByte('0');
hyGsSetTxByte('=');
hyGsSetTxByte('1');
hyGsSetTxByte(0x0D);
hyGsSetTxByte(0x0A);
}
void hyBT_ATZ()
{
hyGsSetTxByte('a');
hyGsSetTxByte('t');
hyGsSetTxByte('z');
hyGsSetTxByte(0x0D);
hyGsSetTxByte(0x0A);
}
void hyBluetooth_Init()
{
GS_UART_INIT();
GS_PORT_SPEED_SET(9600) ;
hyTransUartWait(WAIT_CNT_BT_STEP) ;
hyBT_STOP() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
hyBT_MODE() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
hyBT_115200(); hyTransUartWait(WAIT_CNT_BT_STEP) ;
// hyBT_ATS() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
hyBT_ATZ() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
GS_PORT_SPEED_SET(GS_TX_SPEED);
// hyBT_MODE() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
// hyBT_ATZ() ; hyTransUartWait(WAIT_CNT_BT_STEP) ;
//
GS_PORT_SPEED_SET(GS_TX_SPEED);
}
// SIZE :: when received 76 00 34 00 04 00 00 XX YY //
unsigned char sCameraReceive_SizeFlag = 0 ;
unsigned char hyCameraImageSize[2];
// DATA :: when received 76 00 34 00 04 00 00 XX YY //
void hyCamera_Reset()
{
Pl_Tx_QueueFlush() ;
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x26);
Pl_Tx_QueueIn(0x00);
}
void hyCamera_Reset_Set()
{
Pl_Tx_QueueFlush() ;
hyPlTxByte(0x56);
hyPlTxByte(0x00);
hyPlTxByte(0x26);
hyPlTxByte(0x00);
}
void hyGs_Reset_Reply()
{
Gs_Tx_QueueIn(0x76);
Gs_Tx_QueueIn(0x00);
Gs_Tx_QueueIn(0x26);
Gs_Tx_QueueIn(0x00);
}
// 카메라 Sleep 함수
void hyCamera_Sleep()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x3E);
Pl_Tx_QueueIn(0x03);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x01);
}
// 카메라 Wake 함수
void hyCamera_Wake()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x3E);
Pl_Tx_QueueIn(0x03);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
}
// 카메라 전송 속도 9600 설정 요청 함수
void hyCamera_9600_bps()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x24);
Pl_Tx_QueueIn(0x03);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0xAE);
Pl_Tx_QueueIn(0xC8);
}
// 카메라 이미지 320 모드 설정 요청 함수 (직접명령)
void hyCamera_38400_bps()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x24);
Pl_Tx_QueueIn(0x03);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x2A);
Pl_Tx_QueueIn(0xF2);
}
// 카메라 전송 속도 115200 설정 요청 함수
void hyCamera_115200_bps()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x24);
Pl_Tx_QueueIn(0x03);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x0D);
Pl_Tx_QueueIn(0xA6);
}
// 카메라 전송 속도 115200 설정 요청 함수 ( 직접 명령 )
void hyCamera_115200_bps_Set()
{
Pl_Tx_QueueFlush();
hyPlTxByte(0x56);
hyPlTxByte(0x00);
hyPlTxByte(0x24);
hyPlTxByte(0x03);
hyPlTxByte(0x01);
hyPlTxByte(0x0D);
hyPlTxByte(0xA6);
}
// 카메라 이미지 160 모드 설정 요청 함수
void hyCamera_160()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x31);
Pl_Tx_QueueIn(0x05);
Pl_Tx_QueueIn(0x04);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x19);
Pl_Tx_QueueIn(0x22);
WAIT_CNT_CAMERA_IMAGE = WAIT_CNT_CAMERA_IMAGE_160 ;
}
// 카메라 이미지 320 모드 설정 요청 함수
void hyCamera_320()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x31);
Pl_Tx_QueueIn(0x05);
Pl_Tx_QueueIn(0x04);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x19);
Pl_Tx_QueueIn(0x11);
WAIT_CNT_CAMERA_IMAGE = WAIT_CNT_CAMERA_IMAGE_320 ;
}
// 카메라 이미지 640 모드 설정 요청 함수
void hyCamera_640()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x31);
Pl_Tx_QueueIn(0x05);
Pl_Tx_QueueIn(0x04);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x19);
Pl_Tx_QueueIn(0x00);
WAIT_CNT_CAMERA_IMAGE = WAIT_CNT_CAMERA_IMAGE_640 ;
}
// 카메라 이미지 Stop 요청 함수
void hyCamera_Stop()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x36);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x03);
}
// 카메라 이미지 Take 요청 함수
void hyCamera_Take()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x36);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
}
// 카메라 이미지 Resume 요청 함수
void hyCamera_Resume()
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x36);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x02);
}
unsigned char Char_to_OSD(char ich)
{
if( '0' <= ich && ich <= '9' ) return ich - '0' ; // 0 : 10
if( 'A' <= ich && ich <= 'Z' ) return ich - 'A' + 10 ; // 10 : 10 + 26
if( 'a' <= ich && ich <= 'z' ) return ich - 'a' + 36 ; // 36 : 10 + 26 + 26 => 62
switch ( ich )
{
case '-' : return 62 ;
case '_' : return 63 ;
case ':' : return 64 ;
case '.' : return 65 ;
case '/' : return 66 ;
case '*' : return 67 ;
case '(' : return 68 ;
case ')' : return 69 ;
case '[' : return 70 ;
case ']' : return 71 ;
case '@' : return 72 ;
case '!' : return 73 ;
case '+' : return 74 ;
case '|' : return 75 ;
case '\\': return 76 ;
case '#' : return 77 ;
case '=' : return 78 ;
}
return 79 ;
}
#if 0
void hyCamera_Osd_Add_Char(char *istr)
{
unsigned char slen ; for( slen = 0 ; slen < 14 && *istr ; slen++ ) ;
unsigned char i ;
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x45);
Pl_Tx_QueueIn(slen+1); // data_length
Pl_Tx_QueueIn(slen); // chracter number : max 14
Pl_Tx_QueueIn(0x00); // starting address [x][y] = x 2 bits y 5 bits
for ( i = 0 ; i < slen ; i++ )
Pl_Tx_QueueIn(Char_to_OSD(istr[i])); // characters
}
#else
void hyCamera_Osd_Add_Char(char *istr)
{
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x45);
Pl_Tx_QueueIn(0x07); // data_length
Pl_Tx_QueueIn(0x06); // chracter number : max 14
Pl_Tx_QueueIn(0x24); // starting address [x][y] = x 2 bits y 5 bits
Pl_Tx_QueueIn(0x1F); // characters
Pl_Tx_QueueIn(0x2C); // characters
Pl_Tx_QueueIn(0x30); // characters
Pl_Tx_QueueIn(0x2C); // characters
Pl_Tx_QueueIn(0x26); // characters
Pl_Tx_QueueIn(0x35); // characters
Pl_Tx_QueueIn(0x32); // characters
}
#endif
// 카메라 이미지 크기 요청 함수
void hyCamera_Size()
{
sCameraReceive_SizeFlag = 0 ;
Pl_Tx_QueueIn(0x56);
Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x34);
Pl_Tx_QueueIn(0x01);
Pl_Tx_QueueIn(0x00);
}
// 카메라 이미지 수신 요청 함수
void hyCamera_ImageGet(unsigned char b0,unsigned char b1,unsigned char b2,unsigned char b3)
{
Pl_Tx_QueueIn(0x56); Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(0x32); Pl_Tx_QueueIn(0x0C);
Pl_Tx_QueueIn(0x00); Pl_Tx_QueueIn(0x0A);
Pl_Tx_QueueIn(0x00); Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(b0) ; Pl_Tx_QueueIn(b1) ;
Pl_Tx_QueueIn(0x00); Pl_Tx_QueueIn(0x00);
Pl_Tx_QueueIn(b2); Pl_Tx_QueueIn(b3);
Pl_Tx_QueueIn(0x00); Pl_Tx_QueueIn(0x0A);
}
// 카메라 이미지 크기 수신 함수
// 카메라로 부터 영상 키기 신호를 수신 받으면
// sCameraImageSize 에 값 설정
// Receive : 76 00 34 00 04 00 00 XX YY //
void hyCamera_Receive_Size(unsigned char rx)
{
static unsigned char sSizeMode = 0 ;
switch( sSizeMode )
{
case 0 : sSizeMode = ( rx == 0x76 ) ? 1 : 0 ; break; // 76
case 1 : sSizeMode = ( rx == 0x00 ) ? 2 : (( rx == 0x76 ) ? 1 : 0) ; break; // 00
case 2 : sSizeMode = ( rx == 0x34 ) ? 3 : (( rx == 0x76 ) ? 1 : 0) ; break; // 34
case 3 : sSizeMode = ( rx == 0x00 ) ? 4 : (( rx == 0x76 ) ? 1 : 0) ; break; // 00
case 4 : sSizeMode = ( rx == 0x04 ) ? 5 : (( rx == 0x76 ) ? 1 : 0) ; break; // 04
case 5 : sSizeMode = ( rx == 0x00 ) ? 6 : (( rx == 0x76 ) ? 1 : 0) ; break; // 00
case 6 : sSizeMode = ( rx == 0x00 ) ? 7 : (( rx == 0x76 ) ? 1 : 0) ; break; // 00
case 7 : hyCameraImageSize[0] = rx ; sSizeMode = 8 ; break;
case 8 : hyCameraImageSize[1] = rx ; sSizeMode = 0 ;
sCameraReceive_SizeFlag = 1 ;