vdkeybus Posted February 13, 2005 Report Share Posted February 13, 2005 Hello Pete, In the last week, I have accumulated three questions about NWI. 1. The manual states that I should only write a station if the timestamp has changed. Do you mean that I should look at the ulTimeStamp of a NWI Read (at 0xCC00) preceding the intended Write ? Which brings me to question 2. 2. A Read is always in response to a Written request. Is it sufficient to re-Read until the ICAO in the response matches the one specified in the request ? If so, doesn't that imply that ulTimeStamp has changed and, hence, I should never bother about it at all ? 3. Is it more efficient - during the re-Reading stage - to ask only for the ICAO (using FSUIPC_Read(0xCC08, 4, chIcao, &dwResult)) and, if that 'suddenly' matches, ask for the lot, having a size of sizeof(NewWeather) ? Thanks, J. Link to comment Share on other sites More sharing options...
Pete Dowson Posted February 13, 2005 Report Share Posted February 13, 2005 The manual states that I should only write a station if the timestamp has changed. Do you mean that I should look at the ulTimeStamp of a NWI Read (at 0xCC00) preceding the intended Write ? For writing a station the TimeStamp is at C824. What are you doing with CC00? If you meant read the timestamp at C824, then yes. If you are setting a string of stations you would read it in the same Process call as the previous station. Something like this: 1 read timestamp 2 write station 3 Process 4 save timestamp read as "x" 5 read timestamp 6 Process 7 if timestamp changed frm "x"? If not loop to 5 (at next time interval) 8 save new timestamp as 'x' 9 continue at 2 till done all This "timestamp" business is a hand-shaking protocol -- there's only one set of weather data being processed in FSUIPC at a time, so you have to know it's done one before sending the next. A Read is always in response to a Written request. For reading weather, not writing. Is that what you are trying to do? Is it sufficient to re-Read until the ICAO in the response matches the one specified in the request ? If so, doesn't that imply that ulTimeStamp has changed and, hence, I should never bother about it at all ? If you mean when SETTING stations, then I'm afraid that you will read back what you've just written. It will only get changed to "GLOB" (say) if it's not a WX station. If you are talking about only reading weather, then, yes. In fact once you've set the station and it is accepted it will update every second and the timestamp will change accordingly. But if someone else asks for weather, or the ICAO isn't a listed WX station, you might wait forever, so take precautions. Many programs simply ask for weather by Lat/Lon to get around the problems of WX station lists. Is it more efficient - during the re-Reading stage - to ask only for the ICAO (using FSUIPC_Read(0xCC08, 4, chIcao, &dwResult)) and, if that 'suddenly' matches, ask for the lot, having a size of sizeof(NewWeather) ? Well, I'm confused -- are you asking about READING weather stations, or WRITING them? Your subject line implies writing, but the questions are then a bit, er, skewed. :wink: Regards Pete Link to comment Share on other sites More sharing options...
vdkeybus Posted February 13, 2005 Author Report Share Posted February 13, 2005 Thank you for clearing things up. I regarded the C800 - CBFF area as 'write-only' and I was puzzled how I could get the ulTimeStamp value mentioned in the NewWeather readme: only the ulTimeStamp is used -- this is set by FSUIPC to the time at which the specified weather was written to FS. I therefore assumed I had to use one of the Read's to a read area (from either 0xC000, 0xC400 or 0xCC00) to get it. I was simply wrong. As to the re-reading thing: Is it more efficient - during the re-Reading stage - to ask only for the ICAO (using FSUIPC_Read(0xCC08, 4, chIcao, &dwResult)) and, if that 'suddenly' matches, ask for the lot, having a size of sizeof(NewWeather) ? I indeed meant to probe for the success of a read. You see, until 15 mins. ago I thought the only way of getting ulTimeStamp was by reading in the 3 read areas mentioned earlier, which use an ICAO. Because my program actually needs to modify existing weather, things were easy to combine. Just for clarity, I include my relevant code section here. bool set_station(char *icao, struct weather *weather, bool activate) { NewWeather w; memset(&w, 0, 0x24); // Only set upto nElevation strncpy((char *)&w.chICAO, icao, 4); // Insert ICAO w.ulSignature = 0x00000F5C; // FSC signature fs->write(0xCC00, 0x24, &w); fs->process(); int n; for (n = 10; n > 0; n--) { char chIcao[4]; fs->read(0xCC08, 4, chIcao); fs->process(); if (!strncmp(chIcao, icao, 4)) break; Sleep(25); } if (n == 0) return(false); fs->read(0xCC00, sizeof(NewWeather), &w); fs->process(); if (weather->wind) { struct wind *wind = weather->wind; for (int i = 0; i < w.nWindsCtr; i++) { if (wind->spd != WX_UNMODIFIED) { w.Wind[i].Speed = wind->spd; w.Wind[i].SpeedFract = 0; } if (wind->spd_gust != WX_UNMODIFIED) w.Wind[i].Gust = wind->spd_gust; if (wind->dir != WX_UNMODIFIED) w.Wind[i].Direction = wind->dir; if (wind->dir_var != WX_UNMODIFIED) w.Wind[i].Variance = wind->dir_var; } } if (activate) w.uCommand = NW_ACTIVATE; else w.uCommand = NW_SETEXACT_PENDING; fs->write(0xC800, sizeof(NewWeather), &w); fs->process(); return(true); } The function uses a signature and it will fail if someone else 'locked' the weather system. The function is called for every weather station in the area of the aircraft. Feel free to comment on this function, if you like. My coding style also might not be up to standards... Regards, J. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now