Ejemplo n.º 1
0
// TODO: add input buffer
int main(int argc, char *argv[]) { 
  int q;
  int ppc_fd = 0; 
  int  num_q = 4;
  miner_t miner[4];
  int start_port = 8087;

  unsigned int nonce;
  unsigned char bufferin[64];  // 512 bits
  unsigned char bufferout[4];  // 32 bits

  // Initialize HW interface and reset
  ppc_fd = InitQuadInterface();

  if (argc == 2){
    num_q = atoi(argv[1]);
    if (num_q <= 0 || num_q > 4){
      printf("Num Quads must be 1-4\n");
      print_usage(argv);
      exit(1);
    }
  }
  
  for (q = 0; q < num_q; q++){
    SetQuad(q, ppc_fd);
    ResetRW(ppc_fd);
  }

  // Initialize miners: numQ consecutive ports
  for (q = 0; q < num_q; ++q) {
    NetGetConnection(start_port + q,
		     &miner[q].connection);
    miner[q].state = STATE_IDLE;
  }

  while (1) {
    // feed / consume FPGA data
    // Note: several potential sources of lockups here.
    for (q = 0; q < num_q; ++q) {
      SetQuad(q, ppc_fd);
      if (miner[q].state == STATE_WORKING) {
	// Check for available data and read if available.
	if (ReadByteNB(&bufferout[0], ppc_fd)) {
	  ReadByte(&bufferout[1], ppc_fd);
	  ReadByte(&bufferout[2], ppc_fd);
	  ReadByte(&bufferout[3], ppc_fd);
	  // Send
	  NetWrite(&miner[q].connection, bufferout, 4);
	  miner[q].state = STATE_IDLE;
	  // Debug
	  nonce = BufferToNonce(bufferout);
	  printf("Miner(%d) TX nonce: %d  (0x%08x)\n", q, nonce, nonce); 
	}
      } 
      //else if (miner[q].state == STATE_READY) {
      // Just always do this.
      // RX net data and forward to FPGA
      if (NetRead(&miner[q].connection, bufferin, 64) == 64) {
	WriteBuffer(bufferin, 64, ppc_fd);
	miner[q].state = STATE_WORKING;
	printf("Miner(%d) RX data\n", q); 
      }
    } // quad iterator
    
    // TODO: Check sideband for commands.
    
  } // while (1)
  
  // Close connections
  for (q = 0; q < num_q; ++q) {
    NetClose(&miner[q].connection);
  }

  return 0;
} 
Ejemplo n.º 2
0
// -2  cant make dir
long FtpFileUpload( void *fs, char *localfilename, char *remotepath, char *file )
{
	long length=0, failedmkdir=FALSE, datadone;

	if ( fs && !IsStopped() )
	{
		void	*hFtpFile;
		FILE	*ff;
		long	dataleft, dataread, perc;
		char	*buffer=NULL;
		char	msg[500];

		if ( !(ff = fopen( localfilename, "rb" )) )
		{
			StatusSetID( IDS_ERR_FILEFAILED, localfilename );
			return FTPERR_NOFILE;
		}

		if ( fs && ff )
		{
			char dir[256], *p;
			static char lastdir[256];
			int tries = 0;

			// Convert all Windows slashes to Unix ones.
			p = remotepath;
			while( *p )
			{
				if ( *p == '\\' ) *p = '/';
				p++;
			}

			// Try to create the remote directories first.
			if ( p )
			{
				// Try to open remote file, if we cant make the remote dir.
				while( (hFtpFile = (void*)FtpOpen( fs, remotepath, 'W' )) == NULL && tries<5 )
				{
					PathFromFullPath( remotepath, dir );
					if ( strcmp( dir, lastdir ) ){
						//long l=mystrcpy( lastdir, dir );
						//if ( dir[l-1] == '/' ) dir[l-1]=0;
						sprintf( msg, "Making dir %s...", dir );
						StatusSet( msg );

						if ( !FtpMakeDir( fs, dir ) )
						{
							failedmkdir = TRUE;
							OutDebugs( "Cannot create remote ftp directory %s", dir );
						} else {
							failedmkdir = FALSE;
						}
					}
					tries++;
					OutDebug( "Trying again to write to server..." );
				}
			}


			// If remote file is opened.
			if ( hFtpFile ) 
			{
				StatusSetID( IDS_UPLOADINGTO, remotepath );
				const long read_size = (4*1024);

				datadone = 0;
				length = dataleft = (long)GetFileLength( localfilename );
				if ( length )
					buffer = (char*)malloc( read_size );

				if ( buffer )
				{
					while( dataleft>0 && buffer && !IsStopped() )
					{
						dataread = fread( buffer, 1, read_size, ff );
						if ( dataread )
							NetWrite( hFtpFile, buffer, dataread );

						dataleft -= dataread;
						datadone += dataread;

						// ------------------------------------------------------
						perc = (long)(100*((length-dataleft)/(float)length));
						sprintf( msg, "Uploading %s  (%d bytes %d%%)", remotepath, datadone, perc );
						StatusSet( msg );
						// ------------------------------------------------------
					}
					if ( datadone == length )
						OutDebug( "Uploaded complete." );

					free( buffer );
				}
				FtpClose( hFtpFile );
				OutDebug( "Ftp File Closed" );
			}
		}
		if ( ff )
			fclose( ff );
	}

	if ( failedmkdir )
		return FTPERR_CANTMAKEDIR;

	if ( IsStopped() )
		return FTPERR_STOPPED;

	if ( datadone == length )
		return FTPERR_COMPLETE;

	return FTPERR_COMPLETEFAIL;
}