티스토리 뷰

void h_TreatSerialCommand(){
  if(!RxString_Serial.startsWith("CD")) return;
#if(USER_SERIAL == 901)
  Serial.println("");
  Serial.println(RxString_Serial);
#endif  
  int Index1 = RxString_Serial.indexOf("/");
  if(Index1 < 0) return;
  int Index2 = RxString_Serial.indexOf(":");
  if(Index1 >= Index2) return;
  String DeviceName = RxString_Serial.substring(0, Index1);
  char CommandType0 = RxString_Serial.charAt(Index1+1);
  char CommandType1 = RxString_Serial.charAt(Index1+2);
  int CommandValue = (RxString_Serial.substring(Index2+1)).toInt();
  if(DeviceName.equals(String(DEVICENAME))){
    StartTime_LastRequest = millis();
    switch(CommandType0){
      case 'P': // Port control
      {
        int PortValue = 0;
        int PortNo = 0;
        if(CommandType1 == 'R'){ // Port control for RELAY
          PortNo = PIN_RELAY;
        }else if(CommandType1 == 'O'){ // Port control for RELAY
          PortNo = PIN_DIGITALOUT;
        } else{
          PortNo = (int)(String(CommandType1).toInt());
          if(PortNo == 0) return;
        }
        if(CommandValue == 1) digitalWrite(PortNo, HIGH);
        if(CommandValue == 0) digitalWrite(PortNo, LOW);
      }
        break;
      case 'A':
        if(CommandType1 == 'D'){
          if(CommandValue == DeviceAddress) IsRegistered = true;
        }
        break;
      case 'Q': // Request
        if(CommandType1 == 'D') h_SendDeviceStatus();
        break;
      case 'C': // Command
        if(CommandType1 == 'I') h_InitializeDeviceParameters(); // Initialize
        if(CommandType1 == 'C') h_SetChargeCondition(CommandValue);
        if(CommandType1 == 'D') h_SetDischargeCondition(CommandValue);
        if(CommandType1 == 'A') AlarmTime_Minute = CommandValue; // Alarm
        break;
    }
  }else if(DeviceName.equals(String(COMMONDEVICENAME))){
    switch(CommandType0){
      case 'C': // Request initialization
        if(CommandType1 == 'P') h_InitializeDeviceParameters();
        if(CommandType1 == 'A') h_InitializeDeviceAddress();
        break;
      case 'A': // Checking Address
        if(CommandType1 == '?') h_ChecknResponse(CommandValue);
        break;
    }
  }
}

 

반응형

'SWDesk > Firmware' 카테고리의 다른 글

[BPM] Firmware Source for Master  (0) 2020.07.19
[BMS] Command Process for VIC Instrument  (0) 2020.07.19
[BMS] Command Process for LoRa Device  (0) 2020.07.19
[BMS] Command Process for Master  (0) 2020.07.19
[BPM] Firmware Source for Master  (0) 2020.06.15