/* Helper function to both transmit a request packet and receive the reponse packet, if applicable (unicast).  */
static uint8_t TbxMbClientTransceive(tTbxMbClientCtx *clientCtx, uint8_t isBroadcast)
/* Helper function to both transmit a request packet and receive the reponse packet, if applicable (unicast).  */
static uint8_t TbxMbClientTransceive(tTbxMbClientCtx *clientCtx, uint8_t isBroadcast)
{
  uint8_t  result      = TBX_ERROR;
  uint16_t waitTimeout = clientCtx->responseTimeout;
  if (isBroadcast == TBX_TRUE)
  {
    waitTimeout = clientCtx->turnaroundDelay;
  }
  result = clientCtx->tpCtx->transmitFcn(clientCtx->tpCtx);
  if (result == TBX_OK)
  {
    if (TbxMbOsalSemTake(clientCtx->transceiveSem, clientCtx->responseTimeout)
        == TBX_FALSE)
    {
      result = TBX_ERROR;
    }
    if (result == TBX_OK)
    {
      if (TbxMbOsalSemTake(clientCtx->transceiveSem, waitTimeout) == TBX_FALSE)
      {
        if (isBroadcast == TBX_FALSE)
        {
          result = TBX_ERROR;
        }
      }
    }
  }
  return result;
}