Changeset 17:2b7d9b08ce3f in xplra
- Timestamp:
- 01/31/13 16:56:18 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/c/hu/varadiistvan/xplra/XPlane.cc
r16 r17 90 90 91 91 //------------------------------------------------------------------------------ 92 93 inline void XPlane::checkResult() throw(ProtocolException) 94 { 95 uint8_t result = stream->readU8(); 96 checkStream(); 97 checkResult(result); 98 } 99 100 //------------------------------------------------------------------------------ 92 101 //------------------------------------------------------------------------------ 93 102 … … 142 151 if (!stream->flush()) checkStream(); 143 152 144 uint8_t result = stream->readU8(); 145 checkStream(); 146 checkResult(result); 153 checkResult(); 147 154 } 148 155 … … 285 292 //------------------------------------------------------------------------------ 286 293 294 void XPlane::setScalar(const char* name, uint8_t type) throw(Exception) 295 { 296 stream->writeU8(Protocol::COMMAND_SET_SINGLE); 297 stream->writeString(name, strlen(name)); 298 stream->writeU8(type); 299 } 300 301 //------------------------------------------------------------------------------ 302 303 void XPlane::setInt(const char* name, int value) throw(Exception) 304 { 305 setScalar(name, Protocol::TYPE_INT); 306 stream->writeS32(value); 307 stream->flush(); 308 checkResult(); 309 } 310 311 //------------------------------------------------------------------------------ 312 313 void XPlane::setFloat(const char* name, float value) throw(Exception) 314 { 315 setScalar(name, Protocol::TYPE_FLOAT); 316 stream->writeFloat(value); 317 stream->flush(); 318 checkResult(); 319 } 320 321 //------------------------------------------------------------------------------ 322 323 void XPlane::setDouble(const char* name, double value) throw(Exception) 324 { 325 setScalar(name, Protocol::TYPE_DOUBLE); 326 stream->writeDouble(value); 327 stream->flush(); 328 checkResult(); 329 } 330 331 //------------------------------------------------------------------------------ 332 287 333 // Local Variables: 288 334 // mode: C++ -
src/client/c/hu/varadiistvan/xplra/XPlane.h
r16 r17 183 183 std::string getString(const char* name, size_t offset = 0) throw(Exception); 184 184 185 /** 186 * Set the given dataref to the given integer value. 187 */ 188 void setInt(const char* name, int value) throw(Exception); 189 190 /** 191 * Set the given dataref to the given float value. 192 */ 193 void setFloat(const char* name, float value) throw(Exception); 194 195 /** 196 * Set the given dataref to the given double value. 197 */ 198 void setDouble(const char* name, double value) throw(Exception); 199 185 200 private: 186 201 /** … … 194 209 */ 195 210 void checkResult(uint8_t result) throw(ProtocolException); 211 212 /** 213 * Read and check the result. If it signifies an error, 214 * throw a ProtocolException with the correct error code. 215 */ 216 void checkResult() throw(ProtocolException); 196 217 197 218 /** … … 211 232 ssize_t length, size_t offset) throw(Exception); 212 233 234 235 /** 236 * Issue the command to set a scalar value of the given type. 237 */ 238 void setScalar(const char* name, uint8_t type) throw(Exception); 213 239 }; 214 240 -
test/basictest.cc
r16 r17 133 133 printf("\n\n"); 134 134 135 printf("Setting the number of the engines to %d...\n", numEngines + 1); 136 xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1); 137 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines"); 138 printf("The new number of engines: %d\n\n", numEngines); 139 140 float acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up"); 141 printf("Setting the aircraft elevator up control from %f to %f...\n", 142 acfElevUp, acfElevUp + 15.0); 143 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp); 144 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up"); 145 printf("The aircraft elevator up control set to %f\n\n", acfElevUp); 146 147 double acfElevDown = xplane.getDouble("sim/flightmodel/position/local_x"); 148 printf("Setting the aircraft elevator down control from %f to %f...\n", 149 acfElevDown, acfElevDown + 15.0); 150 xplane.setDouble("sim/flightmodel/position/local_x", acfElevDown + 15.0); 151 acfElevDown = xplane.getDouble("sim/flightmodel/position/local_x"); 152 printf("The aircraft elevator down control set to %f\n\n", acfElevDown); 153 154 try { 155 printf("Querying an invalid dataref...\n"); 156 xplane.getInt("sim/aircraft/engine/num_engines"); 157 printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n"); 158 } catch(const ProtocolException& exception) { 159 printf("Exception caugth: %s\n\n", exception.what()); 160 } 161 162 135 163 return 0; 136 164 } catch(const Exception& exception) {
Note:
See TracChangeset
for help on using the changeset viewer.