当前位置:文档之家› 分析BACnet协议栈1

分析BACnet协议栈1

从现在开始分析BACnet协议栈了,版本号是bacnet-stack-0.7.1。目录是bacnet-stack-0.7.1\ports\linux\rs485.c

rs485.c文件主要要解决在物理层发送和接收数据的作用。不同的开发板需要移植该文件。

#include

#include

#include

#include

#include

#include

#include

/* Linux includes */

#include

#include

#include

#include

#include

#include

/* Local includes */

#include "mstp.h"

#include "rs485.h"

#include "fifo.h"

#include

#include

/* Posix serial programming reference:

/~mike/serial/serial.html */

/* Use ionice wrapper to improve serial performance:

$ sudo ionice -c 1 -n 0 ./bin/bacserv 12345

*/

/* handle returned from open() */

static int RS485_Handle = -1;

/* baudrate settings are defined in , which is

included by */

static unsigned int RS485_Baud = B38400;//波特率选择38400 bps

/* serial port name, /dev/ttyS0,

/dev/ttyUSB0 for USB->RS485 from B&B Electronics USOPTL4 */

static char *RS485_Port_Name = "/dev/ttyUSB0"; /*系统默认是通过USB转485的,根据需要设置,若你的开发板用485接口,则用static char *RS485_Port_Name = "/dev/ttyS0";代替*/

/* some terminal I/O have RS-485 specific functionality */

#ifndef RS485MOD

#define RS485MOD 0

#endif

/* serial I/O settings */

static struct termios RS485_oldtio;

/* Ring buffer for incoming bytes, in order to speed up the receiving. */ static FIFO_BUFFER Rx_FIFO;

/* buffer size needs to be a power of 2 */

static uint8_t Rx_Buffer[4096];

#define _POSIX_SOURCE 1 /* POSIX compliant source */

/*********************************************************************

* DESCRIPTION: Configures the interface name

* RETURN: none

* ALGORITHM: none

* NOTES: none

*********************************************************************/

void RS485_Set_Interface(

char *ifname)

{

/* note: expects a constant char, or char from the heap */

if (ifname) {

RS485_Port_Name = ifname;

}

}

/*********************************************************************

* DESCRIPTION: Returns the interface name

* RETURN: none

* ALGORITHM: none

* NOTES: none

*********************************************************************/

const char *RS485_Interface(

void)

{

return RS485_Port_Name;

}

/****************************************************************************

* DESCRIPTION: Returns the baud rate that we are currently running at * RETURN: none

* ALGORITHM: none

相关主题