CAN adopted, Linux work
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
#include "pican.h"
|
||||
#include "pipropertystorage.h"
|
||||
#include "piincludes_p.h"
|
||||
#include "piwaitevent_p.h"
|
||||
#if !defined(WINDOWS) && !defined(MAC_OS) && !defined(MICRO_PIP)
|
||||
# define PIP_CAN
|
||||
#endif
|
||||
@@ -39,17 +39,24 @@
|
||||
REGISTER_DEVICE(PICAN)
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PICAN)
|
||||
PIWaitEvent event;
|
||||
PRIVATE_DEFINITION_END(PICAN)
|
||||
|
||||
|
||||
PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) {
|
||||
setThreadedReadBufferSize(256);
|
||||
setPath(path);
|
||||
can_id = 0;
|
||||
sock = 0;
|
||||
PRIVATE->event.create();
|
||||
}
|
||||
|
||||
|
||||
PICAN::~PICAN() {
|
||||
stop();
|
||||
stopAndWait();
|
||||
close();
|
||||
PRIVATE->event.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +99,7 @@ bool PICAN::openDevice() {
|
||||
|
||||
bool PICAN::closeDevice() {
|
||||
#ifdef PIP_CAN
|
||||
interrupt();
|
||||
if (sock > 0) ::close(sock);
|
||||
#endif
|
||||
return true;
|
||||
@@ -103,9 +111,8 @@ ssize_t PICAN::readDevice(void * read_to, ssize_t max_size) {
|
||||
//piCout << "PICAN read";
|
||||
can_frame frame;
|
||||
ssize_t ret = 0;
|
||||
reading_now = true;
|
||||
ret = ::read(sock, &frame, sizeof(can_frame));
|
||||
reading_now = false;
|
||||
if (PRIVATE->event.wait(sock))
|
||||
ret = ::read(sock, &frame, sizeof(can_frame));
|
||||
if (ret < 0) {/*piCoutObj << "Error while read CAN frame " << ret;*/ return -1;}
|
||||
//piCoutObj << "receive CAN frame Id =" << frame.can_id;
|
||||
memcpy(read_to, frame.data, piMini(frame.can_dlc, max_size));
|
||||
@@ -148,6 +155,11 @@ int PICAN::readedCANID() const {
|
||||
}
|
||||
|
||||
|
||||
void PICAN::interrupt() {
|
||||
PRIVATE->event.interrupt();
|
||||
}
|
||||
|
||||
|
||||
PIString PICAN::constructFullPathDevice() const {
|
||||
PIString ret;
|
||||
ret += path() + ":" + PIString::fromNumber(CANID(), 16);
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
void setCANID(int id);
|
||||
int CANID() const;
|
||||
int readedCANID() const;
|
||||
void interrupt() override;
|
||||
|
||||
protected:
|
||||
bool openDevice() override;
|
||||
@@ -52,6 +53,7 @@ protected:
|
||||
DeviceInfoFlags deviceInfoFlags() const override {return PIIODevice::Reliable;}
|
||||
|
||||
private:
|
||||
PRIVATE_DECLARATION(PIP_EXPORT)
|
||||
int sock;
|
||||
int can_id, readed_id;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user