Example #1
0
void Player::Render(){

	for (size_t i = 0; i < MAX_BULLETS; i++) {
		bullets[i].Render();
	}

	float heightRatio = mapValue(fabs(velocityY), 0.0, 1.0, 1.0, 1.6);
	float widthRatio = mapValue(fabs(velocityY), 0.0, 1.0, 0.8, 1.0);
	float renderheight = heightRatio * 0.15;
	float renderwidth = widthRatio * 0.15;

	sprite.Draw(renderwidth, renderheight, xPos, yPos+0.001f, rotation);
}
Example #2
0
/**
 * @internal
 * @brief QBsonConverter::mapArray map a array to QJSValue. Converts values with
 * mapValue method.
 *
 * @param bsonArray
 *
 * @return QJSValue
 */
QJSValue QBsonConverter::mapArray(const QBsonArray &bsonArray)
{
    QList<QBsonValue> arValues = bsonArray.values();
    QList<QBsonValue>::iterator it;
    QJSValue jsArray = m_jsEngine->newArray(bsonArray.size());
    int i = 0;
    for (it = arValues.begin(); it != arValues.end(); it++) {
        jsArray.setProperty(i++, mapValue(*it));
    }
    return jsArray;
}
Example #3
0
/**
 * @internal
 * @brief QBsonConverter::mapArray converts a jsArray to a bsonArray. Redirect
 * to mapValue method to convert array values.
 *
 * @param jsArray
 *
 * @return QBsonArray
 */
QBsonArray QBsonConverter::mapArray(const QJSValue &jsArray)
{
    QJSValueIterator it(jsArray);
    QBsonArray bsonArray;
    while (it.next()) {
        const QString name = it.name();
        if (name != QString::fromLatin1("length")) {
            bsonArray.append(mapValue(it.value()));
        }
    }
    return bsonArray;
}
Example #4
0
/**
 * @internal
 * @brief QBsonConverter::mapObject
 * @param bsonObject
 * @return
 */
QJSValue QBsonConverter::mapObject(const QBsonObject &bsonObject)
{
    const QBsonValueHash values = bsonObject.values();
    QBsonValueHash::const_iterator it;
    QJSValue jsObject = m_jsEngine->newObject();
    if (bsonObject.hasOid()) {
        jsObject.setProperty("_id", bsonObject.oid().toString());
    }
    for (it = values.begin(); it != values.end(); it++) {

        jsObject.setProperty(it.key(), mapValue(it.value()));
    }
    return jsObject;
}
Example #5
0
/**
 * @internal
 * @brief QBsonConverter::mapObject converts a jsObject to a bsonObject. Redirect
 * to mapValue method to convert child values. Map property name id to _id.
 *
 * @param jsObject
 *
 * @return
 */
