コード例 #1
0
ファイル: bson.c プロジェクト: algernon/libmongo-client
gboolean
bson_append_javascript_w_scope (bson *b, const gchar *name,
                                const gchar *js, gint32 len,
                                const bson *scope)
{
  gint size;
  size_t length;

  if (!js || !scope || bson_size (scope) < 0 || len < -1)
    return FALSE;

  if (!_bson_append_element_header (b, BSON_TYPE_JS_CODE_W_SCOPE, name))
    return FALSE;

  length = (len != -1) ? (size_t)len + 1: strlen (js) + 1;

  size = length + sizeof (gint32) + sizeof (gint32) + bson_size (scope);

  _bson_append_int32 (b, GINT32_TO_LE (size));

  /* Append the JS code */
  _bson_append_int32 (b, GINT32_TO_LE (length));
  b->data = g_byte_array_append (b->data, (const guint8 *)js, length - 1);
  _bson_append_byte (b, 0);

  /* Append the scope */
  b->data = g_byte_array_append (b->data, bson_data (scope),
                                 bson_size (scope));

  return TRUE;
}
コード例 #2
0
ファイル: properties.c プロジェクト: Sandec/openjfx-8u-dev-rt
/* FOURCC */
guint64
prop_copy_fourcc (guint32 prop, guint8 ** buffer, guint64 * size,
    guint64 * offset)
{
  prop = GINT32_TO_LE (prop);
  return copy_func (&prop, sizeof (guint32), buffer, size, offset);
}
コード例 #3
0
ファイル: bson.c プロジェクト: algernon/libmongo-client
gboolean
bson_append_int32 (bson *b, const gchar *name, gint32 i)
{
  if (!_bson_append_element_header (b, BSON_TYPE_INT32, name))
    return FALSE;

  _bson_append_int32 (b, GINT32_TO_LE (i));
  return TRUE;
 }
コード例 #4
0
ファイル: bson.c プロジェクト: algernon/libmongo-client
gboolean
bson_append_binary (bson *b, const gchar *name, bson_binary_subtype subtype,
                    const guint8 *data, gint32 size)
{
  if (!data || !size || size <= 0)
    return FALSE;

  if (!_bson_append_element_header (b, BSON_TYPE_BINARY, name))
    return FALSE;

  _bson_append_int32 (b, GINT32_TO_LE (size));
  _bson_append_byte (b, (guint8)subtype);

  b->data = g_byte_array_append (b->data, data, size);
  return TRUE;
}
コード例 #5
0
ファイル: gf_p2p_natcheck.c プロジェクト: gfireproject/gfire
static void gfire_p2p_natcheck_query(gfire_p2p_natcheck *p_nat, int p_server, int p_stage)
{
	static unsigned char packet[18] = { 'S', 'C', '0', '1',
										0x04, 0x5a, 0xcb, 0x00,
										0x01, 0x00, 0x00, 0x00,
										0x00, 0x00, 0x00, 0x00,
										0x00, 0x00 };

	p_stage = GINT32_TO_LE(p_stage);
	memcpy(packet + 12, &p_stage, 4);

	guint16 port = g_htons(purple_network_get_port_from_fd(p_nat->socket));
	memcpy(packet + 16, &port, 2);

	purple_debug_misc("gfire", "P2P: NAT Check: Sending IP request to server %d...\n", p_server + 1);
	sendto(p_nat->socket, packet, 18, 0, (struct sockaddr*)&p_nat->nat_servers[p_server], sizeof(struct sockaddr_in));
}
コード例 #6
0
/* No need to access it from outside */
static struct message1 * encode_connection_request(struct connection_request * req) {
  struct message1 * msg;
  msg = (struct message1 *)calloc(1, sizeof(struct message1));

  msg->function = GUINT32_TO_LE(0x0003bef4);
  msg->counter = GUINT32_TO_LE(1);

  msg->client_size = 9;
  memcpy(msg->client, "TeamSpeak", 9);

  /* cut machine if too long */
  if(strlen(req->machine) > 29)
    req->machine[29] = '\0';
  msg->machine_size = (uint8_t)strlen(req->machine);
  memcpy(msg->machine, req->machine, strlen(req->machine));

