티스토리 뷰

 

void h_TreatSerial(){
  if(!RxString_Serial.startsWith("VI")) return;
  int Index1 = RxString_Serial.indexOf("/");
  if(Index1 < 0) return;
  int Index2 = RxString_Serial.indexOf(":");
  if(Index1 >= Index2) return;
  String VICName = RxString_Serial.substring(0, Index1);
  char CommandType0 = RxString_Serial.charAt(Index1+1);
  char CommandType1 = RxString_Serial.charAt(Index1+2);
  String ValueString = RxString_Serial.substring(Index2+1);
  int CommandValue = -1;
  char Char1 = ValueString.charAt(0);
  if((isDigit(Char1)) || (Char1 == '-')) CommandValue = (ValueString).toInt();
  if(VICName.equals(String(DEVICENAME))){
    StartTime_LastRequest = millis();
    switch(CommandType0){
      case 'D': // Data Request ?
      {
        if(!IsRegistered) return;
        if(FixedChannel >= 0){
          h_SendData(FixedChannel);
          return;
        }
        switch(CommandType1){
          case '?':
            h_SendData(-1);
            break;
          case '0':
          case '1':
          case '2':
          case '3':
            h_SendData(int(CommandType1)-0x30);
            break;
        }
      }
        break;
      case 'A': 
        if(CommandType1 == 'D'){
          if(CommandValue == DeviceAddress) IsRegistered = true;
        }
        if(CommandType1 == 'N'){
          DEVICENAME = ValueString;
        }
        break;
      case 'C': // Clear ...
        if(CommandType1 == 'P') h_InitializeDeviceParameters(CommandValue-1);
        if(CommandType1 == 'V') h_InitializeDeviceValues(CommandValue-1);
        if(CommandType1 == 'A') h_InitializeDeviceAddress();
        if(CommandType1 == 'C') b_SetFixedChannel(CommandValue);
        if(CommandType1 == '0') MeasuredValues[0].h_InitializeValues(ElapsedMins);
        if(CommandType1 == '1') MeasuredValues[1].h_InitializeValues(ElapsedMins);
        if(CommandType1 == '2') MeasuredValues[2].h_InitializeValues(ElapsedMins);
        if(CommandType1 == '3') MeasuredValues[3].h_InitializeValues(ElapsedMins);
        break;
      case 'M': // Monitoring
      {
        int ChannelNo = atoi(CommandType1);
        if(ChannelNo < 0) return;
        if(ChannelNo >= CHANNELNUMBER) return;
        if(CommandValue == 0) MeasuredValues[ChannelNo].IsMonitored = false;
        if(CommandValue == 1) MeasuredValues[ChannelNo].IsMonitored = true;
      }
        break;
      case 'P': // Port control
      {
        int PortNo = 0;
        PortNo = (int)(String(CommandType1).toInt());
        if(CommandValue == 1) digitalWrite(PortNo, HIGH);
        if(CommandValue == 0) digitalWrite(PortNo, LOW);
      }
        break;
      
    }
  }else if(VICName.equals(String(COMMONDEVICENAME))){
    switch(CommandType0){
      case 'C': // Request initialization
        if(CommandType1 == 'P') h_InitializeDeviceParameters(CommandValue-1);
        if(CommandType1 == 'V') h_InitializeDeviceValues(CommandValue-1);
        if(IsRegistered) break;
        if(CommandType1 == 'A') h_InitializeDeviceAddress();
        break;
      case 'A': // Checking Address
        if(CommandType1 == '?') h_ChecknResponse(CommandValue);
        break;
    }
  }
}

 

반응형

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

[Arduino] JSON 예제  (0) 2020.11.25
[BPM] Firmware Source for Master  (0) 2020.07.19
[BMS] Command Process for CD Devices  (0) 2020.07.19
[BMS] Command Process for LoRa Device  (0) 2020.07.19
[BMS] Command Process for Master  (0) 2020.07.19