|
@@ -75,9 +75,9 @@ uint8_t rx2_data[1];
|
75
|
75
|
|
76
|
76
|
|
77
|
77
|
uint8_t ring_buf[buf_size];
|
78
|
|
-uint8_t count_in1 = 0;//, count_out = 0;
|
79
|
|
-uint8_t count_in2 = 0;//, count_out = 0;
|
80
|
|
-uint8_t count_in3 = 0, count_out = 0;
|
|
78
|
+uint8_t count_in1 = 0, count_out1 = 0;
|
|
79
|
+uint8_t count_in2 = 0, count_out2 = 0;
|
|
80
|
+//uint8_t count_in3 = 0, count_out = 0;
|
81
|
81
|
|
82
|
82
|
|
83
|
83
|
uint8_t UartDataisReved;
|
|
@@ -91,6 +91,10 @@ volatile uint32_t LoraTxTimerCnt = 0;
|
91
|
91
|
|
92
|
92
|
|
93
|
93
|
uint8_t buf[buf_size] = {0,};
|
|
94
|
+uint8_t buf1[buf_size] = {0,};
|
|
95
|
+uint8_t buf2[buf_size] = {0,};
|
|
96
|
+
|
|
97
|
+
|
94
|
98
|
|
95
|
99
|
uint8_t MyControllerID = 0;
|
96
|
100
|
uint8_t SensorID = 0;
|
|
@@ -109,7 +113,12 @@ static void MX_NVIC_Init(void);
|
109
|
113
|
void RGB_SensorIDAutoSet(uint8_t set);
|
110
|
114
|
uint8_t RGB_SensorIDAutoGet(void);
|
111
|
115
|
void UartDataRecvSet(uint8_t val);
|
|
116
|
+#if 0 // PYJ.2019.04.19_BEGIN --
|
112
|
117
|
void Uart_dataCheck(uint8_t* cnt);
|
|
118
|
+#else
|
|
119
|
+void Uart_dataCheck(uint8_t*,uint8_t* cnt);
|
|
120
|
+
|
|
121
|
+#endif // PYJ.2019.04.19_END --
|
113
|
122
|
void Uart1_Data_Send(uint8_t* data,uint8_t size);
|
114
|
123
|
/* USER CODE END PFP */
|
115
|
124
|
|
|
@@ -118,24 +127,30 @@ void Uart1_Data_Send(uint8_t* data,uint8_t size);
|
118
|
127
|
|
119
|
128
|
|
120
|
129
|
|
|
130
|
+
|
121
|
131
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
122
|
132
|
{
|
123
|
133
|
if(huart->Instance == USART1)//RGB Comunication
|
124
|
134
|
{
|
125
|
|
- buf[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
|
|
135
|
+ buf1[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
|
|
136
|
+ if(++count_in1>=buf_size){ count_in1 = 0; }
|
126
|
137
|
// printf("data %02x \r\n",rx1_data[0]);
|
|
138
|
+#if 0 // PYJ.2019.04.19_BEGIN --
|
127
|
139
|
if(buf[count_in1++] == 0xEB){
|
128
|
140
|
if(buf[bluecell_length] == (count_in1 - 3))
|
129
|
141
|
UartDataRecvSet(1);
|
130
|
142
|
else
|
131
|
143
|
count_in1 = 0;
|
132
|
144
|
}
|
|
145
|
+#endif // PYJ.2019.04.19_END --
|
133
|
146
|
HAL_UART_Receive_IT(&huart1,&rx1_data[0],1);
|
134
|
147
|
}
|
135
|
148
|
if(huart->Instance == USART2) // Lora?? ?†µ?‹ ?•˜?Š” ?¬?Џ
|
136
|
149
|
{
|
137
|
|
- buf[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
|
138
|
|
-// if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
|
|
150
|
+ buf2[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
|
|
151
|
+ if(++count_in2>=buf_size){ count_in2 = 0; }
|
|
152
|
+// if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
|
|
153
|
+#if 0 // PYJ.2019.04.19_BEGIN --
|
139
|
154
|
if(buf[count_in2++] == 0xEB){
|
140
|
155
|
if(buf[bluecell_length] == (count_in2 - 3))
|
141
|
156
|
UartDataRecvSet(2);
|
|
@@ -143,7 +158,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
143
|
158
|
count_in1 = 0;
|
144
|
159
|
// printf("UART 2 %d",((count_in2 -1) - 3));
|
145
|
160
|
}
|
146
|
|
-
|
|
161
|
+#endif // PYJ.2019.04.19_END --
|
147
|
162
|
HAL_UART_Receive_IT(&huart2,&rx2_data[0],1);
|
148
|
163
|
}
|
149
|
164
|
#if 0 // PYJ.2019.04.13_BEGIN --
|
|
@@ -199,6 +214,7 @@ int _write (int file, uint8_t *ptr, uint16_t len)
|
199
|
214
|
HAL_UART_Transmit (&huart1, ptr, len, 10);
|
200
|
215
|
return len;
|
201
|
216
|
}
|
|
217
|
+#if 0 // PYJ.2019.04.19_BEGIN --
|
202
|
218
|
void Uart_dataCheck(uint8_t* cnt){
|
203
|
219
|
|
204
|
220
|
etError crccheck = 0;
|
|
@@ -228,6 +244,39 @@ void Uart_dataCheck(uint8_t* cnt){
|
228
|
244
|
|
229
|
245
|
memset(buf,0x00,buf_size);
|
230
|
246
|
}
|
|
247
|
+#else
|
|
248
|
+void Uart_dataCheck(uint8_t* Que_Buf,uint8_t* cnt){
|
|
249
|
+
|
|
250
|
+ etError crccheck = 0;
|
|
251
|
+#if 0
|
|
252
|
+ for(uint8_t i = 0; i < (* cnt); i++){
|
|
253
|
+ printf("%02x ",buf[i]);
|
|
254
|
+ }
|
|
255
|
+ printf("\r\n");
|
|
256
|
+#endif
|
|
257
|
+
|
|
258
|
+ crccheck = STH30_CheckCrc(&Que_Buf[bluecell_type],Que_Buf[bluecell_length],Que_Buf[Que_Buf[bluecell_length] + 1]);
|
|
259
|
+ if(crccheck == CHECKSUM_ERROR){
|
|
260
|
+ for(uint8_t i = 0; i < (*cnt); i++){
|
|
261
|
+ printf("%02x ",Que_Buf[i]);
|
|
262
|
+ }
|
|
263
|
+ printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,Que_Buf[Que_Buf[bluecell_length] + 1]);
|
|
264
|
+ }
|
|
265
|
+ else if(crccheck == NO_ERROR){
|
|
266
|
+ RGB_Controller_Func(&Que_Buf[bluecell_stx]);
|
|
267
|
+ }
|
|
268
|
+ else{
|
|
269
|
+ printf("What Happen?\r\n");
|
|
270
|
+ /*NOP*/
|
|
271
|
+ }
|
|
272
|
+
|
|
273
|
+ //*cnt = 0;
|
|
274
|
+
|
|
275
|
+ memset(Que_Buf,0x00,buf_size);
|
|
276
|
+}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+#endif // PYJ.2019.04.19_END --
|
231
|
280
|
void RGB_Sensor_PowerOnOff(uint8_t id){
|
232
|
281
|
printf("%d Power ON \r\n",id);
|
233
|
282
|
|
|
@@ -588,7 +637,9 @@ int main(void)
|
588
|
637
|
}
|
589
|
638
|
#endif // PYJ.2019.04.16_END --
|
590
|
639
|
|
591
|
|
-
|
|
640
|
+ uint8_t data1[100]= {0,};
|
|
641
|
+ uint8_t data2[100]= {0,};
|
|
642
|
+ uint8_t uartrecv1=0,uartrecv2=0,cnt1 = 0,cnt2=0;
|
592
|
643
|
while (1)
|
593
|
644
|
{
|
594
|
645
|
if(LoraTxTimerCnt > LORA_TIMER_CNT){
|
|
@@ -607,7 +658,7 @@ int main(void)
|
607
|
658
|
// printf("%02x ",buffer[i]);
|
608
|
659
|
// printf("\n");
|
609
|
660
|
}else {
|
610
|
|
- HAL_Delay(1);
|
|
661
|
+// HAL_Delay(1);
|
611
|
662
|
ret = SX1276_LoRaRxPacket(&SX1276);
|
612
|
663
|
if (ret > 0) {
|
613
|
664
|
SX1276_read(&SX1276, &buffer[0], ret);
|
|
@@ -618,15 +669,47 @@ int main(void)
|
618
|
669
|
}
|
619
|
670
|
|
620
|
671
|
}
|
|
672
|
+
|
|
673
|
+ if(count_in1 != count_out1){ // <-------
|
|
674
|
+ data1[cnt1++] = buf1[count_out1++];
|
|
675
|
+ if(count_out1 >= 100){ count_out1 = 0; }
|
|
676
|
+ UartTimerCnt = 0;
|
|
677
|
+// uartrecv1 = 1;
|
|
678
|
+ UartDataRecvSet(1);
|
|
679
|
+ }
|
|
680
|
+ if(count_in2 != count_out2){ // <-------
|
|
681
|
+ data2[cnt2++] = buf2[count_out2++];
|
|
682
|
+ if(count_out2 >= 100){ count_out2 = 0; }
|
|
683
|
+ UartTimerCnt = 0;
|
|
684
|
+// uartrecv2 = 1;
|
|
685
|
+ UartDataRecvSet(2);
|
|
686
|
+
|
|
687
|
+ }
|
|
688
|
+#if 0 // PYJ.2019.04.19_BEGIN --
|
621
|
689
|
uartdatarecv = UartDataRecvGet();
|
622
|
690
|
if(uartdatarecv != 0){
|
623
|
691
|
if(uartdatarecv == 1){
|
624
|
|
- Uart_dataCheck(&count_in1);
|
|
692
|
+ Uart_dataCheck(data1,&count_in1);
|
625
|
693
|
}else if(uartdatarecv == 2){
|
626
|
|
- Uart_dataCheck(&count_in2);
|
|
694
|
+ Uart_dataCheck(data2,&count_in2);
|
627
|
695
|
}
|
628
|
696
|
UartDataRecvSet(0);
|
629
|
697
|
}
|
|
698
|
+#endif // PYJ.2019.04.19_END --
|
|
699
|
+ uartdatarecv = UartDataRecvGet();
|
|
700
|
+
|
|
701
|
+ if(uartdatarecv == 1 && UartTimerCnt > 100){
|
|
702
|
+ cnt1 = 0;
|
|
703
|
+ UartDataRecvSet(0);
|
|
704
|
+ Uart_dataCheck(&data1[0],&count_in1);
|
|
705
|
+ memset(&data1[0],0,100);
|
|
706
|
+ }
|
|
707
|
+ if(uartdatarecv == 2 && UartTimerCnt > 100){
|
|
708
|
+ cnt2 = 0;
|
|
709
|
+ UartDataRecvSet(0);
|
|
710
|
+ Uart_dataCheck(&data2[0],&count_in2);
|
|
711
|
+ memset(&data2[0],0,100);
|
|
712
|
+ }
|
630
|
713
|
else{
|
631
|
714
|
if(LedTimerCnt > 500){
|
632
|
715
|
if(RGB_SensorIDAutoGet() == 1){
|
|
@@ -648,7 +731,7 @@ int main(void)
|
648
|
731
|
if(temp_sensorid > (SensorID_Cnt)){
|
649
|
732
|
temp_sensorid = 0;
|
650
|
733
|
}
|
651
|
|
- RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
|
|
734
|
+ RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
|
652
|
735
|
}
|
653
|
736
|
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
|
654
|
737
|
LedTimerCnt = 0;
|