Jump to content
Sign in to follow this  
Guest matt-c

How do i show Morse Code as a string?

Recommended Posts

Guest matt-c

Hi,I need some help displaying Morse Code for a VOR, you can already see it displayed on the world map, when you click on a VOR it shows up like ".. - .. .-" etc. I want to be able to display it on a panel, any help would be much appreciated.ThanksMatt

Share this post


Link to post
Share on other sites
Guest matt-c

I've got the VOR1_IDENTITY to display and it would seem that FS converts the letters to morse rather than store the morse codes for each vor. Does any1 know an easy way i could either use FS to convert the letters and then display or just convert using C?Thanks Matt

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Well, unless there is a variable with it in ASCII, then just parse it. Should be a bit of fun writing that loop. :)

Share this post


Link to post
Share on other sites
Guest matt-c

This is what i use to print the string:lookup_var(&vor_id);sprintf(pelement->string,"%s",vor_id.var_value.p);how do i find out what each character is 1 by 1?thanksmatt

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Actually, you may want to take a look at using the GPS variables (through XML in C) like: WaypointVorICAO ( the code you are seeking ) WaypointVorIdent ( the morse ) using: (C:fs9gps:Variable Name , Units)You do something like this: CHAR* VorIcaoCode; execute_calculator_code("(C:fs9gps:WaypointICAO, string)", VorIcaoCode, NULL, NULL);Do a search through the FS gps xml code to find the units used if 'string' doesn't work for you.Good luck.

Share this post


Link to post
Share on other sites
Guest matt-c

Thanks for your help.With your code: FLOAT64 *VorIcaoCode; execute_calculator_code("(C:fs9gps:WaypointVorICAO,string)", VorIcaoCode, NULL, NULL); sprintf(pelement->string,"%s",VorIcaoCode);all i get is null, tried playing around with it but always get null.ThanksMatt

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Matt,>Thanks for your help.No problem, many of us were where you are now. As long as you are trying, we enjoy helping.>With your code:>> FLOAT64 *VorIcaoCode;> >execute_calculator_code("(C:fs9gps:WaypointVorICAO,string)", VorIcaoCode, NULL, NULL);> sprintf(pelement->string,"%s",VorIcaoCode);>>all i get is null, tried playing around with it but always get>null.Matt, this is because you are doing several basic things wrong. The first step is you have to understand what you are doing.The parameter you need to pass in the execute_calculator_code function is a pointer (or address of) a variable to hold the result of the call.In your code, you pass "VorIcaoCode", which you did indeed declare to be of type FLOAT64* (pointer to FLOAT64), however, that pointer is not initialized to point at anything, and is therefore NULL, and so when the function attempts to see where to put the value it would like to "return" (store) for you, it finds that there is no where to put it. Normally, we would name that variable in Hungarian notation to be pVorIcaoCode to remind us it is a pointer, and not the variable itself. Moreover, you are wanting a zero terminate string back, not a FLOAT64.You need to declare the variable itself, and then pass the pointer to it like this for numeric returns:FLOAT64 isBaggageDoorOpen;FLOAT64 FSAPI BaggageDoor_cb(PELEMENT_ICON pelement){ execute_calculator_code("(A:EXIT OPEN:1, bool)", &isBaggageDoorOpen, NULL, NULL); bool isWarnBaggageDoor = isBaggageDoorOpen ? true : false;}In the above code, I passed the pointer in the 2nd parameter as I was passing the address of a FLOAT64. The & operator takes the address of the variable I have declared (set aside space for) and passes it (a pointer) to the function.If we look at the actual definition of the call in the gauge.h file we see: BOOL (FSAPI *execute_calculator_code) (PCSTRINGZ code, FLOAT64* fvalue, SINT32* ivalue, PCSTRINGZ* svalue);And this tells us that if you want a PCSTRINGZ* (pointer to a zero terminated c-string) returned, you have to send the point in the last parameter.In summary, your code should be more like this: CHAR* VorIcaoCode; // Declaring a C-String (null terminated) execute_calculator_code("(C:fs9gps:WaypointVorICAO, string)", NULL, NULL, &VorIcaoCode); sprintf(pelement->string,"%s",VorIcaoCode);Good luck.

Share this post


Link to post
Share on other sites
Guest matt-c

It no longer displays "(null)" but "0." instead, i've tried changing waypoints on the gps and also changing WaypointVorICAO for others such as WaypointAirportIdent etc but still displays "0.".Thanks Matt

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Probably your printf.Post more of your code so we can help you.

Share this post


Link to post
Share on other sites

I've found you will get inconsistent results when looking for strings using execute_calculator_code(); unless you declare the desired variable as PCSTRINGZ. For example:char buf[100];PCSTRINGZ atc_flight_number; execute_calculator_code("(A:atc flight number,string)",NULL,NULL,&atc_flight_number); swprintf(buf,L"%S", atc_flight_number);In the case above, I would use this:PCSTRINGZ VorIcaoCode;execute_calculator_code("(C:fs9gps:WaypointICAO,string)",NULL,NULL,&VorIcaoCode);swprintf(buf,L"%S", VorIcaoCode);Of course, my swprintf routine is for use with GDI+... Another print routine is needed for non-GDI+ gauges. :)


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 matt-c

Hers's what i've got so far:FLOAT64 FSAPI dom_Morse1_string_cb( PELEMENT_STRING pelement ){ PCSTRINGZ VorIcaoCode; execute_calculator_code("(C:fs9gps:WaypointVorICAO,string)", NULL, NULL, &VorIcaoCode); sprintf(pelement->string,"%s",VorIcaoCode); return 0;}MAKE_STRING( dom_Morse1_stdby_freq_string, NULL, NULL, IMAGE_USE_ERASE | IMAGE_USE_BRIGHT , 0, 55,145, 280,80, 6, VOR1_IDENTITY, MODULE_VAR_NONE, MODULE_VAR_NONE, RGB(255,128,0), RGB(0,0,0), RGB(92,92,92), GAUGE_dom_FONT_DEFAULT, GAUGE_dom_WEIGHT_DEFAULT, GAUGE_dom_Q, 0, DT_CENTER | DT_VCENTER | DT_SINGLELINE, NULL, dom_Morse1_string_cb)PELEMENT_HEADER dom_Morse1_stdby_freq_string_list[] ={ &dom_Morse1_stdby_freq_string.header, NULL};MAKE_STATIC( dom_Morse1_background, BMP_BACKGROUND, &dom_Morse1_stdby_freq_string_list, NULL, IMAGE_USE_TRANSPARENCY, 0, 0,0)PELEMENT_HEADER dom_Morse1_background_list = &dom_Morse1_background.header;This still only prints "0." i've played around changing the printf but still no luck.I changed C:fs9gps:WaypointVorICAO to A:atc id and that worked.Thanks againMatt

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...