QBsonObject QBsonConverter::mapObject(const QJSValue &jsObject)
{
    QJSValueIterator it(jsObject);
    QBsonObject bsonObject;
    for (; it.next();) {
        const QString name = it.name();
        if (name == "_id") {
            bsonObject.setOid(QBsonOid(it.value().toString()));
            continue;
        }
        bsonObject.append(name, mapValue(it.value()));
    }
    return bsonObject;
}
Example #6
0
void TXaxis::setAnswersList(QList<TQAunit*> *answers, Tlevel* level) {
    m_answers = answers;
    m_level = level;
    setLength(m_qWidth * (m_answers->size() + 1));
    update(boundingRect());
    m_ticTips.clear();
    for (int i = 0; i < m_answers->size(); i++) {
        QGraphicsTextItem *ticTip = new QGraphicsTextItem();
        setTicText(ticTip, m_answers->operator[](i), i + 1);
        scene()->addItem(ticTip);
        ticTip->setPos(pos().x() + mapValue(i+1) - ticTip->boundingRect().width() / 2 , pos().y() + 15);
        m_ticTips << ticTip;
    }
}
Example #7
0
void TXaxis::setAnswersForBarChart(QList<TgroupedQAunit>& listOfLists) {
    setLength(m_qWidth * (listOfLists.size() + 1));
    update(boundingRect());
    m_ticTips.clear();
    for (int i = 0; i < listOfLists.size(); i++) {
        QGraphicsTextItem *ticTip = new QGraphicsTextItem();
        ticTip->setHtml(listOfLists[i].description());
        TgraphicsTextTip::alignCenter(ticTip);
        if ((ticTip->boundingRect().width() * scale()) > m_qWidth)
            ticTip->setScale(((qreal)m_qWidth * scale()) / ticTip->boundingRect().width());
        scene()->addItem(ticTip);
        ticTip->setPos(pos().x() + mapValue(i + 1) - (ticTip->boundingRect().width() * ticTip->scale()) / 2 , pos().y() + 15);
        m_ticTips << ticTip;
    }
}
Example #8
0
int getKeyTypeTag( IN_HANDLE_OPT const CRYPT_CONTEXT cryptContext,
				   IN_ALGO_OPT const CRYPT_ALGO_TYPE cryptAlgo,
				   OUT int *tag )
	{
	static const MAP_TABLE tagMapTbl[] = {
		{ CRYPT_ALGO_RSA, 100 },
		{ CRYPT_ALGO_DH, CTAG_PK_DH },
		{ CRYPT_ALGO_ELGAMAL, CTAG_PK_DH },
		{ CRYPT_ALGO_DSA, CTAG_PK_DSA },
		{ CRYPT_ALGO_ECDSA, CTAG_PK_ECC },
		{ CRYPT_ERROR, CRYPT_ERROR }, { CRYPT_ERROR, CRYPT_ERROR }
		};
	int keyCryptAlgo, value, status;

	REQUIRES( ( isHandleRangeValid( cryptContext ) && \
				cryptAlgo == CRYPT_ALGO_NONE ) || \
			  ( cryptContext == CRYPT_UNUSED && \
				isPkcAlgo( cryptAlgo ) ) );

	/* Clear return value */
	*tag = 0;

	/* If the caller hasn't already supplied the algorithm details, get them
	   from the context */
	if( cryptAlgo != CRYPT_ALGO_NONE )
		keyCryptAlgo = cryptAlgo;
	else
		{
		status = krnlSendMessage( cryptContext, IMESSAGE_GETATTRIBUTE,
								  &keyCryptAlgo, CRYPT_CTXINFO_ALGO );
		if( cryptStatusError( status ) )
			return( status );
		}

	/* Map the algorithm to the corresponding tag.  We have to be a bit 
	   careful with the tags because the out-of-band special-case value 
	   DEFAULT_TAG looks like an error value, so we supply a dummy value
	   of '100' for this tag and map it back to DEFAULT_TAG when we return
	   it to the caller */
	status = mapValue( keyCryptAlgo, &value, tagMapTbl, 
					   FAILSAFE_ARRAYSIZE( tagMapTbl, MAP_TABLE ) );
	ENSURES( cryptStatusOK( status ) );
	*tag = ( value == 100 ) ? DEFAULT_TAG : value;

	return( CRYPT_OK );
	}
