“把原来单一串口单一传感器改成多串口多传感器模式”
parent
0d85bc6f2f
commit
9f61f98cab
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,51 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by hyz on 2024/6/5.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef WEATHERCOMM_H
|
|
||||||
#define WEATHERCOMM_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "GPIOControl.h"
|
|
||||||
|
|
||||||
#define MAX_STRING_LEN 32
|
|
||||||
#define IOT_PARAM_WRITE 0xAE
|
|
||||||
#define IOT_PARAM_READ 0xAF
|
|
||||||
|
|
||||||
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, "serial_port_comm", fmt, ##args)
|
|
||||||
|
|
||||||
// 串口参数
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int baudrate; /* 波特率*/
|
|
||||||
int databit; /* 数据位*/
|
|
||||||
char stopbit[8]; /* 停止位*/
|
|
||||||
char parity; /* 校验位*/
|
|
||||||
char pathname[128];/* 串口文件名及路径*/
|
|
||||||
} SERIAL_PARAM;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int m_iRevStatus; /* */
|
|
||||||
int m_iRecvLen; /* */
|
|
||||||
int m_iNeedRevLength; /* */
|
|
||||||
int iRecvTime; /* */
|
|
||||||
int RevCmdFlag;
|
|
||||||
unsigned char m_au8RecvBuf[128];/* */
|
|
||||||
} SIO_PARAM_SERIAL_DEF;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int cmd;
|
|
||||||
int value;
|
|
||||||
int result;
|
|
||||||
long value2;
|
|
||||||
char str[MAX_STRING_LEN];
|
|
||||||
}IOT_PARAM;
|
|
||||||
|
|
||||||
void PortDataProcess( void );
|
|
||||||
int serial_port_comm();
|
|
||||||
static int weather_comm(SERIAL_PARAM weatherport);
|
|
||||||
int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin );
|
|
||||||
|
|
||||||
#endif //WEATHERCOMM_H
|
|
@ -0,0 +1,117 @@
|
|||||||
|
#include <jni.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <linux/spi/spidev.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "GPIOControl.h"
|
||||||
|
#include "serialComm.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void set_baudrate (struct termios *opt, unsigned int baudrate)
|
||||||
|
{
|
||||||
|
cfsetispeed(opt, baudrate);
|
||||||
|
cfsetospeed(opt, baudrate);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_data_bit (struct termios *opt, unsigned int databit)
|
||||||
|
{
|
||||||
|
opt->c_cflag &= ~CSIZE;
|
||||||
|
switch (databit)
|
||||||
|
{
|
||||||
|
case 8:
|
||||||
|
opt->c_cflag |= CS8;
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
opt->c_cflag |= CS7;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
opt->c_cflag |= CS6;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
opt->c_cflag |= CS5;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
opt->c_cflag |= CS8;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_parity (struct termios *opt, char parity)
|
||||||
|
{
|
||||||
|
switch (parity)
|
||||||
|
{
|
||||||
|
case'N':/* 无校验 */
|
||||||
|
case 'n':
|
||||||
|
opt->c_cflag &= ~PARENB;
|
||||||
|
break;
|
||||||
|
case'E':/*偶校验*/
|
||||||
|
case 'e':
|
||||||
|
opt->c_cflag |= PARENB;
|
||||||
|
opt->c_cflag &= ~PARODD;
|
||||||
|
break;
|
||||||
|
case'O':/* 奇校验 */
|
||||||
|
case 'o':
|
||||||
|
opt->c_cflag |= PARENB;
|
||||||
|
opt->c_cflag |= ~PARODD;
|
||||||
|
break;
|
||||||
|
default: /*其它选择为无校验 */
|
||||||
|
opt->c_cflag &= ~PARENB;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_stopbit (struct termios *opt, const char *stopbit)
|
||||||
|
{
|
||||||
|
if (strcmp(stopbit, "1") == 0)
|
||||||
|
{
|
||||||
|
opt->c_cflag &= ~CSTOPB;/*1 位停止位 t */
|
||||||
|
}
|
||||||
|
else if(0 == strcmp(stopbit, "1.5"))
|
||||||
|
{
|
||||||
|
opt->c_cflag &= ~CSTOPB;/*1.5 位停止位 */
|
||||||
|
}
|
||||||
|
else if(0 == strcmp (stopbit,"2"))
|
||||||
|
{
|
||||||
|
opt->c_cflag |= CSTOPB; /*2 位停止位 */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opt->c_cflag &= ~CSTOPB; /*1 位停止位 */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin )
|
||||||
|
{
|
||||||
|
struct termios opt;
|
||||||
|
tcgetattr(fd, &opt);
|
||||||
|
set_baudrate(&opt, baudrate);
|
||||||
|
//opt.c_cflag |= CLOCAL|CREAD; /*|CRTSCTS */
|
||||||
|
opt.c_lflag &= ~(ICANON | ECHO |ECHOE |ISIG);
|
||||||
|
set_data_bit(&opt, databit);
|
||||||
|
set_parity(&opt, parity);
|
||||||
|
set_stopbit(&opt, stopbit);
|
||||||
|
opt.c_iflag &=~(INLCR|ICRNL);
|
||||||
|
opt.c_iflag &=~(IXON);/* 流控*/
|
||||||
|
opt.c_oflag = 0;
|
||||||
|
//opt.c_lflag |= 0;
|
||||||
|
opt.c_oflag &= ~OPOST;
|
||||||
|
opt.c_cc[VTIME] = vtime;
|
||||||
|
opt.c_cc[VMIN] = vmin;
|
||||||
|
tcflush (fd, TCIFLUSH);
|
||||||
|
return (tcsetattr (fd, TCSANOW, &opt));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by hyz on 2024/6/5.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SERIAL_COMM_BASE89656_H
|
||||||
|
#define SERIAL_COMM_BASE89656_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "GPIOControl.h"
|
||||||
|
|
||||||
|
#define MAX_STRING_LEN 32
|
||||||
|
#define IOT_PARAM_WRITE 0xAE
|
||||||
|
#define IOT_PARAM_READ 0xAF
|
||||||
|
|
||||||
|
#define LOGE(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, "serial_port_comm", fmt, ##args)
|
||||||
|
|
||||||
|
int set_port_attr (int fd, int baudrate, int databit, const char *stopbit, char parity, int vtime, int vmin );
|
||||||
|
|
||||||
|
#endif //SERIAL_COMM_BASE89656_H
|
Loading…
Reference in New Issue