Give water to plants if dry amd pla meanwhile music the music vou can define with note length bind and breake also select several instruments for the sound

Dependencies:   mbed

Committer:
helmut
Date:
Wed Sep 19 14:16:56 2012 +0000
Revision:
0:5150b09127e3
plays mostly music that you can do with notes length breakes and bind; Some already defined; Tool is to start a pump for water to give plant is too dry.; Meanwhie plays music the most part of all

Who changed what in which revision?

UserRevisionLine numberNew contents of line
helmut 0:5150b09127e3 1
helmut 0:5150b09127e3 2 /*
helmut 0:5150b09127e3 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
helmut 0:5150b09127e3 4
helmut 0:5150b09127e3 5 Permission is hereby granted, free of charge, to any person obtaining a copy
helmut 0:5150b09127e3 6 of this software and associated documentation files (the "Software"), to deal
helmut 0:5150b09127e3 7 in the Software without restriction, including without limitation the rights
helmut 0:5150b09127e3 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
helmut 0:5150b09127e3 9 copies of the Software, and to permit persons to whom the Software is
helmut 0:5150b09127e3 10 furnished to do so, subject to the following conditions:
helmut 0:5150b09127e3 11
helmut 0:5150b09127e3 12 The above copyright notice and this permission notice shall be included in
helmut 0:5150b09127e3 13 all copies or substantial portions of the Software.
helmut 0:5150b09127e3 14
helmut 0:5150b09127e3 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
helmut 0:5150b09127e3 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
helmut 0:5150b09127e3 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
helmut 0:5150b09127e3 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
helmut 0:5150b09127e3 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
helmut 0:5150b09127e3 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
helmut 0:5150b09127e3 21 THE SOFTWARE.
helmut 0:5150b09127e3 22 */
helmut 0:5150b09127e3 23
helmut 0:5150b09127e3 24 /** \file
helmut 0:5150b09127e3 25 TCP Socket header file
helmut 0:5150b09127e3 26 */
helmut 0:5150b09127e3 27
helmut 0:5150b09127e3 28 #ifndef TCPSOCKET_H
helmut 0:5150b09127e3 29 #define TCPSOCKET_H
helmut 0:5150b09127e3 30
helmut 0:5150b09127e3 31 #include "core/net.h"
helmut 0:5150b09127e3 32 #include "core/host.h"
helmut 0:5150b09127e3 33 //Essentially it is a safe interface to NetTcpSocket
helmut 0:5150b09127e3 34
helmut 0:5150b09127e3 35 ///TCP Socket error codes
helmut 0:5150b09127e3 36 enum TCPSocketErr
helmut 0:5150b09127e3 37 {
helmut 0:5150b09127e3 38 __TCPSOCKET_MIN = -0xFFFF,
helmut 0:5150b09127e3 39 TCPSOCKET_SETUP, ///<TCPSocket not properly configured
helmut 0:5150b09127e3 40 TCPSOCKET_TIMEOUT, ///<Connection timed out
helmut 0:5150b09127e3 41 TCPSOCKET_IF, ///<Interface has problems, does not exist or is not initialized
helmut 0:5150b09127e3 42 TCPSOCKET_MEM, ///<Not enough mem
helmut 0:5150b09127e3 43 TCPSOCKET_INUSE, ///<Interface / Port is in use
helmut 0:5150b09127e3 44 TCPSOCKET_EMPTY, ///<Connections queue is empty
helmut 0:5150b09127e3 45 TCPSOCKET_RST, ///<Connection was reset by remote host
helmut 0:5150b09127e3 46 //...
helmut 0:5150b09127e3 47 TCPSOCKET_OK = 0 ///<Success
helmut 0:5150b09127e3 48 };
helmut 0:5150b09127e3 49
helmut 0:5150b09127e3 50 ///TCP Socket Events
helmut 0:5150b09127e3 51 enum TCPSocketEvent
helmut 0:5150b09127e3 52 {
helmut 0:5150b09127e3 53 TCPSOCKET_CONNECTED, ///<Connected to host
helmut 0:5150b09127e3 54 TCPSOCKET_ACCEPT, ///<Client is connected, must call accept() to get a new Socket
helmut 0:5150b09127e3 55 TCPSOCKET_READABLE, ///<Data in buf
helmut 0:5150b09127e3 56 TCPSOCKET_WRITEABLE, ///<Can write data to buf
helmut 0:5150b09127e3 57 TCPSOCKET_CONTIMEOUT, ///<Connection timed out
helmut 0:5150b09127e3 58 TCPSOCKET_CONRST, ///<Connection was reset by remote host
helmut 0:5150b09127e3 59 TCPSOCKET_CONABRT, ///<Connection was aborted
helmut 0:5150b09127e3 60 TCPSOCKET_ERROR, ///<Unknown error
helmut 0:5150b09127e3 61 TCPSOCKET_DISCONNECTED ///<Disconnected
helmut 0:5150b09127e3 62 };
helmut 0:5150b09127e3 63
helmut 0:5150b09127e3 64 class NetTcpSocket;
helmut 0:5150b09127e3 65 enum NetTcpSocketEvent;
helmut 0:5150b09127e3 66
helmut 0:5150b09127e3 67 ///This is a simple TCP Socket class
helmut 0:5150b09127e3 68 /**
helmut 0:5150b09127e3 69 This class exposes an API to deal with TCP Sockets
helmut 0:5150b09127e3 70 */
helmut 0:5150b09127e3 71 class TCPSocket
helmut 0:5150b09127e3 72 {
helmut 0:5150b09127e3 73 public:
helmut 0:5150b09127e3 74 ///Creates a new socket
helmut 0:5150b09127e3 75 TCPSocket();
helmut 0:5150b09127e3 76 protected:
helmut 0:5150b09127e3 77 TCPSocket(NetTcpSocket* pNetTcpSocket);
helmut 0:5150b09127e3 78 public:
helmut 0:5150b09127e3 79 ///Closes if needed and destroys the socket
helmut 0:5150b09127e3 80 ~TCPSocket(); //close()
helmut 0:5150b09127e3 81
helmut 0:5150b09127e3 82 ///Binds the socket to (local) host
helmut 0:5150b09127e3 83 TCPSocketErr bind(const Host& me);
helmut 0:5150b09127e3 84
helmut 0:5150b09127e3 85 ///Starts listening
helmut 0:5150b09127e3 86 TCPSocketErr listen();
helmut 0:5150b09127e3 87
helmut 0:5150b09127e3 88 ///Connects socket to host
helmut 0:5150b09127e3 89 TCPSocketErr connect(const Host& host);
helmut 0:5150b09127e3 90
helmut 0:5150b09127e3 91 ///Accepts connection from client and gets connected socket
helmut 0:5150b09127e3 92 TCPSocketErr accept(Host* pClient, TCPSocket** ppNewTcpSocket);
helmut 0:5150b09127e3 93
helmut 0:5150b09127e3 94 ///Sends data
helmut 0:5150b09127e3 95 /*
helmut 0:5150b09127e3 96 @return a negative error code or the number of bytes transmitted
helmut 0:5150b09127e3 97 */
helmut 0:5150b09127e3 98 int /*if < 0 : TCPSocketErr*/ send(const char* buf, int len);
helmut 0:5150b09127e3 99
helmut 0:5150b09127e3 100 ///Receives data
helmut 0:5150b09127e3 101 /*
helmut 0:5150b09127e3 102 @return a negative error code or the number of bytes received
helmut 0:5150b09127e3 103 */
helmut 0:5150b09127e3 104 int /*if < 0 : TCPSocketErr*/ recv(char* buf, int len);
helmut 0:5150b09127e3 105
helmut 0:5150b09127e3 106 /* TODO NTH : printf / scanf helpers that call send/recv */
helmut 0:5150b09127e3 107
helmut 0:5150b09127e3 108 ///Closes socket
helmut 0:5150b09127e3 109 TCPSocketErr close();
helmut 0:5150b09127e3 110
helmut 0:5150b09127e3 111 //Callbacks
helmut 0:5150b09127e3 112 ///Setups callback
helmut 0:5150b09127e3 113 /**
helmut 0:5150b09127e3 114 @param pMethod : callback function
helmut 0:5150b09127e3 115 */
helmut 0:5150b09127e3 116 void setOnEvent( void (*pMethod)(TCPSocketEvent) );
helmut 0:5150b09127e3 117
helmut 0:5150b09127e3 118 class CDummy;
helmut 0:5150b09127e3 119 ///Setups callback
helmut 0:5150b09127e3 120 /**
helmut 0:5150b09127e3 121 @param pItem : instance of class on which to execute the callback method
helmut 0:5150b09127e3 122 @param pMethod : callback method
helmut 0:5150b09127e3 123 */
helmut 0:5150b09127e3 124 template<class T>
helmut 0:5150b09127e3 125 void setOnEvent( T* pItem, void (T::*pMethod)(TCPSocketEvent) )
helmut 0:5150b09127e3 126 {
helmut 0:5150b09127e3 127 m_pCbItem = (CDummy*) pItem;
helmut 0:5150b09127e3 128 m_pCbMeth = (void (CDummy::*)(TCPSocketEvent)) pMethod;
helmut 0:5150b09127e3 129 }
helmut 0:5150b09127e3 130
helmut 0:5150b09127e3 131 ///Disables callback
helmut 0:5150b09127e3 132 void resetOnEvent();
helmut 0:5150b09127e3 133
helmut 0:5150b09127e3 134 protected:
helmut 0:5150b09127e3 135 void onNetTcpSocketEvent(NetTcpSocketEvent e);
helmut 0:5150b09127e3 136 TCPSocketErr checkInst();
helmut 0:5150b09127e3 137
helmut 0:5150b09127e3 138 private:
helmut 0:5150b09127e3 139 NetTcpSocket* m_pNetTcpSocket;
helmut 0:5150b09127e3 140
helmut 0:5150b09127e3 141 CDummy* m_pCbItem;
helmut 0:5150b09127e3 142 void (CDummy::*m_pCbMeth)(TCPSocketEvent);
helmut 0:5150b09127e3 143
helmut 0:5150b09127e3 144 void (*m_pCb)(TCPSocketEvent);
helmut 0:5150b09127e3 145
helmut 0:5150b09127e3 146 };
helmut 0:5150b09127e3 147
helmut 0:5150b09127e3 148 #endif