  msg->data1 = GUINT32_TO_LE(0x02000000);
  msg->data2 = GUINT32_TO_LE(0x20003C00);

  msg->assign_nick = req->assign_nick;
  msg->always1 = 0x01;

  /* Insert login */
  if(strlen(req->login) > 29)
    req->login[29] = '\0';
  msg->login_size = (uint8_t)strlen(req->login);
  memcpy(msg->login, req->login, strlen(req->login));

  /* Insert password */
  if(strlen(req->pass) > 29)
    req->pass[29] = '\0';
  msg->pass_size = (uint8_t)strlen(req->pass);
  memcpy(msg->pass, req->pass, strlen(req->pass));

  /* Insert nick */
  if(strlen(req->nick) > 29)
    req->nick[29] = '\0';
  msg->nick_size = (uint8_t)strlen(req->nick);
  memcpy(msg->nick, req->nick, strlen(req->nick));

  msg->checksum = GINT32_TO_LE(crc_32(msg, sizeof(struct message1), 0xEDB88320));

  return msg;
}
コード例 #7
0
ファイル: test.c プロジェクト: chrisrob/libmongo-client
mongo_packet *
test_mongo_wire_generate_reply (gboolean valid, gint32 nreturn,
                                gboolean with_docs)
{
  mongo_reply_packet_header rh;
  mongo_packet_header h;
  mongo_packet *p;
  guint8 *data;
  gint data_size = sizeof (mongo_reply_packet_header);
  bson *b1 = NULL, *b2 = NULL;

  p = mongo_wire_packet_new ();

  h.opcode = (valid) ? GINT32_TO_LE (1) : GINT32_TO_LE (42);
  h.id = GINT32_TO_LE (1984);
  h.resp_to = GINT32_TO_LE (42);
  if (with_docs)
    {
      b1 = test_bson_generate_full ();
      b2 = test_bson_generate_full ();
      data_size += bson_size (b1) + bson_size (b2);
    }
  h.length = GINT32_TO_LE (sizeof (mongo_packet_header) + data_size);

  mongo_wire_packet_set_header (p, &h);

  data = g_try_malloc (data_size);

  rh.flags = 0;
  rh.cursor_id = GINT64_TO_LE ((gint64)12345);
  rh.start = 0;
  rh.returned = GINT32_TO_LE (nreturn);

  memcpy (data, &rh, sizeof (mongo_reply_packet_header));
  if (with_docs)
    {
      memcpy (data + sizeof (mongo_reply_packet_header),
              bson_data (b1), bson_size (b1));
      memcpy (data + sizeof (mongo_reply_packet_header) + bson_size (b1),
              bson_data (b2), bson_size (b2));
    }

  mongo_wire_packet_set_data (p, data, data_size);
  g_free (data);
  bson_free (b1);
  bson_free (b2);

  return p;
}
コード例 #8
0
ファイル: bson.c プロジェクト: algernon/libmongo-client
gboolean
bson_finish (bson *b)
{
  gint32 *i;

  if (!b)
    return FALSE;

  if (b->finished)
    return TRUE;

  _bson_append_byte (b, 0);

  i = (gint32 *) (&b->data->data[0]);
  *i = GINT32_TO_LE ((gint32) (b->data->len));

  b->finished = TRUE;

  return TRUE;
}
コード例 #9
0
ファイル: bson.c プロジェクト: algernon/libmongo-client
/** @internal Append a string-like element to a BSON object.
 *
 * There are a few string-like elements in the BSON spec that differ
 * only in type, not in structure. This convenience function is used
 * to append them with the appropriate type.
 *
 * @param b is the BSON object to append to.
 * @param type is the string-like type to append.
 * @param name is the key name.
 * @param val is the value to append.
 * @param length is the length of the value.
 *
 * @note Passing @a -1 as length will use the full length of @a
 * val.
 *
 * @returns TRUE on success, FALSE otherwise.
 */
