mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Empty application for testing
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* \addtogroup helloworld
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* An example of how to write uIP applications
|
||||
* with protosockets.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a short example of how to write uIP applications using
|
||||
* protosockets.
|
||||
*/
|
||||
|
||||
/*
|
||||
* We define the application state (struct hello_world_state) in the
|
||||
* hello-world.h file, so we need to include it here. We also include
|
||||
* uip.h (since this cannot be included in hello-world.h) and
|
||||
* <string.h>, since we use the memcpy() function in the code.
|
||||
*/
|
||||
#include "hello-world.h"
|
||||
#include "../rtl837x_common.h"
|
||||
#include "uip.h"
|
||||
|
||||
#pragma codeseg BANK1
|
||||
|
||||
/*
|
||||
* Declaration of the protosocket function that handles the connection
|
||||
* (defined at the end of the code).
|
||||
*/
|
||||
static uint8_t handle_connection(__xdata struct hello_world_state *s);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* The initialization function. We must explicitly call this function
|
||||
* from the system initialization code, some time after uip_init() is
|
||||
* called.
|
||||
*/
|
||||
void
|
||||
hello_world_init(void)
|
||||
{
|
||||
/* We start to listen for connections on TCP port 1000. */
|
||||
uip_listen(HTONS(1000));
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* In hello-world.h we have defined the UIP_APPCALL macro to
|
||||
* hello_world_appcall so that this funcion is uIP's application
|
||||
* function. This function is called whenever an uIP event occurs
|
||||
* (e.g. when a new connection is established, new data arrives, sent
|
||||
* data is acknowledged, data needs to be retransmitted, etc.).
|
||||
*/
|
||||
void
|
||||
hello_world_appcall(void)
|
||||
{
|
||||
/*
|
||||
* The uip_conn structure has a field called "appstate" that holds
|
||||
* the application state of the connection. We make a pointer to
|
||||
* this to access it easier.
|
||||
*/
|
||||
__xdata struct hello_world_state *s = &(uip_conn->appstate);
|
||||
|
||||
/*
|
||||
* If a new connection was just established, we should initialize
|
||||
* the protosocket in our applications' state structure.
|
||||
*/
|
||||
if(uip_connected()) {
|
||||
PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, we run the protosocket function that actually handles
|
||||
* the communication. We pass it a pointer to the application state
|
||||
* of the current connection.
|
||||
*/
|
||||
write_char('A');
|
||||
handle_connection(s);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* This is the protosocket function that handles the communication. A
|
||||
* protosocket function must always return an int, but must never
|
||||
* explicitly return - all return statements are hidden in the PSOCK
|
||||
* macros.
|
||||
*/
|
||||
static uint8_t
|
||||
handle_connection(__xdata struct hello_world_state *s)
|
||||
{
|
||||
__xdata char buf[100];
|
||||
|
||||
PSOCK_BEGIN(&s->p);
|
||||
|
||||
strtox(buf, "Hello. What is your name?\n");
|
||||
// PSOCK_SEND_STR(&s->p, &buf[0]);
|
||||
// PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n");
|
||||
PSOCK_READTO(&s->p, '\n');
|
||||
// strncpy(s->name, s->inputbuffer, sizeof(s->name));
|
||||
strtox(buf, "Name: ");
|
||||
// PSOCK_SEND_STR(&s->p, &buf[0]);
|
||||
// PSOCK_SEND_STR(&s->p, s->name);
|
||||
PSOCK_CLOSE(&s->p);
|
||||
|
||||
PSOCK_END(&s->p);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
Reference in New Issue
Block a user