Exemplo n.º 1
0
static int Run() {
	int retval = 0;

	try {
		// Find the list of addresses at the specified VID/PID.
		printf("\n"
				"Enumerating ASR-2300 devices...\n"
				"--------------------------------------\n");

		int addr = s_cfgDevice.Attach();

		printf("Attached to ASR-2300 at address = %d\n", addr);

	} catch (std::runtime_error& re) {
		printf("Error:  %s\n", re.what());
		return -8;
	}

	// Dump the device information
	DumpDeviceInformation();

	// Calibrate the device
	retval = DoCalibrate ();

	// Detach from device
	s_cfgDevice.Detach();

	return retval;
}
Exemplo n.º 2
0
static int Run() {
	int retval = 0;

	try {
		// Find the list of addresses at the specified VID/PID.
		printf("\n"
			"Enumerating ASR-2300 devices...\n"
			"--------------------------------------\n");

		int addr = s_cfgDevice.Attach();

		printf("Attached to ASR-2300 at address = %d\n", addr);

	} catch (std::runtime_error& re) {
		printf("Error:  %s\n", re.what());
		return -8;
	}

	// Dump the device information
	DumpDeviceInformation();


	printf("**\n** PLEASE MAKE SURE ALL SIGNALS ARE DISCONNECTED\n** FROM THE ASR-2300 BEFORE CALIBRATING\n**\n\n\n");
	SLEEP_SEC(5);

	// Calibrate the device
	retval = DoCalibrate ();

	// Detach from device
	s_cfgDevice.Detach();

	return retval;
}
Exemplo n.º 3
0
static int Run() {

	int retval = 0;

	try {
		// Find the list of addresses at the specified VID/PID.
		printf("\n"
				"Enumerating ASR-2300 devices...\n"
				"--------------------------------------\n");

		int addr = s_config.Attach();

		printf("Attached to ASR-2300 at address = %d\n", addr);

	} catch (std::runtime_error& re) {
		printf("Error:  %s\n", re.what());
		return -8;
	}

	//Dump the device information
	DumpDeviceInformation();

	// grab the DCI transport interface.
	s_ptd = &(s_config.Dci0Transport());

	//1) Tell the user what we are doing
	printf("--------------------------------------\n");
	printf( s_pOp->szDescriptionFormat, s_fileName);
	printf("--------------------------------------\n");

	//2) set up the BIT operations manager
	Dci_BitOperationMgrInit(&s_bitmgr, &OnSendMessage);

	//3) set up the BIT client and its callbacks.

	//NOTE: Make our component ID the same as the target component, so it knows
	//how to send the data back.  This worksaround a design issue with the BIT
	//structure.
	Dci_BitClient_Init(&s_BITClient, s_pOp->idTargetComponent);
	s_BITClient.fncInitiateSourceTransfer = &OnBitInitiateSourceTransfer;
	s_BITClient.fncInitiateTargetTransfer = &OnBitInitiateTargetTransfer;
	s_BITClient.fncGetFrameData = &OnBitGetFrameData;
	s_BITClient.fncSetFrameData = &OnBitSetFrameData;
	s_BITClient.fncTransferComplete = &OnBitTransferComplete;

	//4) Register the Client with the BIT operations manager.
	Dci_BitRegisterClient(&s_bitmgr, &s_BITClient);

	// Do the specified operation
	retval = (*(s_pOp->fncOpHandler))();

	s_config.Detach();
	return retval;
}
Exemplo n.º 4
0
/**
* <summary>
* Main Program Entry Point.
* </summary>
*/
int main(int argc, const char** argv) 
{
	int retval = 0;
	WriteHeader();

	//Add all the arguments.
	s_args.AddMapEntries( s_argmap);
	s_s1.RegisterArgs( "s1", s_args);
	s_s2.RegisterArgs( "s2", s_args);

	//Parse the arguments.
	retval = s_args.Parse( argc, argv);
	if( retval > 0)
	{
		int addr = (int) s_args.GetLong( "address");
		try {
			addr = s_cfgDevice.Attach(addr);
			printf("Attached to ASR-2300 at address = %d\n", addr);

		} catch (std::runtime_error& re) {
			printf("Error:  %s0\n", re.what());
			return -1;
		}

		// Dump the device information
		DumpDeviceInformation();

		//Initialize the stream loggers.
		retval = s_s1.Init( s_args, &s_cfgDevice);
		if( retval == 0)
			retval = s_s2.Init( s_args, &s_cfgDevice);
	
		//Receive the data and store to disk.
		if( retval == 0)
		{
			s_s1.DisplayConfiguration();
			s_s2.DisplayConfiguration();

			s_cfgDevice.Dci0Transport().ClearReceiveQueue();

			retval = ReceiveData((size_t) (s_args.GetDouble("duration")*1000.0));
		}

		s_s1.Terminate();
		s_s2.Terminate();
		s_cfgDevice.Detach();
	}
	else //Arguments were not right.
	{
		PrintUsage();
	}
	return retval;
}
Exemplo n.º 5
0
static void DumpDeviceInformation ()
{
	std::string sId = s_cfgDevice.IdentifyDevice();
	std::string sVer = s_cfgDevice.FirmwareVersion();
	uint16 idFpga = s_cfgDevice.FpgaId();
	uint16 verFpga = s_cfgDevice.FpgaVersion();
	int iVer = (verFpga >> 8);
	int iRev = (verFpga & 0x00ff);

	printf("\n");
	printf("Identity:    %s\n", sId.c_str());
	printf("FW Ver:      %s\n", sVer.c_str());
	printf("FPGA ID-Ver: %04X-%02X.%02X\n\n", idFpga, iVer, iRev);
}
Exemplo n.º 6
0
// This program demonstrates how to use the ConfigeDevice class to easily attach
// to an ASR-2300 device.  Then using the TransportDci to set a custom property on the default waveform 
// component.  The property (A0) sets an LED blink rate in the custom HDL container demonstrated at the 
// Loctronix A2300 Open Source Webinar presentation dated 2/18/14.  Be sure to build and load the corresponding
// verilog container in the hdl/containers directory to use with this demo application. See
// http://www.loctronix.com/news/webinars/LoctronixWebinar-2-140218.pdf for discussion and setup.
int main(int, char**)
{

	// Attach to the first device we find.
	ConfigDevice config;
	int result = config.Attach();
	if( result < 0)
	{
		printf("Could not attach ASR-2300 device\n");
		return result;
	}
	else
		printf( "ASR-2300 Device Opened\n");

	//Get the FPGA ID and Version
	uint16	    idFpga 		= config.FpgaId();
	uint16 		verFpga 	= config.FpgaVersion();
	int  		iVer = (verFpga>>8);
	int	 		iRev = (verFpga& 0x00ff);
	printf("  FPGA ID-Ver:  %04X - %02X.%02X\n\n", idFpga, iVer, iRev);


	//Set the custom register( id = A0) setting the frequency
	//on the LED blinker from slowest rate to 16 times slowest rate
	TransportDci& dt = config.Dci0Transport();
	for( uint32 i = 0; i < 4; i++)
	{
		uint32 countval = 1 + i*16;

		printf("Setting Blink Rate Count Value = %d\n", countval);  
		
		dt.SetProperty<uint32>( 0x00, 0xA0, 1 + i*16);
		SLEEP_SEC(5);		
	}

	//Detach from ASR-2300 
	config.Detach();
	return(0);
}
Exemplo n.º 7
0
/**
* <summary>
* Function configures the ASR-2300 to receive a specified frequency
* and then streams the data to the host via BulkDataPort interface.
* </summary>
*/
static int ReceiveData (size_t msecDur)
{
	int retval = 0;

	printf( msecDur == 0 ? "Duration: inifinite\n" : "Duration: %lu sec.\n",
		msecDur/1000);

	printf("\n--> Starting Run\n");
	printf("Hit any key to stop data collection ...\n");

	// start a separate thread waiting on any keyboard entry
#if defined(LINUX) || defined(APPLE)
	pthread_t keyThread;
	if (pthread_create (&keyThread, NULL, KeyThreadFunc, NULL) != 0) {
		printf ("Error creating key entry thread; use ^C to exit data connection if necessary.\n");
	}
#endif

	//SLEEP_SEC(1);

	//Synchronize the RF Front-ends 
	s_cfgDevice.SynchRfState();

	//SLEEP_SEC(1);


	//Start the loggers.
	retval = s_s1.Start(msecDur, false);  //Starts but does not enable.
	if( !retval )  s_s2.Start(msecDur, true); //Enables both, effectively synchronizing the DSP.

	// Periodically poll and check status of processing.
	while ((retval == 0) && (!s_bKeyHit))
	{
#if defined(HAVE_LIBUSB)
		retval= s_cfgDevice.Device().PollAsynchronousEvents();
#elif defined(WIN32) || defined(WIN64)
		Sleep(10);
#endif
		//Check status of processing.
		if( !retval)
			retval = s_s1.CheckStatus();
		if( !retval)
			retval = s_s2.CheckStatus();
	}

	s_cfgDevice.Dci0Transport().ClearReceiveQueue();
	s_s2.Stop();
	s_s1.Stop();

	printf("\n--> Completed Run\n");


	// join the keyboard entry thread
#if defined(LINUX) || defined(APPLE)
	if (!s_bKeyHit) {
		pthread_kill (keyThread, SIGINT);
	}
	pthread_join (keyThread, NULL);
#endif

	return 0;
}
Exemplo n.º 8
0
/**
 * Operation Handler function implements message processing performing the specified BIT Transfer operation.
 */
