def _CTRFUNC(name, *params, out=None, library=_dll, handle_missing=False): return _RETFUNC( name, C.c_int, ("handle", TalonSRX_ptr), *params, out=out, library=library, handle_missing=handle_missing, errcheck=_CTRFUNC_errcheck )
def _STATUSFUNC(name, restype, *params, out=None, library=_dll, handle_missing=False): realparams = list(params) realparams.append(("status", C.POINTER(C.c_int32))) _inner = _RETFUNC(name, restype, *realparams, out=out, library=library, handle_missing=handle_missing) def outer(*args, **kwargs): status = C.c_int32(0) rv = _inner(*args, status=status, **kwargs) if status.value != 0: if status.value == -44086: raise CANError("invalid buffer") if status.value == -44087: raise CANMessageNotFound("message not found") if status.value == -44088: raise CANError("not allowed") if status.value == -44089: raise CANNotInitializedException("not initialized") if status.value == 44087: warnings.warn("CAN session mux: no token", RuntimeWarning) elif status.value < 0: raise CANError("unknown error %d" % status.value) else: warnings.warn("CAN session mux: unknown warning %d" % status.value, RuntimeWarning) return rv return outer
def _STATUSFUNC(name, restype, *params, out=None, library=_dll, handle_missing=False): realparams = list(params) realparams.append(("status", C.POINTER(C.c_int32))) _inner = _RETFUNC(name, restype, *realparams, out=out, library=library, handle_missing=handle_missing) def outer(*args, **kwargs): status = C.c_int32(0) rv = _inner(*args, status=status, **kwargs) if status.value != 0: if status.value == -44086: raise CANError("invalid buffer") if status.value == -44087: raise CANMessageNotFound("message not found") if status.value == -44088: raise CANError("not allowed") if status.value == -44089: raise CANNotInitializedException("not initialized") if status.value == 44087: warnings.warn("CAN session mux: no token", RuntimeWarning) elif status.value < 0: raise CANError("unknown error %d" % status.value) else: warnings.warn( "CAN session mux: unknown warning %d" % status.value, RuntimeWarning) return rv return outer
buffer = (C.c_uint8 * 8)() dataSize, timeStamp = _CANSessionMux_receiveMessage( idbuf, messageIDMask, buffer) if dataSize is 0: return idbuf.value, None, timeStamp else: return idbuf.value, [x for x in buffer[0:dataSize]], timeStamp CANSessionMux_openStreamSession = _STATUSFUNC( "FRC_NetworkCommunication_CANSessionMux_openStreamSession", None, ("sessionHandle", C.POINTER(C.c_uint32)), ("messageID", C.c_uint32), ("messageIDMask", C.c_uint32), ("maxMessages", C.c_uint32), out=["sessionHandle"]) CANSessionMux_closeStreamSession = _RETFUNC( "FRC_NetworkCommunication_CANSessionMux_closeStreamSession", None, ("sessionHandle", C.c_uint32)) _CANSessionMux_readStreamSession = _STATUSFUNC( "FRC_NetworkCommunication_CANSessionMux_readStreamSession", None, ("sessionHandle", C.c_uint32), ("messages", C.POINTER(CANStreamMessage)), ("messagesToRead", C.c_uint32), ("messagesRead", C.POINTER(C.c_uint32)), out=["messagesRead"]) def CANSessionMux_readStreamSession(sessionHandle, messagesToRead): messages = (CANStreamMessage * messagesToRead)() messagesRead = _CANSessionMux_readStreamSession(sessionHandle, messages, messagesToRead) return messages[0:messagesRead]
############################################################################# # Python-specific hal functions ############################################################################# def isSimulation(): return __hal_simulation__ HALIsSimulation = isSimulation ############################################################################# # HAL ############################################################################# getPort = _RETFUNC("getPort", PortHandle, ("pin", C.c_int32)) getPortWithModule = _RETFUNC("getPortWithModule", PortHandle, ("module", C.c_int32), ("pin", C.c_int32)) _getErrorMessage = _RETFUNC("getErrorMessage", C.c_char_p, ("code", C.c_int32)) @hal_wrapper def getErrorMessage(code): return _getErrorMessage(code).decode('utf_8') getFPGAVersion = _STATUSFUNC("getFPGAVersion", C.c_int32) getFPGARevision = _STATUSFUNC("getFPGARevision", C.c_uint64) getFPGATime = _STATUSFUNC("getFPGATime", C.c_uint64) getRuntimeType = _RETFUNC("getRuntimeType", C.c_int32) getFPGAButton = _STATUSFUNC("getFPGAButton", C.c_bool) getSystemActive = _STATUSFUNC("getSystemActive", C.c_bool)
def _CTRFUNC_errcheck(result, func, args): if result != 0: warnings.warn(getHALErrorMessage(result)) return args def _CTRFUNC(name, *params, out=None, library=_dll, handle_missing=False): return _RETFUNC(name, C.c_int, ("handle", TalonSRX_ptr), *params, out=out, library=library, handle_missing=handle_missing, errcheck=_CTRFUNC_errcheck, c_name='c_%s' % name) ############################################################################# # Semaphore.hpp ############################################################################# initializeMutexNormal = _RETFUNC("initializeMutexNormal", MUTEX_ID) deleteMutex = _RETFUNC("deleteMutex", None, ("sem", MUTEX_ID)) takeMutex = _RETFUNC("takeMutex", C.c_int8, ("sem", MUTEX_ID)) tryTakeMutex = _RETFUNC("tryTakeMutex", C.c_bool, ("sem", MUTEX_ID)) giveMutex = _RETFUNC("giveMutex", C.c_int8, ("sem", MUTEX_ID)) initializeMultiWait = _RETFUNC("initializeMultiWait", MULTIWAIT_ID) deleteMultiWait = _RETFUNC("deleteMultiWait", None, ("sem", MULTIWAIT_ID)) takeMultiWait = _RETFUNC("takeMultiWait", C.c_int8, ("sem", MULTIWAIT_ID),("mutex", MUTEX_ID)) giveMultiWait = _RETFUNC("giveMultiWait", C.c_int8, ("sem", MULTIWAIT_ID)) ############################################################################# # HAL ############################################################################# getPort = _RETFUNC("getPort", Port_ptr, ("pin", C.c_uint8))
############################################################################# # Python-specific hal functions ############################################################################# def isSimulation(): return __hal_simulation__ HALIsSimulation = isSimulation ############################################################################# # HAL ############################################################################# getPort = _RETFUNC("getPort", PortHandle, ("channel", C.c_int32)) getPortWithModule = _RETFUNC("getPortWithModule", PortHandle, ("module", C.c_int32), ("channel", C.c_int32)) _getErrorMessage = _RETFUNC("getErrorMessage", C.c_char_p, ("code", C.c_int32)) @hal_wrapper def getErrorMessage(code): return _getErrorMessage(code).decode('utf_8') getFPGAVersion = _STATUSFUNC("getFPGAVersion", C.c_int32) getFPGARevision = _STATUSFUNC("getFPGARevision", C.c_uint64) getFPGATime = _STATUSFUNC("getFPGATime", C.c_uint64) getRuntimeType = _RETFUNC("getRuntimeType", C.c_int32) getFPGAButton = _STATUSFUNC("getFPGAButton", C.c_bool) getSystemActive = _STATUSFUNC("getSystemActive", C.c_bool)
buffer = (C.c_uint8 * size)(*data) _CANSessionMux_sendMessage(messageID, buffer, size, periodMs) _CANSessionMux_receiveMessage = _STATUSFUNC("FRC_NetworkCommunication_CANSessionMux_receiveMessage", None, ("messageID", C.POINTER(C.c_uint32)), ("messageIDMask", C.c_uint32), ("data", C.POINTER(C.c_uint8)), ("dataSize", C.POINTER(C.c_uint8)), ("timeStamp", C.POINTER(C.c_uint32)), out=["dataSize", "timeStamp"]) def CANSessionMux_receiveMessage(messageID, messageIDMask): idbuf = C.c_uint32(messageID) buffer = (C.c_uint8 * 8)() dataSize, timeStamp = _CANSessionMux_receiveMessage(idbuf, messageIDMask, buffer) if dataSize is 0: return idbuf.value, None, timeStamp else: return idbuf.value, [x for x in buffer[0:dataSize]], timeStamp CANSessionMux_openStreamSession = _STATUSFUNC("FRC_NetworkCommunication_CANSessionMux_openStreamSession", None, ("sessionHandle", C.POINTER(C.c_uint32)), ("messageID", C.c_uint32), ("messageIDMask", C.c_uint32), ("maxMessages", C.c_uint32), out=["sessionHandle"]) CANSessionMux_closeStreamSession = _RETFUNC("FRC_NetworkCommunication_CANSessionMux_closeStreamSession", None, ("sessionHandle", C.c_uint32)) _CANSessionMux_readStreamSession = _STATUSFUNC("FRC_NetworkCommunication_CANSessionMux_readStreamSession", None, ("sessionHandle", C.c_uint32), ("messages", C.POINTER(CANStreamMessage)), ("messagesToRead", C.c_uint32), ("messagesRead", C.POINTER(C.c_uint32)), out=["messagesRead"]) def CANSessionMux_readStreamSession(sessionHandle, messagesToRead): messages = (CANStreamMessage * messagesToRead)() messagesRead = _CANSessionMux_readStreamSession(sessionHandle, messages, messagesToRead) return messages[0:messagesRead] _CANSessionMux_getCANStatus = _STATUSFUNC("FRC_NetworkCommunication_CANSessionMux_getCANStatus", None, ("percentBusUtilization", C.POINTER(C.c_float)), ("busOffCount", C.POINTER(C.c_uint32)), ("txFullCount", C.POINTER(C.c_uint32)), ("receiveErrorCount", C.POINTER(C.c_uint32)), ("transmitErrorCount", C.POINTER(C.c_uint32)), out=["percentBusUtilization", "busOffCount", "txFullCount", "receiveErrorCount", "transmitErrorCount"]) def CANSessionMux_getCANStatus(): percentBusUtilization, busOffCount, txFullCount, receiveErrorCount, transmitErrorCount = _CANSessionMux_getCANStatus() return dict(percentBusUtilization=percentBusUtilization, busOffCount=busOffCount, txFullCount=txFullCount, receiveErrorCount=receiveErrorCount, transmitErrorCount=transmitErrorCount)
def _CTRFUNC(name, *params, out=None, library=_dll, handle_missing=False): return _RETFUNC(name, C.c_int, ("handle", TalonSRX_ptr), *params, out=out, library=library, handle_missing=handle_missing, errcheck=_CTRFUNC_errcheck)
return _STATUSFUNC(_inner_func=_THUNKFUNC, *a, **k) def _CTRFUNC_errcheck(result, func, args): if result != 0: warnings.warn(getHALErrorMessage(result)) return args def _CTRFUNC(name, *params, out=None, library=_dll, handle_missing=False): return _RETFUNC(name, C.c_int, ("handle", TalonSRX_ptr), *params, out=out, library=library, handle_missing=handle_missing, errcheck=_CTRFUNC_errcheck) ############################################################################# # Semaphore.hpp ############################################################################# initializeMutexNormal = _RETFUNC("initializeMutexNormal", MUTEX_ID) deleteMutex = _RETFUNC("deleteMutex", None, ("sem", MUTEX_ID)) takeMutex = _RETFUNC("takeMutex", C.c_int8, ("sem", MUTEX_ID)) tryTakeMutex = _RETFUNC("tryTakeMutex", C.c_bool, ("sem", MUTEX_ID)) giveMutex = _RETFUNC("giveMutex", C.c_int8, ("sem", MUTEX_ID)) initializeMultiWait = _RETFUNC("initializeMultiWait", MULTIWAIT_ID) deleteMultiWait = _RETFUNC("deleteMultiWait", None, ("sem", MULTIWAIT_ID)) takeMultiWait = _RETFUNC("takeMultiWait", C.c_int8, ("sem", MULTIWAIT_ID),("mutex", MUTEX_ID)) giveMultiWait = _RETFUNC("giveMultiWait", C.c_int8, ("sem", MULTIWAIT_ID)) ############################################################################# # HAL ############################################################################# getPort = _RETFUNC("getPort", Port_ptr, ("pin", C.c_uint8))