git-svn-id: svn://db.shs.com.ru/pip@609 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -317,7 +317,7 @@ endif()
|
||||
|
||||
|
||||
# Check if PIP support compress/decompress using zlib library
|
||||
find_library(zlib_FOUND NAMES zlib z)
|
||||
find_library(zlib_FOUND NAMES z zlib)
|
||||
if(zlib_FOUND)
|
||||
message(STATUS "Building with zlib compress support")
|
||||
add_definitions(-DPIP_COMPRESS)
|
||||
|
||||
58
main.cpp
58
main.cpp
@@ -60,11 +60,40 @@ int main(int argc, char *argv[]) {
|
||||
piCout << "decrypted" << dba.toHex() << PIString(dba);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
piCout << "=======================================";
|
||||
|
||||
PIAuth server(PIAuth::generateSign(pkey1));
|
||||
|
||||
msg = "This is Server with PIAuth";
|
||||
server.setInfoData(msg.toUTF8());
|
||||
|
||||
PIAuth client(PIAuth::generateSign(pkey2));
|
||||
|
||||
client.setAuthorizedPublicKeys(PIVector<PIByteArray>() << server.getSignPublicKey());
|
||||
// server.setAuthorizedPublicKeys(PIVector<PIByteArray>() << client.getSignPublicKey());
|
||||
Obj o;
|
||||
@@ -77,6 +106,9 @@ int main(int argc, char *argv[]) {
|
||||
ba = server.startServer();
|
||||
int st = PIAuth::AuthProbe;
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
|
||||
|
||||
|
||||
// ba[40] = 2;
|
||||
// {
|
||||
// int s;
|
||||
@@ -94,6 +126,9 @@ int main(int argc, char *argv[]) {
|
||||
// rsign = crypt.signMessage(ba, sign2);
|
||||
// ba << rsign;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
@@ -113,3 +148,26 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
131
src_main/io/pican.cpp
Normal file
131
src_main/io/pican.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "pican.h"
|
||||
#include "piincludes_p.h"
|
||||
#if !defined(WINDOWS) && !defined(MAC_OS)
|
||||
# define PIP_CAN
|
||||
#endif
|
||||
#ifdef PIP_CAN
|
||||
# include <sys/ioctl.h>
|
||||
# include <net/if.h>
|
||||
# include <linux/can.h>
|
||||
# include <linux/can/raw.h>
|
||||
# ifndef AF_CAN
|
||||
# define AF_CAN 29
|
||||
# endif
|
||||
# ifndef PF_CAN
|
||||
# define PF_CAN AF_CAN
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
//PRIVATE_DEFINITION_START(PICAN)
|
||||
//#ifdef PIP_CAN
|
||||
//int fd;
|
||||
//spi_ioc_transfer spi_ioc_tr;
|
||||
//#endif
|
||||
//PRIVATE_DEFINITION_END(PICAN)
|
||||
|
||||
|
||||
REGISTER_DEVICE(PICAN)
|
||||
|
||||
|
||||
PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(path, mode) {
|
||||
setThreadedReadBufferSize(256);
|
||||
setPath(path);
|
||||
can_id = 0;
|
||||
}
|
||||
|
||||
|
||||
bool PICAN::openDevice() {
|
||||
#ifdef PIP_CAN
|
||||
sock = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if(sock < 0){
|
||||
piCoutObj << "Error! while opening socket";
|
||||
return false;
|
||||
}
|
||||
struct ifreq ifr;
|
||||
strcpy(ifr.ifr_name, path.dataAscii());
|
||||
if(ioctl(sock, SIOCGIFINDEX, &ifr) < 0){
|
||||
piCoutObj << "Error! while determin the interface ioctl";
|
||||
return false;
|
||||
}
|
||||
// bind socket to all CAN interface
|
||||
struct sockaddr_can addr;
|
||||
addr.can_family = AF_CAN;
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
if(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0){
|
||||
piCoutObj << "Error! while binding socket";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
piCoutObj << "PICAN not implemented on windows";
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PICAN::closeDevice() {
|
||||
#ifdef PIP_CAN
|
||||
if (sock > 0) ::close(sock);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int PICAN::readDevice(void * read_to, int max_size) {
|
||||
#ifdef PIP_CAN
|
||||
int ret = 0;
|
||||
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));
|
||||
return max_size;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int PICAN::writeDevice(const void * data, int max_size) {
|
||||
#ifdef PIP_CAN
|
||||
if (max_size > 8) {piCoutObj << "Can't send CAN frame bigger than 8 bytes (requested " << max_size << ")!"; return -1;}
|
||||
can_frame frame;
|
||||
frame.can_id = can_id;
|
||||
frame.can_dlc = max_size;
|
||||
memcpy(frame.data, data, max_size);
|
||||
int ret = 0;
|
||||
ret = write(sock, &frame, sizeof(can_frame));
|
||||
if(ret < 0) {piCoutObj << "Error while send CAN frame " << ret; return -1;}
|
||||
return max_size;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void PICAN::setCANID(int id) {
|
||||
can_id = id;
|
||||
}
|
||||
|
||||
|
||||
int PICAN::CANID() const {
|
||||
return can_id;
|
||||
}
|
||||
|
||||
|
||||
PIString PICAN::constructFullPathDevice() const {
|
||||
PIString ret;
|
||||
ret << path() << ":" << CANID();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PICAN::configureFromFullPathDevice(const PIString & full_path) {
|
||||
PIStringList pl = full_path.split(":");
|
||||
for (int i = 0; i < pl.size_s(); ++i) {
|
||||
PIString p(pl[i]);
|
||||
switch (i) {
|
||||
case 0: setPath(p); break;
|
||||
case 1: setCANID(p.toInt(16)); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
src_main/io/pican.h
Normal file
33
src_main/io/pican.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef PICAN_H
|
||||
#define PICAN_H
|
||||
|
||||
#include "piiodevice.h"
|
||||
|
||||
|
||||
class PIP_EXPORT PICAN: public PIIODevice
|
||||
{
|
||||
PIIODEVICE(PICAN)
|
||||
public:
|
||||
explicit PICAN(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
|
||||
~PICAN() {}
|
||||
|
||||
protected:
|
||||
bool openDevice();
|
||||
bool closeDevice();
|
||||
int readDevice(void * read_to, int max_size);
|
||||
int writeDevice(const void * data, int max_size);
|
||||
|
||||
void setCANID(int id);
|
||||
int CANID() const;
|
||||
|
||||
PIString fullPathPrefix() const {return PIStringAscii("can");}
|
||||
PIString constructFullPathDevice() const;
|
||||
void configureFromFullPathDevice(const PIString & full_path);
|
||||
DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Reliable;}
|
||||
|
||||
private:
|
||||
int sock;
|
||||
int can_id;
|
||||
};
|
||||
|
||||
#endif // PICAN_H
|
||||
Reference in New Issue
Block a user