Example #1
0
// This routine checks plane loading and grabs anyone we're missing.
void	XPMPLoadPlanesIfNecessary(void)
{
	int	active, models;
	XPLMPluginID	owner;
	XPLMCountAircraft(&models, &active, &owner);
	if (owner != XPLMGetMyID())
		return;
		
	if (models > gPlanePaths.size())
		models = gPlanePaths.size();
	for (int n = 1; n < models; ++n)
	{
		if (!gPlanePaths[n].empty())
		{
			const char *	ourPath = gPlanePaths[n].c_str();
			char	realPath[512];
			char	fileName[256];
			XPLMGetNthAircraftModel(n, fileName, realPath);
			if (strcmp(ourPath, realPath))
			{
#if DEBUG_MANUAL_LOADING			
				XPLMDebugString("Manually Loading plane: ");
				XPLMDebugString(ourPath);
				XPLMDebugString("\n");
#endif				
				XPLMSetAircraftModel(n, ourPath);
			}
		}
	}

}
Example #2
0
/**
 timer.stop( timer_id )
 Stops a timer. The function for timer_id will not be called again.
 */
int gizmo_builtin_timer_stop(lua_State *L){ 

	//This function marks a timer for destruction.
	//Actual destruction is done at the head of the core flight loop.

	
	int iSlotNumber = lua_tointeger( L, -1 );
	
	
	//basic protection, stop sim from crashing
	if(( iSlotNumber > (int)gizmo_svAllUserTimers.size()-1 ) || ( iSlotNumber < 0 )){
		XPLMDebugString("Gizmo: timer.stop() called on invalid timer handle. Ignored.\n");
		return 0;
	}
	
		gizmo_user_timer_info* ip = gizmo_svAllUserTimers[ iSlotNumber ];	
		ip->iEnabled = 0;

		char caDbg[2048];
		sprintf(caDbg, "Gizmo: timer.stop(%i)\n", iSlotNumber);
		XPLMDebugString(caDbg);

	return 0; 
	
}
Example #3
0
int cb_panel_open() {
	int res = 0;

	cbHandle = hid_open(CB_VENDOR_ID, CB_PROD_ID, NULL);

	if (!cbHandle) {
		XPLMDebugString("-> CP: cb_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(cbHandle, wstr, MAX_STR);
	sprintf(tmp, "-> CP: cb_driver.panel_open: Manufacturer String %ls\n", wstr);
	XPLMDebugString(tmp);

	cb_panel_read_non_blocking(tempInbuf);
	cb_panel_read_non_blocking(tempInbuf);
	cb_panel_read_non_blocking(tempInbuf);
	cb_panel_write(cb_blank_panel);
	//	res = hid_send_feature_report(cbHandle, cb_blank_panel, CB_OUT_BUF_SIZE);
	//	if (res < 0) {
	//	    sprintf(tmp, "-> CP: cb_driver.panel_open: Error: %ls\n", hid_error(cbHandle));
	//		XPLMDebugString(tmp);
	//	}
	return 0;
}
Example #4
0
float
ReceiveClientTalkCallback(float inElapsedSinceLastCall, float inElapsedTimeSinceLastFlightLoop,
    int inCounter, void *inRefcon)
{
	if ((plugin_enabled == 1) && (recv_enabled == 1) && (recv_socket_open == 1)) {
		char buffer[256];
		int ret = 0;
		struct timeval nowait;
		nowait.tv_sec = 0;
		nowait.tv_usec = 0; /* nowait please */
		FD_ZERO(&receiverReadfs);
		FD_SET(receiverSocket, &receiverReadfs);
		if ((ret = select(receiverSocket + 1, &receiverReadfs, NULL, NULL, &nowait)) < 0) {
			XPLMDebugString("XPUDPNG: caught error while select (");
			XPLMDebugString((char * const)strerror(errno));
			XPLMDebugString(")\n");
			return -1;
		}

		if (ret == 0) {
		}

		if (FD_ISSET(receiverSocket, &receiverReadfs))
		    {
			    recv(receiverSocket, buffer, sizeof(buffer), 0);
			    XPLMDebugString("XPUDPNG: Got input packet\n");
			    return XPUDPNG_RECV_FREQ_RETURN;
		    }
		return XPUDPNG_RECV_FREQ_RETURN;
	} else {
		return 1;
	}
}
Example #5
0
int mcp_panel_open() {
	int res = 0;

	mcpHandle = hid_open(VENDOR_ID, MCP_PROD_ID, NULL);

	if (!mcpHandle) {
		XPLMDebugString("-> CP: mcp_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(mcpHandle, wstr, MAX_STR);
    sprintf(tmp, "-> CP: mcp_driver.panel_open: Manufacturer String %ls\n", wstr);
	XPLMDebugString(tmp);

	hid_set_nonblocking(mcpHandle, 1);
	res = hid_read(mcpHandle, mcp_in_buf, MCP_IN_BUF_SIZE);
	if (res < 0) {
	    sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle));
		XPLMDebugString(tmp);
	}
	res = hid_send_feature_report(mcpHandle, mcp_all_on_panel, sizeof(mcp_all_on_panel));
	res = hid_send_feature_report(mcpHandle, mcp_course_left, sizeof(mcp_course_left));
	res = hid_send_feature_report(mcpHandle, mcp_course_right, sizeof(mcp_course_right));
	res = hid_send_feature_report(mcpHandle, mcp_ias_mach, sizeof(mcp_ias_mach));
	res = hid_send_feature_report(mcpHandle, mcp_heading, sizeof(mcp_heading));
	res = hid_send_feature_report(mcpHandle, mcp_altitude, sizeof(mcp_altitude));
	res = hid_send_feature_report(mcpHandle, mcp_vert_speed, sizeof(mcp_vert_speed));
	if (res < 0) {
	    sprintf(tmp, "-> CP: mcp_driver.panel_open: Error: %ls\n", hid_error(mcpHandle));
		XPLMDebugString(tmp);
	}
	return 0;
}
Example #6
0
// Callback for Error Tests
void	SDK210TestsErrorCB(const char * msg)
{
    XPLMDebugString("================================================================\n");
    XPLMDebugString("SDK210Tests: SDK210TestsErrorCB - error CB called: ");
    XPLMDebugString(msg);
    XPLMDebugString("\n");
    XPLMDebugString("----------------------------------------------------------------\n");
}
Example #7
0
const  char * XPMPMultiplayerEnable(void)
{
	// First build up a list of all of Austin's planes, and assign
	// their effective index numbers.
	gPlanePaths.clear();
	std::vector<char *>		ptrs;
	gPlanePaths.push_back("");
	
	for (int p = 0; p < gPackages.size(); ++p)
	{
		for (int pp = 0; pp < gPackages[p].planes.size(); ++pp)
		{
			if (gPackages[p].planes[pp].plane_type == plane_Austin)
			{
				gPackages[p].planes[pp].austin_idx = gPlanePaths.size();
				char	buf[1024];
				strcpy(buf,gPackages[p].planes[pp].file_path.c_str());
				#if APL
					Posix2HFSPath(buf,buf,1024);
				#endif
				gPlanePaths.push_back(buf);
			}
		}
	}
	
	// Copy the list into something that's not permanent, but is needed by the XPLM.
	for (int n = 0; n < gPlanePaths.size(); ++n)
	{
#if DEBUG_MANUAL_LOADING
		char	strbuf[1024];
		sprintf(strbuf, "Plane %d = '%s'\n", n, gPlanePaths[n].c_str());
		XPLMDebugString(strbuf);
#endif	
		ptrs.push_back((char *) gPlanePaths[n].c_str());
	}	
	ptrs.push_back(NULL);
	
	
	// Attempt to grab multiplayer planes, then analyze.
	int	result = XPLMAcquirePlanes(&(*ptrs.begin()), NULL, NULL);
	if (result)
		XPLMSetActiveAircraftCount(1);
	else
		XPLMDebugString("WARNING: XSquawkBox did not acquire multiplayer planes!!\n");

		int	total, 		active;
		XPLMPluginID	who;
	
	XPLMCountAircraft(&total, &active, &who);
	if (result == 0)
	{
		return "XSquawkBox was not able to start up multiplayer visuals because another plugin is controlling aircraft.";
	} else 
		return "";
}
Example #8
0
void set_addresses(void)
{
	XPLMDebugString("XPUDPNG: Setting addresses\n");

	receiverSocketSrcAddr.sin_family = AF_INET;
	receiverSocketSrcAddr.sin_port = htons(XPUDPNG_RECV_PORT);
	receiverSocketSrcAddr.sin_addr.s_addr = htonl(INADDR_ANY);

	char for_port[100];
	sprintf(for_port, "XPUDPNG: Prefs: IP=any, RECV-PORT=%i\n", XPUDPNG_RECV_PORT);
	XPLMDebugString(for_port);
}
Example #9
0
int mcp_panel_close() {
	int res = 0;
	if (mcpHandle) {
		res = hid_send_feature_report(mcpHandle, mcp_blank_panel, sizeof(mcp_blank_panel));
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_close: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
		hid_close(mcpHandle);
		XPLMDebugString("-> CP: mcp_driver.panel_close: panel closed.\n");
		mcpHandle = NULL;
	}
	return res;
}
Example #10
0
PLUGIN_API int XPluginStart(char *outName, char *outSig, char *outDesc)
{


	strcpy(outName, "XPUDPng " VERSION);
	strcpy(outSig, "li.rhaamo.xpudpng");
	strcpy(outDesc, "Send simuator data to an XPUDPNG-compliant application using UDP.");

	/* Initialize status variables */
	plugin_enabled = 0; /* set to 1 if the plugin is enabled from the menu. 0 otherwise */
	send_enabled = 1;   /* set to 1 if socket is open and preferences window is not shown. 0 otherwise */
	recv_enabled = 1;   /* set to 1 if socket is open and preferences window is not shown. 0 otherwise */
	recv_socket_open = 0;

	XPLMDebugString("XPUDPNG: Plugin " VERSION "\n");


	/* Create socket and addresses */
	receiverSocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);

	(void)set_addresses();
	(void)create_menu();

	/* Flag to tell us if the widget is being displayed */
	gMenuItem = 0;
	return 1;
}
Example #11
0
void parseJSON() {
    JSON_Value *root_value = json_parse_string(getData);
    
    if (root_value != NULL) {
        JSON_Value_Type type = root_value->type;
        
        if (type == JSONArray) {
            JSON_Array *stations = json_value_get_array(root_value);
            
            char lookupCallsign[32];
            sprintf(lookupCallsign, "%s%s", icaoCode, "_ATIS");
            
            for (int i = 0; i < json_array_get_count(stations); i++) {
                const JSON_Object *station = json_array_get_object(stations, i);
                const char *callsign = json_object_dotget_string(station, "callsign");
                
                if (strcmp(callsign, lookupCallsign) == 0) {
                    message = json_object_dotget_string(station, "atis");
                    XPLMDebugString(message);
                    break;
                }
            }
        }
        
        json_value_free(root_value);
    }
    
    newData = 0;
}
Example #12
0
PLUGIN_API int XPluginDisable(void)
{
	XPLMUnregisterFlightLoopCallback(ReceiveClientTalkCallback, NULL);
	XPLMDebugString("XPUDPNG: disabled\n");
	plugin_enabled = 0;
	recv_enabled = 0;
	return 1;
}
Example #13
0
/**
 timer.newOneShot( "timer_function_name", interval )
 Returns: timer_id
 Create a timer that will fire once and die.
 */
int gizmo_builtin_timer_newOneShot(lua_State *L){ 

	size_t szLen;
	const char *caPayload = lua_tolstring( L, -2, &szLen );
	float fInterval = lua_tonumber( L, -1 );

	
		std::string sSig = caPayload;
		for( unsigned int x=0; x < gizmo_svAllUserTimers.size(); x++ ){
			if(gizmo_svAllUserTimers[x]->sFunctionName == sSig){
				if( gizmo_svAllUserTimers[x]->iEnabled ){
					//A timer exists with this name already. Fail.
					
					{
					char caDbg[1024];
					sprintf(caDbg, "Gizmo: FAIL: timer.newOneShot(\"%s\", %0.3f) - function already registered for timers.\n", caPayload, fInterval);
					XPLMDebugString(caDbg);
					}
					
					return 0;
				}
			}
		}
	
	
	
		gizmo_user_timer_info* ip = new gizmo_user_timer_info();
			ip->sFunctionName = caPayload;
			ip->fInterval = fInterval;
			ip->iOneShot = 1;
		
		int ret = gizmo_svAllUserTimers.size();
		gizmo_svAllUserTimers.push_back( ip );
		
		//timer init is defered and done from the pool
		
		#if 0
			char caDbg[2048];
			sprintf(caDbg, "Gizmo: timer.newOneShot('%s',%0.3f)\n", caPayload, fInterval);
			XPLMDebugString(caDbg);
		#endif

	lua_pushinteger(L, ret);
	return 1; 

}
Example #14
0
void sendAircraftPacket() {
	XPLMDebugString("XData: sendAircraftPacket called.\n");

	int i;
	int packet_size;
	int res;
#if IBM
	char msg[80];
#endif
	
	if (xdata_plugin_enabled && xdata_send_enabled && xdata_socket_open) {

		packet_size = createAircraftPacket();

		for (i=0; i<NUM_DEST; i++) {
			if (dest_enable[i]) {
				res = sendto(sockfd, (const char*)&acf_packet, packet_size, 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
#if IBM
				if ( res == SOCKET_ERROR ) {
					XPLMDebugString("XData: caught error while sending ACFT packet! (");
                    sprintf(msg, "%d", WSAGetLastError());
					XPLMDebugString(msg);
					XPLMDebugString(")\n");
				}
#else
				if ( res < 0 ) {
					XPLMDebugString("XData: caught error while sending ACFT packet! (");
					XPLMDebugString((char * const) strerror(GET_ERRNO));
					XPLMDebugString(")\n");
				}
#endif
			}
		}
	}
}
Example #15
0
void sendCrashedPacket() {
	XPLMDebugString("XData: sendCrashedPacket called.\n");

	int i;
	int res;
#if IBM
	char msg[80];
#endif
	
	if (xdata_plugin_enabled && xdata_send_enabled && xdata_socket_open) {
		char data[4];
		strncpy(data, "CRSH", 4);

		for (i=0; i<NUM_DEST; i++) {
			if (dest_enable[i]) {
				res = sendto(sockfd, (const char*)&data, 4, 0, (struct sockaddr *)&dest_sockaddr[i], sizeof(struct sockaddr));
#if IBM
				if ( res == SOCKET_ERROR ) {
					XPLMDebugString("XData: caught error while sending CRSH packet! (");
                    sprintf(msg, "%d", WSAGetLastError());
					XPLMDebugString(msg);
					XPLMDebugString(")\n");
				}
#else
				if ( res < 0 ) {
					XPLMDebugString("XData: caught error while sending CRSH packet! (");
					XPLMDebugString((char * const) strerror(GET_ERRNO));
					XPLMDebugString(")\n");
				}
#endif
			}
		}
	}
}
Example #16
0
int ensure_socket_bound(void)
{
	if (recv_socket_open != 1) {
		if (bind(receiverSocket, (struct sockaddr*)&receiverSocketSrcAddr, sizeof(struct sockaddr)) == -1) {
			XPLMDebugString("XPUDPNG: caught error while binding socket (");
			XPLMDebugString((char * const)strerror(errno));
			XPLMDebugString(")\n");
			recv_socket_open = 0;
			return -1;
		} else {
			XPLMDebugString("XPUDPNG: Socket bound!\n");
			recv_socket_open = 1;
			return 1;
		}
	} else {
		return 1;
	}
}
Example #17
0
PLUGIN_API void XPluginStop(void)
{
	if (gMenuItem == 1)
	    {
		    XPDestroyWidget(AboutWidget, 1);
		    gMenuItem = 0;
	    }
	if (recv_socket_open == 1) {
		if (close(receiverSocket) == -1) {
			XPLMDebugString("XPUDPNG: failed - Caught error while closing socket!(");
			XPLMDebugString((char * const)strerror(errno));
			XPLMDebugString(")\n");
		} else {
			XPLMDebugString("XPUDPNG: Closed socket\n");
		}
		recv_socket_open = 0;
		recv_enabled = 0;
	}
}
Example #18
0
PLUGIN_API int XPluginEnable(void)
{
	recv_enabled = 1;
	plugin_enabled = 1;
	XPLMDebugString("XPUDPNG: enabled\n");

	/* Register Flight Loop Callbacks */
	XPLMRegisterFlightLoopCallback(ReceiveClientTalkCallback, XPUDPNG_RECV_FREQ_CALL, NULL);

	return ensure_socket_bound();
}
Example #19
0
int startWinsock() {
	WSADATA wsa;
	WORD version;
	int rc;
	char debug_message[256];

	//version = (2<<8)+1;
	version = MAKEWORD(2, 2);

	rc = WSAStartup(version, &wsa);

	if ( rc ) {
		sprintf(debug_message, "XData failed: could not start winsock! errno: %d\n", WSAGetLastError());
		XPLMDebugString(debug_message);
		return 0;
	} else {
		XPLMDebugString("XData: winsock started\n");
		return 1;
	}
}
Example #20
0
int cb_panel_write(unsigned char buf[]) {
	int res = 0;
	if (cbHandle) {
		res = hid_write(cbHandle, buf, CB_OUT_BUF_SIZE);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_write: Error: %ls\n",
					hid_error(cbHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Example #21
0
int mp_panel_open() {
	int res = 0;

	mpHandle = hid_open(VENDOR_ID, MP_PROD_ID, NULL);

	if (!mpHandle) {
		XPLMDebugString("-> CP: mp_driver.panel_open: unable to open device.\n");
		return -1;
	}
	wchar_t wstr[MAX_STR];
	res = hid_get_manufacturer_string(mpHandle, wstr, MAX_STR);
    sprintf(tmp, "-> CP: mp_driver.panel_open: Manufacturer String %ls\n", wstr);
	XPLMDebugString(tmp);

	res = hid_send_feature_report(mpHandle, mp_blank_panel, MP_OUT_BUF_SIZE);
	if (res < 0) {
	    sprintf(tmp, "-> CP: mp_driver.panel_open: Error: %ls\n", hid_error(mpHandle));
		XPLMDebugString(tmp);
	}
	return 0;
}
Example #22
0
int mcp_panel_read_non_blocking(unsigned char *buf) {
	int res = 0;
	if (mcpHandle) {
		hid_set_nonblocking(mcpHandle, 1);
		res = hid_read(mcpHandle, buf, MCP_IN_BUF_SIZE);
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_read_non_blocking: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Example #23
0
void *PullUrl(void *arg)
{
    if (icaoCode != NULL) {
        char url[255];
        sprintf(url, "%s%s%s", URL_BASE, icaoCode, URL_EXTENSION);
        XPLMDebugString(url);
    
        getData = HandleUrl(url);
        newData = 1;
    }
    
    return NULL;
}
Example #24
0
int cb_panel_write_empty() {
	int res = 0;
	unsigned char cb_empty_buf[0];
	if (cbHandle) {
		res = hid_send_feature_report(cbHandle, cb_empty_buf, 0);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_write_empty: Error: %ls\n",
					hid_error(cbHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Example #25
0
int cb_panel_read_blocking(unsigned char *buf) {
	int res = 0;
	if (cbHandle) {
		hid_set_nonblocking(cbHandle, 0);
		res = hid_read_timeout(cbHandle, buf, CB_IN_BUF_SIZE, 100);
		if (res < 0) {
			sprintf(tmp, "-> CP: cb_driver.panel_read_blocking: Error: %ls\n",
					hid_error(cbHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Example #26
0
void registerCallbacks()
{
	XPLMDebugString("Registering callbacks\n");
	XPLMRegisterFlightLoopCallback(
							sendRequestedDataCallback,
							situation_update_period,
							NULL);
							
	
	XPLMRegisterFlightLoopCallback(
							receiveCallback,
							recv_delay,
							NULL);							
}
Example #27
0
int cb_panel_close() {
	int res = 0;
	if (cbHandle) {
		cb_panel_write(cb_blank_panel);
		//		res = hid_send_feature_report(cbHandle, cb_blank_panel, CB_OUT_BUF_SIZE);
		//		if (res < 0) {
		//		    sprintf(tmp, "-> CP: cb_driver.panel_close: Error: %ls\n", hid_error(cbHandle));
		//			XPLMDebugString(tmp);
		//		}
		hid_close(cbHandle);
		XPLMDebugString("-> CP: cb_driver.panel_close: panel closed.\n");
		cbHandle = NULL;
	}
	return res;
}
Example #28
0
int mcp_panel_write(unsigned char buf[]) {
	int res = 0;
	int i = 0;
	unsigned char tmpBuffer[MCP_OUT_BUF_SIZE];
	for (i = 0; i < MCP_OUT_BUF_SIZE; i++) {
		tmpBuffer[i] = buf[i];
	}
	if (mcpHandle) {
		res = hid_send_feature_report(mcpHandle, tmpBuffer,
				sizeof(tmpBuffer));
		if (res < 0) {
		    sprintf(tmp, "-> CP: mcp_driver.panel_write: Error: %ls\n", hid_error(mcpHandle));
			XPLMDebugString(tmp);
		}
	}
	return res;
}
Example #29
0
/**
 timer.getValue( timer_id )
 Returns: numeric timber value, the current value of a timer, can be used to detect current fill %.
 */
int gizmo_builtin_timer_getValue(lua_State *L){ 

	int iSlotNumber = lua_tointeger( L, -1 );
	
	//basic protection, stop sim from crashing
	if(( iSlotNumber > (int)gizmo_svAllUserTimers.size()-1 ) || ( iSlotNumber < 0 )){
		XPLMDebugString("Gizmo: timer.getValue() called on invalid timer handle. Ignored.\n");
		return 0;
	}
	
		gizmo_user_timer_info* ip = gizmo_svAllUserTimers[ iSlotNumber ];	
		
		lua_pushnumber( L, ip->fCounter );


	return 1; 
	
}
Example #30
0
/**
 timer.reset( timer_id )
 Reset the internal value of a timer so that it restarts.
 This function will restart a timer.stop()ed timer_id.
 */
int gizmo_builtin_timer_reset(lua_State *L){ 
	
	int iSlotNumber = lua_tointeger( L, -1 );
	
	//basic protection, stop sim from crashing
	if(( iSlotNumber > (int)gizmo_svAllUserTimers.size()-1 ) || ( iSlotNumber < 0 )){
		XPLMDebugString("Gizmo: timer.reset() called on invalid timer handle. Ignored.\n");
		return 0;
	}
	
	gizmo_user_timer_info* ip = gizmo_svAllUserTimers[ iSlotNumber ];	
	ip->fCounter = 0.f; //restart timer.
	ip->iEnabled = 1;

	//char caDbg[2048];
	//sprintf(caDbg, "Gizmo: timer.stop(%i)\n", iSlotNumber);
	//XPLMDebugString(caDbg);

	
	return 0; 
	
}