시리얼 통신중 데이터가 사라지는 문제

paeksj98의 이미지

while(main_run_stat)
{
FD_ZERO(&read_fds);
FD_SET(m_handle, &read_fds);
res = select(m_handle+1, &read_fds, NULL, NULL, NULL);

rxcnt = read(m_handle, rxbuff, sizeof(rxbuff));

int SerialThrProc::SerialOpen()
{

struct termios oldtio,newtio;
m_handle = open("/dev/ttySAC2",O_RDWR | O_NOCTTY);
tcgetattr(m_handle, &oldtio);
memset(&newtio,0,sizeof(newtio));

newtio.c_cflag=B460800 | CS8 | CLOCAL | CREAD;
newtio.c_iflag=IGNPAR;
newtio.c_oflag=0;
newtio.c_lflag=0;
newtio.c_cc[VTIME]=1;
newtio.c_cc[VMIN]=0;
tcflush(m_handle,TCIFLUSH);
tcsetattr(m_handle,TCSANOW,&newtio);

return m_handle;
}

예) 통신데이터
stx,1,2,3,4,5,~100,etx
stx,1,2,3,4,5,~20,etx
stx,1,2,3,4,5,~150,etx
stx,1,2,3,4,5,~10,etx
stx,1,2,3,4,5,~22,etx
stx,1,2,3,4,5,~44,etx
stx,1,2,3,4,5,~80,etx
stx,1,2,3,4,5,~15,etx

시리얼 통신을 메인코어와 서브코어사이에 통신을 하는데 문제가 있습니다.
115200에서는 stx데이터에서 etx데이까지 정상적으로 통신이 됩니다.
921600에서는 통신데이터까 깨져서 들어오고
460800에서는 5번에 한번 정도는 stx부터 데이터가 들어오긴 하는데 뒤쪽 몇바이트가 계속 짤리네요.

read할때 뒤쪽 부분이 안들어와서 다시한번 읽어보면 뛰쪽 바이트는 사라지고 다음 프레임이 바로 들어오네요.
실제 문제가 있는 통신예
stx,1,2,3,4,5,~100,etx(완료)
stx,1,2,3,4,5,~20,etx(완료)
stx,1,2,3,4,5,~(한번더 read)
stx,1,2,3,4,5,~10,etx(바로전 못받은 데이터가 받아져야 하는데 그건 사라지고 다음 프레임이 read되는 문제가 있네요.

위와 같은 경우 어떤식으로 해결을 해야 하나요..??

bushi의 이미지

http://en.wikipedia.org/wiki/High-Level_Data_Link_Control

글 끝부분에 "PPP in HDLC-like Framing" 란 제목으로 RFC1662 로 링크가 걸려있는게 보이실 겁니다.

framing 기법에 대한 개념만 잡히시면,
주의해야 할 것들을 침착하게 추려내셔서 본인의 상황에 맞도록 적당히 간추린 프로토콜을 설계하실 수 있을 겁니다.

paeksj98의 이미지

공부좀 해야겠습니다.

여기 산적한 버그에 헤어나오질 못하고 있네요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.