Jump to content
Sign in to follow this  
n4gix

Reading/Using the "Fifth Parameter"

Recommended Posts

I need to pass a unique filename to use to a file I/O gauge using the "Fifth Parameter," so that the same gaugecode may be used in any project without having to compile a new gauge for each one.In the panel.cfg the name will be entered thusly:gauge00=escj1fmc!escj1fmc, 0,0,220,288,do328fmc In the gauge itself, I need to be able to read the extra_data, assign it to a variable, and then use that variable to provide the filename...So, instead of this:case PANEL_SERVICE_CONNECT_TO_WINDOW:if((blackbox=fopen("ESDGblackbox.dat","r"))==NULL)I could have this:case PANEL_SERVICE_CONNECT_TO_WINDOW:if((blackbox=fopen(filename + ".dat","r"))==NULL)I've read Dai's tutorial & studied Arne's examples for several hours now and still haven't a clue how to accomplish this trivial task...Any help for this clueless-clod out there? :)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest bartels

I have to go home to check the exact PANEL_SERVICE_ID (still in office), but the fifths parameter is not available at PANEL_SERVICE_CONNECT_TO_WINDOW, it isn't available before PANEL_SERVICE_POST_INITIALIZE I think.And then it is "pgauge->parameters", a string to read the fifths parameter from. The simple concat string+string doesn't work in C though.Arne Bartels

Share this post


Link to post
Share on other sites
Guest zip

Try this in the callback function (note, the forum does strange things to square brackets when posting):PCHAR pcharGaugeParameter;CHAR pcharFileName[[MAX_PATH]]; // max_path defined in windows.h...case PANEL_SERVICE_POST_INSTALL: pcharGaugeParameter=(PCHAR)pgauge->parameters; if (pcharGaugeParameter) { strcpy(pcharFileName,pcharGaugeParameter); strcat(pcharFileName,".dat"); // check format, ensure file exists ... } }Note that the gauge parameter is not provided in every callback.You may also need to use the GetModuleFilename() win32 call to determine the name of the executing Gauge file, so you get the relative path. Gauge parameters do not like weird characters in the name.As another solution, use an INI file, and use the GetPrivateProfileString() and SetPrivateProfileString() functions to store common file and config information.

Share this post


Link to post
Share on other sites

Thanks Arne...I notice from your "Registration.gau" that you are apparently reading this in the PANEL_SERVICE_PRE_INSTALL case.void FSAPI C_GAUGE(gauge_cb)( PGAUGEHDR pgauge, int service_id, UINT32 extra_data){ switch(service_id) { case PANEL_SERVICE_PRE_INSTALL: CheckOnChangedFontandColour( pgauge); break; }So I would then fetch the name from a callback routine.I'll have to spend some time working this out I guess... :)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Thank you for the suggestions.Unless I specify differently, the gauge should look for the .dat file in the Flight Simulator 9 root folder, so fetching a pathname shouldn't be needed, unless I wanted to store the .dat file in the a/c's panel folder, right?There is no MAX_PATH in the window.h file at all. Using grep, I did find it in many different include files though.The WinDef.h file #define(s) it, but that is all... ???Also, apptypes.h has a #define for MAX_PATH:// this is just needed in the driver#ifndef MAX_PATH#define MAX_PATH 260#endifCould I not simply #define it in the .c file?Please keep in mind that I'm a complete idiot with C++ and gauge building, and I know I'm trying to fly before I've learned to read the checklist properly... :)However, I do have the 'blackbox' program running and need to add this functionality quickly, even if I don't understand everything I'm doing... :)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Hi Bill,I am about half way through a very similar example. When I get home from work I will e-mail you what I have. I have been able to get the 5th parameter read into a character array.Doug

Share this post


Link to post
Share on other sites

>Hi Bill,>>I am about half way through a very similar example. When I>get home from work I will e-mail you what I have. I have been>able to get the 5th parameter read into a character array.Thanks, Doug! That would be great! Lonny's wanting to use my 'blackbox' file I/O gauge to read/write data to a file, but it seems silly to have to build a new gauge for every project... :)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

OK, I have the "fifth parameter" stored in a pointer variable called ptotalname...How do I write the following to USE that stored name???if((blackbox=fopen("ESDGdatESDGblackbox.dat","r"))==NULL)...blackbox=fopen("ESDGdatESDGblackbox.dat","w");I'm totally lost on the proper syntax!Sorry for being a complete boob! :(


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

>OK, I have the "fifth parameter" stored in a pointer variable>called ptotalname...>>How do I write the following to USE that stored name???>>if((blackbox=fopen("ESDGdatESDGblackbox.dat","r"))==NULL)>>...>>blackbox=fopen("ESDGdatESDGblackbox.dat","w");Just to finish off this thread, I'd like to post the solution, kindly provided by Doug S. Dawson!It appears that if you use the correctly named pointer variable, it indeed works just as expected... if((blackbox=fopen(ptotal_name,"r"))==NULL)blackbox=fopen(ptotal_name,"w");


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest zip

Bill, you're right, it's not in windows.h, but it's in one of the include files included by windows.h. As a rule, if you use the Windows API, you should include windows.h and it will make the proper includes depending on your compiler and platform.My point was that if you include windows.h, MAX_PATH will be defined somewhere along the line. I should have stated that differently.

Share this post


Link to post
Share on other sites

>Bill, you're right, it's not in windows.h, but it's in one of>the include files included by windows.h. As a rule, if you use>the Windows API, you should include windows.h and it will make>the proper includes depending on your compiler and platform.>>My point was that if you include windows.h, MAX_PATH will be>defined somewhere along the line. I should have stated that>differently.Thanks for the clarification, Ettiene. As you can read in the message above, I did manage to get the desired result, although I'm sure that there's a simpler, and more efficient way to accomplish my goal.One of these days, all the pieces will fit into place for me. I should be used to dealing with so many disparate "include" type files, since LISP actually pioneered in this form of compiling, but my LISP days are twenty years ago... I'm lucky I can still remember how to spell LISP as it is... :)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites
Guest Skymed

Now why can't we do this in XML ??:-bang :-bang Steve

Share this post


Link to post
Share on other sites

>Now why can't we do this in XML ??:-bang :-bang XML does not support file I/O, but it may be coming via my "blackbox.gau"Doug Dawson and I are working on incorporating some L:variables into the gauge to allow file I/O of up to 20 numeric values.


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...