Esempio n. 1
0
MStatus mDblGauss::doIt( const MArgList& args )
{
	MStatus stat;
	int count = 1;
    
    srand(mfSeed);
    
	// check how many arguments we have
	if (args.length() == 0)
	{
		// no args
		// just return a single double
		setResult(MDoubleArray(1,gauss()));
		return MS::kSuccess;
	}
	else if (args.length() == 1)
	{
		// one args, check if its an int - if yes return int identity arrays
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);
        MDoubleArray result(count);
        
        double randDif = ((double)RAND_MAX + 1);
        
        for (int i=0; i< count; i++)
			result[i] = gauss();
        
        setResult(result);
		return MS::kSuccess;
	}
	else if (args.length() == 3)
	{
		double mean, diff;
        
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 1, mean);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 2, diff);
		ERROR_FAIL(stat);

      	MDoubleArray result(count);
                  
        for (int i=0; i< count; i++)
			result[i] = gauss()*diff+mean;
        
        setResult(result);
		return MS::kSuccess;
	}
	else
	{
		ERROR_FAIL(MS::kFailure);	
	}
}
Esempio n. 2
0
int ICACHE_FLASH_ATTR cgiPropLoadFile(HttpdConnData *connData)
{
    PropellerConnection *connection = &myConnection;
    char fileName[128];
    int fileSize = 0;
    
    // check for the cleanup call
    if (connData->conn == NULL) {
        if (connection->file) {
            roffs_close(connection->file);
            connection->file = NULL;
        }
        return HTTPD_CGI_DONE;
    }

    if (connection->state != stIdle) {
        char buf[128];
        os_sprintf(buf, "Transfer already in progress: state %s\r\n", stateName(connection->state));
        httpdSendResponse(connData, 400, buf, -1);
        return HTTPD_CGI_DONE;
    }
    connData->cgiData = connection;
    connection->connData = connData;
    
    os_timer_setfn(&connection->timer, timerCallback, connection);
    
    if (httpdFindArg(connData->getArgs, "file", fileName, sizeof(fileName)) < 0) {
        httpdSendResponse(connData, 400, "Missing file argument\r\n", -1);
        return HTTPD_CGI_DONE;
    }

    if (!(connection->file = roffs_open(fileName))) {
        httpdSendResponse(connData, 400, "File not found\r\n", -1);
        return HTTPD_CGI_DONE;
    }
    fileSize = roffs_file_size(connection->file);

    if (!getIntArg(connData, "baud-rate", &connection->baudRate))
        connection->baudRate = flashConfig.loader_baud_rate;
    if (!getIntArg(connData, "final-baud-rate", &connection->finalBaudRate))
        connection->finalBaudRate = flashConfig.baud_rate;
    if (!getIntArg(connData, "reset-pin", &connection->resetPin))
        connection->resetPin = flashConfig.reset_pin;
    
    DBG("load-file: file %s, size %d, baud-rate %d, final-baud-rate %d, reset-pin %d\n", fileName, fileSize, connection->baudRate, connection->finalBaudRate, connection->resetPin);

    startLoading(connection, NULL, fileSize);

    return HTTPD_CGI_MORE;
}
Esempio n. 3
0
int ICACHE_FLASH_ATTR cgiPropLoad(HttpdConnData *connData)
{
    PropellerConnection *connection = &myConnection;
    
    // check for the cleanup call
    if (connData->conn == NULL)
        return HTTPD_CGI_DONE;

    if (connection->state != stIdle) {
        char buf[128];
        os_sprintf(buf, "Transfer already in progress: state %s\r\n", stateName(connection->state));
        httpdSendResponse(connData, 400, buf, -1);
        return HTTPD_CGI_DONE;
    }
    connData->cgiData = connection;
    connection->connData = connData;

    os_timer_setfn(&connection->timer, timerCallback, connection);
    
    if (connData->post->len == 0) {
        httpdSendResponse(connData, 400, "No data\r\n", -1);
        abortLoading(connection);
        return HTTPD_CGI_DONE;
    }
    else if (connData->post->buffLen != connData->post->len) {
        httpdSendResponse(connData, 400, "Data too large\r\n", -1);
        return HTTPD_CGI_DONE;
    }
    
    if (!getIntArg(connData, "baud-rate", &connection->baudRate))
        connection->baudRate = flashConfig.loader_baud_rate;
    if (!getIntArg(connData, "final-baud-rate", &connection->finalBaudRate))
        connection->finalBaudRate = flashConfig.baud_rate;
    if (!getIntArg(connData, "reset-pin", &connection->resetPin))
        connection->resetPin = flashConfig.reset_pin;
    if (!getIntArg(connData, "response-size", &connection->responseSize))
        connection->responseSize = 0;
    if (!getIntArg(connData, "response-timeout", &connection->responseTimeout))
        connection->responseTimeout = 1000;
    
    DBG("load: size %d, baud-rate %d, final-baud-rate %d, reset-pin %d\n", connData->post->buffLen, connection->baudRate, connection->finalBaudRate, connection->resetPin);
    if (connection->responseSize > 0)
        DBG("  responseSize %d, responseTimeout %d\n", connection->responseSize, connection->responseTimeout);

    connection->file = NULL;
    startLoading(connection, (uint8_t *)connData->post->buff, connData->post->buffLen);

    return HTTPD_CGI_MORE;
}
Esempio n. 4
0
PilotLab::PilotLab()
      : RackDataModule( MODULE_CLASS_ID,
                    5000000000llu,    // 5s datatask error sleep time
                    16,               // command mailbox slots
                    48,               // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    5,                // max buffer entries
                    10)               // data buffer listener
{
    // get static module parameter
    chassisInst  = getIntArg("chassisInst", argTab);
    positionInst = getIntArg("positionInst", argTab);
    scan2dInst   = getIntArg("scan2dInst", argTab);

    dataBufferMaxDataSize   = sizeof(pilot_data_msg);
}
Esempio n. 5
0
Position::Position()
      : RackDataModule( MODULE_CLASS_ID,
                    2000000000llu,    // 2s cmdtask error sleep time
                    2000000000llu,    // 2s datatask error sleep time
                     100000000llu,    // 100ms datatask disable sleep time
                    16,               // command mailbox slots
                    48,               // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    1000,             // max buffer entries
                    10)               // data buffer listener
{
    // get value(s) out of your argument table
    odometryInst    = getIntArg("odometryInst", argTab);
    updateInterpol  = getIntArg("updateInterpol", argTab);

    refPos.x   = 0;
    refPos.y   = 0;
    refPos.z   = 0;
    refPos.phi = 0;
    refPos.psi = 0;
    refPos.rho = 0;

    refOdo.x   = 0;
    refOdo.y   = 0;
    refOdo.z   = 0;
    refOdo.phi = 0;
    refOdo.psi = 0;
    refOdo.rho = 0;
    sinRefOdo  = 0.0;
    cosRefOdo  = 1.0;

    refTime    = 0;

    interpolDiff.x   = 0;
    interpolDiff.y   = 0;
    interpolDiff.z   = 0;
    interpolDiff.phi = 0;
    interpolDiff.psi = 0;
    interpolDiff.rho = 0;
    
    interpolStartTime = 0;

    // set dataBuffer size
    setDataBufferMaxDataSize(sizeof(position_data));
}
Esempio n. 6
0
CameraJpeg::CameraJpeg()
    : DataModule( MODULE_CLASS_ID,
                  5000000000llu,        // 5s cmdtask error sleep time
                  5000000000llu,        // 5s datatask error sleep time
                  100000000llu,         // 100ms datatask disable sleep time
                  16,                   // command mailbox slots
                  48,                   // command mailbox data size per slot
                  MBX_IN_KERNELSPACE | MBX_SLOT, // command mailbox flags //## it should be user space
                  10,                    // max buffer entries
                  10)                   // data buffer listener
{
    // get value(s) out of your argument table
    cameraInst    = getIntArg("cameraInst", argTab);
    quality       = getIntArg("quality", argTab);

    // set dataBuffer size
    setDataBufferMaxDataSize(sizeof(camera_data_msg));
}
Esempio n. 7
0
Scan2dMerge::Scan2dMerge(void)
      : RackDataModule( MODULE_CLASS_ID,
                    5000000000llu,    // 5s datatask error sleep time
                    16,               // command mailbox slots
                    240,              // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    10,               // max buffer entries
                    10)               // data buffer listener
{
    // get static module parameter
    odometryInst  = getIntArg("odometryInst", argTab);
    scan2dInst[0] = getIntArg("scan2dInstA", argTab);
    scan2dInst[1] = getIntArg("scan2dInstB", argTab);
    scan2dInst[2] = getIntArg("scan2dInstC", argTab);
    scan2dInst[3] = getIntArg("scan2dInstD", argTab);

    dataBufferMaxDataSize   =sizeof(scan2d_data_msg);
}
Esempio n. 8
0
GpsNmea::GpsNmea()
        : RackDataModule( MODULE_CLASS_ID,
                      5000000000llu,    // 5s cmdtask error sleep time
                      5000000000llu,    // 5s datatask error sleep time
                      100000000llu,     // 100ms datatask disable sleep time
                      16,               // command mailbox slots
                      48,               // command mailbox data size per slot
                      MBX_IN_KERNELSPACE | MBX_SLOT, // command mailbox flags
                      5,                // max buffer entries
                      10)               // data buffer listener
{
    // get value(s) out of your argument table
    serialDev    = getIntArg("serialDev", argTab);
    periodTime   = getIntArg("periodTime", argTab);
    trigMsg      = getIntArg("trigMsg", argTab);
    posGKOffsetX = getIntArg("posGKOffsetX", argTab);
    posGKOffsetY = getIntArg("posGKOffsetY", argTab);
    gps_serial_config.baud_rate  = getIntArg("baudrate", argTab);

    // set dataBuffer size
    setDataBufferMaxDataSize(sizeof(gps_data));

    // set databuffer period time
    setDataBufferPeriodTime(periodTime);
}
Esempio n. 9
0
Position::Position()
      : RackDataModule( MODULE_CLASS_ID,
                    2000000000llu,    // 2s datatask error sleep time
                    8,                // command mailbox slots
                    240,              // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    1000,             // max buffer entries
                    10)               // data buffer listener
{
    // get static module parameter parameter
    odometrySys       = getIntArg("odometrySys", argTab);
    odometryInst      = getIntArg("odometryInst", argTab);

    oldPos.x    = 0;
    oldPos.y    = 0;
    oldPos.z    = 0;
    oldPos.phi  = 0.0f;
    oldPos.psi  = 0.0f;
    oldPos.rho  = 0.0f;

    dataBufferMaxDataSize   = sizeof(position_data);
}
ObjRecogRelayLadar::ObjRecogRelayLadar(void)
      : RackDataModule( MODULE_CLASS_ID,
                    5000000000llu,    // 5s datatask error sleep time
                    16,               // command mailbox slots
                    128,              // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    10,               // max buffer entries
                    10)               // data buffer listener


