【XR806开发板试用】1、UDP通信测试
上篇文章测试了XR806的UDP通信.
控制PWM控制相关的函数在device/xradio/xr806/adapter/hals/iot_hardware/wifiiot_lite文件夹下的iot_pwm.c
.
├── BUILD.gn
├── iot_flash.c
├── iot_gpio.c
├── iot_i2c.c
├── iot_pwm.c
├── iot_uart.c
├── iot_watchdog.c
├── lowpower.c
└── reset.c
//port 指定输出引脚
//duty 指定输出PWM占空比 范围1-99
//freq 指定PWM输出频率
unsigned int IoTPwmInit(unsigned int port);
unsigned int IoTPwmDeinit(unsigned int port);
unsigned int IoTPwmStart(unsigned int port, unsigned short duty,unsigned int freq);
unsigned int IoTPwmStop(unsigned int port);
#include "iot_pwm.h"
#define pwm_channl1 0U
#define pwm_channl2 1U
#define pwm_channl3 2U
#define pwm_channl4 3U
void udp_echoserver_init(void)
{
//略
//在udp初始化结束后初始化PWM输出引脚.
IoTPwmInit(pwm_channl1);
IoTPwmInit(pwm_channl2);
IoTPwmInit(pwm_channl3);
IoTPwmInit(pwm_channl4);
}
void udp_echoserver_receive_callback(void *arg, struct udp_pcb *upcb,struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
udp_connect(upcb, addr, UDP_CLIENT_PORT);
udp_send(upcb, p);
udpReceiveCallback(p->payload, p->len); //recave call
udp_disconnect(upcb);
pbuf_free(p);
}
//udp接收回调函数中根据接收到的数据控制PWM占空比.
void udpReceiveCallback(char *p, int len) //recave call
{
if(len<42+5)
return;
p+=42;
//p[0]留作开关量控制.
if(p[1]<5||p[1]>99)
IoTPwmStop(pwm_channl1);
else
IoTPwmStart(pwm_channl1, p[1], 2000);
if(p[2]<5||p[2]>99)
IoTPwmStop(pwm_channl2);
else
IoTPwmStart(pwm_channl2, p[2], 2000);
if(p[3]<5||p[3]>99)
IoTPwmStop(pwm_channl3);
else
IoTPwmStart(pwm_channl3, p[3], 2000);
if(p[4]<5||p[4]>99)
IoTPwmStop(pwm_channl4);
else
IoTPwmStart(pwm_channl4, p[4], 2000);