static int DoBitTransfer()
{
	byte buff[MAX_MSG_SIZE];

	Dci_Context ctxt;
	memset(&ctxt, 0, sizeof(ctxt));
	ctxt.pConv = s_ptd->Conversation();

	byte idStatus = BSE_OperationNotAvailable;

	printf("\n** Initiating BIT Operation ... \n");

	//Get firmware version to see if advanced bit operations supported.
	bool bChecksum = false;
	bool bOverride = false;
	Dci_VersionInfo vi;
	if( s_config.FirmwareVersionRaw( &vi))
	{
		int   ver = (vi.VerMajor <<8) + vi.VerMinor;
		bChecksum = ver >= 0x0101;  //must be greater than 1.1.0 
		bOverride = ver >= 0x0101;

		printf(" - Checksum Validation Enabled\n - Existing Transfers Will be Terminated\n");
	}

	fflush (stdout);

	if (s_pOp->dir == e_Download) 
	{
		byte flags = 1; // Save the data.
		if( bChecksum) flags |= BCF_ChecksumValidation;
		if( bOverride) flags |= BCF_TerminateExisting;

		idStatus = Dci_BitInitiateTargetTransfer(&s_bitmgr, &s_BITClient,
				s_pOp->idTargetComponent, flags, 0, &ctxt);
		// flags: 1 == save; 0 means don't save

		if (idStatus != BSE_InitiatingTransfer) {
			printf("  Error initiating target transfer:\n");
			if (idStatus == BSE_OperationNotAvailable) {
				printf("  Operation not available.\n");
				return -5;
			} else {
				printf("  Read error.\n");
				return -6;
			}
		}
	} 
	else 
	{
		byte flags = 1; // Save the data.
		if( bChecksum) flags |= BQF_ChecksumValidation;
		if( bOverride) flags |= BQF_TerminateExisting;

		Dci_BitRequestSourceTransfer(&s_bitmgr, &s_BITClient,
				s_pOp->idTargetComponent, flags, 0, &ctxt);
	}

	// enter while loop to process messages while BIT operation completes
	int nread = 0;
	int cntLoop = 0;

	while (cntLoop < 20) {
		memset(buff, 0, sizeof(buff));
		nread = s_ptd->ReceiveMsg(buff, MAX_MSG_SIZE,5);
		if (nread > 0) {

			Dci_Hdr* pMsg = (Dci_Hdr*) buff;

			// Prepare the context and send received message off for
			// processing.
			memset(&ctxt, 0, sizeof(ctxt));
			ctxt.pMsg = pMsg;
			ctxt.lenMsg = nread;
			ctxt.pConv = s_ptd->Conversation();
			ctxt.bHandled = false;
			ctxt.idMessage = Dci_Hdr_MessageId(pMsg);
			ctxt.idComponent = 0xFF;

			//If WCA Message grab the component ID to help WCA
			// based message processing.
			if (pMsg->idCategory == 0x21)
				ctxt.idComponent = ((byte*) pMsg)[WCA_COMPONENT_INDEX ];

			if (!Dci_BitProcessDciMsg(&s_bitmgr, &ctxt)) {
				switch( ctxt.idMessage)
				{
				case Dci_DebugMsg_Id:
					{
						Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
						std::string smsg = TransportDci::DebugMsgToString( plog);
						puts( smsg.c_str());
						putc( '\n', stdout);
					}
					break;

				default:
					printf("Unhandled Dci message: %04X.\n", ctxt.idMessage);
					break;

				}

			}

			// should go idle when finished
			if (s_bitmgr.aBitOps[0].state == DCI_BOS_IDLE) {
				break;
			}

			// got something; reset loop counter
			cntLoop = 0;

		} else {
			// got nothing; increment loop counter towards failure
			++cntLoop;
		}
	}

	//If not transfer complete, then we had a transfer error (-7);
	return (s_idLastBitStatus  == BSE_TransferComplete) ? 0: -7;
}
Exemplo n.º 9
0
static int DoCalibrate ()
{
  byte buff[DCI_MAX_MSGSIZE];
  int msgSize, ctSent, ctAck;
  TransportDci& tDci = s_cfgDevice.Dci0Transport ();

  struct _rxPath {
    byte Value;
    const char* Name;
  };

  struct _rxPath rx0Paths[] = {
    {(byte) RX0DPE_GpsL1Int, "GpsL1Int"},
    {(byte) RX0DPE_GpsL1Ext, "GpsL1Ext"},
    {(byte) RX0DPE_PcsExt, "PcsExt"},
    {(byte) RX0DPE_Wideband, "Wideband"}
  };
  const size_t numRx0Paths = sizeof(rx0Paths) / sizeof(struct _rxPath);

  struct _rxPath rx1Paths[] = {
    {(byte) RX1DPE_UhfExt, "UhfExt"},
    {(byte) RX1DPE_IsmInt, "IsmInt"},
    {(byte) RX1DPE_IsmExt, "IsmExt"},
    {(byte) RX1DPE_Wideband, "Wideband"}
  };
  const size_t numRx1Paths = sizeof(rx1Paths) / sizeof(struct _rxPath);

  struct _RxInfo {
    ConfigRf& cRf;
    byte numPaths;
    struct _rxPath* rxPaths;
  };

  struct _RxInfo rxInfo[] = {
    {s_cfgDevice.RF0(), (byte) numRx0Paths, rx0Paths},
    {s_cfgDevice.RF1(), (byte) numRx1Paths, rx1Paths}
  };
  const size_t numRxComponents = sizeof(rxInfo) / sizeof(struct _RxInfo);

  // disable both Tx and Rx paths
  s_cfgDevice.RF0().TxPath(TX0DPE_Disabled);
  s_cfgDevice.RF1().TxPath(TX1DPE_Disabled);
  s_cfgDevice.RF0().RxPath(RX0DPE_Disabled);
  s_cfgDevice.RF1().RxPath(RX1DPE_Disabled);

  SLEEP_SEC(1);

  // Set the RF Profile component into cache mode
  printf ("Setting the RF Profile component into cache mode ...\n");
  memset(buff, 0, sizeof(buff));
  msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, WCACOMP_RFPROFILES, RFP_ACTION_CACHEDATA, 0, NULL);
  ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
  // get ack, and verify
  memset(buff, 0, sizeof(buff));
  ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
  if ((ctAck <= 0) || (ctSent != msgSize)) {
    printf ("Warning: Unable to set device into cache mode (%d, %d).\n",
	    ctSent, ctAck);
    printf ("  Proceeding anyway.");
  }
  // print received ack info
  if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
    Dci_Hdr* pMsg = (Dci_Hdr*) buff;
    Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
    std::string smsg = TransportDci::DebugMsgToString( plog);
    puts( smsg.c_str());
    putc( '\n', stdout);
  }
  SLEEP_SEC(1);
  printf ("Done.\n");

  for (byte nn = 0; nn < (byte) numRxComponents; ++nn) {

    // calibrate profiles for this Rx component
    struct _RxInfo& tRxInfo = rxInfo[nn];

    // Reset Top-Level Calibration
    printf ("Resetting Top-Level Calibration for Rx component %d ...\n", (nn+1));

    memset(buff, 0, sizeof(buff));
    msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, tRxInfo.cRf.componentId(), RFACTION_RESETTOPCALIB, 0, NULL);
    ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
    // get ack, and verify
    memset(buff, 0, sizeof(buff));
    ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
    if ((ctAck <= 0) || (ctSent != msgSize)) {
      printf ("Warning: Unable to Reset Top-Level Calibration for Rx component #%d (%d, %d).\n", nn, ctSent, ctAck);
      printf ("  Proceeding anyway.");
    }
    // print received ack info
    if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
      Dci_Hdr* pMsg = (Dci_Hdr*) buff;
      Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
      std::string smsg = TransportDci::DebugMsgToString( plog);
      puts( smsg.c_str());
      putc( '\n', stdout);
    }
    SLEEP_SEC(1);
    printf ("Done.\n");

    // Calibrate Top-Level
    printf ("Calibration Top-Level for Rx component %d ...\n", (nn+1));
    memset(buff, 0, sizeof(buff));
    msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, tRxInfo.cRf.componentId(), RFACTION_TOPCALIBRATE, 0, NULL);
    ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
    // get ack, and verify
    memset(buff, 0, sizeof(buff));
    ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
    if ((ctAck <= 0) || (ctSent != msgSize)) {
      printf ("Warning: Unable to Calibrate Top-Level for Rx component #%d  (%d, %d).\n", nn, ctSent, ctAck);
      printf ("  Proceeding anyway.");
    }
    // print received ack info
    if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
      Dci_Hdr* pMsg = (Dci_Hdr*) buff;
      Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
      std::string smsg = TransportDci::DebugMsgToString( plog);
      puts( smsg.c_str());
      putc( '\n', stdout);
    }
    SLEEP_SEC(1);
    printf ("Done.\n");

    ConfigRf& cRf = tRxInfo.cRf;

    // calibrate all Rx paths, one at a time
    for (byte mm = 0; mm < tRxInfo.numPaths; ++mm) {

      // Set RX Path to Calibrate
      struct _rxPath& thisRxPath = tRxInfo.rxPaths[mm];
      cRf.RxPath(thisRxPath.Value);

      // Reset RX Calibration for this path
      printf ("Resetting Calibration for Rx component %d path %d (%s) ...\n", (nn+1), (mm+1), thisRxPath.Name);
      memset(buff, 0, sizeof(buff));
      msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, tRxInfo.cRf.componentId(), RFACTION_RESETRXCALIB, 0, NULL);
      ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
      // get ack, and verify
      memset(buff, 0, sizeof(buff));
      ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
      if ((ctAck <= 0) || (ctSent != msgSize)) {
	printf ("Warning: Unable to Reset RX Calibration for Rx%d path %s (%d, %d).\n", nn, thisRxPath.Name, ctSent, ctAck);
	printf ("  Proceeding anyway.");
      }
      // print received ack info
      if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
	Dci_Hdr* pMsg = (Dci_Hdr*) buff;
	Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
	std::string smsg = TransportDci::DebugMsgToString( plog);
	puts( smsg.c_str());
	putc( '\n', stdout);
      }
      SLEEP_SEC(1);
      printf ("Done.\n");

      // Calibrate this path
      printf ("Calibrating Rx component %d path %d (%s) ...\n", (nn+1), (mm+1), thisRxPath.Name);
      memset(buff, 0, sizeof(buff));
      msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, tRxInfo.cRf.componentId(), RFACTION_SAVERXPROFILE, 0, NULL);
      ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
      // get ack, and verify
      memset(buff, 0, sizeof(buff));
      ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
      if ((ctAck <= 0) || (ctSent != msgSize)) {
	printf ("Warning: Unable to Calibrate Rx%d path %s (%d, %d).\n", nn, thisRxPath.Name, ctSent, ctAck);
	printf ("  Proceeding anyway.");
      }
      // print received ack info
      if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
	Dci_Hdr* pMsg = (Dci_Hdr*) buff;
	Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
	std::string smsg = TransportDci::DebugMsgToString( plog);
	puts( smsg.c_str());
	putc( '\n', stdout);
      }
      SLEEP_SEC(1);
      printf ("Done.\n");
    }
  }

  // Save Cached Changes
  printf ("Saving all cached calibrations ...\n");
  memset(buff, 0, sizeof(buff));
  msgSize = Dci_ExecuteAction_Init (buff, DCI_MAX_MSGSIZE, WCACOMP_RFPROFILES, RFP_ACTION_SAVECHANGES, 0, NULL);
  ctSent = tDci.SendMsg (buff, (size_t) msgSize, true);
  // get ack, and verify
  memset(buff, 0, sizeof(buff));
  ctAck = tDci.ReceiveMsg (buff, DCI_MAX_MSGSIZE);
  if ((ctAck <= 0) || (ctSent != msgSize)) {
    printf ("Warning: Unable to set device into cache mode (%d, %d).\n",
	    ctSent, ctAck);
    printf ("  Proceeding anyway.");
  }
  // print received ack info
  if (Dci_Hdr_MessageId((Dci_Hdr*) buff) == Dci_DebugMsg_Id) {
    Dci_Hdr* pMsg = (Dci_Hdr*) buff;
    Dci_DebugMsg* plog = (Dci_DebugMsg*)( pMsg);
    std::string smsg = TransportDci::DebugMsgToString( plog);
    puts( smsg.c_str());
    putc( '\n', stdout);
  }
  printf ("Done.\n");

  // disable both Tx and Rx paths
  s_cfgDevice.RF0().TxPath(TX0DPE_Disabled);
  s_cfgDevice.RF1().TxPath(TX1DPE_Disabled);
  s_cfgDevice.RF0().RxPath(RX0DPE_Disabled);
  s_cfgDevice.RF1().RxPath(RX1DPE_Disabled);

  return 0;
}