static gboolean
_bson_append_string_element (bson *b, bson_type type, const gchar *name,
                             const gchar *val, gint32 length)
{
  size_t len;

  if (!val || !length || length < -1)
    return FALSE;

  len = (length != -1) ? (size_t)length + 1: strlen (val) + 1;

  if (!_bson_append_element_header (b, type, name))
    return FALSE;

  _bson_append_int32 (b, GINT32_TO_LE (len));

  b->data = g_byte_array_append (b->data, (const guint8 *)val, len - 1);
  _bson_append_byte (b, 0);

  return TRUE;
}
コード例 #10
0
ファイル: wpg.c プロジェクト: mpuels/dia
G_END_DECLS

#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
/* shortcut if testing of indirection isn't needed anymore */
#define fwrite_le(a,b,c,d) fwrite(a,b,c,d)
#else
static size_t
fwrite_le(void* buf, size_t size, size_t count, FILE* f)
{
  size_t n = 0;
  guint i;

  g_assert((1 == size) || (2 == size) || (4 == size));

  if (4 == size)
  {
    gint32 i32;

    for (i = 0; i < count; i++)
    {
      i32 = GINT32_TO_LE(((gint32*)buf)[i]);
      n += fwrite(&i32, sizeof(gint32), 1, f);
    }
  }
  else if (2 == size)
  {
    gint16 i16;

    for (i = 0; i < count; i++)
    {
      i16 = GINT16_TO_LE(((gint16*)buf)[i]);
      n += fwrite(&i16, sizeof(gint16), 1, f);
    }
  }
  else
    n = fwrite(buf, size, count, f);

  return n;
}
コード例 #11
0
ファイル: qmi-utils.c プロジェクト: ebichu/dd-wrt
/**
 * qmi_utils_write_gint32_to_buffer:
 * @buffer: a buffer.
 * @buffer_size: size of @buffer.
 * @endian: endianness of firmware value; swapped from host byte order if necessary
 * @in: location of the variable to be written.
 *
 * Writes a signed 32-bit integer into the buffer. The number to be written
 * is expected to be given in host endianness, and this method takes care of
 * converting the value written to the byte order specified by @endian.
 *
 * The user needs to make sure that the buffer is at least 4 bytes long.
 *
 * Also note that both @buffer and @buffer_size get updated after the 4 bytes
 * write.
 */
