Modify:删除旧版的rtmp推流的feature和原有的串口通信类,改用libserial进行串口通信

This commit is contained in:
Pulsar-V 2021-08-26 22:16:58 +08:00
parent 2a99201e30
commit 2d6ba5629c
8 changed files with 0 additions and 486 deletions

View File

@ -1,8 +0,0 @@
//
// Created by PulsarV on 18-5-16.
//
#ifndef ROBOCAR_RCRTMP_H
#define ROBOCAR_RCRTMP_H
#endif //ROBOCAR_RCRTMP_H

View File

@ -1,165 +0,0 @@
//
// Created by PulsarV on 18-10-26.
//
#ifndef ROBOCAR_JY901_H
#define ROBOCAR_JY901_H
#define SAVE 0x00
#define CALSW 0x01
#define RSW 0x02
#define RRATE 0x03
#define BAUD 0x04
#define AXOFFSET 0x05
#define AYOFFSET 0x06
#define AZOFFSET 0x07
#define GXOFFSET 0x08
#define GYOFFSET 0x09
#define GZOFFSET 0x0a
#define HXOFFSET 0x0b
#define HYOFFSET 0x0c
#define HZOFFSET 0x0d
#define D0MODE 0x0e
#define D1MODE 0x0f
#define D2MODE 0x10
#define D3MODE 0x11
#define D0PWMH 0x12
#define D1PWMH 0x13
#define D2PWMH 0x14
#define D3PWMH 0x15
#define D0PWMT 0x16
#define D1PWMT 0x17
#define D2PWMT 0x18
#define D3PWMT 0x19
#define IICADDR 0x1a
#define LEDOFF 0x1b
#define GPSBAUD 0x1c
#define YYMM 0x30
#define DDHH 0x31
#define MMSS 0x32
#define MS 0x33
#define AX 0x34
#define AY 0x35
#define AZ 0x36
#define GX 0x37
#define GY 0x38
#define GZ 0x39
#define HX 0x3a
#define HY 0x3b
#define HZ 0x3c
#define Roll 0x3d
#define Pitch 0x3e
#define Yaw 0x3f
#define TEMP 0x40
#define D0Status 0x41
#define D1Status 0x42
#define D2Status 0x43
#define D3Status 0x44
#define PressureL 0x45
#define PressureH 0x46
#define HeightL 0x47
#define HeightH 0x48
#define LonL 0x49
#define LonH 0x4a
#define LatL 0x4b
#define LatH 0x4c
#define GPSHeight 0x4d
#define GPSYAW 0x4e
#define GPSVL 0x4f
#define GPSVH 0x50
#define DIO_MODE_AIN 0
#define DIO_MODE_DIN 1
#define DIO_MODE_DOH 2
#define DIO_MODE_DOL 3
#define DIO_MODE_DOPWM 4
#define DIO_MODE_GPS 5
struct JY901DATA{
unsigned char data1;
unsigned char data2;
unsigned char data3;
unsigned char data4;
unsigned char data5;
unsigned char data6;
unsigned char data7;
unsigned char data8;
unsigned char data9;
unsigned char data10;
unsigned char sum;
};
struct STime
{
unsigned char ucYear;
unsigned char ucMonth;
unsigned char ucDay;
unsigned char ucHour;
unsigned char ucMinute;
unsigned char ucSecond;
unsigned short usMiliSecond;
};
struct SAcc
{
short a[3];
short T;
};
struct SGyro
{
short w[3];
short T;
};
struct SAngle
{
short Angle[3];
short T;
};
struct SMag
{
short h[3];
short T;
};
struct SDStatus
{
short sDStatus[4];
};
struct SPress
{
long lPressure;
long lAltitude;
};
struct SLonLat
{
long lLon;
long lLat;
};
struct SGPSV
{
short sGPSHeight;
short sGPSYaw;
long lGPSVelocity;
};
class CJY901
{
public:
struct STime stcTime;
struct SAcc stcAcc;
struct SGyro stcGyro;
struct SAngle stcAngle;
struct SMag stcMag;
struct SDStatus stcDStatus;
struct SPress stcPress;
struct SLonLat stcLonLat;
struct SGPSV stcGPSV;
CJY901 ();
void CopeSerialData(char ucData[],unsigned short usLength);
};
//extern CJY901 JY901;
void CharToLong(char Dest[],char Source[]);
#endif //ROBOCAR_JY901_H

View File

@ -1,13 +0,0 @@
//
// Created by PulsarV on 18-5-15.
//
#include <rc_serial/rcserial.h>
namespace RC{
class GyroDevice:public Serial{
public:
void setBackContent(char **arg);
void setBackSpeed(int speed);
void getContent(char *buffer,int size);
};
}

