/******************************************************************************************** The FVTX LV/Bias Mod5270 Ethernet FTP Server This example will create an FTP Server running on the NetBurner board. The FTP Server will start up and wait for a FTP client connection. The FTP Server provides two functions: 1. Allows the FTP Client to upload an ASCII text file. The file is not stored in memory, but is sent out on the 16 bit data bus to control the VME crate containing the LV and Bias distribution cards. 2. Allows the FTP Client to download a single file ReadFile.txt , which contains statistics about the last file upload, the last 16 bits written to the data bus and any error messages concerning the processing of the data. A checksum on the file contents will eventually be added. ********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include <..\MOD5270\system\sim5270.h> extern "C" { void UserMain( void *pd ); } const char *AppName = "Ftpd_trivial Example"; int nbytes; int badbytes; int response; // UserMain Function void UserMain( void *pd ) { InitializeStack(); // Initialize TCP/IP Stack EnableAutoUpdate(); // Enable NetBurner AutoUpdate downloads EnableTaskMonitor(); OSChangePrio( MAIN_PRIO ); // Set UserMain priority level to default nbytes=0; badbytes=0; response=0; // datah is data bus, datal is address bus sim.gpio.par_ad &= ~(0x1); // Set the databus 15-0 pins to GPIO // sim.gpio.pddr_datal = 0xEF; // Set the databus 7-0 to be address outputs + OE input, bits swapped sim.gpio.pddr_datal = 0xDF; // Set the databus 7-0 to be address outputs + OE input // sim.gpio.pddr_datah = 0xBF; // Set the databus 15-8 to be data outputs + resp input, bits swapped sim.gpio.pddr_datah = 0x7F; // Set the databus 15-8 to be data outputs + resp input sim.gpio.podr_datal = 192; // initialize 8 bit address bus inactive sim.gpio.podr_datah = 0; // initialize 8 bit data bus inactive iprintf( "Starting FVTXLV Control FTP Server\n" ); OSTimeDly( 5 ); FTPDStart( 21, MAIN_PRIO - 1 ); iprintf( "Start complete\r\n" ); while ( 1 ); } /******************************************************************************************** FILE READ/LIST FUNCTIONS ********************************************************************************************/ /* This function is called by the FTP Server in response to a FTP Client's request to list the files (e.g. the "ls" command) */ int FTPD_ListFile( const char *current_directory, void *pSession, FTPDCallBackReportFunct *pFunc, int handle ) { /* Only one file exists ReadFile.txt */ pFunc( handle, "ReadFile.txt" ); return FTPD_OK; } /* This function is called by the FTP Server in response to a FTP Client's request to receive a file. In this example, only ReadFile.txt is available for download, and it's contents are a summary of the previous upload */ int FTPD_SendFileToClient( const char *full_directory, const char *file_name, void *pSession, int fd ) { char temp[80]; int lvaddr; int lvdata; int onoff; /* Only one file exists */ if ( strcmp( file_name, "ReadFile.txt" ) == 0 ) { /* Now construct and send the one line file */ lvaddr = sim.gpio.ppdsdr_datal; // get addressbus value lvdata = sim.gpio.ppdsdr_datah; // get databus value // onoff = lvaddr & 0x10; // check OE value, high is off, bits swapped onoff = (lvaddr & 0x20); // check OE value, high is off if ((nbytes != 0) && (badbytes == 0) && (response == 0)) { if (onoff != 0) { sprintf( temp, "Power is OFF, bytes copied = %d, last addr = %d, data = %d\r\n", \ nbytes, lvaddr, lvdata); } else { sprintf( temp, "Power is ON, bytes copied = %d, last addr = %d, data = %d\r\n", \ nbytes, lvaddr, lvdata); } } else if (response != 0) { sprintf(temp,"Response error, address word %d\r\n", response); } else { sprintf(temp,"Address or data word errors, %d bad bytes out of %d total bytes\r\n", badbytes, nbytes); } writestring( fd, temp); iprintf( temp ); return FTPD_OK; } else { return FTPD_FAIL; } } /* This function is called by the FTP Server to determine if a file exists. */ int FTPD_FileExists( const char *full_directory, const char *file_name, void *pSession ) { /* Only one file exists */ if ( strcmp( file_name, "ReadFile.txt" ) == 0 ) { return FTPD_OK; } return FTPD_FAIL; } /******************************************************************************************** FILE SEND FUNCTIONS ********************************************************************************************/ /* This example only allows one file (WriteFile.txt) to be sent to the board. The file contents are a list of address and data words that are driven onto the 16 pin user I/O bus. */ char tmp_resultbuff[255]; int lvaddr; int lvdata; /* This function reads the data stream from the input stream file descriptor fd and writes it to the 16 pin GPIO data bus. The lower 8 bits are used for address/control and the upper 8 bits for data/control. All but one are outputs. */ void ShowFileContents( int fdr ) { iprintf( "\r\n" ); int rv; int len; int testr; nbytes=0; badbytes=0; response=0; do { rv = ReadWithTimeout( fdr, tmp_resultbuff, 9, 20 ); if ( rv < 0 ) { // iprintf( "RV = %d\r\n", rv ); } else { nbytes += rv; // record format is 8 characters: addr data in ascii format "%3d %3d\n" lvaddr = -1; lvdata = -1; // must make sure buffer is null terminated for scanf to work right! tmp_resultbuff[rv] = '\0'; // iprintf("decoded string %s\r\n",tmp_resultbuff); len = sscanf(tmp_resultbuff,"%d %d",&lvaddr,&lvdata); if (rv !=9 || lvaddr<0 || lvdata<0 || len!=2) { iprintf("address or data word error, transfer ignored!\r\n"); // keep byte count for bad data // could terminate transfer here by setting rv = 0? badbytes += rv; } else { // iprintf( "address = %d, data = %d]\r\n", lvaddr, lvdata ); sim.gpio.podr_datal = lvaddr; // set addressbus value sim.gpio.podr_datah = lvdata; // set databus value // check for response requested, bits swapped // iprintf("address = %d\r\n",lvaddr); // if ((lvaddr & 0x10) != 0) { // bits swapped if ((lvaddr & 0x20) != 0) { // testr = sim.gpio.ppdsdr_datah & 0x40; // get response value, should be low, bits swapped testr = sim.gpio.ppdsdr_datah & 0x80; // get response value, should be low if (testr != 0) response = lvaddr; // save unresponsive address } } } } while ( rv > 0 ); iprintf( "bytes transferred = %d, last addr = %d, data = %d\r\n", nbytes, lvaddr, lvdata ); } /* This function gets called by the FTP Server when a FTP client sends a file */ int FTPD_GetFileFromClient( const char *full_directory, const char *file_name, void *pSession, int fd ) { if ( strcmp( file_name, "WriteFile.txt" ) == 0 ) { ShowFileContents( fd ); return FTPD_OK; } return FTPD_FAIL; } /* This function gets called by the FTP Server to determine if it is ok to create a file on the system. This case is will occur when a FTP client sends a file. */ int FTPD_AbleToCreateFile( const char *full_directory, const char *file_name, void *pSession ) { if ( strcmp( file_name, "WriteFile.txt" ) == 0 ) { return FTPD_OK; } return FTPD_FAIL; } /* This function is called to determine if a FTP session is allowed to start. This is where username and password verification occur. */ void * FTPDSessionStart( const char *user, const char *passwd, const IPADDR hi_ip ) { if ( strcmp ( user, "plm" ) != 0 ) return FTPD_FAIL; if ( strcmp ( passwd, "plm" ) != 0 ) return FTPD_FAIL; return ( void * ) 1; /* Return a non zero value */ } /****************FTPD Functions that are not supported/used in this trivial case *******************/ void FTPDSessionEnd( void *pSession ) { /* Do nothing */ } int FTPD_ListSubDirectories( const char *current_directory, void *pSession, FTPDCallBackReportFunct *pFunc, int handle ) { /* No directories to list */ return FTPD_OK; } int FTPD_DirectoryExists( const char *full_directory, void *pSession ) { return FTPD_FAIL; } int FTPD_CreateSubDirectory( const char *current_directory, const char *new_dir, void *pSession ) { //Always fails return FTPD_FAIL; } int FTPD_DeleteSubDirectory( const char *current_directory, const char *sub_dir, void *pSession ) { //Always fails return FTPD_FAIL; } int FTPD_DeleteFile( const char *current_directory, const char *file_name, void *pSession ) { //Always fails return FTPD_FAIL; } int FTPD_Rename( const char *current_directory,const char *cur_file_name,const char *new_file_name,void *pSession ) { return FTPD_FAIL; }