private async Task ProcessOnReceived(BaseRequest request) { switch (request.TypeCode) { case TYPE_CODE.EVENT_PIN_STATE: break; case TYPE_CODE.UNKNOWN: break; case TYPE_CODE.SET_ALARM: break; case TYPE_CODE.SET_GPIO: if (string.IsNullOrEmpty(request.RequestObject)) { return; } SetGpioRequest setGpioRequest = JsonConvert.DeserializeObject <SetGpioRequest>(request.RequestObject); if (!PiController.IsValidPin(setGpioRequest.PinNumber)) { return; } if (Core.PiController == null || !Core.PiController.IsControllerProperlyInitialized || Core.PinController == null) { return; } if (Client == null || Client.IsDisposed) { return; } if (Core.PinController.SetGpioValue(setGpioRequest.PinNumber, (GpioPinMode)setGpioRequest.PinMode, (GpioPinState)setGpioRequest.PinState)) { GpioPinConfig config = Core.PinController.GetGpioConfig(setGpioRequest.PinNumber); if (await Client.SendAsync(new BaseResponse(DateTime.Now, TYPE_CODE.SET_GPIO, "Success!", GpioPinConfig.AsJson(config))).ConfigureAwait(false)) { Logger.Log($"{request.TypeCode.ToString()} response send!", LogLevels.Trace); return; } } await Client.SendAsync(new BaseResponse(DateTime.Now, TYPE_CODE.SET_GPIO, "Failed.", string.Empty)).ConfigureAwait(false); break; case TYPE_CODE.SET_GPIO_DELAYED: if (string.IsNullOrEmpty(request.RequestObject)) { return; } SetGpioDelayedRequest setGpioDelayedRequest = JsonConvert.DeserializeObject <SetGpioDelayedRequest>(request.RequestObject); if (!PiController.IsValidPin(setGpioDelayedRequest.PinNumber)) { return; } if (Core.PiController == null || !Core.PiController.IsControllerProperlyInitialized || Core.PinController == null) { return; } if (Client == null || Client.IsDisposed) { return; } if (Core.PinController.SetGpioWithTimeout(setGpioDelayedRequest.PinNumber, (GpioPinMode)setGpioDelayedRequest.PinMode, (GpioPinState)setGpioDelayedRequest.PinState, TimeSpan.FromMinutes(setGpioDelayedRequest.Delay))) { GpioPinConfig config = Core.PinController.GetGpioConfig(setGpioDelayedRequest.PinNumber); if (await Client.SendAsync(new BaseResponse(DateTime.Now, TYPE_CODE.SET_GPIO_DELAYED, "Success!", GpioPinConfig.AsJson(config))).ConfigureAwait(false)) { Logger.Log($"{request.TypeCode.ToString()} response send!", LogLevels.Trace); return; } } await Client.SendAsync(new BaseResponse(DateTime.Now, TYPE_CODE.SET_GPIO_DELAYED, "Failed.", string.Empty)).ConfigureAwait(false); break; case TYPE_CODE.SET_REMAINDER: break; case TYPE_CODE.GET_GPIO: break; case TYPE_CODE.GET_GPIO_PIN: break; case TYPE_CODE.GET_WEATHER: break; case TYPE_CODE.GET_ASSISTANT_INFO: break; case TYPE_CODE.GET_PI_INFO: break; case TYPE_CODE.SET_PI: break; case TYPE_CODE.SET_ASSISTANT: break; default: break; } }