Wifly Driver  V1.0
Udp.c
Go to the documentation of this file.
1 /*
2  * Udp.c
3  *
4  * Created on: 25/12/2015
5  * Author: Victor
6  */
7 #include "LPC17xx.h"
8 #include <stdio.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include "Type.h"
12 
13 #include "WiFly.h"
14 #include "Udp.h"
15 #include "FreeRTOS.h"
16 #include "semphr.h"
17 
18 
19 #define UDP_SEND "SET VALUE=%d"
20 #define UDP_RECEIVE "GET RANDOM VALUE"
21 #define UDP_SET_RESPONSE "SET OK"
22 #define UDP_GET_RESPONSE "GET OK"
23 
24 #define IP_REMOTE 80
25 #define IP_PROTO 18
26 
27 xSemaphoreHandle xMutexUdp;
28 static char *Udpssid;
29 static char *UdpPasw;
30 static uint32_t UdpAuthMode;
31 
32 
33 
41 uint8_t Udp_start(char *ssid, uint32_t AuthMode, char *passw)
42 {
43  uint8_t rtn= FALSE;
44  if( xMutexUdp == NULL )
45  {
46  xMutexUdp = xSemaphoreCreateMutex();
47  }
48  /*S'utilitza el semàfor per inicialitzar el Port */
49  xSemaphoreTakeRecursive( xMutexUdp, portMAX_DELAY );
50  {
51  Udpssid = ssid;
52  UdpAuthMode =AuthMode;
53  UdpPasw= passw;
54  }
55  xSemaphoreGiveRecursive( xMutexUdp );
56 
57  return rtn;
58 }
59 
60 uint8_t Udp_sendValue( char *ipAddress, uint32_t localPort, uint32_t remotePort, uint32_t value)
61 {
62  uint8_t rtn= FALSE;
63  char commRemote[128];
64 
65  xSemaphoreTakeRecursive( xMutexUdp, portMAX_DELAY );
66  {
67  if(Wifly_WLANConnectPing(UdpAuthMode, Udpssid, UdpPasw, ipAddress)==TRUE)
68  {
69  sprintf(commRemote, UDP_SEND,value);
70  if(Wifly_UDPSend(ipAddress, localPort, remotePort, UDP_SET_RESPONSE, commRemote)==TRUE)
71  rtn=TRUE;
72 
73  }
74  }
75  xSemaphoreGiveRecursive( xMutexUdp );
76 
77  return rtn;
78 }
79 
80 int32_t Udp_receiveValue( char *address, uint32_t localPort, uint32_t remotePort)
81 {
82  int32_t value;
83  char* resp;
84 
85  xSemaphoreTakeRecursive( xMutexUdp, portMAX_DELAY );
86  {
87  if(Wifly_WLANConnectPing(UdpAuthMode, Udpssid, UdpPasw, address)==TRUE)
88  {
89  resp= Wifly_UDPReceive(address, localPort, remotePort, UDP_RECEIVE);
90 
91  resp=strstr(resp, "VALUE=") + strlen("VALUE=");
92  value = strtol(resp , &resp, 10);
93 
94  }
95  }
96  xSemaphoreGiveRecursive( xMutexUdp );
97 
98  return value;
99 }
#define UDP_SEND
Definition: Udp.c:19
xSemaphoreHandle xMutexUdp
Definition: Udp.c:27
int32_t Udp_receiveValue(char *address, uint32_t localPort, uint32_t remotePort)
Definition: Udp.c:80
uint8_t Wifly_WLANConnectPing(uint32_t AuthMode, char *ssid, char *passw, char *pingIP)
Definition: WiFly.c:408
#define FALSE
Definition: type.h:22
char resp[BUFSIZE]
Definition: Arpalab.c:32
#define TRUE
Definition: type.h:26
#define UDP_RECEIVE
Definition: Udp.c:20
#define NULL
Definition: type.h:18
uint8_t Udp_start(char *ssid, uint32_t AuthMode, char *passw)
Definition: Udp.c:41
uint8_t Udp_sendValue(char *ipAddress, uint32_t localPort, uint32_t remotePort, uint32_t value)
Definition: Udp.c:60
char * Wifly_UDPReceive(char *address, uint32_t localPort, uint32_t remotePort, const char *restrict command,...)
Definition: WiFly.c:955
#define UDP_SET_RESPONSE
Definition: Udp.c:21
uint8_t Wifly_UDPSend(char *address, uint32_t localPort, uint32_t remotePort, char *exResp, const char *restrict command,...)
Definition: WiFly.c:978