티스토리 뷰

bool h_TreatLoRaCommand(){
  if(!(RxString_LoRa.startsWith("LR"))){
    IsCommand2VIC = true;
    Command2VIC = RxString_LoRa;
    return false;
  }

  int Index1 = RxString_LoRa.indexOf('/');
  if(Index1 < 1) return false;
  int Index2 = RxString_LoRa.indexOf(':');
  if(Index2 < Index1) return false;
  char DataType0 = RxString_LoRa.charAt(Index1+1);
  char DataType1 = RxString_LoRa.charAt(Index1+2);
  String deviceName = RxString_LoRa.substring(0, Index1);
  int CommandValue = RxString_LoRa.substring(Index2+1).toInt();
  if(deviceName.equals(String(DEVICENAME))){
    StartTime_LastRequest = millis();
    switch(DataType0){
      case 'C':
        if(DataType1 == 'P') h_ClearDeviceParameters();
        if(DataType1 == 'A') h_ClearDeviceAddress();
        break;
      case 'A':
        if(DataType1 == '?') h_RespondDeviceAddress(deviceName, CommandValue);
        if(DataType1 == 'D') h_ReceiveACK(deviceName, CommandValue);
        break;
      case 'D':
        if(IsRegistered){
          if(DataType1 == '?') h_SendVICData(deviceName);
        }
        break;
      case 'P':
      {
        int PortNo = -1;
        if(DataType1 == 'R'){ // RELAY
          PortNo = PIN_RELAY;
          if(CommandValue == 1) IsPowerON = true;
          if(CommandValue == 0) IsPowerON = false;
        }else if(DataType1 == 'O'){
          PortNo = PIN_BUZZER;
        }else{
          PortNo = (int)(String(DataType1).toInt());
          if(PortNo == 0) return false;
        }
        if(CommandValue == 1) digitalWrite(PortNo, HIGH);
        if(CommandValue == 0) digitalWrite(PortNo, LOW);
      }
        break;
      case 'L': // list of device
        if(DataType1 != 'D') break;
        b_SendVICList();
        break;
      default:
        return false;
    }
  }else if(deviceName.equals(String(ALLLORADEVICES))){
    if(IsRegistered) return false;
    StartTime_LastRequest = millis();
    switch(DataType0){
      case 'C':
        if(DataType1 == 'P') h_ClearDeviceParameters();
        if(DataType1 == 'A') h_ClearDeviceAddress();
        break;
      case 'A':
        if(DataType1 == '?') h_RespondDeviceAddress(deviceName, CommandValue);
        if(DataType1 == 'D') h_ReceiveACK(deviceName, CommandValue);
        break;
      default:
        return false;
    }
  }
  return true;
}
반응형
반응형
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
글 보관함