View File

@ -1,59 +0,0 @@
//
// Created by PulsarV on 18-5-10.
//
#ifndef ROBOCAR_RCSERIAL_H
#define ROBOCAR_RCSERIAL_H
#include <rc_log/rclog.h>
#include <fcntl.h>
#include <iostream>
#include <rc_globalVarable/rc_global_serial.h>
#include <rc_serial/imu_device/JY901.h>
#include <map>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
#include <zconf.h>
#include <linux/serial.h>
namespace RC {
int set_serial(int fd, int nSpeed, int nBits, char nEvent, int nStop);
typedef std::map<std::string, std::string> SERIAL_FLAGS;
typedef std::pair<std::string, std::string> SERIAL_FLAG;
class Serial {
public:
int open_serial(const std::string& serial_device_path);
int send(const std::string& str);
int send(long comm);
int recive(char *buffer, int size);
bool is_opend();
int release();
static int data_encode(int data);
static int data_encode(char data);
static int data_encode(std::string data);
private:
int device_point;
char *device;
};
}
#endif //ROBOCAR_RCSERIAL_H

View File

@ -1,4 +0,0 @@
//
// Created by PulsarV on 18-5-14.
//

View File

@ -1,9 +0,0 @@
//
// Created by PulsarV on 18-10-26.
//
void CharToLong(char Dest[],char Source[]){
*Dest = Source[3];
*(Dest+1) = Source[2];
*(Dest+2) = Source[1];
*(Dest+3) = Source[0];
}

View File

@ -1,64 +0,0 @@
//
// Created by PulsarV on 18-5-15.
//
#include <rc_serial/rc_gyro_serial.h>
#include <rc_serial/rcserial.h>
#include <rc_log/slog.hpp>
#ifdef __linux__
void RC::GyroDevice::setBackSpeed(int speed) {
switch (speed) {
case GYRO_0D1HZ:
this->send(GYRO_SERIAL_BACK_SPEED_0D1HZ);
break;
case GYRO_0D5HZ:
this->send(GYRO_SERIAL_BACK_SPEED_0D5HZ);
break;
case GYRO_1HZ:
this->send(GYRO_SERIAL_BACK_SPEED_1HZ);
break;
case GYRO_2HZ:
this->send(GYRO_SERIAL_BACK_SPEED_2HZ);
break;
case GYRO_5HZ:
this->send(GYRO_SERIAL_BACK_SPEED_5HZ);
break;
case GYRO_10HZ:
this->send(GYRO_SERIAL_BACK_SPEED_10HZ);
break;
case GYRO_20HZ:
this->send(GYRO_SERIAL_BACK_SPEED_20HZ);
break;
case GYRO_50HZ:
this->send(GYRO_SERIAL_BACK_SPEED_5HZ);
break;
case GYRO_100HZ:
this->send(GYRO_SERIAL_BACK_SPEED_100HZ);
break;
case GYRO_200HZ:
this->send(GYRO_SERIAL_BACK_SPEED_200HZ);
break;
case GYRO_ONCE:
this->send(GYRO_SERIAL_BACK_SPEED_ONCE);
break;
case GYRO_CLOSE:
this->send(GYRO_SERIAL_BACK_SPEED_CLOSE);
break;
default:
slog::info<<GYRO_COMMOND_ERROE<<slog::endl;
break;
}
}
void RC::GyroDevice::getContent(char *buffer, int size) {
this->send(GYRO_SERIAL_BACK_SPEED_ONCE);
this->recive(buffer, size);
}
void RC::GyroDevice::setBackContent(char **arg) {
}
#endif // __linux__

View File

