001 /*----------------------------------------------------------------------------*/
002 /* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
003 /* Open Source Software - may be modified and shared by FRC teams. The code */
004 /* must be accompanied by the FIRST BSD license file in the root directory of */
005 /* the project. */
006 /*----------------------------------------------------------------------------*/
007
008 package edu.wpi.first.wpilibj.can;
009
010 import com.ni.rio.NiRioStatus;
011 import edu.wpi.first.wpilibj.util.UncleanStatusException;
012
013 /**
014 * Exception indicating that the Jaguar CAN Driver layer refused to send a
015 * restricted message ID to the CAN bus.
016 */
017 public class CANExceptionFactory {
018 // FRC Error codes
019 static final int ERR_JaguarCANDriver_InvalidBuffer = -44086;
020 static final int ERR_JaguarCANDriver_TimedOut = -44087;
021 static final int ERR_JaguarCANDriver_NotAllowed = -44088;
022 static final int ERR_JaguarCANDriver_NotInitialized = -44089;
023
024 public static void checkStatus(int status, int messageID) throws
025 CANInvalidBufferException, CANTimeoutException,
026 CANMessageNotAllowedException, CANNotInitializedException,
027 UncleanStatusException
028 {
029 switch (status) {
030 case NiRioStatus.kRioStatusSuccess:
031 // Everything is ok... don't throw.
032 return;
033 case ERR_JaguarCANDriver_InvalidBuffer:
034 case NiRioStatus.kRIOStatusBufferInvalidSize:
035 throw new CANInvalidBufferException();
036 case ERR_JaguarCANDriver_TimedOut:
037 case NiRioStatus.kRIOStatusOperationTimedOut:
038 throw new CANTimeoutException();
039 case ERR_JaguarCANDriver_NotAllowed:
040 case NiRioStatus.kRIOStatusFeatureNotSupported:
041 throw new CANMessageNotAllowedException("MessageID = " + Integer.toString(messageID));
042 case ERR_JaguarCANDriver_NotInitialized:
043 case NiRioStatus.kRIOStatusResourceNotInitialized:
044 throw new CANNotInitializedException();
045 default:
046 throw new UncleanStatusException("Fatal status code detected: " + Integer.toString(status));
047 }
048 }
049 }