티스토리 뷰

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);
        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;
    }
  }
}
반응형
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함