i can get stuff over zmq now
parent
9b3e884aba
commit
55403fad86
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,78 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-c",
|
||||||
|
"-Og",
|
||||||
|
"-Wall",
|
||||||
|
"-fdata-sections",
|
||||||
|
"-ffunction-sections",
|
||||||
|
"-g3",
|
||||||
|
"-DDEBUG",
|
||||||
|
"-Icfg",
|
||||||
|
"-Iinc",
|
||||||
|
"-o",
|
||||||
|
"build/p_idp.o",
|
||||||
|
"src/p_idp.cpp"
|
||||||
|
],
|
||||||
|
"directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager",
|
||||||
|
"file": "src/p_idp.cpp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-c",
|
||||||
|
"-Og",
|
||||||
|
"-Wall",
|
||||||
|
"-fdata-sections",
|
||||||
|
"-ffunction-sections",
|
||||||
|
"-g3",
|
||||||
|
"-DDEBUG",
|
||||||
|
"-Icfg",
|
||||||
|
"-Iinc",
|
||||||
|
"-o",
|
||||||
|
"build/p_serial_bus.o",
|
||||||
|
"src/p_serial_bus.cpp"
|
||||||
|
],
|
||||||
|
"directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager",
|
||||||
|
"file": "src/p_serial_bus.cpp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-c",
|
||||||
|
"-Og",
|
||||||
|
"-Wall",
|
||||||
|
"-fdata-sections",
|
||||||
|
"-ffunction-sections",
|
||||||
|
"-g3",
|
||||||
|
"-DDEBUG",
|
||||||
|
"-Icfg",
|
||||||
|
"-Iinc",
|
||||||
|
"-o",
|
||||||
|
"build/p_serial_packet.o",
|
||||||
|
"src/p_serial_packet.cpp"
|
||||||
|
],
|
||||||
|
"directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager",
|
||||||
|
"file": "src/p_serial_packet.cpp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-c",
|
||||||
|
"-Og",
|
||||||
|
"-Wall",
|
||||||
|
"-fdata-sections",
|
||||||
|
"-ffunction-sections",
|
||||||
|
"-g3",
|
||||||
|
"-DDEBUG",
|
||||||
|
"-Icfg",
|
||||||
|
"-Iinc",
|
||||||
|
"-o",
|
||||||
|
"build/main.o",
|
||||||
|
"src/main.cpp"
|
||||||
|
],
|
||||||
|
"directory": "/storage/Shared/Projects/Penguinator/pi_serial_bus_manager",
|
||||||
|
"file": "src/main.cpp"
|
||||||
|
}
|
||||||
|
]
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __P_IDP_H__
|
||||||
|
#define __P_IDP_H__
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <zmq.hpp>
|
||||||
|
#endif
|
@ -1,63 +1,34 @@
|
|||||||
#include <cstring>
|
#include "p_serial_bus.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <linux/serial.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <stdlib.h>
|
||||||
|
#include <zmq.hpp>
|
||||||
|
|
||||||
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
|
#define SERIAL_DEV ("/dev/ttyAMA1")
|
||||||
#include <sys/ioctl.h>
|
#define ZMQ_IPC_ADDR ("ipc:///penguinator/pubsub")
|
||||||
|
|
||||||
int main()
|
void sigint_handler(int param)
|
||||||
{
|
|
||||||
uint8_t send_buffer[14] = {0x7E, 0x01, 0x02, 8, 0x01, 0x02, 0x03,
|
|
||||||
0x7D, 0x5E, 0x05, 0x06, 0x07, 0x08, 0xFF};
|
|
||||||
|
|
||||||
/* Open your specific device (e.g., /dev/mydevice): */
|
|
||||||
int fd = open("/dev/ttyAMA1", O_RDWR);
|
|
||||||
if (fd < 0)
|
|
||||||
{
|
{
|
||||||
/* Error handling. See errno. */
|
std::cout << "Exiting..." << std::endl;
|
||||||
fprintf(stderr, "Failed... error:%s", strerror(errno));
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct serial_rs485 rs485conf;
|
int main()
|
||||||
|
|
||||||
/* Enable RS485 mode: */
|
|
||||||
rs485conf.flags |= SER_RS485_ENABLED;
|
|
||||||
|
|
||||||
/* Set logical level for RTS pin equal to 1 when sending: */
|
|
||||||
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
|
|
||||||
/* or, set logical level for RTS pin equal to 0 when sending: */
|
|
||||||
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
|
|
||||||
|
|
||||||
/* Set logical level for RTS pin equal to 1 after sending: */
|
|
||||||
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
|
|
||||||
/* or, set logical level for RTS pin equal to 0 after sending: */
|
|
||||||
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
|
|
||||||
|
|
||||||
// /* Set rts delay before send, if needed: */
|
|
||||||
// rs485conf.delay_rts_before_send = ...;
|
|
||||||
|
|
||||||
// /* Set rts delay after send, if needed: */
|
|
||||||
// rs485conf.delay_rts_after_send = ...;
|
|
||||||
|
|
||||||
/* Set this flag if you want to receive data even while sending data */
|
|
||||||
// rs485conf.flags |= SER_RS485_RX_DURING_TX;
|
|
||||||
|
|
||||||
if (ioctl(fd, TIOCSRS485, &rs485conf) < 0)
|
|
||||||
{
|
{
|
||||||
/* Error handling. See errno. */
|
signal(SIGINT, sigint_handler);
|
||||||
}
|
ps_bus sbus(SERIAL_DEV);
|
||||||
|
zmq::context_t ctx;
|
||||||
/* Use read() and write() syscalls here... */
|
zmq::socket_t sub(ctx, ZMQ_SUB);
|
||||||
ssize_t rc = 0;
|
sub.connect(ZMQ_IPC_ADDR);
|
||||||
write(fd, send_buffer, 14);
|
sub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
|
||||||
|
|
||||||
/* Close the device when finished: */
|
for (;;)
|
||||||
if (close(fd) < 0)
|
|
||||||
{
|
{
|
||||||
/* Error handling. See errno. */
|
zmq::message_t msg;
|
||||||
|
sub.recv(&msg, 0);
|
||||||
|
std::cout << msg << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
#include "p_idp.h"
|
@ -0,0 +1,64 @@
|
|||||||
|
#include "p_serial_bus.h"
|
||||||
|
#include <cstring>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <linux/serial.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Include definition for RS485 ioctls: TIOCGRS485 and TIOCSRS485 */
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
ps_bus::ps_bus(const char* dev)
|
||||||
|
{
|
||||||
|
/* Open your specific device (e.g., /dev/mydevice): */
|
||||||
|
int fd = open(dev, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
/* Error handling. See errno. */
|
||||||
|
fprintf(stderr, "Creation of the bus failed... error: %s",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct serial_rs485 rs485conf;
|
||||||
|
|
||||||
|
/* Enable RS485 mode: */
|
||||||
|
rs485conf.flags |= SER_RS485_ENABLED;
|
||||||
|
|
||||||
|
/* Set logical level for RTS pin equal to 1 when sending: */
|
||||||
|
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
|
||||||
|
/* or, set logical level for RTS pin equal to 0 when sending: */
|
||||||
|
rs485conf.flags &= ~(SER_RS485_RTS_ON_SEND);
|
||||||
|
|
||||||
|
/* Set logical level for RTS pin equal to 1 after sending: */
|
||||||
|
rs485conf.flags |= SER_RS485_RTS_AFTER_SEND;
|
||||||
|
/* or, set logical level for RTS pin equal to 0 after sending: */
|
||||||
|
rs485conf.flags &= ~(SER_RS485_RTS_AFTER_SEND);
|
||||||
|
|
||||||
|
// /* Set rts delay before send, if needed: */
|
||||||
|
// rs485conf.delay_rts_before_send = ...;
|
||||||
|
|
||||||
|
// /* Set rts delay after send, if needed: */
|
||||||
|
// rs485conf.delay_rts_after_send = ...;
|
||||||
|
|
||||||
|
/* Set this flag if you want to receive data even while sending data */
|
||||||
|
// rs485conf.flags |= SER_RS485_RX_DURING_TX;
|
||||||
|
|
||||||
|
if (ioctl(fd, TIOCSRS485, &rs485conf) < 0)
|
||||||
|
{
|
||||||
|
/* Error handling. See errno. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ps_bus::~ps_bus()
|
||||||
|
{
|
||||||
|
/* Close the device when finished: */
|
||||||
|
if (close(dev_fd) < 0)
|
||||||
|
{
|
||||||
|
/* Error handling. See errno. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ps_bus::ps_bus_start()
|
||||||
|
{}
|
@ -1,19 +1,40 @@
|
|||||||
#include "p_serial_packet.h"
|
#include "p_serial_packet.h"
|
||||||
|
|
||||||
ps_packet::ps_packet()
|
ps_packet::ps_packet(uint8_t* data)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
ps_packet::~ps_packet()
|
ps_packet::~ps_packet()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// takes members and prepares the buffer for transmission
|
// takes members and prepares the buffer for transmission
|
||||||
bool ps_packet::encode(uint8_t* buffer)
|
bool ps_packet::encode()
|
||||||
{}
|
{
|
||||||
|
bool ret = true;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool ps_packet::decode()
|
bool ps_packet::decode()
|
||||||
{}
|
{
|
||||||
|
bool ret = true;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool ps_packet::validate()
|
bool ps_packet::validate()
|
||||||
{}
|
{
|
||||||
|
bool ret = true;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
void ps_packet::calc_checksum()
|
void ps_packet::calc_checksum()
|
||||||
{}
|
{}
|
||||||
|
Loading…
Reference in New Issue