Ignore:
Timestamp:
01/31/13 18:44:47 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the setting of array values

Location:
src/client/c/hu/varadiistvan/xplra
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/client/c/hu/varadiistvan/xplra/XPlane.cc

    r17 r18  
    331331//------------------------------------------------------------------------------
    332332
     333void XPlane::setArray(const char* name, uint8_t type, size_t length,
     334                      size_t offset) throw(Exception)
     335{
     336    stream->writeU8(Protocol::COMMAND_SET_SINGLE);
     337    stream->writeString(name, strlen(name));
     338    stream->writeU8(type);
     339    stream->writeS32(static_cast<int32_t>(length));
     340    stream->writeS32(static_cast<int32_t>(offset));
     341}
     342
     343//------------------------------------------------------------------------------
     344
     345void XPlane::setFloatArray(const char* name, const float* values, size_t length,
     346                           size_t offset) throw(Exception)
     347{
     348    setArray(name, Protocol::TYPE_FLOAT_ARRAY, length, offset);
     349    stream->write(values, length*sizeof(*values));
     350    stream->flush();
     351    checkResult();
     352}
     353
     354//------------------------------------------------------------------------------
     355
     356void XPlane::setIntArray(const char* name, const int32_t* values, size_t length,
     357                         size_t offset) throw(Exception)
     358{
     359    setArray(name, Protocol::TYPE_INT_ARRAY, length, offset);
     360    stream->write(values, length*sizeof(*values));
     361    stream->flush();
     362    checkResult();
     363}
     364
     365//------------------------------------------------------------------------------
     366
     367void XPlane::setByteArray(const char* name, const uint8_t* values, size_t length,
     368                          size_t offset) throw(Exception)
     369{
     370    setArray(name, Protocol::TYPE_BYTE_ARRAY, length, offset);
     371    stream->write(values, length*sizeof(*values));
     372    stream->flush();
     373    checkResult();
     374}
     375
     376//------------------------------------------------------------------------------
     377
     378void XPlane::setString(const char* name, const char* value, size_t length,
     379                       size_t offset) throw(Exception)
     380{
     381    size_t valueLength = strlen(value);
     382    if ((valueLength+1)>=length) {
     383        setByteArray(name, reinterpret_cast<const uint8_t*>(value),
     384                     length, offset);
     385    } else {
     386        auto_ptr<uint8_t> buffer(new uint8_t[length]);
     387        memcpy(buffer.get(), value, valueLength);
     388        memset(buffer.get() + valueLength, 0, length - valueLength);
     389        setByteArray(name, buffer.get(), length, offset);
     390    }
     391}
     392//------------------------------------------------------------------------------
     393
    333394// Local Variables:
    334395// mode: C++
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r17 r18  
    198198    void setDouble(const char* name, double value) throw(Exception);
    199199
     200    /**
     201     * Set the given float array to values in the given buffer.
     202     */
     203    void setFloatArray(const char* name, const float* values, size_t length,
     204                       size_t offset = 0) throw(Exception);
     205
     206    /**
     207     * Set the given integer array to values in the given buffer.
     208     */
     209    void setIntArray(const char* name, const int32_t* values, size_t length,
     210                     size_t offset = 0) throw(Exception);
     211
     212    /**
     213     * Set the given byte array to values in the given buffer.
     214     */
     215    void setByteArray(const char* name, const uint8_t* values, size_t length,
     216                      size_t offset = 0) throw(Exception);
     217
     218    /**
     219     * Set the given string to the given value. Since strings are byte
     220     * arrays, and the bytes after the string should be zeroed, the
     221     * length must be given. The string will be converted to a byte
     222     * array of the given length, padded with 0s.
     223     */
     224    void setString(const char* name, const char* value, size_t length,
     225                   size_t offset = 0) throw(Exception);
     226
    200227private:
    201228    /**
     
    237264     */
    238265    void setScalar(const char* name, uint8_t type) throw(Exception);
     266
     267    /**
     268     * Issue the command to set an array value of the given type.
     269     */
     270    void setArray(const char* name, uint8_t type, size_t length,
     271                  size_t offset) throw(Exception);
    239272};
    240273
Note: See TracChangeset for help on using the changeset viewer.