//-----------------------------------------------------------------------
//
// Copyright © 2012 Nils Hammar. All rights reserved.
//
//-----------------------------------------------------------------------
/*
* Software to access vehicle information via the OBD-II connector.
*
* Copyright © 2012 Nils Hammar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Alternative licensing is possible, see the licensing document.
*
* The above text may not be removed or modified.
*/
namespace SharedObjects.Api
{
using System.Collections.Generic;
///
/// List of possible errors from the J2534 API.
///
public class J2534_Error
{
///
/// Gets J2534 errors with explanations.
///
public static IDictionary errors
{
get
{
return errorsInt;
}
}
///
/// J2534 errors with explanations.
///
private static Dictionary errorsInt = new Dictionary()
{
{
PassThruConstants.resultCode.ERR_SUCCESS,
new J2534_Error(PassThruConstants.resultCode.ERR_SUCCESS, "STATUS_NOERROR", "Success")
},
{
PassThruConstants.resultCode.ERR_NOT_SUPPORTED,
new J2534_Error(PassThruConstants.resultCode.ERR_NOT_SUPPORTED, "ERR_NOT_SUPPORTED", "Device does not support requested functionality")
},
{
PassThruConstants.resultCode.ERR_INVALID_CHANNEL_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_CHANNEL_ID, "ERR_INVALID_CHANNEL_ID", "Invalid ChannelID value")
},
{
PassThruConstants.resultCode.ERR_INVALID_PROTOCOL_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_PROTOCOL_ID, "ERR_INVALID_PROTOCOL_ID", "Invalid or unsupported ProtocolID or a resource conflict")
},
{
PassThruConstants.resultCode.ERR_NULL_PARAMETER,
new J2534_Error(PassThruConstants.resultCode.ERR_NULL_PARAMETER, "ERR_NULL_PARAMETER", "NULL pointer supplied where non-null pointer required")
},
{
PassThruConstants.resultCode.ERR_INVALID_IOCTL_VALUE,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_IOCTL_VALUE, "ERR_INVALID_IOCTL_VALUE", "Invalid value for IOCTL")
},
{
PassThruConstants.resultCode.ERR_INVALID_FLAGS,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_FLAGS, "ERR_INVALID_FLAGS", "Invalid flag values")
},
{
PassThruConstants.resultCode.ERR_FAILED,
new J2534_Error(PassThruConstants.resultCode.ERR_FAILED, "ERR_FAILED", "Undefined Error, see PassThruGetLastError for details")
},
{
PassThruConstants.resultCode.ERR_DEVICE_NOT_CONNECTED,
new J2534_Error(PassThruConstants.resultCode.ERR_DEVICE_NOT_CONNECTED, "ERR_DEVICE_NOT_CONNECTED", "Device ID invalid")
},
{
PassThruConstants.resultCode.ERR_TIMEOUT,
new J2534_Error(PassThruConstants.resultCode.ERR_TIMEOUT, "ERR_TIMEOUT", "Timeout when reading or writing message(s)")
},
{
PassThruConstants.resultCode.ERR_INVALID_MSG,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_MSG, "ERR_INVALID_MSG", "Pointer for message points to invalid structure")
},
{
PassThruConstants.resultCode.ERR_INVALID_TIME_INTERVAL,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_TIME_INTERVAL, "ERR_INVALID_TIME_INTERVAL", "Invalid time interval value")
},
{
PassThruConstants.resultCode.ERR_EXCEEDED_LIMIT,
new J2534_Error(PassThruConstants.resultCode.ERR_EXCEEDED_LIMIT, "ERR_EXCEEDED_LIMIT", "Exceeded maximum number of message ID:s or allocated space")
},
{
PassThruConstants.resultCode.ERR_INVALID_MSG_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_MSG_ID, "ERR_INVALID_MSG_ID", "Invalid MsgID value")
},
{
PassThruConstants.resultCode.ERR_DEVICE_IN_USE,
new J2534_Error(PassThruConstants.resultCode.ERR_DEVICE_IN_USE, "ERR_DEVICE_IN_USE", "Device is in use by another process")
},
{
PassThruConstants.resultCode.ERR_INVALID_IOCTL_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_IOCTL_ID, "ERR_INVALID_IOCTL_ID", "Invalid IoctlID value")
},
{
PassThruConstants.resultCode.ERR_BUFFER_EMPTY,
new J2534_Error(PassThruConstants.resultCode.ERR_BUFFER_EMPTY, "ERR_BUFFER_EMPTY", "No messages available to read")
},
{
PassThruConstants.resultCode.ERR_BUFFER_FULL,
new J2534_Error(PassThruConstants.resultCode.ERR_BUFFER_FULL, "ERR_BUFFER_FULL", "Send message buffer full, some may not have been sent")
},
{
PassThruConstants.resultCode.ERR_BUFFER_OVERFLOW,
new J2534_Error(PassThruConstants.resultCode.ERR_BUFFER_OVERFLOW, "ERR_BUFFER_OVERFLOW", "A buffer overflow occurred and messages were lost")
},
{
PassThruConstants.resultCode.ERR_PIN_INVALID,
new J2534_Error(PassThruConstants.resultCode.ERR_PIN_INVALID, "ERR_PIN_INVALID", "Invalid pin number, pin already in use or voltage applied to another pin")
},
{
PassThruConstants.resultCode.ERR_CHANNEL_IN_USE,
new J2534_Error(PassThruConstants.resultCode.ERR_CHANNEL_IN_USE, "ERR_CHANNEL_IN_USE", "Channel number is already connected")
},
{
PassThruConstants.resultCode.ERR_MSG_PROTOCOL_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_MSG_PROTOCOL_ID, "ERR_MSG_PROTOCOL_ID", "Protocol in Message does not match protocol for Channel")
},
{
PassThruConstants.resultCode.ERR_INVALID_FILTER_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_FILTER_ID, "ERR_INVALID_FILTER_ID", "Invalid FilterID value")
},
{
PassThruConstants.resultCode.ERR_NO_FLOW_CONTROL,
new J2534_Error(PassThruConstants.resultCode.ERR_NO_FLOW_CONTROL, "ERR_NO_FLOW_CONTROL", "No flow control filter set or matched (ISO15765 only)")
},
{
PassThruConstants.resultCode.ERR_NOT_UNIQUE,
new J2534_Error(PassThruConstants.resultCode.ERR_NOT_UNIQUE, "ERR_NOT_UNIQUE", "A CAN ID in Pattern or Flow message is already used by another filter")
},
{
PassThruConstants.resultCode.ERR_INVALID_BAUDRATE,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_BAUDRATE, "ERR_INVALID_BAUDRATE", "The selected baud rate can't be used")
},
{
PassThruConstants.resultCode.ERR_INVALID_DEVICE_ID,
new J2534_Error(PassThruConstants.resultCode.ERR_INVALID_DEVICE_ID, "ERR_INVALID_DEVICE_ID", "Unable to communicate with device")
},
};
///
/// Gets the error code.
///
public PassThruConstants.resultCode code { get; private set; }
///
/// Gets the error name.
///
public string name { get; private set; }
///
/// Gets the error description.
///
public string text { get; private set; }
///
/// Initializes a new instance of the class.
///
/// Code value for error.
/// Name of error.
/// Error description.
private J2534_Error(PassThruConstants.resultCode code, string name, string text)
{
this.code = code;
this.name = name;
this.text = text;
}
///
/// Get error description instance by error code.
///
/// Error code.
/// Error description instance.
public static J2534_Error getErrorByCode(int code)
{
return getErrorByCode((PassThruConstants.resultCode)code);
}
///
/// Get error description instance by error code.
///
/// Error code.
/// Error description instance.
public static J2534_Error getErrorByCode(PassThruConstants.resultCode code)
{
J2534_Error error = null;
if (errors.ContainsKey(code))
{
error = errors[code];
}
return error;
}
///
/// Get the error by name.
///
/// Error code.
/// Error name string.
public static string getErrorName(int code)
{
return getErrorName((PassThruConstants.resultCode)code);
}
///
/// Get the error by name.
///
/// Error code.
/// Error name string.
public static string getErrorName(PassThruConstants.resultCode code)
{
string desc = string.Empty;
J2534_Error err = J2534_Error.getErrorByCode(code);
if (err != null)
{
desc = err.name;
}
return desc;
}
}
}