Esempio n. 1
0
/* Reset Energy Signals
 * @Return	-	CTR_Code	-	Error code (if any)
 */
CTR_Code PDP::ResetEnergy()
{
	int32_t status = 0;
	uint8_t pdpControl[] = { 0x40 }; /* only bit set is ResetEnergy */
	FRC_NetworkCommunication_CANSessionMux_sendMessage(CONTROL_1  | GetDeviceNumber(), pdpControl, sizeof(pdpControl), 0, &status);
	if(status)
		return CTR_TxFailed;
	return CTR_OKAY;
}
Esempio n. 2
0
void CtreCanNode::FlushTx(uint32_t arbId)
{
	int32_t status = 0;
	txJobs_t::iterator iter = _txJobs.find(arbId);
	if(iter != _txJobs.end())
		FRC_NetworkCommunication_CANSessionMux_sendMessage(	iter->second.arbId,
															iter->second.toSend,
															iter->second.dlc,
															iter->second.periodMs,
															&status);
}
Esempio n. 3
0
/**
 * Change the transmit period of an already scheduled CAN frame.
 * This keeps the frame payload contents the same without caller having to perform
 * a read-modify-write.
 * @param arbId 	CAN Frame Arbitration ID.  Set BIT31 for 11bit ids, otherwise we use 29bit ids.
 * @param periodMs	Period to transmit CAN frame.  Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
 * @return true if scheduled job was found and updated, false if there was no preceding job for the specified arbID.
 */
bool CtreCanNode::ChangeTxPeriod(uint32_t arbId, uint32_t periodMs)
{
	int32_t status = 0;
	/* lookup the data bytes and period for this message */
	txJobs_t::iterator iter = _txJobs.find(arbId);
	if(iter != _txJobs.end()) {
		/* modify th periodMs */
		iter->second.periodMs = periodMs;
		/* reinsert into scheduler with the same data bytes, only the period changed. */
		FRC_NetworkCommunication_CANSessionMux_sendMessage(	iter->second.arbId,
															iter->second.toSend,
															iter->second.dlc,
															iter->second.periodMs,
															&status);
		return true;
	}
	return false;
}
Esempio n. 4
0
/**
 * Schedule a CAN Frame for periodic transmit.
 * @param arbId 	CAN Frame Arbitration ID.  Set BIT31 for 11bit ids, otherwise we use 29bit ids.
 * @param periodMs	Period to transmit CAN frame.  Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
 * @param dlc 		Number of bytes to transmit (0 to 8).
 * @param initialFrame	Ptr to the frame data to schedule for transmitting.  Passing null will result
 *						in defaulting to zero data value.
 */
void CtreCanNode::RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame)
{
	int32_t status = 0;
	if(dlc > 8)
		dlc = 8;
	txJob_t job = {0};
	job.arbId = arbId;
	job.periodMs = periodMs;
	job.dlc = dlc;
	if(initialFrame){
		/* caller wants to specify original data */
		memcpy(job.toSend, initialFrame, dlc);
	}
	_txJobs[arbId] = job;
	FRC_NetworkCommunication_CANSessionMux_sendMessage(	job.arbId,
														job.toSend,
														job.dlc,
														job.periodMs,
														&status);
}
Esempio n. 5
0
/*
 * Class:     edu_wpi_first_wpilibj_can_CANJNI
 * Method:    FRCNetworkCommunicationCANSessionMuxSendMessage
 * Signature: (ILjava/nio/ByteBuffer;I)V
 */
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_can_CANJNI_FRCNetworkCommunicationCANSessionMuxSendMessage
  (JNIEnv * env, jclass, jint messageID, jobject data, jint periodMs)
{
    CANJNI_LOG(logDEBUG) << "Calling CANJNI FRCNetworkCommunicationCANSessionMuxSendMessage";

    uint8_t *dataBuffer = (uint8_t *)(data? env->GetDirectBufferAddress(data) : 0);
    uint8_t dataSize = (uint8_t)(data? env->GetDirectBufferCapacity(data) : 0);

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

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

            Log().Get(logDEBUG) << "Data: " << str.str();
        }
        else
        {
            CANJNI_LOG(logDEBUG) << "Data: null";
        }
    }

    CANJNI_LOG(logDEBUG) << "Period: " << periodMs;

    int32_t status = 0;
    FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, dataBuffer, dataSize, periodMs, &status);

    CANJNI_LOG(logDEBUG) << "Status: " << status;
    CheckCANStatus(env, status, messageID);
}
Esempio n. 6
0
void HAL_CAN_SendMessage(uint32_t messageID, const uint8_t* data,
                         uint8_t dataSize, int32_t periodMs, int32_t* status) {
  FRC_NetworkCommunication_CANSessionMux_sendMessage(messageID, data, dataSize,
                                                     periodMs, status);
}