Beispiel #1
0
/*
 * Class:     edu_wpi_first_wpilibj_can_CANJNI
 * Method:    FRCNetworkCommunicationCANSessionMuxReceiveMessage
 * Signature: (Ljava/nio/IntBuffer;ILjava/nio/ByteBuffer;Ljava/nio/IntBuffer;)Ljava/nio/ByteBuffer;
 */
JNIEXPORT jobject JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxReceiveMessage
	(JNIEnv * env, jclass, jobject messageID, jint messageIDMask, jobject timeStamp, jobject status)
{
    CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxReceiveMessage";

    uint32_t *messageIDPtr = (uint32_t *)env->GetDirectBufferAddress(messageID);
    uint32_t *timeStampPtr = (uint32_t *)env->GetDirectBufferAddress(timeStamp);
    int32_t *statusPtr = (int32_t *)env->GetDirectBufferAddress(status);

    uint8_t dataSize = 0;

    FRC_NetworkCommunication_CANSessionMux_receiveMessage(messageIDPtr, messageIDMask, buffer, &dataSize, timeStampPtr, statusPtr);

    CANJNI_LOG(logDEBUG) << "Message ID " << std::hex << *messageIDPtr;

    if(logDEBUG <= canJNILogLevel)
    {
        std::ostringstream str;
        str << std::setfill('0') << std::hex;
        for(int i = 0; i < dataSize; i++)
        {
            str << std::setw(2) << (int)buffer[i] << ' ';
        }

        Log().Get(logDEBUG) << "Data: " << str.str();
    }

    CANJNI_LOG(logDEBUG) << "Timestamp: " << *timeStampPtr;
    CANJNI_LOG(logDEBUG) << "Status: " << *statusPtr;

    return env->NewDirectByteBuffer(buffer, dataSize);
}
Beispiel #2
0
CTR_Code CtreCanNode::GetRx(uint32_t arbId,uint8_t * dataBytes, uint32_t timeoutMs)
{
	CTR_Code retval = CTR_OKAY;
	int32_t status = 0;
	uint8_t len = 0;
	uint32_t timeStamp;
	/* cap timeout at 999ms */
	if(timeoutMs > 999)
		timeoutMs = 999;
	FRC_NetworkCommunication_CANSessionMux_receiveMessage(&arbId,kFullMessageIDMask,dataBytes,&len,&timeStamp,&status);
	if(status == 0){
		/* fresh update */
		rxEvent_t & r = _rxRxEvents[arbId]; /* lookup entry or make a default new one with all zeroes */
		clock_gettime(2,&r.time); 			/* fill in time */
		memcpy(r.bytes,  dataBytes,  8);	/* fill in databytes */
	}else{
		/* did not get the message */
		rxRxEvents_t::iterator i = _rxRxEvents.find(arbId);
		if(i == _rxRxEvents.end()){
			/* we've never gotten this mesage */
			retval = CTR_RxTimeout;
			/* fill caller's buffer with zeros */
			memset(dataBytes,0,8);
		}else{
			/* we've gotten this message before but not recently */
			memcpy(dataBytes,i->second.bytes,8);
			/* get the time now */
			struct timespec temp;
			clock_gettime(2,&temp); /* get now */
			/* how long has it been? */
			temp = diff(i->second.time,temp); /* temp = now - last */
			if(temp.tv_sec > 0){
				retval = CTR_RxTimeout;
			}else if(temp.tv_nsec > ((int32_t)timeoutMs*1000*1000)){
				retval = CTR_RxTimeout;
			}else {
				/* our last update was recent enough */
			}
		}
	}

	return retval;
}
Beispiel #3
0
void HAL_CAN_ReceiveMessage(uint32_t* messageID, uint32_t messageIDMask,
                            uint8_t* data, uint8_t* dataSize,
                            uint32_t* timeStamp, int32_t* status) {
  FRC_NetworkCommunication_CANSessionMux_receiveMessage(
      messageID, messageIDMask, data, dataSize, timeStamp, status);
}