00001
00052 #define _EXPORT_CCL_
00053
00054 #include "CigiWeatherCtrlV3.h"
00055 #include "CigiSwapping.h"
00056 #include "CigiExceptions.h"
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 CigiWeatherCtrlV3::CigiWeatherCtrlV3()
00068 {
00069
00070 PacketID = CIGI_WEATHER_CTRL_PACKET_ID_V3;
00071 PacketSize = CIGI_WEATHER_CTRL_PACKET_SIZE_V3;
00072 Version = 3;
00073 MinorVersion = 0;
00074
00075 EntityID = 0;
00076 RegionID = 0;
00077 LayerID = 0;
00078 Humidity = 0;
00079 PhenomenonType = 0;
00080 WeatherEn = false;
00081 ScudEn = false;
00082 RandomWindsEn = false;
00083 RandomLightningEn = false;
00084 CloudType = None;
00085 Scope = Global;
00086 Severity = 0;
00087 AirTemp = 0.0;
00088 VisibilityRng = 0.0;
00089 Opacity = 0.0;
00090 ScudFreq = 0.0;
00091 Coverage = 0.0;
00092 BaseElev = 0.0;
00093 Thickness = 0.0;
00094 Transition = 0.0;
00095 HorizWindSp = 0.0;
00096 VertWindSp = 0.0;
00097 WindDir = 0.0;
00098 BaroPress = 1013.25;
00099 Aerosol = 0.0;
00100
00101 }
00102
00103
00104
00105
00106 CigiWeatherCtrlV3::~CigiWeatherCtrlV3()
00107 {
00108
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118 int CigiWeatherCtrlV3::Pack(CigiBasePacket * Base, Cigi_uint8 * Buff, void *Spec) const
00119 {
00120 PackPointer CDta;
00121
00122 CigiBaseWeatherCtrl * Data = ( CigiBaseWeatherCtrl *)Base;
00123
00124 CDta.c = Buff;
00125
00126 *CDta.c++ = PacketID;
00127 *CDta.c++ = PacketSize;
00128
00129 if(Data->Scope == Global)
00130 *CDta.s++ = 0;
00131 else if(Data->Scope == Regional)
00132 *CDta.s++ = Data->RegionID;
00133 else
00134 *CDta.s++ = Data->EntityID;
00135
00136 *CDta.c++ = Data->LayerID;
00137 *CDta.c++ = Data->Humidity;
00138
00139 Cigi_uint8 HDta = (Data->WeatherEn) ? 0x01 : 0x00;
00140 HDta |= (Data->ScudEn) ? 0x02 : 0x00;
00141 HDta |= (Data->RandomWindsEn) ? 0x04 : 0x00;
00142 HDta |= (Data->RandomLightningEn) ? 0x08 : 0x00;
00143 HDta |= (Data->CloudType << 4) & 0xf0;
00144
00145 *CDta.c++ = HDta;
00146
00147 HDta = Data->Scope & 0x03;
00148 HDta |= (Data->Severity << 2) & 0x1c;
00149
00150 *CDta.c++ = HDta;
00151
00152 *CDta.f++ = Data->AirTemp;
00153 *CDta.f++ = Data->VisibilityRng;
00154 *CDta.f++ = Data->ScudFreq;
00155 *CDta.f++ = Data->Coverage;
00156 *CDta.f++ = Data->BaseElev;
00157 *CDta.f++ = Data->Thickness;
00158 *CDta.f++ = Data->Transition;
00159 *CDta.f++ = Data->HorizWindSp;
00160 *CDta.f++ = Data->VertWindSp;
00161
00162 float Wndir = Data->WindDir;
00163 if(Wndir > 180.0)
00164 Wndir -= 360.0;
00165 *CDta.f++ = Wndir;
00166
00167 *CDta.f++ = Data->BaroPress;
00168 *CDta.f++ = Data->Aerosol;
00169
00170 return(PacketSize);
00171
00172 }
00173
00174
00175
00176
00177 int CigiWeatherCtrlV3::Unpack(Cigi_uint8 * Buff, bool Swap, void *Spec)
00178 {
00179 PackPointer CDta;
00180
00181 static Cigi_uint8 PhenTbl[10] = { 3,1,2,2,4,5,5,5,6,6 };
00182
00183 CDta.c = Buff;
00184
00185 CDta.c += 2;
00186
00187 if(!Swap)
00188 {
00189 EntityID = *CDta.s++;
00190 LayerID = *CDta.c++;
00191 Humidity = *CDta.c++;
00192
00193 Cigi_uint8 HDta = *CDta.c++;
00194 WeatherEn = ((HDta & 0x01) != 0);
00195 ScudEn = ((HDta & 0x02) != 0);
00196 RandomWindsEn = ((HDta & 0x04) != 0);
00197 RandomLightningEn = ((HDta & 0x08) != 0);
00198 CloudType = (CloudTypeGrp)((HDta >> 4) & 0x0f);
00199
00200 HDta = *CDta.c++;
00201 Scope = (ScopeGrp)(HDta & 0x03);
00202 Severity = (HDta >> 2) & 0x07;
00203
00204 AirTemp = *CDta.f++;
00205 VisibilityRng = *CDta.f++;
00206 ScudFreq = *CDta.f++;
00207 Coverage = *CDta.f++;
00208 BaseElev = *CDta.f++;
00209 Thickness = *CDta.f++;
00210 Transition = *CDta.f++;
00211 HorizWindSp = *CDta.f++;
00212 VertWindSp = *CDta.f++;
00213 WindDir = *CDta.f++;
00214 BaroPress = *CDta.f++;
00215 Aerosol = *CDta.f++;
00216 }
00217 else
00218 {
00219 CigiSwap2(&EntityID, CDta.s++);
00220 LayerID = *CDta.c++;
00221 Humidity = *CDta.c++;
00222
00223 Cigi_uint8 HDta = *CDta.c++;
00224 WeatherEn = ((HDta & 0x01) != 0);
00225 ScudEn = ((HDta & 0x02) != 0);
00226 RandomWindsEn = ((HDta & 0x04) != 0);
00227 RandomLightningEn = ((HDta & 0x08) != 0);
00228 CloudType = (CloudTypeGrp)((HDta >> 4) & 0x0f);
00229
00230 HDta = *CDta.c++;
00231 Scope = (ScopeGrp)(HDta & 0x03);
00232 Severity = (HDta >> 2) & 0x07;
00233
00234 CigiSwap4(&AirTemp, CDta.f++);
00235 CigiSwap4(&VisibilityRng, CDta.f++);
00236 CigiSwap4(&ScudFreq, CDta.f++);
00237 CigiSwap4(&Coverage, CDta.f++);
00238 CigiSwap4(&BaseElev, CDta.f++);
00239 CigiSwap4(&Thickness, CDta.f++);
00240 CigiSwap4(&Transition, CDta.f++);
00241 CigiSwap4(&HorizWindSp, CDta.f++);
00242 CigiSwap4(&VertWindSp, CDta.f++);
00243 CigiSwap4(&WindDir, CDta.f++);
00244 CigiSwap4(&BaroPress, CDta.f++);
00245 CigiSwap4(&Aerosol, CDta.f++);
00246 }
00247
00248 RegionID = EntityID;
00249
00250 if(Scope == Entity)
00251 PhenomenonType = 0;
00252 else if(LayerID < 10)
00253 {
00254 PhenomenonType = PhenTbl[LayerID];
00255 }
00256 else
00257 PhenomenonType = LayerID;
00258
00259 Opacity = ((VisibilityRng/70000.0f)*100.0f);
00260
00261
00262
00263 return(PacketSize);
00264
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 int CigiWeatherCtrlV3::SetLayerID(const Cigi_uint8 LayerIDIn, bool bndchk)
00278 {
00279 LayerID = LayerIDIn;
00280
00281 return(CIGI_SUCCESS);
00282 }
00283
00284
00285
00286
00287
00288 int CigiWeatherCtrlV3::SetHumidity(const Cigi_uint8 HumidityIn, bool bndchk)
00289 {
00290
00291 #ifndef CIGI_NO_BND_CHK
00292 if(bndchk && ((HumidityIn < 0)||(HumidityIn > 100)))
00293 {
00294 #ifndef CIGI_NO_EXCEPT
00295 throw CigiValueOutOfRangeException("Humidity",(Cigi_uint8)HumidityIn,0,100);
00296 #endif
00297 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00298 }
00299 #endif
00300
00301 Humidity = HumidityIn;
00302 return(CIGI_SUCCESS);
00303
00304 }
00305
00306
00307
00308
00309
00310 int CigiWeatherCtrlV3::SetCloudType(const CloudTypeGrp CloudTypeIn, bool bndchk)
00311 {
00312
00313 #ifndef CIGI_NO_BND_CHK
00314 if(bndchk && ((CloudTypeIn < 0)||(CloudTypeIn > 15)))
00315 {
00316 #ifndef CIGI_NO_EXCEPT
00317 throw CigiValueOutOfRangeException("CloudType",(CloudTypeGrp)CloudTypeIn,0,15);
00318 #endif
00319 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00320 }
00321 #endif
00322
00323 CloudType = CloudTypeIn;
00324 return(CIGI_SUCCESS);
00325
00326 }
00327
00328
00329
00330
00331
00332 int CigiWeatherCtrlV3::SetScope(const ScopeGrp ScopeIn, bool bndchk)
00333 {
00334
00335 #ifndef CIGI_NO_BND_CHK
00336 if(bndchk && ((ScopeIn < 0)||(ScopeIn > 2)))
00337 {
00338 #ifndef CIGI_NO_EXCEPT
00339 throw CigiValueOutOfRangeException("Scope",(ScopeGrp)ScopeIn,0,2);
00340 #endif
00341 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00342 }
00343 #endif
00344
00345 Scope = ScopeIn;
00346 return(CIGI_SUCCESS);
00347
00348 }
00349
00350
00351
00352
00353
00354 int CigiWeatherCtrlV3::SetWindDir(const float WindDirIn, bool bndchk)
00355 {
00356
00357 #ifndef CIGI_NO_BND_CHK
00358 if(bndchk && ((WindDirIn < -180.0)||(WindDirIn > 180.0)))
00359 {
00360 #ifndef CIGI_NO_EXCEPT
00361 throw CigiValueOutOfRangeException("WindDir",(float)WindDirIn,-180.0,180.0);
00362 #endif
00363 return(CIGI_ERROR_VALUE_OUT_OF_RANGE);
00364 }
00365 #endif
00366
00367 WindDir = WindDirIn;
00368 return(CIGI_SUCCESS);
00369
00370 }
00371
00372