|
@@ -97,6 +97,11 @@ uint8_t buf[buf_size] = {0,};
|
97
|
97
|
uint8_t buf1[buf_size] = {0,};
|
98
|
98
|
uint8_t buf2[buf_size] = {0,};
|
99
|
99
|
|
|
100
|
+Default_SX1276_t Default_SX1276;
|
|
101
|
+SX1276_hw_t SX1276_hw;
|
|
102
|
+SX1276_t SX1276;
|
|
103
|
+
|
|
104
|
+
|
100
|
105
|
|
101
|
106
|
|
102
|
107
|
uint8_t MyControllerID = 0;
|
|
@@ -259,7 +264,7 @@ void Uart_dataCheck(uint8_t* Que_Buf,uint8_t* cnt){
|
259
|
264
|
etError crccheck = 0;
|
260
|
265
|
#if 0
|
261
|
266
|
for(uint8_t i = 0; i < (* cnt); i++){
|
262
|
|
- printf("%02x ",buf[i]);
|
|
267
|
+ printf("%02x ",*Que_Buf[i]);
|
263
|
268
|
}
|
264
|
269
|
printf("\r\n");
|
265
|
270
|
#endif
|
|
@@ -287,7 +292,9 @@ void Uart_dataCheck(uint8_t* Que_Buf,uint8_t* cnt){
|
287
|
292
|
|
288
|
293
|
#endif // PYJ.2019.04.19_END --
|
289
|
294
|
void RGB_Sensor_PowerOnOff(uint8_t id){
|
290
|
|
- printf("%d Power ON \r\n",id);
|
|
295
|
+ uint8_t SensorSerchStart_cmd[5] = {0xbe,RGB_Controller_Init_Start,2,STH30_CreateCrc(&SensorSerchStart_cmd[bluecell_type],SensorSerchStart_cmd[bluecell_length]),0xeb};
|
|
296
|
+ uint8_t SensorSerchEnd_cmd[5] = {0xbe,RGB_Controller_Init_End,2,STH30_CreateCrc(&SensorSerchEnd_cmd[bluecell_type],SensorSerchEnd_cmd[bluecell_length]),0xeb};
|
|
297
|
+// printf("%d Power ON \r\n",id);
|
291
|
298
|
|
292
|
299
|
switch(id){
|
293
|
300
|
case 0:
|
|
@@ -301,6 +308,7 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
|
301
|
308
|
HAL_GPIO_WritePin(SENSOR_EN8_GPIO_Port,SENSOR_EN8_Pin,GPIO_PIN_SET);
|
302
|
309
|
break;
|
303
|
310
|
case 1:
|
|
311
|
+ Uart1_Data_Send(&SensorSerchStart_cmd[bluecell_stx], SensorSerchStart_cmd[bluecell_length] + 3);
|
304
|
312
|
HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_RESET);
|
305
|
313
|
HAL_Delay(50);
|
306
|
314
|
HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
|
|
@@ -383,6 +391,7 @@ void RGB_Sensor_PowerOnOff(uint8_t id){
|
383
|
391
|
|
384
|
392
|
break;
|
385
|
393
|
case 8:
|
|
394
|
+ Uart1_Data_Send(&SensorSerchEnd_cmd[bluecell_stx], SensorSerchEnd_cmd[bluecell_length] + 3);
|
386
|
395
|
HAL_GPIO_WritePin(SENSOR_EN1_GPIO_Port,SENSOR_EN1_Pin,GPIO_PIN_SET);
|
387
|
396
|
HAL_GPIO_WritePin(SENSOR_EN2_GPIO_Port,SENSOR_EN2_Pin,GPIO_PIN_SET);
|
388
|
397
|
HAL_GPIO_WritePin(SENSOR_EN3_GPIO_Port,SENSOR_EN3_Pin,GPIO_PIN_SET);
|
|
@@ -546,8 +555,8 @@ void Flash_InitRead(void) // ?
|
546
|
555
|
|
547
|
556
|
#endif // PYJ.2019.03.19_END --
|
548
|
557
|
|
549
|
|
-SX1276_hw_t SX1276_hw;
|
550
|
|
-SX1276_t SX1276;
|
|
558
|
+
|
|
559
|
+
|
551
|
560
|
Default_SX1276_t Default_SX1276 =
|
552
|
561
|
{
|
553
|
562
|
SX1276_917MHZ,
|
|
@@ -556,6 +565,7 @@ Default_SX1276_t Default_SX1276 =
|
556
|
565
|
SX1276_LORA_BW_20_8KHZ,
|
557
|
566
|
10,
|
558
|
567
|
SX1276_LORA_G1,
|
|
568
|
+ SX1276_15dBm,
|
559
|
569
|
};
|
560
|
570
|
|
561
|
571
|
|
|
@@ -568,7 +578,28 @@ int message_length;
|
568
|
578
|
int message;
|
569
|
579
|
|
570
|
580
|
|
571
|
|
-
|
|
581
|
+void Lora_Initialize(void){
|
|
582
|
+
|
|
583
|
+ SX1276_hw.dio0.port = SX1276_DIO0_GPIO_Port;
|
|
584
|
+ SX1276_hw.dio0.pin = SX1276_DIO0_Pin;
|
|
585
|
+ SX1276_hw.nss.port = GPIOA;
|
|
586
|
+ SX1276_hw.nss.pin = GPIO_PIN_15;
|
|
587
|
+ SX1276_hw.reset.port = SX1276_RESET_GPIO_Port;
|
|
588
|
+ SX1276_hw.reset.pin = SX1276_RESET_Pin;
|
|
589
|
+ // SX1276_hw.spi = &hspi3;
|
|
590
|
+ SX1276.hw = &SX1276_hw;
|
|
591
|
+// printf("Configuring LoRa module\r\n");
|
|
592
|
+ SX1276_begin(&SX1276, Default_SX1276.frequency, Default_SX1276.power,
|
|
593
|
+ Default_SX1276.LoRa_Rate,Default_SX1276.LoRa_BW, 10,Default_SX1276.LoRa_Lna,Default_SX1276.LoRa_Pa_boost);
|
|
594
|
+
|
|
595
|
+// printf("Done configuring LoRaModule\r\n");
|
|
596
|
+ master = 0;
|
|
597
|
+ if (master == 1) {
|
|
598
|
+ ret = SX1276_LoRaEntryTx(&SX1276, LORA_MAX_DATA_CNT, 2000);
|
|
599
|
+ } else {
|
|
600
|
+ ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
|
|
601
|
+ }
|
|
602
|
+}
|
572
|
603
|
|
573
|
604
|
|
574
|
605
|
|
|
@@ -582,10 +613,12 @@ int message;
|
582
|
613
|
int main(void)
|
583
|
614
|
{
|
584
|
615
|
/* USER CODE BEGIN 1 */
|
585
|
|
- uint8_t StatusRequest_data[RGB_SensorDataRequest_Length] = {0xbe,RGB_Status_Data_Request,RGB_SensorDataRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&StatusRequest_data[bluecell_type],StatusRequest_data[bluecell_length]),0xeb};
|
586
|
|
- uint8_t IDAutoSetRequest_data[RGB_SensorIDAutoSetRequest_Length] = {0xbe,RGB_SensorID_SET,RGB_SensorIDAutoSetRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&IDAutoSetRequest_data[bluecell_type],IDAutoSetRequest_data[bluecell_length]),0xeb};
|
587
|
|
- uint8_t temp_sensorid = 0;
|
588
|
|
- uint8_t uartdatarecv= 0;
|
|
616
|
+ uint8_t SensorSerchStart_cmd[5] = {0xbe,RGB_Controller_Init_Start,2,STH30_CreateCrc(&SensorSerchStart_cmd[bluecell_type],SensorSerchStart_cmd[bluecell_length]),0xeb};
|
|
617
|
+ uint8_t StatusRequest_data[RGB_SensorDataRequest_Length] = {0xbe,RGB_Status_Data_Request,RGB_SensorDataRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&StatusRequest_data[bluecell_type],StatusRequest_data[bluecell_length]),0xeb};
|
|
618
|
+ uint8_t IDAutoSetRequest_data[RGB_SensorIDAutoSetRequest_Length] = {0xbe,RGB_SensorID_SET,RGB_SensorIDAutoSetRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&IDAutoSetRequest_data[bluecell_type],IDAutoSetRequest_data[bluecell_length]),0xeb};
|
|
619
|
+ uint8_t cnt1 = 0,cnt2=0,uartdatarecv = 0;
|
|
620
|
+ uint8_t data1[100]= {0,};
|
|
621
|
+ uint8_t data2[100]= {0,};
|
589
|
622
|
/* USER CODE END 1 */
|
590
|
623
|
|
591
|
624
|
/* MCU Configuration--------------------------------------------------------*/
|
|
@@ -616,59 +649,26 @@ int main(void)
|
616
|
649
|
MX_NVIC_Init();
|
617
|
650
|
/* USER CODE BEGIN 2 */
|
618
|
651
|
HAL_TIM_Base_Start_IT(&htim6);
|
|
652
|
+ RGB_SensorIDAutoSet(1);
|
619
|
653
|
HAL_UART_Receive_DMA(&huart1, rx1_data, 1);
|
620
|
654
|
HAL_UART_Receive_IT(&huart2, &rx2_data[0],1);
|
621
|
655
|
setbuf(stdout, NULL); // \n ?�„ ? �?�„ ?–„ë§?
|
622
|
|
-#if 1 // PYJ.2019.03.04_BEGIN --
|
|
656
|
+ Uart1_Data_Send(&SensorSerchStart_cmd[bluecell_stx], SensorSerchStart_cmd[bluecell_length] + 3);
|
|
657
|
+#if 0 // PYJ.2019.03.04_BEGIN --
|
623
|
658
|
printf("****************************************\r\n");
|
624
|
659
|
printf("RGB Project\r\n");
|
625
|
660
|
printf("Build at %s %s\r\n", __DATE__, __TIME__);
|
626
|
661
|
printf("Copyright (c) 2019. BLUECELL\r\n");
|
627
|
662
|
printf("****************************************\r\n");
|
628
|
663
|
#endif // PYJ.2019.03.04_END --
|
629
|
|
- RGB_SensorIDAutoSet(1);
|
630
|
664
|
Flash_InitRead();
|
631
|
665
|
RGB_Data_Init();
|
|
666
|
+ Lora_Initialize();
|
632
|
667
|
/* USER CODE END 2 */
|
633
|
668
|
|
634
|
669
|
/* Infinite loop */
|
635
|
670
|
/* USER CODE BEGIN WHILE */
|
636
|
|
- //initialize LoRa module
|
637
|
|
- SX1276_hw.dio0.port = SX1276_DIO0_GPIO_Port;
|
638
|
|
- SX1276_hw.dio0.pin = SX1276_DIO0_Pin;
|
639
|
|
- SX1276_hw.nss.port = GPIOA;
|
640
|
|
- SX1276_hw.nss.pin = GPIO_PIN_15;
|
641
|
|
- SX1276_hw.reset.port = SX1276_RESET_GPIO_Port;
|
642
|
|
- SX1276_hw.reset.pin = SX1276_RESET_Pin;
|
643
|
|
- // SX1276_hw.spi = &hspi3;
|
644
|
|
- SX1276.hw = &SX1276_hw;
|
645
|
|
-
|
646
|
671
|
|
647
|
|
-
|
648
|
|
- printf("Configuring LoRa module\r\n");
|
649
|
|
- SX1276_begin(&SX1276, Default_SX1276.frequency, Default_SX1276.power, Default_SX1276.LoRa_Rate,
|
650
|
|
- Default_SX1276.LoRa_BW, 10,Default_SX1276.LoRa_Lna);
|
651
|
|
- printf("Done configuring LoRaModule\r\n");
|
652
|
|
- master = 0;
|
653
|
|
- if (master == 1) {
|
654
|
|
- ret = SX1276_LoRaEntryTx(&SX1276, LORA_MAX_DATA_CNT, 2000);
|
655
|
|
- } else {
|
656
|
|
- ret = SX1276_LoRaEntryRx(&SX1276, LORA_MAX_DATA_CNT, 2000);
|
657
|
|
- }
|
658
|
|
-#if 0 // PYJ.2019.04.16_BEGIN --
|
659
|
|
- for(uint8_t i = 0; i < 100; i++){
|
660
|
|
- Test_data[i] = i;
|
661
|
|
- M24C32_Data_Write(&hi2c2,&Test_data[i],(uint16_t)i,1);
|
662
|
|
- }
|
663
|
|
-
|
664
|
|
- for(uint8_t i = 0; i < 100; i++){
|
665
|
|
- printf("%d \n",M24C32_Data_Read(&hi2c2,(uint16_t)i));
|
666
|
|
- }
|
667
|
|
-#endif // PYJ.2019.04.16_END --
|
668
|
|
-
|
669
|
|
- uint8_t data1[100]= {0,};
|
670
|
|
- uint8_t data2[100]= {0,};
|
671
|
|
- uint8_t uartrecv1=0,uartrecv2=0,cnt1 = 0,cnt2=0;
|
672
|
672
|
while (1)
|
673
|
673
|
{
|
674
|
674
|
if(LoraTxTimerCnt > LORA_TIMER_CNT){
|
|
@@ -692,12 +692,11 @@ int main(void)
|
692
|
692
|
ret = SX1276_LoRaRxPacket(&SX1276);
|
693
|
693
|
if (ret > 0) {
|
694
|
694
|
SX1276_read(&SX1276, &buffer[0], ret);
|
695
|
|
- printf("Received Data : ");
|
696
|
|
- for(uint8_t i = 0; i < ret; i++)
|
697
|
|
- printf("%02x ", buffer[i]);
|
698
|
|
- printf("\n");
|
699
|
|
-
|
700
|
695
|
Uart_dataCheck(&buffer[bluecell_stx],&ret);
|
|
696
|
+// printf("Received Data : ");
|
|
697
|
+// for(uint8_t i = 0; i < ret; i++)
|
|
698
|
+// printf("%02x ", buffer[i]);
|
|
699
|
+// printf("\n");
|
701
|
700
|
}
|
702
|
701
|
}
|
703
|
702
|
|
|
@@ -705,67 +704,48 @@ int main(void)
|
705
|
704
|
data1[cnt1++] = buf1[count_out1++];
|
706
|
705
|
if(count_out1 >= 100){ count_out1 = 0; }
|
707
|
706
|
UartTimerCnt = 0;
|
708
|
|
-// uartrecv1 = 1;
|
709
|
707
|
UartDataRecvSet(1);
|
710
|
708
|
}
|
711
|
709
|
if(count_in2 != count_out2){ // <-------
|
712
|
710
|
data2[cnt2++] = buf2[count_out2++];
|
713
|
711
|
if(count_out2 >= 100){ count_out2 = 0; }
|
714
|
712
|
UartTimerCnt = 0;
|
715
|
|
-// uartrecv2 = 1;
|
716
|
713
|
UartDataRecvSet(2);
|
717
|
|
-
|
718
|
714
|
}
|
719
|
|
-#if 0 // PYJ.2019.04.19_BEGIN --
|
720
|
|
- uartdatarecv = UartDataRecvGet();
|
721
|
|
- if(uartdatarecv != 0){
|
722
|
|
- if(uartdatarecv == 1){
|
723
|
|
- Uart_dataCheck(data1,&count_in1);
|
724
|
|
- }else if(uartdatarecv == 2){
|
725
|
|
- Uart_dataCheck(data2,&count_in2);
|
726
|
|
- }
|
727
|
|
- UartDataRecvSet(0);
|
728
|
|
- }
|
729
|
|
-#endif // PYJ.2019.04.19_END --
|
730
|
|
- uartdatarecv = UartDataRecvGet();
|
731
|
|
-
|
732
|
|
- if(uartdatarecv == 1 && UartTimerCnt > 100){
|
733
|
|
- cnt1 = 0;
|
734
|
|
- UartDataRecvSet(0);
|
735
|
|
- Uart_dataCheck(&data1[0],&count_in1);
|
736
|
|
- memset(&data1[0],0,100);
|
737
|
|
- }
|
738
|
|
- if(uartdatarecv == 2 && UartTimerCnt > 100){
|
739
|
|
- cnt2 = 0;
|
740
|
|
- UartDataRecvSet(0);
|
741
|
|
- Uart_dataCheck(&data2[0],&count_in2);
|
742
|
|
- memset(&data2[0],0,100);
|
743
|
|
- }
|
744
|
|
- else{
|
745
|
|
- if(LedTimerCnt > 500){
|
746
|
|
- if(RGB_SensorIDAutoGet() == 1){
|
747
|
|
- if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
|
748
|
|
- IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
|
749
|
|
- if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
|
750
|
|
- RGB_SensorIDAutoSet(0);
|
751
|
|
- RGB_Sensor_PowerOnOff(0);
|
752
|
|
- SensorID = 0;
|
753
|
|
- }else{
|
754
|
|
- RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
|
755
|
|
- HAL_Delay(75);
|
756
|
|
- RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
|
757
|
|
- }
|
758
|
|
- }
|
759
|
|
- else{
|
760
|
|
- StatusRequest_data[bluecell_srcid + 1] = SensorID_buf[temp_sensorid++];
|
761
|
|
- if(temp_sensorid > (SensorID_Cnt)){
|
762
|
|
- temp_sensorid = 0;
|
763
|
|
- }
|
764
|
|
- RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
|
|
715
|
+ uartdatarecv = UartDataRecvGet();
|
|
716
|
+ if(uartdatarecv == 1 && UartTimerCnt > 100){
|
|
717
|
+ cnt1 = 0;
|
|
718
|
+ UartDataRecvSet(0);
|
|
719
|
+ Uart_dataCheck(&data1[0],&count_in1);
|
|
720
|
+ memset(&data1[0],0,100);
|
|
721
|
+ }
|
|
722
|
+ if(uartdatarecv == 2 && UartTimerCnt > 100){
|
|
723
|
+ cnt2 = 0;
|
|
724
|
+ UartDataRecvSet(0);
|
|
725
|
+ Uart_dataCheck(&data2[0],&count_in2);
|
|
726
|
+ memset(&data2[0],0,100);
|
|
727
|
+ }
|
|
728
|
+
|
|
729
|
+ if(LedTimerCnt > 500){
|
|
730
|
+ if(RGB_SensorIDAutoGet() == 1){
|
|
731
|
+ if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
|
|
732
|
+ IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
|
|
733
|
+ if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
|
|
734
|
+ RGB_SensorIDAutoSet(0);
|
|
735
|
+ RGB_Sensor_PowerOnOff(0);
|
|
736
|
+ SensorID = 0;
|
|
737
|
+ }else{
|
|
738
|
+ RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
|
|
739
|
+ HAL_Delay(100);
|
|
740
|
+ RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
|
765
|
741
|
}
|
766
|
|
- HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
|
767
|
|
- LedTimerCnt = 0;
|
768
|
742
|
}
|
|
743
|
+ /* else{
|
|
744
|
+
|
|
745
|
+// RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
|
|
746
|
+ }*/
|
|
747
|
+ HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
|
|
748
|
+ LedTimerCnt = 0;
|
769
|
749
|
}
|
770
|
750
|
/* USER CODE END WHILE */
|
771
|
751
|
|