|
@@ -81,6 +81,8 @@ uint8_t count_in3 = 0, count_out = 0;
|
81
|
81
|
|
82
|
82
|
|
83
|
83
|
uint8_t UartDataisReved;
|
|
84
|
+uint8_t LoraDataSend;
|
|
85
|
+
|
84
|
86
|
uint8_t RGB_SensorIDAutoset = 0;
|
85
|
87
|
|
86
|
88
|
volatile uint32_t UartTimerCnt = 0;
|
|
@@ -121,7 +123,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
121
|
123
|
buf[count_in1] = rx1_data[0];//(uint8_t)USART2->DR;
|
122
|
124
|
// printf("data %02x \r\n",rx1_data[0]);
|
123
|
125
|
if(buf[count_in1++] == 0xEB){
|
124
|
|
- if(buf[blucell_length] == (count_in1 - 3))
|
|
126
|
+ if(buf[bluecell_length] == (count_in1 - 3))
|
125
|
127
|
UartDataRecvSet(1);
|
126
|
128
|
else
|
127
|
129
|
count_in1 = 0;
|
|
@@ -133,7 +135,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
133
|
135
|
buf[count_in2] = rx2_data[0];//(uint8_t)USART2->DR;
|
134
|
136
|
// if(buf[count_in++] == 0xEB)UartDataRecvSet(1);
|
135
|
137
|
if(buf[count_in2++] == 0xEB){
|
136
|
|
- if(buf[blucell_length] == (count_in2 - 3))
|
|
138
|
+ if(buf[bluecell_length] == (count_in2 - 3))
|
137
|
139
|
UartDataRecvSet(2);
|
138
|
140
|
else
|
139
|
141
|
count_in1 = 0;
|
|
@@ -163,6 +165,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
163
|
165
|
|
164
|
166
|
}
|
165
|
167
|
}
|
|
168
|
+void LoraDataSendSet(uint8_t val){
|
|
169
|
+ LoraDataSend = val;
|
|
170
|
+}
|
|
171
|
+uint8_t LoraDataSendGet(void){
|
|
172
|
+ return LoraDataSend;
|
|
173
|
+}
|
166
|
174
|
|
167
|
175
|
void UartDataRecvSet(uint8_t val){
|
168
|
176
|
UartDataisReved = val;
|
|
@@ -199,15 +207,15 @@ void Uart_dataCheck(uint8_t* cnt){
|
199
|
207
|
printf("\r\n");
|
200
|
208
|
#endif
|
201
|
209
|
|
202
|
|
- crccheck = STH30_CheckCrc(&buf[blucell_type],buf[blucell_length],buf[buf[blucell_length] + 1]);
|
|
210
|
+ crccheck = STH30_CheckCrc(&buf[bluecell_type],buf[bluecell_length],buf[buf[bluecell_length] + 1]);
|
203
|
211
|
if(crccheck == CHECKSUM_ERROR){
|
204
|
212
|
for(uint8_t i = 0; i < (*cnt); i++){
|
205
|
213
|
printf("%02x ",buf[i]);
|
206
|
214
|
}
|
207
|
|
- printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,buf[buf[blucell_length] + 1]);
|
|
215
|
+ printf("Original CRC : %02x RecvCRC : %02x \r\n",crccheck,buf[buf[bluecell_length] + 1]);
|
208
|
216
|
}
|
209
|
217
|
else if(crccheck == NO_ERROR){
|
210
|
|
- RGB_Controller_Func(&buf[blucell_stx]);
|
|
218
|
+ RGB_Controller_Func(&buf[bluecell_stx]);
|
211
|
219
|
}
|
212
|
220
|
else{
|
213
|
221
|
printf("What Happen?\r\n");
|
|
@@ -395,9 +403,9 @@ void Flash_RGB_Data_Write(uint32_t Addr,uint8_t* data){
|
395
|
403
|
|
396
|
404
|
uint16_t temp_Red = 0,temp_Green = 0,temp_Blue = 0;
|
397
|
405
|
|
398
|
|
- temp_Red = ((data[blucell_red_H] << 8) |data[blucell_red_L]); //R
|
399
|
|
- temp_Green= ((data[blucell_green_H] << 8) |data[blucell_green_L]); //G
|
400
|
|
- temp_Blue = ((data[blucell_blue_H] << 8) |data[blucell_blue_L]); //B
|
|
406
|
+ temp_Red = ((data[bluecell_red_H] << 8) |data[bluecell_red_L]); //R
|
|
407
|
+ temp_Green= ((data[bluecell_green_H] << 8) |data[bluecell_green_L]); //G
|
|
408
|
+ temp_Blue = ((data[bluecell_blue_H] << 8) |data[bluecell_blue_L]); //B
|
401
|
409
|
|
402
|
410
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 0 , (uint16_t)temp_Red);
|
403
|
411
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,Addr + 2 , (uint16_t)temp_Green);
|
|
@@ -425,7 +433,7 @@ void Flash_write(uint8_t* data) // 쓰기함수
|
425
|
433
|
// printf("Erase Success \r\n");
|
426
|
434
|
// }
|
427
|
435
|
|
428
|
|
- switch(data[blucell_dstid]){
|
|
436
|
+ switch(data[bluecell_dstid]){
|
429
|
437
|
case 1:
|
430
|
438
|
Address += 0;
|
431
|
439
|
break;
|
|
@@ -452,7 +460,7 @@ void Flash_write(uint8_t* data) // 쓰기함수
|
452
|
460
|
break;
|
453
|
461
|
|
454
|
462
|
}
|
455
|
|
- Flash_RGB_Data_Write(Address,&data[blucell_stx]);
|
|
463
|
+ Flash_RGB_Data_Write(Address,&data[bluecell_stx]);
|
456
|
464
|
HAL_FLASH_Lock(); // lock 잠그기
|
457
|
465
|
__HAL_RCC_TIM7_CLK_ENABLE(); // 매인타이머를 재시작합니다
|
458
|
466
|
|
|
@@ -483,7 +491,7 @@ SX1276_t SX1276;
|
483
|
491
|
int master;
|
484
|
492
|
int ret;
|
485
|
493
|
|
486
|
|
-char buffer[64];
|
|
494
|
+char buffer[100];
|
487
|
495
|
|
488
|
496
|
int message;
|
489
|
497
|
int message_length;
|
|
@@ -497,8 +505,8 @@ int message_length;
|
497
|
505
|
int main(void)
|
498
|
506
|
{
|
499
|
507
|
/* USER CODE BEGIN 1 */
|
500
|
|
- uint8_t StatusRequest_data[RGB_SensorDataRequest_Length] = {0xbe,RGB_Status_Data_Request,RGB_SensorDataRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&StatusRequest_data[blucell_type],StatusRequest_data[blucell_length]),0xeb};
|
501
|
|
- uint8_t IDAutoSetRequest_data[RGB_SensorIDAutoSetRequest_Length] = {0xbe,RGB_SensorID_SET,RGB_SensorIDAutoSetRequest_Length - 3,MyControllerID,SensorID,STH30_CreateCrc(&IDAutoSetRequest_data[blucell_type],IDAutoSetRequest_data[blucell_length]),0xeb};
|
|
508
|
+ 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};
|
|
509
|
+ 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};
|
502
|
510
|
uint8_t temp_sensorid = 0;
|
503
|
511
|
uint8_t uartdatarecv= 0;
|
504
|
512
|
/* USER CODE END 1 */
|
|
@@ -563,15 +571,23 @@ int main(void)
|
563
|
571
|
SX1276_LORA_BW_20_8KHZ, 10);
|
564
|
572
|
printf("Done configuring LoRaModule\r\n");
|
565
|
573
|
if (master == 1) {
|
566
|
|
- ret = SX1276_LoRaEntryTx(&SX1276, 16, 2000);
|
|
574
|
+ ret = SX1276_LoRaEntryTx(&SX1276, 65, 2000);
|
567
|
575
|
} else {
|
568
|
|
- ret = SX1276_LoRaEntryRx(&SX1276, 16, 2000);
|
|
576
|
+ ret = SX1276_LoRaEntryRx(&SX1276, 65, 2000);
|
569
|
577
|
}
|
570
|
578
|
|
571
|
579
|
|
572
|
580
|
while (1)
|
573
|
581
|
{
|
574
|
582
|
#if 1 // PYJ.2019.04.11_BEGIN --
|
|
583
|
+ if(LoraDataSendGet() == 1){
|
|
584
|
+ LoraDataSendSet(0);
|
|
585
|
+ memcpy(,&Lora_Buf[0]);
|
|
586
|
+ message_length = Lora_Max_Amount + 2 + 3;////length 1byte + type 1byte + RGB Data 60byte + stx + etx + crc
|
|
587
|
+ ret = SX1276_LoRaEntryTx(&SX1276, message_length, 2000);
|
|
588
|
+ ret = SX1276_LoRaTxPacket(&SX1276, (uint8_t *) buffer, message_length, 2000);
|
|
589
|
+ message += 1;
|
|
590
|
+ }
|
575
|
591
|
uartdatarecv = UartDataRecvGet();
|
576
|
592
|
if(uartdatarecv != 0){
|
577
|
593
|
if(uartdatarecv == 1){
|
|
@@ -615,24 +631,24 @@ int main(void)
|
615
|
631
|
if(LedTimerCnt > 500){
|
616
|
632
|
if(RGB_SensorIDAutoGet() == 1){
|
617
|
633
|
if(SensorID == 0){memset(&SensorID_buf[0],0x00,8);SensorID_Cnt = 0;}
|
618
|
|
- IDAutoSetRequest_data[blucell_srcid + 1] = ++SensorID;//DST ID
|
619
|
|
- if(IDAutoSetRequest_data[blucell_srcid + 1] > 8){
|
|
634
|
+ IDAutoSetRequest_data[bluecell_srcid + 1] = ++SensorID;//DST ID
|
|
635
|
+ if(IDAutoSetRequest_data[bluecell_srcid + 1] > 8){
|
620
|
636
|
RGB_SensorIDAutoSet(0);
|
621
|
637
|
RGB_Sensor_PowerOnOff(0);
|
622
|
638
|
SensorID = 0;
|
623
|
639
|
}else{
|
624
|
640
|
RGB_Sensor_PowerOnOff(IDAutoSetRequest_data[4]);
|
625
|
641
|
HAL_Delay(1500);
|
626
|
|
- RGB_Controller_Func(&IDAutoSetRequest_data[blucell_stx]);
|
|
642
|
+ RGB_Controller_Func(&IDAutoSetRequest_data[bluecell_stx]);
|
627
|
643
|
HAL_Delay(500);
|
628
|
644
|
}
|
629
|
645
|
}
|
630
|
646
|
else{
|
631
|
|
- StatusRequest_data[blucell_srcid + 1] = SensorID_buf[temp_sensorid++];
|
|
647
|
+ StatusRequest_data[bluecell_srcid + 1] = SensorID_buf[temp_sensorid++];
|
632
|
648
|
if(temp_sensorid > (SensorID_Cnt)){
|
633
|
649
|
temp_sensorid = 0;
|
634
|
650
|
}
|
635
|
|
- RGB_Controller_Func(&StatusRequest_data[blucell_stx]);
|
|
651
|
+ RGB_Controller_Func(&StatusRequest_data[bluecell_stx]);
|
636
|
652
|
}
|
637
|
653
|
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_15);
|
638
|
654
|
LedTimerCnt = 0;
|