می خواستم بدونم برنامش چطوری عمل میکنه؟
من برنامه ی EXAMPLEش رو دارم ولی نمیدونم در حالت کلی چطور عمل می کنه تا در واقع یه اطلاعاتی بدست بیارم که براساس اون بشه الگوریتم اصلی رو فهمید تا برنامه ای معادل واسش نوشت؟
اگر ممکنه هرقدر که در موردش می دونید کمک کنید؟
اصل برنامه:
/************************************************** ****************
***** *****
***** Name: easyweb.c *****
***** Ver.: 1.0 *****
***** Date: 07/05/2001 *****
***** Auth: Andreas Dannenberg *****
***** HTWK Leipzig *****
***** university of applied sciences *****
***** Germany *****
***** Func: implements a dynamic HTTP-server by using *****
***** the easyWEB-API *****
***** *****
************************************************** ****************/
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
"LPC17xx.h"
#define
extern
#include
"easyweb.h"
#include
"type.h"
#include
"EMAC.h"
#include
"tcpip.h"
#include
"webpage.h")
unsigned
int pagecounter = 100;
unsigned
int adcValue = 0;
extern
void TCPClockHandler(void);
volatile
DWORD TimeTick = 0;
/* SysTick interrupt happens every 10 ms */
void
SysTick_Handler (void) {
TimeTick++;
if (TimeTick >= 20) {
TimeTick = 0;
LPC_GPIO2->FIOPIN ^= 1 << 0;
TCPClockHandler();
}
}
//void main(void)
int
main(void)
{
//InitOsc(); // Keil: No oscillator initialization necessary at this time.
//InitPorts(); // Keil: No port initialization necessary at this time.
SystemInit();
/* setup core clocks */
SysTick_Config(SystemFrequency/100);
/* Generate interrupt every 10 ms */
LPC_GPIO0->FIODIR |= 1 << 21;
// ÉèÖÃLEDÓÐЧ
LPC_GPIO0->FIOPIN |= 1 << 21;
LPC_GPIO2->FIODIR |= 1 << 0;
/* P2.0 defined as Output (LED) */
LPC_PINCON->PINSEL3 |= (3ul<<30);
/* P1.31 is AD0.5 */
LPC_SC->PCONP |= (1<<12);
/* Enable power to ADC block */
LPC_ADC->ADCR = (1<< 5) |
/* select AD0.5 pin */
(4<< 8) |
/* ADC clock is 25MHz/5 */
(1<<21);
/* enable ADC */
TCPLowLevelInit();
/*
*(unsigned char *)RemoteIP = 24; // uncomment those lines to get the
*((unsigned char *)RemoteIP + 1) = 8; // quote of the day from a real
*((unsigned char *)RemoteIP + 2) = 69; // internet server! (gateway must be
*((unsigned char *)RemoteIP + 3) = 7; // set to your LAN-router)
TCPLocalPort = 2025;
TCPRemotePort = TCP_PORT_QOTD;
TCPActiveOpen();
while (SocketStatus & SOCK_ACTIVE) // read the quote from memory
{ // by using the hardware-debugger
DoNetworkStuff();
}
*/
HTTPStatus = 0;
// clear HTTP-server's flag register
TCPLocalPort = TCP_PORT_HTTP;
// set port we want to listen to
while (1) // repeat forever
{
if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen(); // listen for incoming TCP-connection
DoNetworkStuff();
// handle network and easyWEB-stack
// events
HTTPServer();
}
}
void
HTTPServer(void)
{
if (SocketStatus & SOCK_CONNECTED) // check if somebody has connected to our TCP
{
if (SocketStatus & SOCK_DATA_AVAILABLE) // check if remote TCP sent data
TCPReleaseRxBuffer();
// and throw it away
if (SocketStatus & SOCK_TX_BUF_RELEASED) // check if buffer is free for TX
{
if (!(HTTPStatus & HTTP_SEND_PAGE)) // init byte-counter and pointer to webside
{
// if called the 1st time
HTTPBytesToSend =
sizeof(WebSide) - 1; // get HTML length, ignore trailing zero
PWebSide = (
unsignedchar *)WebSide; // pointer to HTML-code
}
if (HTTPBytesToSend > MAX_TCP_TX_DATA_SIZE) // transmit a segment of MAX_SIZE
{
if (!(HTTPStatus & HTTP_SEND_PAGE)) // 1st time, include HTTP-header
{
memcpy(TCP_TX_BUF, GetResponse,
sizeof(GetResponse) - 1);
memcpy(TCP_TX_BUF + sizeof(GetResponse) - 1, PWebSide, MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1);
HTTPBytesToSend -= MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1;
PWebSide += MAX_TCP_TX_DATA_SIZE - sizeof(GetResponse) + 1;
}
else
{
memcpy(TCP_TX_BUF, PWebSide, MAX_TCP_TX_DATA_SIZE);
HTTPBytesToSend -= MAX_TCP_TX_DATA_SIZE;
PWebSide += MAX_TCP_TX_DATA_SIZE;
}
TCPTxDataCount = MAX_TCP_TX_DATA_SIZE;
// bytes to xfer
InsertDynamicValues();
// exchange some strings...
TCPTransmitTxBuffer();
// xfer buffer
}
elseif (HTTPBytesToSend) // transmit leftover bytes
{
memcpy(TCP_TX_BUF, PWebSide, HTTPBytesToSend);
TCPTxDataCount = HTTPBytesToSend;
// bytes to xfer
InsertDynamicValues();
// exchange some strings...
TCPTransmitTxBuffer();
// send last segment
TCPClose();
// and close connection
HTTPBytesToSend = 0;
// all data sent
}
HTTPStatus |= HTTP_SEND_PAGE;
// ok, 1st loop executed
}
}
else
HTTPStatus &= ~HTTP_SEND_PAGE;
// reset help-flag if not connected
}
// samples and returns the AD-converter value of channel 2
unsigned
int GetAD7Val(void)
{
// Keil: function replaced to handle LPC1768 A/D converter.
unsignedint val;
LPC_ADC->ADCR |= (1<<24); /* start conversion */
while (!(LPC_ADC->ADGDR & (1UL<<31))); /* Wait for Conversion end */
val = ((LPC_ADC->ADGDR >> 4) & 0xFFF);
/* read converted value */
LPC_ADC->ADCR &= ~(7<<24);
/* stop conversion */
return(val); /* result of A/D process */
}
//
void InsertDynamicValues(void)
{
unsignedchar *Key;
char NewKey[5];
unsignedint i;
if (TCPTxDataCount < 4) return; // there can't be any special string
Key = TCP_TX_BUF;
for (i = 0; i < (TCPTxDataCount - 3); i++)
{
if (*Key == 'A')
if (*(Key + 1) == 'D')
if (*(Key + 3) == '%')
switch (*(Key + 2))
{
case'8' : // "AD8%"?
{
adcValue = GetAD7Val();
// get AD value
sprintf(NewKey,
"0x%03X", adcValue); // insert AD converter value
memcpy(Key, NewKey, 5);
break;
}
case'7' : // "AD7%"?
{
sprintf(NewKey,
"%3u", (adcValue*100)/4024); // copy saved value from previous read
memcpy(Key, NewKey, 3);
break;
}
case'1' : // "AD1%"?
{
sprintf(NewKey,
"%3u", ++pagecounter); // increment and insert page counter
memcpy(Key, NewKey, 3);
*(Key + 3) =
' ';
break;
}
}
Key++;
}
}