Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ExperimentServer by
ExperimentServer.h
00001 #include "EthernetInterface.h" 00002 #include "mbed.h" 00003 00004 #define _MAX_BUFFER_SIZE 200 00005 00006 /** 00007 * Experiment Server 00008 */ 00009 00010 class ExperimentServer 00011 { 00012 public: 00013 00014 /** 00015 * Constructor. 00016 * 00017 * Constructs an empty experiment server. Server objects require additional 00018 * initialization before being used. 00019 * Constructs an empty experiment server. Server objects require further 00020 * initialization before use. 00021 */ 00022 ExperimentServer(); 00023 00024 /** 00025 * Link a serial terminal to the server for debugging purposes. 00026 * 00027 * @param terminal Serial terminal to be used for debugging messages 00028 */ 00029 void attachTerminal( RawSerial & terminal); 00030 00031 /** 00032 * Initialize the server. 00033 * 00034 * Following initialization, the getParams, sendData, and setExperimentComplete 00035 * methods may be used. 00036 * 00037 * Applies default server configuration with ip <tt>192.168.1.100</tt>, 00038 * subnet <tt>255.255.255.0</tt>, gateway <tt>192.168.1.1</tt>, port <tt>11223</tt>. 00039 */ 00040 void init(); 00041 00042 /** 00043 * Initialize the server with supplied configuration. 00044 * 00045 * Following initialization, the getParams, sendData, and setExperimentComplete 00046 * methods may be used. 00047 * 00048 * @param addr IP address of the server 00049 * @param subnet Subnet mask of the IP address 00050 * @param gateway Gateway/router IP address 00051 * @param port Port to listen on for connections from MATLAB. 00052 */ 00053 void init(const char * addr, const char * subnet, const char * gateway, unsigned int port); 00054 00055 /** 00056 * Listen for parameters passed to the server. This operation blocks until any data 00057 * is recieved. 00058 * 00059 * @param params Float array of size num_params used to store incoming data 00060 * @param num_params Expected length of incoming data (# of floats) 00061 * 00062 * @return Success of the operation (0 - Failure, 1 - Success) 00063 * The operation is considered failure if the correct number of floats 00064 * is not recieved. 00065 * 00066 */ 00067 int getParams(float params[], int num_params); 00068 00069 /** 00070 * Send data back to host machine. To alleviate the processing burden on the host 00071 * machine, data is actually buffered on the chip and sent to the host in batches. 00072 * 00073 * @param data_output Float array of size data_size containing data to send to host 00074 * @param data_size Length of outgoing data (# of floats) 00075 * 00076 */ 00077 void sendData(float data_output[], int data_size); 00078 00079 /** 00080 * Inform the host that the experiment is complete. 00081 * 00082 * This function also sends any final buffered output data that has yet 00083 * to be relayed to the host. 00084 * 00085 */ 00086 void setExperimentComplete(); 00087 00088 private: 00089 00090 void flushBuffer(); // Sends all data in buffer to the host 00091 00092 EthernetInterface _eth; // Low level ethernet object 00093 Endpoint _client; // Stores client connected to server 00094 UDPSocket _server; // Low level UDP server object 00095 RawSerial * _terminal; // Pointer to attached terminal for debugging 00096 00097 float _buffer[_MAX_BUFFER_SIZE]; // Buffer for batch data storage before sending 00098 int _data_cnt; // Current occupied length of the buffer 00099 };
Generated on Thu Jul 14 2022 10:28:54 by
1.7.2
