/** * Start waiting for a message to be received from the CAN bus. * @param messageID MessageID filter to specify what message ID to be expected. * @param sem Semaphore that indicates that the receive call has completed. * @param timeout Number of seconds to wait for the expected message. * @return Data available now... call complete */ public boolean receiveMessageStart(int messageID, Semaphore sem, double timeout) throws CANTimeoutException { int retVal = 0; IntByReference recvStatus = new IntByReference(0); recvStatus.setValue(0); retVal = receiveMessageStart_semFn.call4(messageID, sem.getPointer(), (int) (timeout * 1000.0), recvStatus.getPointer().address().toUWord().toPrimitive()); int statusValue = recvStatus.getValue(); recvStatus.free(); CANExceptionFactory.checkStatus(statusValue, messageID); return retVal != 0; }
private void acquireResources() throws SemaphoreException { Enumeration e = resources.elements(); while (e.hasMoreElements()) { Semaphore s = (Semaphore) e.nextElement(); s.takeMillis(500); } }
private void releaseResources() { Enumeration e = resources.elements(); while (e.hasMoreElements()) { Semaphore s = (Semaphore) e.nextElement(); try { s.give(); } catch (final SemaphoreException se) { } } }