Browse Source

update

master
tianjialong 2 years ago
parent
commit
bab227d6fa
  1. 9
      .clang-format
  2. 6
      .vscode/settings.json
  3. 54
      main.c

9
.clang-format

@ -0,0 +1,9 @@
# Defines the Chromium style for automatic reformatting.
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 120
AlignConsecutiveMacros: true
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
AlignOperands: true

6
.vscode/settings.json

@ -0,0 +1,6 @@
{
"files.associations": {
"strings.h": "c",
"stat.h": "c"
}
}

54
main.c

@ -1,21 +1,18 @@
#include <error.h>
#include <fcntl.h>
#include <malloc.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <error.h>
#include <termios.h>
#include <malloc.h>
#include <sys/types.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
typedef struct termios termios_t;
typedef struct serial_data
{
typedef struct serial_data {
char databuf[100]; // /
int serfd; //
@ -24,8 +21,7 @@ typedef struct serial_data
void *sersend(void *arg);
void *serrecv(void *arg);
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
pthread_t pid1, pid2;
pthread_attr_t *pthread_arr1, *pthread_arr2;
pthread_arr1 = NULL;
@ -36,8 +32,7 @@ int main(int argc, char *argv[])
termios_t *ter_s = malloc(sizeof(*ter_s));
serport1fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY); //
if (serport1fd < 0)
{
if (serport1fd < 0) {
printf("%s open faild\r\n", argv[1]);
return -1;
}
@ -70,8 +65,7 @@ int main(int argc, char *argv[])
tcflush(serport1fd, TCIFLUSH); // /
if (tcsetattr(serport1fd, TCSANOW, ter_s) != 0)
{
if (tcsetattr(serport1fd, TCSANOW, ter_s) != 0) {
printf("com set error!\r\n");
}
@ -90,9 +84,7 @@ int main(int argc, char *argv[])
pthread_create(&pid2, pthread_arr2, serrecv, (void *)&rec_data);
ssize_t sizec;
while (1)
{
while (1) {
usleep(100000);
}
@ -106,15 +98,11 @@ void *sersend(void *arg) // 串口发送线程函数
{
ser_Data *snd = (ser_Data *)arg;
int ret;
while (1)
{
while (1) {
ret = write(snd->serfd, snd->databuf, strlen(snd->databuf));
if (ret > 0)
{
if (ret > 0) {
printf("send success, data is %s\r\n", snd->databuf);
}
else
{
} else {
printf("send error!\r\n");
}
usleep(300000);
@ -129,15 +117,11 @@ void *serrecv(void *arg) // 串口发送线程函数
{
ser_Data *rec = (ser_Data *)arg;
int ret;
while (1)
{
while (1) {
ret = read(rec->serfd, rec->databuf, 1024);
if (ret > 0)
{
if (ret > 0) {
printf("recv success,recv size is %d,data is %s\r\n", ret, rec->databuf);
}
else
{
} else {
/*
*/

Loading…
Cancel
Save