{
    // get static module parameter
    size_t maxDataSize     = getIntArg("maxDataSize", argTab);
    rack_time_t periodTime = getIntArg("periodTime", argTab);
    positionInst           = getIntArg("positionInst", argTab);

    this->inited = false;

    if ((maxDataSize < 0) || (maxDataSize > sizeof(obj_recog_data_msg)))
    {
           GDOS_ERROR("Invalid image size %d\n", maxDataSize);
           return;
    }

    if (periodTime < 0)
    {
           GDOS_ERROR("Invalid period time %dms\n", periodTime);
           return;
    }

    this->dataTimeOut = periodTime * 2;
    this->dataTimeOut *= RACK_TIME_FACTOR;

    dataBufferMaxDataSize   = maxDataSize;
    dataBufferPeriodTime    = periodTime;

    this->inited = true;
};
LadarHokuyoUrgUsb::LadarHokuyoUrgUsb()
      : RackDataModule( MODULE_CLASS_ID,
                    5000000000llu,    // 5s datatask error sleep time
                    16,               // command mailbox slots
                    48,               // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    5,                // max buffer entries
                    10)               // data buffer listener
{

    // get static module parameter
    serialDev   = getIntArg("serialDev", argTab);

    dataBufferMaxDataSize   = sizeof(ladar_data_msg);
    dataBufferPeriodTime    = 100;
}
Esempio n. 12
0
/*
 * @brief RackModule constructor
 *
 * This function creates a RackModule with all needed mailboxes and tasks.
 *
 * @param class_id
 * @param cmdTaskErrorTime_ns
 * @param cmdMbxMsgSlots
 * @param cmdMbxMsgDataSize
 * @param cmdMbxFlags
 *
 * @return 0 on success, otherwise negative error code
 *
 * Environments:
 *
 * This service can be called from:
 *
 * - User-space task (non-RT)
 *
 * Rescheduling: never.
 */
