六 数据的采集与发送(开发板 客户端)
我现模似一下数据的采集,着重于在数据的发送上。我以tcp客服端为例。
#include <RTL.h>
#include <stdio.h>
#include <LM3Sxxxx.H>
#include <string.h>
//IP 等配置信息
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
// <h>Remote IP Address
// ====================
//
// <o>IP1: Address byte 1 <0-255>
// <i> Default: 192
#define IP1 192
// <o>IP2: Address byte 2 <0-255>
// <i> Default: 168
#define IP2 168
// <o>IP3: Address byte 3 <0-255>
// <i> Default: 0
#define IP3 14
// <o>IP4: Address byte 4 <0-255>
// <i> Default: 100
#define IP4 8
// </h>
// <o>Remote Port <1-65535>
// <i> Do not set number of port too small,
// <i> maybe it is already used.
// <i> Default: 1001
#define PORT_NUM 1001
// <o>Communication Protocol <0=> TCP <1=> UDP
// <i> Selecet a protocol for sending data.
#define PROTOCOL 1
// <o>LED Blinking speed <1-100>
// <i> Blinking speed = SPEED * 100ms
// <i> Default: 2
#define SPEED 2
//------------- <<< end of configuration section >>> -----------------------
#define BLINKLED 0x01 /* Command for blink the leds on board */
#define SENDLEN 2 /* Number of bytes to send */
#define TCP 1
BOOL tick;
U8 socket_tcp;
U8 Rem_IP[4] = {IP1,IP2,IP3,IP4};
static void init () {//初始化
SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL |
SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOF);
GPIOPadConfigSet (GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA,
GPIO_PIN_TYPE_STD);
GPIODirModeSet (GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT);
SysTickPeriodSet(SysCtlClockGet() / 10);
SysTickEnable();
}
|