void
qmi_utils_write_gint32_to_buffer (guint8  **buffer,
                                  guint16  *buffer_size,
                                  QmiEndian endian,
                                  gint32   *in)
{
    gint32 tmp;

    g_assert (in != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= 4);

    if (endian == QMI_ENDIAN_BIG)
        tmp = GINT32_TO_BE (*in);
    else
        tmp = GINT32_TO_LE (*in);
    memcpy (&(*buffer)[0], &tmp, sizeof (tmp));

    *buffer = &((*buffer)[4]);
    *buffer_size = (*buffer_size) - 4;
}
コード例 #12
0
ファイル: surffile.c プロジェクト: cbuehler/gwyddion
static gboolean
surffile_save(GwyContainer *data,
             const gchar *filename,
             G_GNUC_UNUSED GwyRunType mode,
             GError **error)
{
    FILE *fh;
    gboolean ok = TRUE;
    SurfWriter surf;
    gfloat uintmax = 1073741824.0;
    gdouble zmaxreal;
    gdouble zminreal;
    gdouble xreal;
    gdouble yreal;
    gchar *dxunittmp;
    gchar *dyunittmp;
    gchar *dzunittmp;
    GwySIUnit *xysi;
    GwySIUnit *zsi;
    GwyContainer *current_data;
    int power = 0;
    int k = 0;
    GwyDataField *dfield;
    const gdouble *points;
    gint32 *integer_values;

    strncpy(surf.signature, "DIGITAL SURF", 12);
    surf.format = 0;
    surf.nobjects = 1;
    surf.version = 1;
    surf.type = 1;
    strncpy(surf.object_name, "SCRATCH", 30);
    strncpy(surf.operator_name, "csm", 30);
    surf.material_code = 0;
    surf.acquisition = 0;
    surf.range = 1;
    surf.special_points = 0;
    surf.absolute = 1;
    strncpy(surf.reserved, " ", 8);
    surf.pointsize = 32;
    surf.zmin = 0;
    surf.zmax = 1073741824.0;
    strncpy(surf.xaxis, "X", 16);
    strncpy(surf.yaxis, "Y", 16);
    strncpy(surf.zaxis, "Z", 16);
    surf.xunit_ratio = 1;
    surf.yunit_ratio = 1;
    surf.zunit_ratio = 1;
    surf.imprint = 1;
    surf.inversion = 0;
    surf.leveling = 0;
    strncpy(surf.obsolete, " ", 12);
    surf.seconds = 0;
    surf.minutes = 0;
    surf.hours = 0;
    surf.day = 5;
    surf.month = 1;
    surf.year = 2001;
    surf.dayof = 0;
    surf.measurement_duration = 1.0;
    strncpy(surf.obsolete2, " ", 10);
    surf.comment_size = 0;
    surf.private_size = 0;
    strncpy(surf.client_zone," ", 128);

    surf.XOffset = 0.0;
    surf.YOffset = 0.0;
    surf.ZOffset = 0.0;
    strncpy(surf.reservedzone, " ", 34);

    if (!(fh = gwy_fopen( filename, "wb"))) {
        err_OPEN_WRITE(error);
        return FALSE;
    }

    gwy_app_data_browser_get_current(GWY_APP_CONTAINER, &current_data, 0);
    if (!current_data) {
        err_NO_CHANNEL_EXPORT(error);
        return FALSE;
    }

    if (data != current_data) {
        return FALSE;
    }

    gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, 0);
    if (!dfield) {
        err_NO_CHANNEL_EXPORT(error);
        return FALSE;
    }

    /*header values*/
    xysi = gwy_data_field_get_si_unit_xy(dfield);
    zsi = gwy_data_field_get_si_unit_z(dfield);
    dxunittmp = gwy_si_unit_get_string(xysi, GWY_SI_UNIT_FORMAT_PLAIN);
    dyunittmp = gwy_si_unit_get_string (xysi, GWY_SI_UNIT_FORMAT_PLAIN);
    dzunittmp = gwy_si_unit_get_string (zsi, GWY_SI_UNIT_FORMAT_PLAIN);
    strncpy(surf.dx_unit, dxunittmp, 16);
    strncpy(surf.dy_unit, dyunittmp, 16);
    strncpy(surf.dz_unit, dzunittmp, 16);
    g_free(dxunittmp);
    g_free(dyunittmp);
    g_free(dzunittmp);

    /*extrema*/
    zmaxreal = gwy_data_field_get_max(dfield);
    zminreal = gwy_data_field_get_min(dfield);
    surf.xres = gwy_data_field_get_xres(dfield);
    surf.yres = gwy_data_field_get_yres(dfield);
    surf.nofpoints = surf.xres * surf.yres;
    xreal = gwy_data_field_get_xreal(dfield);
    yreal = gwy_data_field_get_yreal(dfield);

    /*units*/
    power = 0;
    surf.dx = (gfloat)(xreal / surf.xres);
    get_unit(surf.dx_unit, &power, xreal);
    surf.dx *= pow10(power);
    strncpy(surf.xlength_unit, surf.dx_unit, 16);
    power = 0;
    surf.dy = (gfloat)(yreal / surf.yres);
    get_unit(surf.dy_unit, &power, yreal);
    surf.dy *= pow10(power);
    strncpy(surf.ylength_unit, surf.dy_unit, 16);

    power = 0;
    if (zmaxreal > zminreal) {
        get_unit(surf.dz_unit, &power, (zmaxreal - zminreal));
    }
    strncpy(surf.zlength_unit, surf.dz_unit, 16);

    zmaxreal *= pow10(power);
    zminreal *= pow10(power);
    surf.dz = (zmaxreal - zminreal) / uintmax;
    surf.ZOffset = zminreal;

    /*convert data into integer32*/
    integer_values = g_new(gint32, surf.nofpoints);
    points = gwy_data_field_get_data_const(dfield);

    if (zminreal != zmaxreal) {
        for (k = 0; k < surf.nofpoints; k++) {  // * pow10( power ) to convert in the dz_unit
            integer_values[k] = floor(uintmax * (points[k] * pow10(power)  - zminreal) / (zmaxreal - zminreal));
        }
    }
    else {
        for (k = 0; k < surf.nofpoints; k++) {
            integer_values[k] = 0;
        }
    }


    /* byte order*/
    surf.format = GINT16_TO_LE(surf.format);
    surf.nobjects = GUINT16_TO_LE(surf.nobjects);
    surf.version = GINT16_TO_LE(surf.version);
    surf.type = GINT16_TO_LE(surf.type);
    surf.material_code = GINT16_TO_LE(surf.material_code);
    surf.acquisition = GINT16_TO_LE(surf.acquisition);
    surf.range = GINT16_TO_LE(surf.range);
    surf.special_points = GINT16_TO_LE(surf.special_points);
    surf.absolute = GINT16_TO_LE(surf.absolute);
    surf.pointsize = GINT16_TO_LE(surf.pointsize);
    surf.zmin = GINT32_TO_LE(surf.zmin);
    surf.zmax = GINT32_TO_LE(surf.zmax);
    surf.xres = GINT32_TO_LE(surf.xres);
    surf.yres = GINT32_TO_LE(surf.yres);
    surf.nofpoints = GINT32_TO_LE(surf.nofpoints);
    surf.dx = GFLOAT_TO_LE(surf.dx);
    surf.dy = GFLOAT_TO_LE(surf.dy);
    surf.dz = GFLOAT_TO_LE(surf.dz);
    surf.xunit_ratio = GFLOAT_TO_LE(surf.xunit_ratio);
    surf.yunit_ratio = GFLOAT_TO_LE(surf.yunit_ratio);
    surf.zunit_ratio = GFLOAT_TO_LE(surf.zunit_ratio);
    surf.imprint = GINT16_TO_LE(surf.imprint);
    surf.inversion = GINT16_TO_LE(surf.inversion);
    surf.leveling = GINT16_TO_LE(surf.leveling);
    surf.seconds = GINT16_TO_LE(surf.seconds);
    surf.minutes = GINT16_TO_LE(surf.minutes);
    surf.hours = GINT16_TO_LE(surf.hours);
    surf.day = GINT16_TO_LE(surf.day);
    surf.month = GINT16_TO_LE(surf.month);
    surf.year = GINT16_TO_LE(surf.year);
    surf.dayof = GINT16_TO_LE(surf.dayof);
    surf.measurement_duration = GFLOAT_TO_LE(surf.measurement_duration);
    surf.comment_size = GINT16_TO_LE(surf.comment_size);
    surf.private_size = GINT16_TO_LE(surf.private_size);
    surf.XOffset = GFLOAT_TO_LE(surf.XOffset);
    surf.YOffset = GFLOAT_TO_LE(surf.YOffset);
    surf.ZOffset = GFLOAT_TO_LE(surf.ZOffset);
    for (k = 0; k < surf.nofpoints; k++) {
        integer_values[k] = GINT32_TO_LE(integer_values[k]);
    }


