#include "RGB_Sensor.h" #define RGB_ControllerID_SET_Length 10 #define RGB_SensorID_SET_Length 10 #define RGB_SensorDataRequest_Length 7 #define RGB_SensorIDAutoSetRequest_Length 7 uint8_t My_RGB_ID = 0; uint8_t My_RGB_ID_Reset_RequestCnt; uint8_t* RGB_Sensor_Func(uint8_t* data){ RGB_CMD_T type = data[Bluecell_Type]; switch(type){ case RGB_Status_Data_Request: if(My_RGB_ID != 0 && data[bluecell_srcid + 1] == My_RGB_ID){ HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET); My_RGB_ID_Reset_RequestCnt = 0; printf("MY RGB Status Send"); for(uint8_t i = 0; i<15; i++) printf("%02x ",RGB_Data[i]); printf("\r\n"); Uart2_Data_Send(&RGB_Data[0],15); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET); }else if(My_RGB_ID == 0 && data[bluecell_srcid + 1] == My_RGB_ID){ printf("MY ID IS NOT SET : %02x \r\n",My_RGB_ID); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET); data[bluecell_stx] = 0xBE; //0 data[bluecell_type] = RGB_SensorID_SET;//1 data[bluecell_length] = 4;//2 // 4 byte data[bluecell_srcid + 1] = data[bluecell_srcid + 0]; data[bluecell_srcid + 0] = My_RGB_ID; data[bluecell_srcid + 2] = STH30_CreateCrc(&data[bluecell_type],data[bluecell_length]); data[bluecell_srcid + 3] = 0xEB; Uart2_Data_Send(&data[bluecell_stx],data[bluecell_length] + 3); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET); }else{ My_RGB_ID_Reset_RequestCnt++; if(My_RGB_ID_Reset_RequestCnt >= 17){ My_RGB_ID = 0; My_RGB_ID_Reset_RequestCnt = 0; } printf("NO MY ID IS %02x \r\n",My_RGB_ID); } break; case RGB_ControllerID_SET: break; case RGB_SensorID_SET: if(My_RGB_ID == 0 || My_RGB_ID == data[bluecell_srcid + 1]){ HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET); data[bluecell_type] = RGB_SensorID_SET_Success; data[bluecell_srcid] = My_RGB_ID = data[bluecell_srcid + 1]; data[5] = STH30_CreateCrc(&data[bluecell_type],data[bluecell_length]); printf("My ID SET Success %02x \r\n",My_RGB_ID); Uart2_Data_Send(&data[bluecell_stx],RGB_SensorIDAutoSetRequest_Length); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET); }else{ printf("My ID aleady exist %02x \r\n",My_RGB_ID); } break; case RGB_Sensor_Check: if(My_RGB_ID == data[bluecell_srcid + 1]){ HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_SET); data[bluecell_stx] = 0xBE; //0 data[bluecell_type] = type + 1;//1 data[bluecell_length] = 4;//2 // 4 byte data[bluecell_srcid + 1] = data[bluecell_srcid + 0]; data[bluecell_srcid + 0] = My_RGB_ID; data[bluecell_srcid + 2] = STH30_CreateCrc(&data[bluecell_type],data[bluecell_length]); data[bluecell_srcid + 3] = 0xEB; Uart2_Data_Send(&data[bluecell_stx],data[bluecell_length] + 3); HAL_GPIO_WritePin(GPIOA,GPIO_PIN_8,GPIO_PIN_RESET); } break; default:break; } return data; } void RGB_Value_Func(void){ }