RackModule::RackModule( uint32_t classId,
                uint64_t dataTaskErrorTime_ns,
                int32_t  cmdMbxMsgSlots,
                uint32_t cmdMbxMsgDataSize,
                uint32_t cmdMbxFlags)
{
    // get instance from module_argTab
    inst                      = getIntArg("instance", module_argTab);
    gdosLevel                 = GDOS_MSG_DEBUG_BEGIN - getIntArg("gdosLevel", module_argTab);
    cmdTaskPrio               = getIntArg("cmdTaskPrio", module_argTab);
    dataTaskPrio              = getIntArg("dataTaskPrio", module_argTab);
    cpu                       = getIntArg("cpu", module_argTab);
    if (cpu > (sysconf(_SC_NPROCESSORS_ONLN) - 1))
    {
        cpu = 0;
    }

    name                      = RackName::create(classId, inst);

    mailboxBaseAdr            = name;
    mailboxFreeAdr            = name + 1;

    this->cmdMbxMsgSlots      = cmdMbxMsgSlots;
    this->cmdMbxFlags         = cmdMbxFlags;
    if(cmdMbxMsgDataSize < 240)
    {
        // minimum size for rack_param_msg
        this->cmdMbxMsgDataSize   = 240;
    }
    else
    {
        this->cmdMbxMsgDataSize   = cmdMbxMsgDataSize;
    }

    moduleInitBits.clearAllBits();
    initBits.clearAllBits();

    terminate                 = 0;
    status                    = MODULE_STATE_DISABLED;
    initializing              = 1;

    if(getIntArg("targetStatus", module_argTab) > 0)
    {
        targetStatus = MODULE_TSTATE_ON;
    }
    else
    {
        targetStatus = MODULE_TSTATE_OFF;
    }

    clearMsgInfo(&replyMsgInfo);
}
NewDataModule::NewDataModule()
      : DataModule( MODULE_CLASS_ID,
                    5000000000llu,    // 5s cmdtask error sleep time
                    5000000000llu,    // 5s datatask error sleep time
                     100000000llu,    // 100ms datatask disable sleep time
                    16,               // command mailbox slots
                    48,               // command mailbox data size per slot
                    MBX_IN_KERNELSPACE | MBX_SLOT,  // command mailbox flags
                    5,                // max buffer entries
                    10)               // data buffer listener
{

  // get value(s) out of your argument table
  reqVal        = getIntArg("reqVal", argTab);

  // set dataBuffer size
  setDataBufferMaxDataSize(sizeof(new_data_msg));

  // set databuffer period time
  setDataBufferPeriodTime(10);
}
Esempio n. 14
0
int ICACHE_FLASH_ATTR cgiPropReset(HttpdConnData *connData)
{
    PropellerConnection *connection = &myConnection;
    
    // check for the cleanup call
    if (connData->conn == NULL)
        return HTTPD_CGI_DONE;

    if (connection->state != stIdle) {
        char buf[128];
        os_sprintf(buf, "Transfer already in progress: state %s\r\n", stateName(connection->state));
        httpdSendResponse(connData, 400, buf, -1);
        return HTTPD_CGI_DONE;
    }
    connData->cgiData = connection;
    connection->connData = connData;

    // turn off SSCP during loading
    sscp_enable(0);

    os_timer_setfn(&connection->timer, timerCallback, connection);
    
    if (!getIntArg(connData, "reset-pin", &connection->resetPin))
        connection->resetPin = flashConfig.reset_pin;

    DBG("reset: reset-pin %d\n", connection->resetPin);

    connection->image = NULL;

    GPIO_OUTPUT_SET(connection->resetPin, 0);
    connection->state = stReset;
    
    armTimer(connection, RESET_DELAY_1);

    return HTTPD_CGI_MORE;
}
Esempio n. 15
0
ChassisEr1::ChassisEr1()
        : RackDataModule( MODULE_CLASS_ID,
                      5000000000llu,        // 5s datatask error sleep time
                      16,                   // command mailbox slots
                      48,                   // command mailbox data size per slot
                      MBX_IN_KERNELSPACE | MBX_SLOT, // command mailbox flags
                      5,                    // max buffer entries
                      10)                   // data buffer listener
{
    // get static module parameter
    serialDev               = getStrArg("serialDev", argTab);
    param.vxMax             = getIntArg("vxMax", argTab);
    param.vxMin             = getIntArg("vxMin", argTab);
    param.accMax            = getIntArg("accMax", argTab);
    param.decMax            = getIntArg("decMax", argTab);
    param.omegaMax          = getIntArg("omegaMax", argTab) * M_PI / 180.0;
    param.minTurningRadius  = getIntArg("minTurningRadius", argTab);
    param.breakConstant     = (float)getIntArg("breakConstant", argTab) / 100.0f;
    param.safetyMargin      = getIntArg("safetyMargin", argTab);
    param.safetyMarginMove  = getIntArg("safetyMarginMove", argTab);
    param.comfortMargin     = getIntArg("comfortMargin", argTab);
    param.boundaryFront     = getIntArg("front", argTab);
    param.boundaryBack      = getIntArg("back", argTab);
    param.boundaryLeft      = getIntArg("left", argTab);
    param.boundaryRight     = getIntArg("right", argTab);
    param.wheelBase         = getIntArg("wheelBase", argTab);
    param.wheelRadius       = getIntArg("wheelRadius", argTab);
    param.trackWidth        = getIntArg("trackWidth", argTab);
    param.pilotParameterA   = (float)getIntArg("pilotParameterA", argTab) / 10000.0f;
    param.pilotParameterB   = (float)getIntArg("pilotParameterB", argTab) / 100.0f;
    param.pilotVTransMax    = getIntArg("pilotVTransMax", argTab);


    dataBufferMaxDataSize   = sizeof(chassis_data);
    dataBufferPeriodTime    = 1000 / SAMPLING_RATE;
}
Esempio n. 16
0
int main(int argc, char *argv[])
{
	if ((argc < 6) || (argc > 9))
	{
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}
	//mtarray numThreads threadMemSize rwRatio maxWrapSize numWraps [wrapType [options]
	numThreads = getIntArg(argv[1]);
	threadMemSize = getIntArg(argv[2]);
	rwRatio = getIntArg(argv[3]);
	wrapSize = getIntArg(argv[4]);
	numWraps = getIntArg(argv[5]);
	delay = getIntArg(argv[6]);

	if ((numThreads < 0) || (threadMemSize < 0) || (delay < 0) || (rwRatio < 0) || (wrapSize < 0) || (numWraps < 0))
	{
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}
	int wrapType;
	int wrapOptions;
	if (argc >= 8)
	{
		wrapType = getIntArg(argv[7]);
		if (wrapType < 0)
		{
			usage(argv[0]);
			exit(EXIT_FAILURE);
		}
		if (wrapType == Wrap_Software)
		{
			setAliasTableWorkers(numThreads);
		}
		setWrapImpl((WrapImplType)wrapType);
		if (argc >= 9)
		{
			wrapOptions = getIntArg(argv[8]);
			if (wrapOptions < 0)
			{
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}
			setWrapImplOptions(wrapOptions);
		}
	}

	//  Display memory attributes.
	printMemoryAttributes();

	arraySize = numThreads * threadMemSize;

	StartPhysicalTracer();
	startStatistics();

	//data = (int *)pmalloc(arraySize * sizeof(int));
	//printf("Array size=%d integers with start address: %p\n", arraySize, data);

	//  Create the test threads
	pthread_t *testers = (pthread_t *)malloc(numThreads * sizeof(pthread_t));
	for (int i = 0; i < numThreads; i++)
	{
		pthread_create(&testers[i], NULL, test, (void*)(int64_t)i);
	}

	printf("joining\n");
	for (int i = 0; i < numThreads; i++)
	{
		pthread_join(testers[i], NULL);
	}
	free(testers);

	EndPhysicalTracer();

	printf("%s \t%s \t%s \t%s \t", argv[0], argv[1], argv[2], argv[3]);
	printStatistics(stdout);

	wrapCleanup();

	return 0;
}
Esempio n. 17
0
int execute(int argc, char* argv[])
{
	if (argc <= 1) {
		showHelp();
		return RESULT_EC_SUCCESS;
	}

	std::string fileInput = argv[1];
	int errorlevel = 0;
	int limit = -1;
	bool info = false;
	bool help = false;
	
	for (int i = 1; i < argc; i++)
	{
		getStringArg(fileInput, argv[i], "file");
		getIntArg(errorlevel, argv[i], "errorlevel");
		getIntArg(limit, argv[i], "limit");
		getBoolArg(info, argv[i], "info");
		getBoolArg(help, argv[i], "help");
	}

	if (help) {
		showHelp();
		return RESULT_EC_SUCCESS;
	}

	if (errorlevel < 0 || errorlevel > 3)
	{
		std::cerr << "Invalid value for errorlevel: " << errorlevel << std::endl;

		return RESULT_EC_INVALIDERRORLEVEL;
	}

	int width = 0;
	int height = 0;
	std::vector<std::string> lines;

	try 
	{
		std::ifstream file(fileInput);

		if (!file.is_open())
		{
			std::cerr << "Cannot open file: " << fileInput << std::endl;

			return RESULT_EC_FILEREADEXCEPTION;
		}

		std::string str;
		bool first = true;
		while (std::getline(file, str))
		{
			// UTF-8 BOM
			if (first && str.length() >= 3 && (uint8_t)str.at(0) == 0xEF && (uint8_t)str.at(1) == 0xBB && (uint8_t)str.at(2) == 0xBF)
			{
				str = str.substr(3);
			}

			lines.push_back(str);
			width = std::max(width, (int)str.length());
			height++;

			first = false;
		}
	}
	catch (const std::exception& ex)
	{
		std::cerr << "Cannot open/read file " << fileInput << std::endl;
		std::cerr << ex.what() << std::endl;

		return RESULT_EC_FILEREADEXCEPTION;
	}
	catch (...)
	{
		std::cerr << "Unknown internal exception in file " << __FILE__ << " at line " << __LINE__ << std::endl;

		return RESULT_EC_UNKNOWNEXCEPTION;
	}

	if (width <= 0 || height <= 0)
	{
		std::cerr << "The program has an size of zero" << std::endl;

		return RESULT_EC_INVALIDSIZE;
	}

	IBefungeRunner *runner;

	if (info)
	{
		runner = new BefungeRunnerInfo(width, height);
	}
	else if (errorlevel == 0)
	{
		runner = new BefungeRunner0(width, height);
	}
	else if (errorlevel == 1)
	{
		runner = new BefungeRunner1(width, height);
	}
	else if (errorlevel == 2)
	{
		runner = new BefungeRunner2(width, height);
	}
	else if (errorlevel == 3)
	{
		runner = new BefungeRunner3(width, height);
	}
	else
	{
		std::cerr << "Cannot create a befunge runner for the supplied parameters" << std::endl;
		return RESULT_EC_INVALIDRUNNER;
	}

	runner->Init(lines);
	runner->SetLimit(limit);

	try
	{
		runner->Run();
	}
	catch (const BFRunException& ex)
	{
		std::cerr << ex.what() << std::endl;

		return ex.exitCode;
	}
	catch (const std::exception& ex)
	{
		std::cerr << "Internal exception while running program:" << std::endl;
		std::cerr << ex.what() << std::endl;

		return RESULT_EC_UNKNOWNEXCEPTION;
	}
	catch (...)
	{
		std::cerr << "Unknown internal exception in file " << __FILE__ << " at line " << __LINE__ << std::endl;

		return RESULT_EC_UNKNOWNEXCEPTION;
	}

	delete runner;

	return RESULT_EC_SUCCESS;
}
Esempio n. 18
0
int main(int argc,const char ** argv)
{
	if ( argc == 1 )
	{
		printf("Usage: TestHACD <wavefront.obj> (options)\r\n");
		printf("\r\n");
		printf("Options:\r\n");
		printf("-v	<count>	: Max Hull Vertices (default 64)\r\n");
		printf("-m	<count>	: Maximum number of hulls output from HACD (default 256)\r\n");
		printf("-merge <count> : Maximum number of hulls after merging the HACD result.\r\n");
		printf("-mergethreshold <volume> : Threshold below which hulls are merged if they are smaller than the given volume.\r\n");
		printf("-c <concavity> : Between 0 and 1 are good ranges to try; default is 0.2.  The smaller the number, the more convex hulls are produced.\r\n");
		printf("-b <backFaceDistanceFactor : The back face distance factor, default is 0.2\r\n");
		printf("-t <threadCount> : Specifies the number of threads to use for a multi-threaded implementation\r\n");
		printf("-d <decompositionDepth> : Specifies the decomposition depth; uses legacy ACD instead of HACD\r\n");
		printf("-n : Normalize the input mesh.\r\n");
		printf("-f : Use legacy 'fast' version of HACD\r\n");
		printf("\r\n");
		printf("Example: TestHACD hornbug.obj -m 40 -v 64\r\n");
		printf("\r\n");
	}
	else
	{
		HACD::HACD_API::Desc desc;
		const char *wavefront = argv[1];
		int scan = 2;
		int threadCount = 0;


		while ( scan < argc )
		{
			const char *option = argv[scan];
			if ( strcmp(option,"-v") == 0 )
			{
				desc.mMaxHullVertices = getIntArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-t") == 0 )
			{
				threadCount  = getIntArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-d") == 0 )
			{
				desc.mDecompositionDepth  = getIntArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-b") == 0 )
			{
				desc.mBackFaceDistanceFactor = getFloatArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-m") == 0 )
			{
				desc.mMaxHullCount = getIntArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-merge") == 0 )
			{
				desc.mMaxMergeHullCount = getIntArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-mergethreshold") == 0 )
			{
				desc.mSmallClusterThreshold = getFloatArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-c") == 0 )
			{
				desc.mConcavity = getFloatArg(scan+1,argc,argv);
				scan+=2;
			}
			else if ( strcmp(option,"-n") == 0 )
			{
				desc.mNormalizeInputMesh = true;
				scan++;
			}
			else if ( strcmp(option,"-f") == 0 )
			{
				desc.mUseFastVersion = true;
				scan++;
			}
			else
			{
				scan++;
			}
		}
		
		HACD::gHACD = HACD::createHACD_API();
		if  ( HACD::gHACD )
		{
			MyCallback callback;
			WavefrontObj obj;
			unsigned int tcount = obj.loadObj(wavefront,false);
			if ( tcount )
			{
				desc.mTriangleCount = obj.mTriCount;
				desc.mVertexCount = obj.mVertexCount;
				desc.mIndices = (hacd::HaU32 *)obj.mIndices;
				desc.mVertices = obj.mVertices;
			}
			desc.mCallback = static_cast<hacd::ICallback*>(&callback);
			if ( desc.mTriangleCount )
			{
				printf("Performing HACD on %d input triangles.\r\n", desc.mTriangleCount );
				printf("\r\n");
				printf("TriangleCount            : %d\r\n", desc.mTriangleCount );
				printf("VertexCount              : %d\r\n", desc.mVertexCount );
				printf("Concavity                : %0.2f\r\n", desc.mConcavity );
				printf("Max Hull Vertex Count    : %3d\r\n", desc.mMaxHullVertices );
				printf("Max Convex Hulls         : %3d\r\n", desc.mMaxHullCount );
				printf("Max Merged Convex Hulls  : %3d\r\n", desc.mMaxMergeHullCount );
				printf("Merge Threshold          : %0.2f\r\n", desc.mSmallClusterThreshold);
				printf("Back Face Distance Factor: %0.2f\r\n", desc.mBackFaceDistanceFactor );
				printf("Small Cluster Threshold  : %0.2f\r\n", desc.mSmallClusterThreshold );
				if ( desc.mDecompositionDepth )
				{
					printf("DecompositionDepth       : %d\r\n", desc.mDecompositionDepth );
				}

				if ( desc.mNormalizeInputMesh )
				{
					printf("Normalizing input mesh.\r\n");
				}

				if ( desc.mUseFastVersion )
				{
					printf("Using 'fast' version of HACD.\r\n");
				}

				printf("\r\n");

				desc.mJobSwarmContext = NULL;

				hacd::HaU32 hullCount = HACD::gHACD->performHACD(desc);

				if ( hullCount != 0 )
				{
					printf("\r\n");
					printf("Produced %d output convex hulls. Saving output to 'ConvexDecomposition.obj' for review.\r\n", hullCount );
					FILE *fph = fopen("ConvexDecomposition.obj", "wb");
					if ( fph )
					{
						fprintf(fph,"# Input mesh '%s' produced %d convex hulls.\r\n", wavefront, hullCount );
						hacd::HaU32 *baseVertex = new hacd::HaU32[hullCount];
						hacd::HaU32 vertexCount = 0;
						for (hacd::HaU32 i=0; i<hullCount; i++)
						{
							const HACD::HACD_API::Hull *hull = HACD::gHACD->getHull(i);
							if ( hull )
							{
								baseVertex[i] = vertexCount;
								fprintf(fph,"## Hull %d has %d vertices.\r\n", i+1, hull->mVertexCount );
								for (hacd::HaU32 i=0; i<hull->mVertexCount; i++)
								{
									const hacd::HaF32 *p = &hull->mVertices[i*3];
									fprintf(fph,"v %0.9f %0.9f %0.9f\r\n", p[0], p[1], p[2] );
								}
								vertexCount+=hull->mVertexCount;
							}
						}
						for (hacd::HaU32 i=0; i<hullCount; i++)
						{
							const HACD::HACD_API::Hull *hull = HACD::gHACD->getHull(i);
							if ( hull )
							{
								hacd::HaU32 startVertex = baseVertex[i];
								fprintf(fph,"# Convex Hull %d contains %d triangles and %d vertices.  Starting vertex index is: %d It has a volume of: %0.9f\r\n", i+1, hull->mTriangleCount, hull->mVertexCount, startVertex);
								fprintf(fph,"g convex_hull%d\r\n", i+1);
								for (hacd::HaU32 j=0; j<hull->mTriangleCount; j++)
								{
									hacd::HaU32 i1 = hull->mIndices[j*3+0]+startVertex+1;
									hacd::HaU32 i2 = hull->mIndices[j*3+1]+startVertex+1;
									hacd::HaU32 i3 = hull->mIndices[j*3+2]+startVertex+1;
									fprintf(fph,"f %d %d %d\r\n", i1, i2, i3 );
								}
							}
						}
					}
					else
					{
						printf("Failed to open output file.\r\n");
					}
				}
			}
			else
			{
				printf("Failed to load Wavefront OBJ file '%s'\r\n",wavefront);
			}
		}
		else
		{
			printf("Failed to load the HACD DLL\r\n");
		}
	}
	
	return 0;
}
Esempio n. 19
0
MStatus mDblRand::doIt( const MArgList& args )
{
	MStatus stat;
	int count = 1;
    
   	srand(mfSeed);
    
	// check how many arguments we have
	if (args.length() == 0)
	{
		// no args
		// just return a single double
		setResult(MDoubleArray(1,(rand()/((double)RAND_MAX + 1))));
		return MS::kSuccess;
	}
	else if (args.length() == 1)
	{
		// one args, check if its an int - if yes return int identity arrays
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);
        MDoubleArray result(count);
        
        double randDif = ((double)RAND_MAX + 1);
        
        for (int i=0; i< count; i++)
			result[i] = rand()/randDif;
        
        setResult(result);
		return MS::kSuccess;
	}
	else if (args.length() == 3)
	{
		double min, max;
        
		stat = getIntArg(args, 0, count);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 1, min);
		ERROR_FAIL(stat);

		stat = getDoubleArg(args, 2, max);
		ERROR_FAIL(stat);

      	MDoubleArray result(count);
        
        if (min == max)
        {
        	result =  MDoubleArray(count,max);
        }
        else
        {
            if (max < min)
        	{
        		//swap
	            double help = max;
    	        max = min;
        	    min = help;
	        }    
        
    	    double randDif = ((double)RAND_MAX + 1) / (max-min);
            
	        for (int i=0; i< count; i++)
				result[i] = (rand()/randDif)+min;
       	}
        
        setResult(result);
		return MS::kSuccess;
	}
	else
	{
		ERROR_FAIL(MS::kFailure);	
	}
}
Esempio n. 20
0
CameraDcam::CameraDcam()
        : RackDataModule( MODULE_CLASS_ID,
                      5000000000llu,        // 5s datatask error sleep time
                      16,                   // command mailbox slots
                      48,                   // command mailbox data size per slot
                      MBX_IN_KERNELSPACE | MBX_SLOT, // command mailbox flags //## it should be user space
                      25,                    // max buffer entries
                      10)                   // data buffer listener
{
    // get static module parameter
    format              = FORMAT_SVGA_NONCOMPRESSED_2;
    frameRate           = FRAMERATE_7_5; // only used in continuous grabbing mode (con. iso transmission, not implemented yet.)
                                         // not used in singleshot opiton! Must be set in protocol.
    device              = "/dev/video1394"; // only possible with only one device!
    cameraGuid          = getIntArg("cameraGuid", argTab);
    mode                = getIntArg("mode", argTab);
                        //bytesPerPixel[i]    included in mode
    vValue              = getIntArg("vValue", argTab);
    uValue              = getIntArg("uValue", argTab);
    minHue              = getIntArg("minHue", argTab);
    maxHue              = getIntArg("maxHue", argTab);
    fps                 = getIntArg("fps", argTab);
    gainMult            = getIntArg("gainMult", argTab);
    shutterMult         = getIntArg("shutterMult", argTab);
    lossRate            = getIntArg("lossrate", argTab);
    autoBrightnessSize  = getIntArg("autoBrightnessSize", argTab);
    whitebalanceMode    = getIntArg("whitebalanceMode", argTab);
    whitebalanceRows    = getIntArg("whitebalanceRows", argTab);
    whitebalanceCols    = getIntArg("whitebalanceCols", argTab);
    intrParFile         = getStrArg("intrParFile", argTab);
    extrParFile         = getStrArg("extrParFile", argTab);

    if (fps > 10)
        fps = 10;

    format7image.mode              = MODE_FORMAT7_0;//fixed!!
    format7image.bytesPerPacket    = USE_MAX_AVAIL;
    format7image.leftImagePosition =   54;//take middle part of image at max image size //values for OUR camera
    format7image.topImagePosition  =   39;//take middle part of image at max image size
    format7image.width             = 1280;//1388
    format7image.height            =  960;//1038
    format7image.colorFilterId     = COLORFILTER_RGGB;
    format7image.colorCodingId     = COLOR_FORMAT7_MONO8; //COLOR_FORMAT7_RAW8; //COLOR_FORMAT7_RAW16;

    dataBufferMaxDataSize   = sizeof(camera_data_msg);
    dataBufferPeriodTime    = 1000 / fps;
}
Esempio n. 21
0
int main(int argc, char *argv[])
{
	if ((argc < 4) || (argc > 6))
	{
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	int arrayTraceOption = getIntArg(argv[1]);
	int wrapSize = getIntArg(argv[2]);
	int numWraps = getIntArg(argv[3]);

	if ((arrayTraceOption < 0) || (wrapSize < 0) || (numWraps < 0))
	{
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}
	int wrapType;
	int wrapOptions;
	if (argc >= 5)
	{
		wrapType = getIntArg(argv[4]);
		if (wrapType < 0)
		{
			usage(argv[0]);
			exit(EXIT_FAILURE);
		}
		setWrapImpl((WrapImplType)wrapType);
		if (argc >= 6)
		{
			wrapOptions = getIntArg(argv[5]);
			if (wrapOptions < 0)
			{
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}
			setWrapImplOptions(wrapOptions);
		}
	}

	//  Display memory attributes.
	printMemoryAttributes();

	if (arrayTraceOption == 0)
		arraySize = numWraps * wrapSize * IntsPerLine;
	else if (arrayTraceOption == 1)
		arraySize = numWraps * wrapSize;
	else if (arrayTraceOption == 2)
		arraySize = wrapSize*numWraps;
		//arraySize = dmax(BlockSize, wrapSize * numWraps);
	else if (arrayTraceOption == 3)
		arraySize = BlockSize /sizeof(int) * numWraps;
	else if (arrayTraceOption == 4)
		arraySize = (BlockSize / sizeof(int))*numWraps;
	else
		assert(0);

	StartPhysicalTracer();
	startStatistics();

	arraySize = 20000;

	int *data = (int *)pmalloc(arraySize * sizeof(int));
	printf("Array size=%d integers with start address: %p\n", arraySize, data);

	//init(data, arraysize, hotCache);

	if (arrayTraceOption == 4)
		blockCow(data, numWraps, wrapSize, arraySize);
	else
		trace(data, numWraps, wrapSize, IntsPerLine, arrayTraceOption);

	EndPhysicalTracer();

	printf("%s \t%s \t%s \t%s \t", argv[0], argv[1], argv[2], argv[3]);
	printStatistics(stdout);

	wrapCleanup();
	pfree(data);
	//  Shadow Paging cleanup.
	if (shadowPaging != NULL)
		pfree(shadowPaging);

	return 0;
}
Esempio n. 22
0
static bool
_parseOptions (int *pargc, char **argv, int *i)
{
  if (argv[*i][0] == '-')
    {
      if (IS_GB)
        {
          if (!strncmp (argv[*i], OPTION_BO, sizeof (OPTION_BO) - 1))
            {
              /* ROM bank */
              int bank = getIntArg (OPTION_BO, argv, i, *pargc);
              struct dbuf_s buffer;

              dbuf_init (&buffer, 16);
              dbuf_printf (&buffer, "CODE_%u", bank);
              dbuf_c_str (&buffer);
              /* ugly, see comment in src/port.h (borutr) */
              gbz80_port.mem.code_name = dbuf_detach (&buffer);
              options.code_seg = (char *)gbz80_port.mem.code_name;
              return TRUE;
            }
          else if (!strncmp (argv[*i], OPTION_BA, sizeof (OPTION_BA) - 1))
            {
              /* RAM bank */
              int bank = getIntArg (OPTION_BA, argv, i, *pargc);
              struct dbuf_s buffer;

              dbuf_init (&buffer, 16);
              dbuf_printf (&buffer, "DATA_%u", bank);
              dbuf_c_str (&buffer);
              /* ugly, see comment in src/port.h (borutr) */
              gbz80_port.mem.data_name = dbuf_detach (&buffer);
              return TRUE;
            }
        }
      else if (!strncmp (argv[*i], OPTION_ASM, sizeof (OPTION_ASM) - 1))
        {
          char *asmblr = getStringArg (OPTION_ASM, argv, i, *pargc);

          if (!strcmp (asmblr, "rgbds"))
            {
              asm_addTree (&_rgbds_gb);
              gbz80_port.assembler.cmd = _gbz80_rgbasmCmd;
              gbz80_port.linker.cmd = _gbz80_rgblinkCmd;
              gbz80_port.linker.do_link = _gbz80_rgblink;
              _G.asmType = ASM_TYPE_RGBDS;
              return TRUE;
            }
          else if (!strcmp (asmblr, "asxxxx"))
            {
              _G.asmType = ASM_TYPE_ASXXXX;
              return TRUE;
            }
          else if (!strcmp (asmblr, "isas"))
            {
              asm_addTree (&_isas_gb);
              /* Munge the function prefix */
              gbz80_port.fun_prefix = "";
              _G.asmType = ASM_TYPE_ISAS;
              return TRUE;
            }
          else if (!strcmp (asmblr, "z80asm"))
            {
              port->assembler.externGlobal = TRUE;
              asm_addTree (&_z80asm_z80);
              _G.asmType = ASM_TYPE_ISAS;
              return TRUE;
            }
        }
      else if (!strncmp (argv[*i], OPTION_PORTMODE, sizeof (OPTION_PORTMODE) - 1))
        {
           char *portmode = getStringArg (OPTION_ASM, argv, i, *pargc);

          if (!strcmp (portmode, "z80"))
            {
              z80_opts.port_mode = 80;
              return TRUE;
            }
          else if (!strcmp (portmode, "z180"))
            {
              z80_opts.port_mode = 180;
              return TRUE;
            }
        }
  }
  return FALSE;
}