//write

// fwrite(&surf, sizeof( SurfWriter ), 1, fh) bad struct align
    if(
        fwrite(&surf.signature, sizeof(char), 12, fh) != 12 ||
        fwrite(&surf.format, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.nobjects, sizeof(guint16), 1, fh) != 1 ||
        fwrite(&surf.version, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.type, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.object_name, sizeof(char), 30, fh) != 30 ||
        fwrite(&surf.operator_name, sizeof(char), 30, fh) != 30 ||
        fwrite(&surf.material_code, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.acquisition, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.range, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.special_points, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.absolute, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.reserved, sizeof(char), 8, fh) != 8 ||
        fwrite(&surf.pointsize, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.zmin, sizeof(gint32), 1, fh) != 1 ||
        fwrite(&surf.zmax, sizeof(gint32), 1, fh) != 1 ||
        fwrite(&surf.xres, sizeof(gint32), 1, fh) != 1 ||
        fwrite(&surf.yres, sizeof(gint32), 1, fh) != 1 ||
        fwrite(&surf.nofpoints, sizeof(gint32), 1, fh) != 1 ||
        fwrite(&surf.dx, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.dy, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.dz, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.xaxis, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.yaxis, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.zaxis, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.dx_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.dy_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.dz_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.xlength_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.ylength_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.zlength_unit, sizeof(char), 16, fh) != 16 ||
        fwrite(&surf.xunit_ratio, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.yunit_ratio, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.zunit_ratio, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.imprint, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.inversion, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.leveling, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.obsolete, sizeof(char), 12, fh) != 12 ||
        fwrite(&surf.seconds, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.minutes, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.hours, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.day, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.month, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.year, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.dayof, sizeof(gint16),1,fh) != 1 ||
        fwrite(&surf.measurement_duration, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.obsolete2, sizeof(char), 10, fh) != 10 ||
        fwrite(&surf.comment_size, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.private_size, sizeof(gint16), 1, fh) != 1 ||
        fwrite(&surf.client_zone, sizeof(char), 128, fh) != 128 ||
        fwrite(&surf.XOffset, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.YOffset, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.ZOffset, sizeof(gfloat), 1, fh) != 1 ||
        fwrite(&surf.reservedzone, sizeof(char), 34, fh)!= 34 ||
        fwrite(integer_values, sizeof(gint32), surf.nofpoints, fh) != surf.nofpoints
	    ) {
            err_WRITE(error);
            ok = FALSE;
            g_unlink(filename);
        }

    g_free(integer_values);
    fclose( fh );

    return ok;
}
コード例 #13
0
ファイル: libreems_comms.c プロジェクト: JacobD10/MegaTunix
/*!
 \brief ECU specifc that gets called to send a value to the ECU. 
 \param canID is the can Identifier
 \param locID is the Location ID to where this value belongs
 \param offset is the offset from the beginning of the page that this data
 refers to.
 \param size is an enumeration corresponding to how big this variable is
 \param value is the value that should be sent to the ECU At page/offset
 \param queue_update if true queues a gui update, used to prevent
 a horrible stall when doing an ECU restore or batch load...
 */
