Small Testprogram to have WebAccess via Webserver to a 433Mhz tranmitter to control remotly some devices from remote, with TFTP, NTP and RMF. This could be a base to develop applications.

Dependencies:   ChaNFSSD TFTPServer RMFWeb

Dependents:   RMFWeb

Committer:
ED7418
Date:
Fri Jun 06 09:06:03 2014 +0000
Revision:
0:51f1ef89ec7b
06062014

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ED7418 0:51f1ef89ec7b 1
ED7418 0:51f1ef89ec7b 2 /*
ED7418 0:51f1ef89ec7b 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
ED7418 0:51f1ef89ec7b 4
ED7418 0:51f1ef89ec7b 5 Permission is hereby granted, free of charge, to any person obtaining a copy
ED7418 0:51f1ef89ec7b 6 of this software and associated documentation files (the "Software"), to deal
ED7418 0:51f1ef89ec7b 7 in the Software without restriction, including without limitation the rights
ED7418 0:51f1ef89ec7b 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
ED7418 0:51f1ef89ec7b 9 copies of the Software, and to permit persons to whom the Software is
ED7418 0:51f1ef89ec7b 10 furnished to do so, subject to the following conditions:
ED7418 0:51f1ef89ec7b 11
ED7418 0:51f1ef89ec7b 12 The above copyright notice and this permission notice shall be included in
ED7418 0:51f1ef89ec7b 13 all copies or substantial portions of the Software.
ED7418 0:51f1ef89ec7b 14
ED7418 0:51f1ef89ec7b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
ED7418 0:51f1ef89ec7b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
ED7418 0:51f1ef89ec7b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
ED7418 0:51f1ef89ec7b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
ED7418 0:51f1ef89ec7b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ED7418 0:51f1ef89ec7b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
ED7418 0:51f1ef89ec7b 21 THE SOFTWARE.
ED7418 0:51f1ef89ec7b 22 */
ED7418 0:51f1ef89ec7b 23
ED7418 0:51f1ef89ec7b 24 #ifndef LWIPNETUDPSOCKET_H
ED7418 0:51f1ef89ec7b 25 #define LWIPNETUDPSOCKET_H
ED7418 0:51f1ef89ec7b 26
ED7418 0:51f1ef89ec7b 27 #define NET_LWIP_STACK 1
ED7418 0:51f1ef89ec7b 28 //#include "lwip/ip_addr.h"
ED7418 0:51f1ef89ec7b 29 #include "if/net/netudpsocket.h"
ED7418 0:51f1ef89ec7b 30 #include "LwipNetIf.h"
ED7418 0:51f1ef89ec7b 31
ED7418 0:51f1ef89ec7b 32 #include "stdint.h"
ED7418 0:51f1ef89ec7b 33
ED7418 0:51f1ef89ec7b 34 #include <list>
ED7418 0:51f1ef89ec7b 35 using std::list;
ED7418 0:51f1ef89ec7b 36
ED7418 0:51f1ef89ec7b 37 //Implements NetUdpSockets over lwIP raw API
ED7418 0:51f1ef89ec7b 38
ED7418 0:51f1ef89ec7b 39 struct udp_pcb; //Represents a Udp Connection, "Protocol Control Block", see rawapi.txt & udp.h
ED7418 0:51f1ef89ec7b 40 struct pbuf; //Lwip Buffer Container
ED7418 0:51f1ef89ec7b 41 typedef struct ip_addr ip_addr_t;
ED7418 0:51f1ef89ec7b 42
ED7418 0:51f1ef89ec7b 43 //typedef signed char err_t;
ED7418 0:51f1ef89ec7b 44 typedef uint16_t u16_t;
ED7418 0:51f1ef89ec7b 45
ED7418 0:51f1ef89ec7b 46 class LwipNetUdpSocket: public NetUdpSocket
ED7418 0:51f1ef89ec7b 47 {
ED7418 0:51f1ef89ec7b 48 public:
ED7418 0:51f1ef89ec7b 49 LwipNetUdpSocket(udp_pcb* pPcb = NULL); //Passes a pcb if already created (by an accept req for instance), in that case transfers ownership
ED7418 0:51f1ef89ec7b 50 virtual ~LwipNetUdpSocket();
ED7418 0:51f1ef89ec7b 51
ED7418 0:51f1ef89ec7b 52 virtual NetUdpSocketErr bind(const Host& me);
ED7418 0:51f1ef89ec7b 53
ED7418 0:51f1ef89ec7b 54 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost);
ED7418 0:51f1ef89ec7b 55 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost);
ED7418 0:51f1ef89ec7b 56
ED7418 0:51f1ef89ec7b 57 virtual NetUdpSocketErr close();
ED7418 0:51f1ef89ec7b 58
ED7418 0:51f1ef89ec7b 59 virtual NetUdpSocketErr poll();
ED7418 0:51f1ef89ec7b 60
ED7418 0:51f1ef89ec7b 61 protected:
ED7418 0:51f1ef89ec7b 62 volatile udp_pcb* m_pPcb;
ED7418 0:51f1ef89ec7b 63
ED7418 0:51f1ef89ec7b 64 //Event callback from lwIp
ED7418 0:51f1ef89ec7b 65 void recvCb(udp_pcb* pcb, struct pbuf* p, ip_addr_t* addr, u16_t port);
ED7418 0:51f1ef89ec7b 66
ED7418 0:51f1ef89ec7b 67 private:
ED7418 0:51f1ef89ec7b 68 void cleanUp(); //Flush input buffer
ED7418 0:51f1ef89ec7b 69 struct InPacket
ED7418 0:51f1ef89ec7b 70 {
ED7418 0:51f1ef89ec7b 71 volatile pbuf* pBuf;
ED7418 0:51f1ef89ec7b 72 ip_addr_t addr;
ED7418 0:51f1ef89ec7b 73 u16_t port;
ED7418 0:51f1ef89ec7b 74 };
ED7418 0:51f1ef89ec7b 75
ED7418 0:51f1ef89ec7b 76 list<InPacket> m_lInPkt;
ED7418 0:51f1ef89ec7b 77 IpAddr m_multicastGroup;
ED7418 0:51f1ef89ec7b 78
ED7418 0:51f1ef89ec7b 79 //Static callback : Transforms into a C++ callback
ED7418 0:51f1ef89ec7b 80 static void sRecvCb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port);
ED7418 0:51f1ef89ec7b 81
ED7418 0:51f1ef89ec7b 82 };
ED7418 0:51f1ef89ec7b 83
ED7418 0:51f1ef89ec7b 84 #endif