@ -1,164 +0,0 @@
//
// Created by norse on 17-4-19.
//
#include <rc_serial/rcserial.h>
#include <cstring>
#include <rc_log/slog.hpp>
int RC::Serial::recive(char *buffer, int size) {
if (this->is_opend()) {
int nread = read(this->device_point, buffer, sizeof(size));
if (nread < 0) {
printf("read data error!!\n");
return -2;
}
}
return -1;
}
int RC::Serial::send(const std::string& str) {
const char *commond = str.c_str();
int wr_num = write(this->device_point, commond, str.length());
if (wr_num)return 1;
return 0;
}
int RC::Serial::send(long comm) {
char *commond = (char *) comm;
int wr_num = write(this->device_point, &comm, sizeof(comm));
if (wr_num)return 1;
return 0;
}
int RC::Serial::data_encode(int data) {
return 0;
}
int RC::Serial::data_encode(char data) {
return 0;
}
int RC::Serial::data_encode(std::string data) {
return 0;
}
int RC::set_serial(int fd, int nSpeed, int nBits, char nEvent, int nStop) {
struct termios newttys1, oldttys1; /*保存原有串口配置*/
if (tcgetattr(fd, &oldttys1) != 0) {
perror("Setupserial 1");
return -1;
}
bzero(&newttys1, sizeof(newttys1));
newttys1.c_cflag |= (CLOCAL | CREAD); /*CREAD 开启串行数据接收CLOCAL并打开本地连接模式*/
newttys1.c_cflag &= ~CSIZE;/*设置数据位*/
/*数据位选择*/
switch (nBits) {
case 7:
newttys1.c_cflag |= CS7;
break;
case 8:
newttys1.c_cflag |= CS8;
break;
}
/*设置奇偶校验位*/
switch (nEvent) {
case '0': /*奇校验*/
newttys1.c_cflag |= PARENB;/*开启奇偶校验*/
newttys1.c_iflag |= (INPCK | ISTRIP);/*INPCK打开输入奇偶校验ISTRIP去除字符的第八个比特 */
newttys1.c_cflag |= PARODD;/*启用奇校验(默认为偶校验)*/
break;
case 'E':/*偶校验*/
newttys1.c_cflag |= PARENB; /*开启奇偶校验 */
newttys1.c_iflag |= (INPCK | ISTRIP);/*打开输入奇偶校验并去除字符第八个比特*/
newttys1.c_cflag &= ~PARODD;/*启用偶校验*/ break;
case 'N': /*无奇偶校验*/
newttys1.c_cflag &= ~PARENB;
break;
} /*设置波特率*/
switch (nSpeed) {
case 2400:
cfsetispeed(&newttys1, B2400);
cfsetospeed(&newttys1, B2400);
break;
case 4800:
cfsetispeed(&newttys1, B4800);
cfsetospeed(&newttys1, B4800);
break;
case 9600:
cfsetispeed(&newttys1, B9600);
cfsetospeed(&newttys1, B9600);
break;
case 115200:
cfsetispeed(&newttys1, B115200);
cfsetospeed(&newttys1, B115200);
break;
default:
cfsetispeed(&newttys1, B9600);
cfsetospeed(&newttys1, B9600);
break;
} /*设置停止位*/
/*设置停止位若停止位为1则清除CSTOPB若停止位为2则激活CSTOPB*/
if (nStop == 1) {
newttys1.c_cflag &= ~CSTOPB;/*默认为一位停止位; */
} else if (nStop == 2) {
newttys1.c_cflag |= CSTOPB;/*CSTOPB表示送两位停止位*/
}
/*设置最少字符和等待时间,对于接收字符和等待时间没有特别的要求时*/
newttys1.c_cc[VTIME] = 0;/*非规范模式读取时的超时时间;*/
newttys1.c_cc[VMIN] = 0; /*非规范模式读取时的最小字符数*/
tcflush(fd, TCIFLUSH);/*tcflush清空终端未完成的输入/输出请求及数据TCIFLUSH表示清空正收到的数据且不读取出来 */
/*激活配置使其生效*/
if ((tcsetattr(fd, TCSANOW, &newttys1)) != 0) {
perror("com set error");
return -1;
}
return 0;
}
int jy901_data_analyse(char *buff, JY901DATA *gps_data) {
char *ptr = NULL;
if (gps_data == NULL) {
return -1;
}
if (strlen(buff) < 10) {
return -1;
}
/*如果buff字符串中包含字符"$GPRMC"则将$GPRMC的地址赋值给ptr*/
if (NULL == (ptr = strstr(buff, "$GPRMC"))) {
return -1;
}
// sscanf(ptr, "$GPRMC,%d.000,%c,%f,N,%f,E,%f,%f,%d,,,%c*", &(gps_data->time), &(gps_data->pos_state),
// &(gps_data->latitude), &(gps_data->longitude), &(gps_data->speed), &(gps_data->direction), &(gps_data->date),
// &(gps_data->mode));
/*sscanf函数为从字符串输入上面这句话的意思是将ptr内存单元的值作为输入分别输入到后面的结构体成员*/
return 0;
}
bool RC::Serial::is_opend() {
return this->device_point != RC_SERIAL_ERROR;
}
int RC::Serial::open_serial(const std::string& serial_device_path) {
this->device_point = open(serial_device_path.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);//O_NDELAY
if (this->device_point < 0) {
slog::err<<RC_SERIAL_STRING_USB_OPEN_ERROR<<" :"<<serial_device_path<<slog::endl;
return -1;
}
slog::success<<"Open Serial Device: "<<serial_device_path<<slog::endl;
set_serial(this->device_point, 9600, 8, 'O', 1);
}
int RC::Serial::release() {
if (this->device_point) {
tcflush(this->device_point, TCIOFLUSH);
close(this->device_point);
}
return 0;
}