linux 串列埠 拼幀處理

2022-06-10 11:30:16 字數 2687 閱讀 3170

串列埠每次read資料可能不是完整的資料,參照網上的**,寫了拼幀的**#include

#include 

#include

#include

#include

#include

#include

int speed_arr =;

int name_arr = ;/**

*@brief set serial port bitrate

*@param fd type : int the file description of serial port

*@param speed type : int serial speed

*@return void

*/void set_speed(int fd, int

speed)

tcflush(fd,tcioflush);

}}}/*

**@brief set serial port databits, stopbits and parity.

*@param fd type: int the file description of serial port

*@param databits type: int databits 7 or 8

*@param stopbits type: int stopbits 1 or 2

*@param parity type: int parity type: n,n,e,e,o,o,s,s

*/int set_parity(int fd, int databits, int parity, int

stopbits)

options.c_cflag &= ~csize;

switch (databits) /*

set datebits

*/

switch (parity) /*

set parity

*/

switch (stopbits) /*

set stobits

*/

/*set input parity option

*/if (parity != 'n'

) options.c_iflag |=inpck;

/*以下兩句新增後傳送方可以不加回車換行,但是read讀取不完整

*/options.c_lflag &= ~(icanon | echo | echoe | isig); /*

input

*/options.c_oflag &= ~opost; /*

output

*///

遮蔽功能: nl(換行)->cr(回車)、cr->nl、忽略輸入回車

options.c_iflag &= ~(inlcr | icrnl |igncr);

options.c_oflag &= ~(onlcr |ocrnl);

tcflush(fd,tciflush);

//未設定o_nonblock或o_ndelay

options.c_cc[vtime] = 150; /*

timeout in 15 seconds

*/options.c_cc[vmin] = 0; /*

update the options and do it now

*/if (tcsetattr(fd,tcsanow,&options) != 0

)

return(0);}

void print_frame(unsigned char *buf,int

size)

printf("\n

");}void getcompleteframe(unsigned char *inbuf,int incnt,unsigned char *outbuf,int *destcnt,int *readstatus)

if(*readstatus == 1)//

body

if(*destcnt == outbuf[2] && *readstatus == 1)//

tail

}}int main(void);

int nread = 0

; fd = open("

/dev/ttys0

", o_rdwr|o_noctty);

if (fd > 0

)

else

set_speed(fd,

115200

);

if(set_parity(fd, 8, '

n', 1) == -1

)

int i = 0, rc = 0

;

int flag = 0

; fd_set rset;

struct

timeval tv;

int read_status = 0

;

int dest_cnt = 0

;

while (1) //

迴圈讀取資料

} }

}close(fd);

return0;

}

Chain TDNN LSTM的拼幀索引 延時

tdnn模型示例 tdnn拼幀 第8層 0,3 第7層 9,0 第6層 0,3 第5層 6,0 第4層 0,3 第3層 3,0 第2層 0,3 第1層 3,0 輸出依賴 要在輸出層處輸出第1幀,各層需要的幀的時間索引如下 第8層 1,4 第7層 9,6,1,4 第6層 9,6,1,4,7 第5層 1...

zhuan 串列埠成幀協議

串列埠成幀協議 串列埠接收中的問題 在電子系統中,最簡單 最廣泛的通訊方式無疑是串列埠了,幾乎所有與模組相關的產品,差不多都有串列埠的操作方式,如串列埠藍芽模組 串列埠wifi模組 串列埠zigbee模組 串列埠語音模組等。不僅是這樣,在嵌入式開發中,很多時侯除錯離不開串列埠,韌體公升級離不開串列埠...

串列埠通訊的幀同步問題

封裝stm32串列埠的底層時,遇到了串列埠幀同步的問題。雖然以前也遇到類似場合,寫出來的 基本能夠解決問題,但是在邏輯上總是不能徹底的解釋一些細節。當前的工作環境 串列埠的方案是開啟收發的dma以及dma的中斷。堅決不考慮直接使用串列埠中斷。乙個位元組中斷一次太費資源 dma陣列作為串列埠的fifo...