private async Task <ErrorCode> SendBroadcastAsyncInternal(BusRequest broadcast, bool sync) { int attempts = 3; while (attempts > 0) { ErrorCode result = sync ? BusAbstraction.Transmit(BroadcastAddress, broadcast.GetByteArray()) : await BusAbstraction.TransmitAsync(BroadcastAddress, broadcast.GetByteArray()); switch (result) { case ErrorCode.Success: ++successfulTransmissions; return(ErrorCode.Success); case ErrorCode.TransportTransmissionError: ++transmitErrors; break; } attempts--; } return(ErrorCode.TransportTransmissionError); }
private async Task <BusTransceiveResult> TransceiveAsyncInternal(int address, BusRequest request, int responseSize, int attempts, bool sync) { BusResponse response = new BusResponse(responseSize); Types.ErrorCode transceiveStatus = Types.ErrorCode.TransportTransmissionError; while (attempts > 0) { (ErrorCode, byte[])result = sync ? BusAbstraction.Transceive(address, request.GetByteArray(), responseSize) : await BusAbstraction.TransceiveAsync(address, request.GetByteArray(), responseSize); transceiveStatus = result.Item1; byte[] receiveBuffer = result.Item2; response = new BusResponse(responseSize); response.Fill(receiveBuffer); switch (transceiveStatus) { case Types.ErrorCode.Success: ++successfulTransmissions; return(new BusTransceiveResult(Types.ErrorCode.Success, response)); case Types.ErrorCode.TransportChecksumError: ++checksumErrors; break; case Types.ErrorCode.TransportReceptionNoAnswerError: ++noAnswer; break; case Types.ErrorCode.TransportReceptionMissingDataError: ++missingData; break; case Types.ErrorCode.TransportTransmissionError: ++transmitErrors; break; } attempts--; } return(new BusTransceiveResult(transceiveStatus, response)); }