bt_mt_rs232.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:2k
- #ifndef _BT_MT_RS232_H_
- #include "bt_mt_rs232.h"
- #endif
- //=============================================================================
- CBTMTRS232::CBTMTRS232(void)
- {
- EventLen = 0;
- EventType = EVTTYPE_NONE;
- }
- //-----------------------------------------------
- bool CBTMTRS232::SetTransport(int port_no, long baudrate, int ena_flowctrl)
- {
- bool ok;
- ok = rs232.Open(port_no, baudrate, 8, 0, 0, 0, ena_flowctrl, 0);
- return ok;
- }
- //-----------------------------------------------
- int CBTMTRS232::SendCommand(unsigned char *command, int len)
- {
- int ok;
- ok = rs232.SendData(command, len);
- return ok;
- }
- //-----------------------------------------------
- int CBTMTRS232::ReadEvent(void)
- {
- int len, len2;
- unsigned char *p, ch;
- long last_read_pos;
- int ok;
- last_read_pos = rs232.pos_read;
- len = rs232.ReadData( &ch, 1 ) ;
- if (len==0)
- {
- return 0;
- }
- ok = 0;
- EventLen = len;
- p = EventBuf;
- *p++ = ch;
- if (ch==0x04) // HCI_event
- {
- EventType = EVTTYPE_EVENT;
- len = rs232.ReadData( p, 2 ) ;
- EventLen += len;
- if (len==2)
- {
- len = p[1]; p = &(p[2]); ok = 1;
- }
- }
- else if (ch==0x03) // SCO Data
- {
- EventType = EVTTYPE_SCO;
- len = rs232.ReadData( p, 3 ) ;
- EventLen += len;
- if (len==3)
- { len = p[2]; p = &(p[3]); ok = 1;
- }
- }
- else if (ch==0x02) // ACL Data
- {
- EventType = EVTTYPE_ACL;
- len = rs232.ReadData( p, 4 ) ;
- EventLen += len;
- if (len==4)
- {
- len = (p[3]<<8)+p[2]; p = &(p[4]); ok = 1;
- }
- }
- else
- {
- }
- if (ok)
- {
- len2 = rs232.ReadData( p, len) ;
- EventLen += len2;
- if (len!=len2)
- { ok = 0;
- }
- }
- if (!ok)
- {
- EventType = EVTTYPE_NONE;
- rs232.pos_read = last_read_pos;
- ConsumeErrorEvent();
- rs232.LogRXQposition();
- return 0;
- }
- rs232.LogRXQposition();
- return 1;
- }
- //-----------------------------------------------
- void CBTMTRS232::ConsumeErrorEvent(void )
- {
- }
- //=============================================================================