50 lines
983 B
C++
50 lines
983 B
C++
/*
|
|
* canclient.cpp
|
|
*
|
|
* Created on: Oct 31, 2016
|
|
* Author: wn
|
|
*/
|
|
|
|
#include "canclient.h"
|
|
|
|
#include <mcp_can.h>
|
|
#include <SPI.h>
|
|
#include <Streaming.h>
|
|
|
|
|
|
const int SPI_CS_PIN = 10;
|
|
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
|
|
|
|
|
|
void CanClientNS::begin() {
|
|
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
|
|
{
|
|
Serial.println("CAN BUS Shield init fail");
|
|
Serial.println(" Init CAN BUS Shield again");
|
|
delay(100);
|
|
}
|
|
Serial.println("CAN BUS Shield init ok!");
|
|
}
|
|
|
|
void CanClientNS::exec() {
|
|
|
|
}
|
|
|
|
void CanClientNS::sendMessage(uint32_t addr, uint8_t payloadLength, uint8_t *payload) {
|
|
// CAN.sendMsgBuf(0x00, 0, 8, stmp);
|
|
|
|
Serial << "Once again:" << endl;
|
|
Serial << "Address: " << addr << endl;
|
|
Serial << "Length: " << (uint16_t)payloadLength << endl;
|
|
Serial << "Data: ";
|
|
for (uint8_t i = 0; i < payloadLength; i++) {
|
|
Serial << (uint16_t)payload[i] << " ";
|
|
}
|
|
Serial << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|