Example #9
0
void TXaxis::setAnswersLists(QList<TgroupedQAunit>& listOfLists, Tlevel* level) {
    int ln = 0, cnt = 0;
    m_level = level;
    for (int i = 0; i < listOfLists.size(); i++) {
        ln += listOfLists[i].size();
    }
    setLength(m_qWidth * (ln + 1));
    update(boundingRect());
    m_ticTips.clear();
    for (int i = 0; i < listOfLists.size(); i++) {
        for (int j = 0; j < listOfLists[i].size(); j++) {
            cnt++;
            QGraphicsTextItem *ticTip = new QGraphicsTextItem();
            setTicText(ticTip, listOfLists[i].operator[](j).qaPtr);
            scene()->addItem(ticTip);
            ticTip->setPos(pos().x() + mapValue(cnt) - ticTip->boundingRect().width() / 2 , pos().y() + 15);
            m_ticTips << ticTip;
        }
    }
}
Example #10
0
void Asteroids::Update(float elapsed) {
	playerStartAnimationTime += elapsed;
	if (playerStartAnimationTime < 1.0f) {
		float animationAValue = mapValue(playerStartAnimationTime, 0.4f, 2.0f, 0.0f, 1.0f);
		player->scale_x = easeOutElastic(0.0, 1.0, animationAValue);
		player->scale_y = easeOutElastic(0.0, 1.0, animationAValue);
	}

	for (size_t i = 0; i < entities.size(); i++) {
		entities[i]->Update(elapsed);
	}

	for (size_t i = 0; i < MAX_BULLETS; i++) {
		bullets[i].Update(elapsed);
	}

	for (size_t i = 0; i < particleEmitters.size(); i++) {
		particleEmitters[i].Update(elapsed);
	}

	shootTimer += elapsed;
	enemySpawnTimer += elapsed;
}
float XBOXController::getAxis(JoyAxis i)
{
	if ((i == ZAxis) && ((m_caps.wCaps&JOYCAPS_HASZ) == 0))
		return 0.0f;
	
	if ((i == RAxis) && ((m_caps.wCaps&JOYCAPS_HASR) == 0))
		return 0.0f;

	if ((i == UAxis) && ((m_caps.wCaps&JOYCAPS_HASU) == 0))
		return 0.0f;

	if ((i == VAxis) && ((m_caps.wCaps&JOYCAPS_HASV) == 0))
		return 0.0f;

	float res = 0.0f;

	switch (i)
	{
	case XAxis:
		res = mapValue(joyInfoEx.dwXpos, m_caps.wXmin, m_caps.wXmax);
		break;
	case YAxis:
		res = mapValue(joyInfoEx.dwYpos, m_caps.wYmin, m_caps.wYmax);
		break;
	case ZAxis:
		res = mapValue(joyInfoEx.dwZpos, m_caps.wZmin, m_caps.wZmax);
		break;
	case RAxis:
		res = mapValue(joyInfoEx.dwRpos, m_caps.wRmin, m_caps.wRmax);
		break;
	case UAxis:
		res = mapValue(joyInfoEx.dwUpos, m_caps.wUmin, m_caps.wUmax);
		break;
	case VAxis:
		res = mapValue(joyInfoEx.dwVpos, m_caps.wVmin, m_caps.wVmax);
		break;
	default:
		break;
	}

	return res;
}
Example #12
0
void Asteroids::FixedUpdate(float fixedElapsed) {

	player->scale_y = mapValue(fabs(player->velocity_y), 0.0, 5.0, 1.0, 1.6);
	player->scale_x = mapValue(fabs(player->velocity_y), 5.0, 0.0, 0.8, 1.0);

	for (size_t i = 0; i < entities.size(); i++) {
		entities[i]->FixedUpdate();

		
		

		if (!entities[i]->isStatic) {
			entities[i]->velocity_x += gravity_x * FIXED_TIMESTEP;
			entities[i]->velocity_y += gravity_y * FIXED_TIMESTEP;
		}


		entities[i]->velocity_x = lerp(entities[i]->velocity_x, 0.0f, FIXED_TIMESTEP * entities[i]->friction_x);
		entities[i]->velocity_y = lerp(entities[i]->velocity_y, 0.0f, FIXED_TIMESTEP * entities[i]->friction_y);

		entities[i]->velocity_x += entities[i]->acceleration_x * FIXED_TIMESTEP;
		entities[i]->velocity_y += entities[i]->acceleration_y * FIXED_TIMESTEP;

		if (!entities[i]->isStatic) {
			for (size_t j = 0; j < entities.size(); j++) {
				if (checkCollision(entities[i], entities[j])) {
					Vector distance = Vector(entities[i]->x - entities[j]->x, entities[i]->y - entities[j]->y, 0.0f);
					float distLength = distance.length();
					distance.normalize();

					entities[i]->x += distance.x * 0.0001f / pow(distLength, 2);
					entities[i]->y += distance.y * 0.0001f / pow(distLength, 2);

					entities[j]->x -= distance.x * 0.0001f / pow(distLength, 2);
					entities[j]->y -= distance.y * 0.0001f / pow(distLength, 2);
				}
			}
			
		}

		entities[i]->y += entities[i]->velocity_y * -cos(entities[i]->rotation) * FIXED_TIMESTEP;
		entities[i]->x += entities[i]->velocity_x * sin(entities[i]->rotation) * FIXED_TIMESTEP;
		

	}

	for (int i = 1; i < entities.size(); i++) {
		//enemy gets hit
		for (int k = 0; k < MAX_BULLETS; k++) {
			if (bullets[k].visible && checkCollision(entities[i], &bullets[k]) ) {
				bullets[k].visible = false;

				ParticleEmitter demoParticles(300);
				demoParticles.maxLifetime = 1.0f;
				demoParticles.position = Vector(entities[i]->x, entities[i]->y, 0.0f);
				demoParticles.velocity = Vector(sin(player->rotation)*bullets[k].velocity_x/2, -cos(player->rotation)*bullets[k].velocity_y/2, 0.0f);
				demoParticles.velocityDeviation = Vector(0.5f, 1.5f, 0.0f);
				particleEmitters.push_back(demoParticles);
				particleEmitters.back().trigger();

				if (entities[i]->scale_x < 1.0f) {
					delete entities[i];
					entities.erase(entities.begin() + i);
					break;
				}
				else {
					entities[i]->scale_x = entities[i]->scale_x * 0.67;
					entities[i]->scale_y = entities[i]->scale_y * 0.67;
					entities[i]->rotation = genRandomNumber(-90.0f, 90.0f);
				}
					
			
			}
		}
	}
}
Example #13
0
		{ CRYPT_IATTRIBUTE_KEY_PGP_PARTIAL, KEYFORMAT_PGP },
		{ CRYPT_IATTRIBUTE_KEY_SPKI, KEYFORMAT_CERT },
		{ CRYPT_IATTRIBUTE_KEY_SPKI_PARTIAL, KEYFORMAT_CERT },
		{ CRYPT_ERROR, 0 }, { CRYPT_ERROR, 0 }
		};
	int value, status;

	assert( isWritePtr( keyformat, sizeof( KEYFORMAT_TYPE ) ) );

	REQUIRES( isAttribute( attribute ) || \
			  isInternalAttribute( attribute ) );

	/* Clear return value */
	*keyformat = KEYFORMAT_NONE;

	status = mapValue( attribute, &value, attributeMapTbl, 
					   FAILSAFE_ARRAYSIZE( attributeMapTbl, MAP_TABLE ) );
	ENSURES( cryptStatusOK( status ) );
	*keyformat = value;

	return( CRYPT_OK );
	}