G_MODULE_EXPORT void libreems_send_to_ecu(gint canID, gint locID, gint offset, DataSize size, gint value, gboolean queue_update)
{
	static Firmware_Details *firmware = NULL;
	OutputData *output = NULL;
	guint8 *data = NULL;
	guint16 u16 = 0;
	gint16 s16 = 0;
	guint32 u32 = 0;
	gint32 s32 = 0;

	ENTER();
	if (!firmware)
		firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(firmware);
	g_return_if_fail(offset >= 0);

	MTXDBG(SERIAL_WR,_("Sending locID %i, offset %i, value %i \n"),locID,offset,value);

	switch (size)
	{
		case MTX_CHAR:
		case MTX_S08:
		case MTX_U08:
			/*printf("8 bit var %i at offset %i\n",value,offset);*/
			break;
		case MTX_S16:
		case MTX_U16:
			/*printf("16 bit var %i at offset %i\n",value,offset);*/
			break;
		case MTX_S32:
		case MTX_U32:
			/*printf("32 bit var %i at offset %i\n",value,offset);*/
			break;
		default:
			printf(_("libreems_send_to_ecu() ERROR!!! Size undefined for variable at canID %i, offset %i\n"),locID,offset);
	}
	output = initialize_outputdata_f();
	DATA_SET(output->data,"location_id", GINT_TO_POINTER(locID));
	DATA_SET(output->data,"payload_id", GINT_TO_POINTER(REQUEST_UPDATE_BLOCK_IN_RAM));
	DATA_SET(output->data,"offset", GINT_TO_POINTER(offset));
	DATA_SET(output->data,"size", GINT_TO_POINTER(size));
	DATA_SET(output->data,"value", GINT_TO_POINTER(value));
	DATA_SET(output->data,"length", GINT_TO_POINTER(get_multiplier_f(size)));
	DATA_SET(output->data,"mode", GINT_TO_POINTER(MTX_SIMPLE_WRITE));
	/* Get memory */
	data = g_new0(guint8,get_multiplier_f(size));
	switch (size)
	{
		case MTX_CHAR:
		case MTX_U08:
			data[0] = (guint8)value;
			break;
		case MTX_S08:
			data[0] = (gint8)value;
			break;
		case MTX_U16:
			if (firmware->bigendian)
				u16 = GUINT16_TO_BE((guint16)value);
			else
				u16 = GUINT16_TO_LE((guint16)value);
			data[0] = (guint8)u16;
			data[1] = (guint8)((guint16)u16 >> 8);
			break;
		case MTX_S16:
			if (firmware->bigendian)
				s16 = GINT16_TO_BE((gint16)value);
			else
				s16 = GINT16_TO_LE((gint16)value);
			data[0] = (guint8)s16;
			data[1] = (guint8)((gint16)s16 >> 8);
			break;
		case MTX_S32:
			if (firmware->bigendian)
				s32 = GINT32_TO_BE((gint32)value);
			else
				s32 = GINT32_TO_LE((gint32)value);
			data[0] = (guint8)s32;
			data[1] = (guint8)((gint32)s32 >> 8);
			data[2] = (guint8)((gint32)s32 >> 16);
			data[3] = (guint8)((gint32)s32 >> 24);
			break;
		case MTX_U32:
			if (firmware->bigendian)
				u32 = GUINT32_TO_BE((guint32)value);
			else
				u32 = GUINT32_TO_LE((guint32)value);
			data[0] = (guint8)u32;
			data[1] = (guint8)((guint32)u32 >> 8);
			data[2] = (guint8)((guint32)u32 >> 16);
			data[3] = (guint8)((guint32)u32 >> 24);
			break;
		default:
			break;
	}
	DATA_SET_FULL(output->data,"data",(gpointer)data, g_free);
	/* Set it here otherwise there's a risk of a missed burn due to 
	 * a potential race condition in the burn checker
	 */
	libreems_set_ecu_data(canID,locID,offset,size,value);
	/* IF the packet fails, update_write_status will rollback properly */

	output->queue_update = queue_update;
	io_cmd_f(firmware->write_command,output);
	EXIT();
	return;
}
コード例 #14
0
static void write_int32(FILE *f, gint32 i) {
    i = GINT32_TO_LE(i);
    fwrite(&i, 1, 4, f);
}
コード例 #15
0
ファイル: write.c プロジェクト: thejefflarson/mdbtools
void
mdb_put_int16(void *buf, guint32 offset, guint32 value)
{
	value = GINT32_TO_LE(value);
	memcpy(buf + offset, &value, 2);
}
コード例 #16
0
static guint8 *
mongo_message_query_save_to_data (MongoMessage *message,
                                  gsize        *length)
{
   static const guint8 empty_bson[] = { 5, 0, 0, 0, 0 };
   MongoMessageQueryPrivate *priv;
   MongoMessageQuery *query = (MongoMessageQuery *)message;
   GByteArray *bytes;
   guint32 v32;
   guint8 *ret;

   ENTRY;

   g_assert(MONGO_IS_MESSAGE_QUERY(query));
   g_assert(length);

   priv = query->priv;

   bytes = g_byte_array_sized_new(64);

   v32 = 0;
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   v32 = GINT32_TO_LE(mongo_message_get_request_id(message));
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   v32 = GINT32_TO_LE(mongo_message_get_response_to(message));
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   v32 = GUINT32_TO_LE(MONGO_OPERATION_QUERY);
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   /* Query flags. */
   v32 = GUINT32_TO_LE(priv->flags);
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   /* Collection name */
   g_byte_array_append(bytes, (guint8 *)(priv->collection ?: ""),
                       strlen(priv->collection ?: "") + 1);

   /* Number to skip */
   v32 = GUINT32_TO_LE(priv->skip);
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   /* Number to return */
   v32 = GUINT32_TO_LE(priv->limit);
   g_byte_array_append(bytes, (guint8 *)&v32, sizeof v32);

   /* Query */
   if (priv->query) {
      g_byte_array_append(bytes, priv->query->data, priv->query->len);
   } else {
      g_byte_array_append(bytes, empty_bson, G_N_ELEMENTS(empty_bson));
   }

   /* Fields */
   if (priv->fields) {
      g_byte_array_append(bytes, priv->fields->data, priv->fields->len);
   }

   /* Update the message length */
   v32 = GUINT32_TO_LE(bytes->len);
   memcpy(bytes->data, &v32, sizeof v32);

   *length = bytes->len;

   DUMP_BYTES(buf, bytes->data, bytes->len);

   ret = g_byte_array_free(bytes, FALSE);
   RETURN(ret);
}