Web server based weather station using Sparkfun Weather Meters.

Dependencies:   FatFileSystem mbed WeatherMeters SDFileSystem

Committer:
AdamGreen
Date:
Sat Feb 25 03:28:05 2012 +0000
Revision:
1:c7958aa34fa1
Parent:
0:616601bde9fb
Use published libraries where possible.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:616601bde9fb 1 /*****************************************************************************
AdamGreen 0:616601bde9fb 2 * fsm.h - Network Control Protocol Finite State Machine header file.
AdamGreen 0:616601bde9fb 3 *
AdamGreen 0:616601bde9fb 4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
AdamGreen 0:616601bde9fb 5 * Copyright (c) 1997 Global Election Systems Inc.
AdamGreen 0:616601bde9fb 6 *
AdamGreen 0:616601bde9fb 7 * The authors hereby grant permission to use, copy, modify, distribute,
AdamGreen 0:616601bde9fb 8 * and license this software and its documentation for any purpose, provided
AdamGreen 0:616601bde9fb 9 * that existing copyright notices are retained in all copies and that this
AdamGreen 0:616601bde9fb 10 * notice and the following disclaimer are included verbatim in any
AdamGreen 0:616601bde9fb 11 * distributions. No written agreement, license, or royalty fee is required
AdamGreen 0:616601bde9fb 12 * for any of the authorized uses.
AdamGreen 0:616601bde9fb 13 *
AdamGreen 0:616601bde9fb 14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
AdamGreen 0:616601bde9fb 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
AdamGreen 0:616601bde9fb 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
AdamGreen 0:616601bde9fb 17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
AdamGreen 0:616601bde9fb 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
AdamGreen 0:616601bde9fb 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
AdamGreen 0:616601bde9fb 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
AdamGreen 0:616601bde9fb 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AdamGreen 0:616601bde9fb 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
AdamGreen 0:616601bde9fb 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AdamGreen 0:616601bde9fb 24 *
AdamGreen 0:616601bde9fb 25 ******************************************************************************
AdamGreen 0:616601bde9fb 26 * REVISION HISTORY
AdamGreen 0:616601bde9fb 27 *
AdamGreen 0:616601bde9fb 28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
AdamGreen 0:616601bde9fb 29 * Ported to lwIP.
AdamGreen 0:616601bde9fb 30 * 97-11-05 Guy Lancaster <glanca@gesn.com>, Global Election Systems Inc.
AdamGreen 0:616601bde9fb 31 * Original based on BSD code.
AdamGreen 0:616601bde9fb 32 *****************************************************************************/
AdamGreen 0:616601bde9fb 33 /*
AdamGreen 0:616601bde9fb 34 * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions.
AdamGreen 0:616601bde9fb 35 *
AdamGreen 0:616601bde9fb 36 * Copyright (c) 1989 Carnegie Mellon University.
AdamGreen 0:616601bde9fb 37 * All rights reserved.
AdamGreen 0:616601bde9fb 38 *
AdamGreen 0:616601bde9fb 39 * Redistribution and use in source and binary forms are permitted
AdamGreen 0:616601bde9fb 40 * provided that the above copyright notice and this paragraph are
AdamGreen 0:616601bde9fb 41 * duplicated in all such forms and that any documentation,
AdamGreen 0:616601bde9fb 42 * advertising materials, and other materials related to such
AdamGreen 0:616601bde9fb 43 * distribution and use acknowledge that the software was developed
AdamGreen 0:616601bde9fb 44 * by Carnegie Mellon University. The name of the
AdamGreen 0:616601bde9fb 45 * University may not be used to endorse or promote products derived
AdamGreen 0:616601bde9fb 46 * from this software without specific prior written permission.
AdamGreen 0:616601bde9fb 47 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
AdamGreen 0:616601bde9fb 48 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
AdamGreen 0:616601bde9fb 49 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
AdamGreen 0:616601bde9fb 50 *
AdamGreen 0:616601bde9fb 51 * $Id: fsm.h,v 1.5 2009/12/31 17:08:08 goldsimon Exp $
AdamGreen 0:616601bde9fb 52 */
AdamGreen 0:616601bde9fb 53
AdamGreen 0:616601bde9fb 54 #ifndef FSM_H
AdamGreen 0:616601bde9fb 55 #define FSM_H
AdamGreen 0:616601bde9fb 56
AdamGreen 0:616601bde9fb 57 /*
AdamGreen 0:616601bde9fb 58 * LCP Packet header = Code, id, length.
AdamGreen 0:616601bde9fb 59 */
AdamGreen 0:616601bde9fb 60 #define HEADERLEN (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
AdamGreen 0:616601bde9fb 61
AdamGreen 0:616601bde9fb 62
AdamGreen 0:616601bde9fb 63 /*
AdamGreen 0:616601bde9fb 64 * CP (LCP, IPCP, etc.) codes.
AdamGreen 0:616601bde9fb 65 */
AdamGreen 0:616601bde9fb 66 #define CONFREQ 1 /* Configuration Request */
AdamGreen 0:616601bde9fb 67 #define CONFACK 2 /* Configuration Ack */
AdamGreen 0:616601bde9fb 68 #define CONFNAK 3 /* Configuration Nak */
AdamGreen 0:616601bde9fb 69 #define CONFREJ 4 /* Configuration Reject */
AdamGreen 0:616601bde9fb 70 #define TERMREQ 5 /* Termination Request */
AdamGreen 0:616601bde9fb 71 #define TERMACK 6 /* Termination Ack */
AdamGreen 0:616601bde9fb 72 #define CODEREJ 7 /* Code Reject */
AdamGreen 0:616601bde9fb 73
AdamGreen 0:616601bde9fb 74
AdamGreen 0:616601bde9fb 75 /*
AdamGreen 0:616601bde9fb 76 * Each FSM is described by an fsm structure and fsm callbacks.
AdamGreen 0:616601bde9fb 77 */
AdamGreen 0:616601bde9fb 78 typedef struct fsm {
AdamGreen 0:616601bde9fb 79 int unit; /* Interface unit number */
AdamGreen 0:616601bde9fb 80 u_short protocol; /* Data Link Layer Protocol field value */
AdamGreen 0:616601bde9fb 81 int state; /* State */
AdamGreen 0:616601bde9fb 82 int flags; /* Contains option bits */
AdamGreen 0:616601bde9fb 83 u_char id; /* Current id */
AdamGreen 0:616601bde9fb 84 u_char reqid; /* Current request id */
AdamGreen 0:616601bde9fb 85 u_char seen_ack; /* Have received valid Ack/Nak/Rej to Req */
AdamGreen 0:616601bde9fb 86 int timeouttime; /* Timeout time in milliseconds */
AdamGreen 0:616601bde9fb 87 int maxconfreqtransmits; /* Maximum Configure-Request transmissions */
AdamGreen 0:616601bde9fb 88 int retransmits; /* Number of retransmissions left */
AdamGreen 0:616601bde9fb 89 int maxtermtransmits; /* Maximum Terminate-Request transmissions */
AdamGreen 0:616601bde9fb 90 int nakloops; /* Number of nak loops since last ack */
AdamGreen 0:616601bde9fb 91 int maxnakloops; /* Maximum number of nak loops tolerated */
AdamGreen 0:616601bde9fb 92 struct fsm_callbacks* callbacks; /* Callback routines */
AdamGreen 0:616601bde9fb 93 char* term_reason; /* Reason for closing protocol */
AdamGreen 0:616601bde9fb 94 int term_reason_len; /* Length of term_reason */
AdamGreen 0:616601bde9fb 95 } fsm;
AdamGreen 0:616601bde9fb 96
AdamGreen 0:616601bde9fb 97
AdamGreen 0:616601bde9fb 98 typedef struct fsm_callbacks {
AdamGreen 0:616601bde9fb 99 void (*resetci)(fsm*); /* Reset our Configuration Information */
AdamGreen 0:616601bde9fb 100 int (*cilen)(fsm*); /* Length of our Configuration Information */
AdamGreen 0:616601bde9fb 101 void (*addci)(fsm*, u_char*, int*); /* Add our Configuration Information */
AdamGreen 0:616601bde9fb 102 int (*ackci)(fsm*, u_char*, int); /* ACK our Configuration Information */
AdamGreen 0:616601bde9fb 103 int (*nakci)(fsm*, u_char*, int); /* NAK our Configuration Information */
AdamGreen 0:616601bde9fb 104 int (*rejci)(fsm*, u_char*, int); /* Reject our Configuration Information */
AdamGreen 0:616601bde9fb 105 int (*reqci)(fsm*, u_char*, int*, int); /* Request peer's Configuration Information */
AdamGreen 0:616601bde9fb 106 void (*up)(fsm*); /* Called when fsm reaches LS_OPENED state */
AdamGreen 0:616601bde9fb 107 void (*down)(fsm*); /* Called when fsm leaves LS_OPENED state */
AdamGreen 0:616601bde9fb 108 void (*starting)(fsm*); /* Called when we want the lower layer */
AdamGreen 0:616601bde9fb 109 void (*finished)(fsm*); /* Called when we don't want the lower layer */
AdamGreen 0:616601bde9fb 110 void (*protreject)(int); /* Called when Protocol-Reject received */
AdamGreen 0:616601bde9fb 111 void (*retransmit)(fsm*); /* Retransmission is necessary */
AdamGreen 0:616601bde9fb 112 int (*extcode)(fsm*, int, u_char, u_char*, int); /* Called when unknown code received */
AdamGreen 0:616601bde9fb 113 char *proto_name; /* String name for protocol (for messages) */
AdamGreen 0:616601bde9fb 114 } fsm_callbacks;
AdamGreen 0:616601bde9fb 115
AdamGreen 0:616601bde9fb 116
AdamGreen 0:616601bde9fb 117 /*
AdamGreen 0:616601bde9fb 118 * Link states.
AdamGreen 0:616601bde9fb 119 */
AdamGreen 0:616601bde9fb 120 #define LS_INITIAL 0 /* Down, hasn't been opened */
AdamGreen 0:616601bde9fb 121 #define LS_STARTING 1 /* Down, been opened */
AdamGreen 0:616601bde9fb 122 #define LS_CLOSED 2 /* Up, hasn't been opened */
AdamGreen 0:616601bde9fb 123 #define LS_STOPPED 3 /* Open, waiting for down event */
AdamGreen 0:616601bde9fb 124 #define LS_CLOSING 4 /* Terminating the connection, not open */
AdamGreen 0:616601bde9fb 125 #define LS_STOPPING 5 /* Terminating, but open */
AdamGreen 0:616601bde9fb 126 #define LS_REQSENT 6 /* We've sent a Config Request */
AdamGreen 0:616601bde9fb 127 #define LS_ACKRCVD 7 /* We've received a Config Ack */
AdamGreen 0:616601bde9fb 128 #define LS_ACKSENT 8 /* We've sent a Config Ack */
AdamGreen 0:616601bde9fb 129 #define LS_OPENED 9 /* Connection available */
AdamGreen 0:616601bde9fb 130
AdamGreen 0:616601bde9fb 131 /*
AdamGreen 0:616601bde9fb 132 * Flags - indicate options controlling FSM operation
AdamGreen 0:616601bde9fb 133 */
AdamGreen 0:616601bde9fb 134 #define OPT_PASSIVE 1 /* Don't die if we don't get a response */
AdamGreen 0:616601bde9fb 135 #define OPT_RESTART 2 /* Treat 2nd OPEN as DOWN, UP */
AdamGreen 0:616601bde9fb 136 #define OPT_SILENT 4 /* Wait for peer to speak first */
AdamGreen 0:616601bde9fb 137
AdamGreen 0:616601bde9fb 138
AdamGreen 0:616601bde9fb 139 /*
AdamGreen 0:616601bde9fb 140 * Prototypes
AdamGreen 0:616601bde9fb 141 */
AdamGreen 0:616601bde9fb 142 void fsm_init (fsm*);
AdamGreen 0:616601bde9fb 143 void fsm_lowerup (fsm*);
AdamGreen 0:616601bde9fb 144 void fsm_lowerdown (fsm*);
AdamGreen 0:616601bde9fb 145 void fsm_open (fsm*);
AdamGreen 0:616601bde9fb 146 void fsm_close (fsm*, char*);
AdamGreen 0:616601bde9fb 147 void fsm_input (fsm*, u_char*, int);
AdamGreen 0:616601bde9fb 148 void fsm_protreject (fsm*);
AdamGreen 0:616601bde9fb 149 void fsm_sdata (fsm*, u_char, u_char, u_char*, int);
AdamGreen 0:616601bde9fb 150
AdamGreen 0:616601bde9fb 151
AdamGreen 0:616601bde9fb 152 /*
AdamGreen 0:616601bde9fb 153 * Variables
AdamGreen 0:616601bde9fb 154 */
AdamGreen 0:616601bde9fb 155 extern int peer_mru[]; /* currently negotiated peer MRU (per unit) */
AdamGreen 0:616601bde9fb 156
AdamGreen 0:616601bde9fb 157 #endif /* FSM_H */