/****************************************************************************
*																			*
*						Key Parameter Handling Functions					*
*																			*
****************************************************************************/

/* Initialise crypto parameters such as the IV and encryption mode, shared 
   by most capabilities.  This is never called directly, but is accessed
   through function pointers in the capability lists */
Example #14
0
//using volume to determine the brightness of the color
float audMode::getValue(float volume) {
	return mapValue(volume, 0, 2)+100;
}
Example #15
0
	{ CTAG_PB_P10CR, CRYPT_REQUESTTYPE_CERTIFICATE },
	{ CTAG_PB_KUR, CRYPT_REQUESTTYPE_KEYUPDATE },
	{ CTAG_PB_RR, CRYPT_REQUESTTYPE_REVOCATION },
	{ CTAG_PB_GENM, CRYPT_REQUESTTYPE_PKIBOOT },
	{ CRYPT_ERROR, CRYPT_ERROR }, { CRYPT_ERROR, CRYPT_ERROR }
	};

CHECK_RETVAL_RANGE( CRYPT_REQUESTYPE_NONE, CRYPT_REQUESTYPE_LAST ) \
static int reqToClibReq( IN_ENUM_OPT( CTAG_PB ) const CMP_MESSAGE_TYPE reqType )
	{
	int value, status;

	REQUIRES( reqType >= CTAG_PB_IR && reqType < CTAG_PB_LAST );
			  /* CTAG_PB_IR == 0 so this is the same as _NONE */

	status = mapValue( reqType, &value, reqClibReqMapTbl, 
					   FAILSAFE_ARRAYSIZE( reqClibReqMapTbl, MAP_TABLE ) );
	return( cryptStatusError( status ) ? status : value );
	}

/* Set up user authentication information (either a MAC context or a public 
   key) based on a request submitted by the client.  This is done whenever 
   the client starts a new transaction with a new user ID or certificate 
   ID */

CHECK_RETVAL STDC_NONNULL_ARG( ( 1, 2 ) ) \
int initServerAuthentMAC( INOUT SESSION_INFO *sessionInfoPtr, 
						  INOUT CMP_PROTOCOL_INFO *protocolInfo )
	{
	CMP_INFO *cmpInfo = sessionInfoPtr->sessionCMP;
	MESSAGE_KEYMGMT_INFO getkeyInfo;
	MESSAGE_DATA msgData;
Example #16
0
float
AbstractSliderBase::getMappedValue(float internalVal) const
{
    return mapValue(internalVal, range_, mapType_);
}
Example #17
0
	assert( isWritePtr( stream, sizeof( STREAM ) ) );
	assert( isWritePtr( objectOffset, sizeof( int ) ) );
	assert( isWritePtr( objectLength, sizeof( int ) ) );
	assert( isWritePtr( objectType, sizeof( CRYPT_CERTTYPE_TYPE ) ) );

	REQUIRES( formatHint >= CRYPT_CERTTYPE_NONE && \
			  formatHint < CRYPT_CERTTYPE_LAST );

	/* Clear return values */
	*objectOffset = *objectLength = 0;
	*objectType = CRYPT_CERTTYPE_NONE;

	/* Figure out how much data we need to have for a minimum-length 
	   object */
	status = mapValue( formatHint, &minLength, minLengthMapTable,
					   FAILSAFE_ARRAYSIZE( minLengthMapTable, MAP_TABLE ) );
	ENSURES( cryptStatusOK( status ) );

	/* If it's an SSL certificate chain then there's no recognisable 
	   tagging, however the caller will have told us what it is */
	if( formatHint == CRYPT_ICERTTYPE_SSL_CERTCHAIN )
		{
		*objectLength = sMemDataLeft( stream );
		*objectType = CRYPT_ICERTTYPE_SSL_CERTCHAIN;
		return( CRYPT_OK );
		}

	/* Check whether we need to process the object wrapper using context-
	   specific tagging rather than the usual SEQUENCE */
	status = tag = peekTag( stream );
	if( cryptStatusError( status ) )
Example #18
0
BOOLEAN checkAttributesConsistent( INOUT SESSION_INFO *sessionInfoPtr,
								   IN_ATTRIBUTE const CRYPT_ATTRIBUTE_TYPE attribute )
	{
	static const MAP_TABLE excludedAttrTbl[] = {
		{ CRYPT_SESSINFO_REQUEST, 
			CHECK_ATTR_REQUEST | CHECK_ATTR_PRIVKEY | CHECK_ATTR_PRIVKEYSET },
		{ CRYPT_SESSINFO_PRIVATEKEY,
			CHECK_ATTR_PRIVKEY | CHECK_ATTR_PRIVKEYSET },
		{ CRYPT_SESSINFO_CACERTIFICATE, 
			CHECK_ATTR_CACERT | CHECK_ATTR_FINGERPRINT },
		{ CRYPT_SESSINFO_SERVER_FINGERPRINT_SHA1, 
			CHECK_ATTR_FINGERPRINT | CHECK_ATTR_CACERT },
		{ CRYPT_ERROR, 0 }, { CRYPT_ERROR, 0 } 
		};
	int flags = 0, status;

	assert( isWritePtr( sessionInfoPtr, sizeof( SESSION_INFO ) ) );
	
	REQUIRES_B( attribute == CRYPT_SESSINFO_REQUEST || \
				attribute == CRYPT_SESSINFO_PRIVATEKEY || \
				attribute == CRYPT_SESSINFO_CACERTIFICATE || \
				attribute == CRYPT_SESSINFO_SERVER_FINGERPRINT_SHA1 );

	/* Find the excluded-attribute information for this attribute */
	status = mapValue( attribute, &flags, excludedAttrTbl,
					   FAILSAFE_ARRAYSIZE( excludedAttrTbl, MAP_TABLE ) );
	ENSURES( cryptStatusOK( status  ) );

	/* Make sure that none of the excluded attributes are present */
	if( ( flags & CHECK_ATTR_REQUEST ) && \
		sessionInfoPtr->iCertRequest != CRYPT_ERROR )
		{
		setErrorInfo( sessionInfoPtr, CRYPT_SESSINFO_REQUEST,
					  CRYPT_ERRTYPE_ATTR_PRESENT );
		return( FALSE );
		}
	if( ( flags & CHECK_ATTR_PRIVKEYSET ) && \
		sessionInfoPtr->privKeyset != CRYPT_ERROR )
		{
		setErrorInfo( sessionInfoPtr, CRYPT_SESSINFO_CMP_PRIVKEYSET,
					  CRYPT_ERRTYPE_ATTR_PRESENT );
		return( FALSE );
		}
	if( ( flags & CHECK_ATTR_CACERT ) && \
		sessionInfoPtr->iAuthInContext != CRYPT_ERROR )
		{
		setErrorInfo( sessionInfoPtr, CRYPT_SESSINFO_CACERTIFICATE,
					  CRYPT_ERRTYPE_ATTR_PRESENT );
		return( FALSE );
		}
	if( ( flags & CHECK_ATTR_FINGERPRINT ) && \
		findSessionInfo( sessionInfoPtr->attributeList,
						 CRYPT_SESSINFO_SERVER_FINGERPRINT_SHA1 ) != NULL )
		{
		setErrorInfo( sessionInfoPtr, CRYPT_SESSINFO_SERVER_FINGERPRINT_SHA1,
					  CRYPT_ERRTYPE_ATTR_PRESENT );
		return( FALSE );
		}
	
	return( TRUE );
	}
Example #19
0
File: main.c Project: kevana/klvgen
//============================================================================
int main(int argc, char *argv[]) {
#ifndef WIN32
	signal(SIGINT, exitProgram);
	signal(SIGTERM, exitProgram);
	signal(SIGHUP, exitProgram);
	signal(SIGKILL, exitProgram);
#endif

	timestamp = updateTimestamp();
	
	// Set Default values
	sendRate = 1.0;
	strcpy(missionId, "Mission 01");
	strcpy(platform, "Demo");
	latitude = (uint32_t)htonl(mapLatitude("44.64423"));
	longitude = (uint32_t)htonl(mapLongitude("-93.24013"));
	altitude = (uint16_t)htons(mapAltitude("333"));
	strcpy(address, "127.0.0.1");
	servPort = 9000;
	DEBUG = 0;
	
	printf("\nUDP Generator, Version 1.0.1\nKevan Ahlquist\nAll Rights Reserved\n\n");
	
	// read user options
	int option_index = 0;
	char optc;
	static struct option long_options[] =
		{
		 {"address", 		required_argument, 0, 'a'},
		 {"port", 	 		required_argument, 0, 'p'},
		 {"rate",  	 		required_argument, 0, 'r'},
		 {"mission-id", required_argument, 0, 'm'},
		 {"platform",   required_argument, 0, 'n'},
		 {"latitude",   required_argument, 0, 't'},
		 {"longitude",  required_argument, 0, 'g'},
		 {"altitude",   required_argument, 0, 'e'},
		 {"help", no_argument,       0, 'h'},
		 {"version", no_argument,       0, 'v'},
		 {0, 0, 0, 0}
		};
	while (( optc = getopt_long(argc, argv, "a:p:r:m:n:t:g:e:hv", long_options, &option_index)) != -1) {
		switch(optc) {
			case 'a':
				strncpy(address, optarg, 16);
				address[15] = '\0'; // Prevent buffer overrun
				printf("Address received: %s\n", address);
				break;
			case 'p':
				servPort = atol(optarg);
				printf("Port received: %d\n", servPort);
				break;
			case 'r':
				sendRate = atof(optarg);
				printf("Rate received: %f\n", sendRate);
				if (sendRate > 1000000) {
					printf("Values greater than 1,000,000 packets per second are not supported\n");
					exit(0);
				}
				break;
			case 'm':
				strncpy(missionId, optarg, 12);
				missionId[12] = '\0'; // Prevent buffer overrun
				if (strlen(optarg) > 12) printf("WARNING: Mission ID truncated to 12 characters\n");
				printf("Mission ID received: %s\n", missionId);
				break;
			case 'n':
				strncpy(platform, optarg, 12);
				platform[12] = '\0'; // Prevent buffer overrun
				if (strlen(optarg) > 12) printf("WARNING: Platform truncated to 12 characters\n");
				printf("Platform received: %s\n", platform);
				break;
			case 't':
				latitude = (uint32_t)htonl(mapLatitude(optarg));
				printf("Latitude received: %s\n", optarg);
				if (atof(optarg) < -90.0 || atof(optarg) > 90.0) {
					printf("ERROR: Latitude out of range (-90,90)\n");
					exit(0);
				}
				break;
			case 'g':
				longitude = (uint32_t)htonl(mapLongitude(optarg));
				printf("Longitude received: %s\n", optarg);
				if (atof(optarg) < -180.0 || atof(optarg) > 180.0) {
					printf("ERROR: Longitude out of range (-180,180)\n");
					exit(0);
				}
				break;
			case 'e':
				altitude = (uint16_t)htons(mapAltitude(optarg));
				printf("Altitude received: %s\n", optarg);
				if (atof(optarg) < -900 || atof(optarg) > 19000) {
					printf("ERROR: Altitude out of range(-900,19000)\n");
					exit(0);
				}
				break;
			case 'h':
				help();
				exit(0);
				break;
			case 'v':
				exit(0);
				break;
			default:
				printf("Usage: klvgen -a <address>:<port> -r <rate> -m<mission-id> -p <platform> -t <lat> -g <long> -e <elev>\n");
				printf("For help use option -h or --help\n");
				exit(0);
		}
	}
	
	if (udpInit() == -1) exit(-1);
	
	// TESTING ================================================================
	int i;
	if (DEBUG) {
		printf("Testing mapping functions===============\n");
		printf("map 0 from 0-10 to 0-100: %d\n", mapValue(0,0,10,0,100));
		printf("map 10 from 0-10 to 0-100: %d\n", mapValue(10,0,10,0,100));
		printf("map 5 from 0-10 to 0-100: %d\n", mapValue(5,0,10,0,100));
	}
	if (DEBUG) {
		printf("uasLdsKey:\n");
		for (i = 0; i < 16; ++i) {
			printf("%X", uasLdsKey[i]);
		}
		printf("\n");
#ifdef WIN32
		printf("Timestamp (truncated): %u\n", (unsigned int)timestamp);
#else
		printf("Timestamp: %llu\n", timestamp);
#endif
	}
	if (DEBUG) {
		printf("Testing makePacket, packetBuffer:\n");
		printf(" K  L  Value...\n");
		makePacket(packetBuffer);
		for (i = 0; i < 80; ++i) {
			printf("%2X ", packetBuffer[i]);
			if ((i == 15) || (i == 25) || (i == 39) || (i == 53) || (i == 59) || (i == 65) || (i == 69) || (i == 72)) {
				printf("\n");
			}
		}
		printf("\n");
		udpSendPacket((const char *)packetBuffer);
	}
	if (DEBUG) {
		printf("Testing htonll function:\n num: 0x 01 02 03 04 05 06 07 08\n");
		uint64_t number = 0x0102030405060708ULL;
		uint64_t num2 = htonll(number);
		printf("number: ");
		printf("%2X ", (char)(number & 0xFF));
		printf("%2X ", (char)((number & 0xFF00) >> 8));
		printf("%2X ", (char)((number & 0xFF0000) >> 16));
		printf("%2X ", (char)((number & 0xFF000000) >> 24));
		printf("%2X ", (char)((number & 0xFF00000000ULL) >> 32));
		printf("%2X ", (char)((number & 0xFF0000000000ULL) >> 40));
		printf("%2X ", (char)((number & 0xFF000000000000ULL) >> 48));
		printf("%2X ", (char)((number & 0xFF00000000000000ULL) >> 56));
		printf("\n");
		printf("num2: ");
		printf("%2X ", (char)(num2 & 0xFF));
		printf("%2X ", (char)((num2 & 0xFF00) >> 8));
		printf("%2X ", (char)((num2 & 0xFF0000) >> 16));
		printf("%2X ", (char)((num2 & 0xFF000000) >> 24));
		printf("%2X ", (char)((num2 & 0xFF00000000ULL) >> 32));
		printf("%2X ", (char)((num2 & 0xFF0000000000ULL) >> 40));
		printf("%2X ", (char)((num2 & 0xFF000000000000ULL) >> 48));
		printf("%2X ", (char)((num2 & 0xFF00000000000000ULL) >> 56));
		printf("\n");
	}
	// END TESTING==========================================================
	
	while (1) {
		timestamp = htonll(updateTimestamp());
		makePacket(packetBuffer);
		udpSendPacket((const char *)packetBuffer);
		if (DEBUG) {
			printf("\n K  L  Value...\n");
			for (i = 0; i < 80; ++i) {
				printf("%2X ", packetBuffer[i]);
				if ((i == 16) || (i == 26) || (i == 40) || (i == 54) || 
						(i == 60) || (i == 66) || (i == 70) || (i == 73)) {
					printf("\n");
				}
			}
		}
#ifdef WIN32
		Sleep((1 / sendRate) * 1000);
#else
		usleep((1 / sendRate) * 1000); // usleep is untested, may not compile
#endif
	}
}
Example #20
0
double Joystick::getY(){
	return (mapValue(analogRead(yAxisPin)));
}