Esempio n. 1
0
void on_add_activity::on_finished(bool added)
{
	if(!added)
		get_reply()->send_error(ioremap::swarm::network_reply::internal_server_error);
	else
		get_reply()->send_error(ioremap::swarm::network_reply::ok);
}
Esempio n. 2
0
/*########################### pop3_retrieve() ###########################*/
int
pop3_retrieve(unsigned int msg_number, off_t *msg_size)
{
   int reply;

   if ((reply = command(pop3_fd, "RETR %u", msg_number)) == SUCCESS)
   {
      if ((reply = get_reply()) == POP3_OK)
      {
         char *ptr;

         ptr = msg_str + 3;
         if (*ptr == ' ')
         {
            int  i;
            char str_number[MAX_LONG_LENGTH + 1];

            i = 0;
            ptr++;
            while (isdigit((int)(*(ptr + i))) && (i < MAX_LONG_LENGTH))
            {
               str_number[i] = *(ptr + i);
               i++;
            }
            if (i <= MAX_LONG_LENGTH)
            {
               if (i > 0)
               {
                  str_number[i] = '\0';
                  *msg_size = (off_t)str2offt(str_number, NULL, 8);
               }
               else
               {
                  trans_log(WARN_SIGN, __FILE__, __LINE__, "pop3_retrieve", msg_str,
                            _("Failed to get size from reply."));
                  *msg_size = 0;
               }
            }
            else
            {
               trans_log(WARN_SIGN, __FILE__, __LINE__, "pop3_retrieve", msg_str,
                         _("Size in reply to large to store."));
               *msg_size = 0;
            }
         }
         else
         {
            trans_log(WARN_SIGN, __FILE__, __LINE__, "pop3_retrieve", msg_str,
                      _("Failed to get size from reply."));
            *msg_size = 0;
         }
      }
      else
      {
         *msg_size = 0;
      }
   }

   return(reply);
}
Esempio n. 3
0
File: xterm.c Progetto: akat1/impala
static void
check_rc(int row, int col)
{
    char *report;
    char *params;
    char expected[80];

    sprintf(expected, "%d;%dR", row, col);

    set_tty_raw(TRUE);
    set_tty_echo(FALSE);
    do_csi("6n");
    report = get_reply();
    restore_ttymodes();

    vt_move(row, 1);
    el(2);
    if ((params = skip_csi(report)) == 0
            || strcmp(params, expected) != 0) {
        printf("cursor save/restore %s, got \"%s\", expected \"%s\"",
               SHOW_FAILURE, params, expected);
    } else {
        printf("cursor save/restore %s", SHOW_SUCCESS);
    }
}
Esempio n. 4
0
int
any_DSR(MENU_ARGS, const char *text, void (*explain) (char *report))
{
    char *report;
    unsigned pmode = (unsigned) ((*text == '?') ? 1 : 0);

    vt_move(1, 1);
    printf("Testing DSR: %s\n", the_title);

    set_tty_raw(TRUE);
    set_tty_echo(FALSE);

    do_csi("%s", text);
    report = get_reply();
    vt_move(3, 10);
    chrprint(report);
    if ((report = skip_csi(report)) != 0
            && strlen(report) > (1 + pmode)
            && (!pmode || (*report++ == '?'))) {
        if (explain != 0)
            (*explain) (report);
        else
            show_result(SHOW_SUCCESS);
    } else {
        show_result(SHOW_FAILURE);
    }

    restore_ttymodes();
    vt_move(max_lines - 1, 1);
    return MENU_HOLD;
}
Esempio n. 5
0
void resume_ondemand(struct th_arg *arg)
{
    if (strlen(arg->ch.data) > 0) {
        printf("Resumed; sending thunked ondemand message\n");
        PthreadScopedLock lock(&socket_lock);
        int rc = cmm_send(shared_sock, arg->ch.data, sizeof(arg->ch), 0,
                          CMM_LABEL_ONDEMAND, 
                          (resume_handler_t)resume_ondemand, arg);
        if (rc < 0) {
            if (rc == CMM_DEFERRED) {
                printf("Deferred ondemand send re-deferred\n");
            } else {
                perror("send");
                printf("Deferred ondemand send failed!\n");
                exit(-1);
            }
        } else {
            printf("Deferred ondemand send succeeded\n");
            delete arg;
            rc = get_reply(shared_sock);
            if (rc < 0) {
                exit(-1);
            }
        }
    }
}
Esempio n. 6
0
/* {{{ MongoCursor->doQuery
 */
PHP_METHOD(MongoCursor, doQuery) {
  int sent;
  mongo_msg_header header;
  mongo_cursor *cursor;
  CREATE_BUF(buf, INITIAL_BUF_SIZE);

  cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC);
  MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor);

  CREATE_HEADER_WITH_OPTS(buf, cursor->ns, OP_QUERY, cursor->opts);

  serialize_int(&buf, cursor->skip);
  serialize_int(&buf, cursor->limit);

  zval_to_bson(&buf, HASH_P(cursor->query), NO_PREP TSRMLS_CC);
  if (cursor->fields && zend_hash_num_elements(HASH_P(cursor->fields)) > 0) {
    zval_to_bson(&buf, HASH_P(cursor->fields), NO_PREP TSRMLS_CC);
  }

  serialize_size(buf.start, &buf);
  // sends
  sent = mongo_say(cursor->link, &buf TSRMLS_CC);
  efree(buf.start);
  if (sent == FAILURE) {
    zend_throw_exception(mongo_ce_CursorException, "couldn't send query.", 0 TSRMLS_CC);
    return;
  }

  get_reply(cursor TSRMLS_CC);
}
Esempio n. 7
0
int freenect_set_tilt_degs_alt(freenect_device *dev, int tilt_degrees)
{
	freenect_context *ctx = dev->parent;

	if (tilt_degrees > 31 || tilt_degrees < -31) {
		FN_WARNING("set_tilt(): degrees %d out of safe range [-31, 31]\n", tilt_degrees);
		return -1;
	}
    
	fn_alt_motor_command cmd;
	cmd.magic = fn_le32(0x06022009);
	cmd.tag = fn_le32(tag_seq++);
	cmd.arg1 = fn_le32(0);
	cmd.cmd = fn_le32(0x803b);
	cmd.arg2 = (uint32_t)(fn_le32((int32_t)tilt_degrees));
	int transferred = 0;
	int res = 0;
	unsigned char buffer[20];
	memcpy(buffer, &cmd, 20);

	res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 20, &transferred, 250);
	if (res != 0) {
		FN_ERROR("freenect_set_tilt_alt(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
		return res;
	}
    
	return get_reply(dev->usb_audio.dev, ctx);
}
Esempio n. 8
0
int set_led(libusb_device_handle* dev, led_state state) {
	int transferred = 0;
	int res = 0;
	motor_command cmd;
	cmd.magic = le32(0x06022009);
	cmd.tag = le32(tag_seq++);
	cmd.arg1 = le32(0);
	cmd.cmd = le32(0x10);
	cmd.arg2 = (uint32_t)(le32((int32_t)state));
	unsigned char buffer[20];
	memcpy(buffer, &cmd, 20);
	// Send command to set LED to solid green
	LOG("About to send bulk transfer:");
	int i;
	for(i = 0; i < 20 ; i++) {
		LOG(" %02X", buffer[i]);
	}
	LOG("\n");
	res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 0);
	if (res != 0) {
		LOG("set_led(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
		return res;
	}
	return get_reply(dev);
}
Esempio n. 9
0
int set_tilt(libusb_device_handle* dev, int tilt_degrees) {
	if (tilt_degrees > 31 || tilt_degrees < -31) {
		LOG("set_tilt(): degrees %d out of safe range [-31, 31]\n", tilt_degrees);
		return -1;
	}
	motor_command cmd;
	cmd.magic = le32(0x06022009);
	cmd.tag = le32(tag_seq++);
	cmd.arg1 = le32(0);
	cmd.cmd = le32(0x803b);
	cmd.arg2 = (uint32_t)(le32((int32_t)tilt_degrees));
	int transferred = 0;
	int res = 0;
	unsigned char buffer[20];
	memcpy(buffer, &cmd, 20);

	LOG("About to send bulk transfer:");
	int i;
	for(i = 0; i < 20 ; i++) {
		LOG(" %02X", buffer[i]);
	}
	LOG("\n");
	res = libusb_bulk_transfer(dev, 0x01, buffer, 20, &transferred, 0);
	if (res != 0) {
		LOG("set_tilt(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
		return res;
	}
	return get_reply(dev);
}
Esempio n. 10
0
/* Test User-Preferred Supplemental Set - VT320 */
static int
tst_DECRQUPSS(MENU_ARGS)
{
  char *report;
  const char *show;

  __(vt_move(1, 1), println("Testing DECRQUPSS/DECAUPSS Window Report"));

  set_tty_raw(TRUE);
  set_tty_echo(FALSE);

  do_csi("&u");
  report = get_reply();
  vt_move(3, 10);
  chrprint(report);
  if ((report = skip_dcs(report)) != 0
      && strip_terminator(report)) {
    if (!strcmp(report, "0!u%5"))
      show = "DEC Supplemental Graphic";
    else if (!strcmp(report, "1!uA"))
      show = "ISO Latin-1 supplemental";
    else
      show = "unknown";
  } else {
    show = SHOW_FAILURE;
  }
  show_result("%s", show);

  restore_ttymodes();
  vt_move(max_lines - 1, 1);
  return MENU_HOLD;
}
Esempio n. 11
0
/* Test Window Report - VT340, VT420 */
static int
tst_DECRQDE(MENU_ARGS)
{
  char *report;
  char chr;
  int Ph, Pw, Pml, Pmt, Pmp;

  vt_move(1, 1);
  println("Testing DECRQDE/DECRPDE Window Report");

  set_tty_raw(TRUE);
  set_tty_echo(FALSE);

  do_csi("\"v");
  report = get_reply();
  vt_move(3, 10);
  chrprint(report);

  if ((report = skip_csi(report)) != 0
      && sscanf(report, "%d;%d;%d;%d;%d\"%c",
                &Ph, &Pw, &Pml, &Pmt, &Pmp, &chr) == 6
      && chr == 'w') {
    vt_move(5, 10);
    show_result("lines:%d, cols:%d, left col:%d, top line:%d, page %d",
                Ph, Pw, Pml, Pmt, Pmp);
  } else {
    show_result(SHOW_FAILURE);
  }

  restore_ttymodes();
  vt_move(max_lines - 1, 1);
  return MENU_HOLD;
}
Esempio n. 12
0
static int send_msg(znl2msg* msg, int sock)
{
    int i;
    int len;
    int err = 0;
    uint32_t* store;

    for (i = 0; i < max_tries; i++) {

        if (nl2_send(sock, &my_addr, msg) < 0) {
            perror("send-msg");
            return -2;
        }

        /* Wait for ACK */
        if ((err = get_reply(sock, &msg->n)) >= 0)
            return err;

        fprintf(stderr, "%s: %s; retrying...\n", progname,
                (err == -2)?"timeout":"error");
    }

    fprintf(stderr, "%s: no reply from the switch, ABORT\n", progname);
    return -1;
}
Esempio n. 13
0
/* Request Terminal State Report */
static int
tst_DECRQTSR(MENU_ARGS)
{
  char *report;
  const char *show;

  vt_move(1, 1);
  println("Testing Terminal State Reports (DECRQTSR/DECTSR)");

  set_tty_raw(TRUE);
  set_tty_echo(FALSE);

  do_csi("1$u");
  report = get_reply();

  vt_move(3, 10);
  chrprint(report);

  if ((report = skip_dcs(report)) != 0
      && strip_terminator(report)
      && !strncmp(report, "1$s", (size_t) 3)) {
    show = SHOW_SUCCESS;
  } else {
    show = SHOW_FAILURE;
  }
  show_result("%s", show);

  restore_ttymodes();
  vt_move(max_lines - 1, 1);
  return MENU_HOLD;
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
   char header[] = "Powered-by: ANSI C scripts\r\n";
   http_header(HEAD_ADD, header, sizeof(header) - 1, argv);
   
   xbuf_cat(get_reply(argv), "Look at the HTTP headers");

   return 200; // return an HTTP code (200:'OK')
}
Esempio n. 15
0
int audit_request_rule_list(int fd)
{
	if (audit_request_rules_list_data(fd) > 0) {
		list_requested = 1;
		get_reply();
		return 1;
	}
	return 0;
}
Esempio n. 16
0
void on_add_log::on_request(const ioremap::swarm::network_request &/*req*/,
                            const boost::asio::const_buffer &buffer)
{
	try {
		std::string request(boost::asio::buffer_cast<const char*>(buffer),
		                    boost::asio::buffer_size(buffer));
		ioremap::swarm::network_query_list query_list(request);

		if(!query_list.has_item(consts::USER_ITEM) ||
		   !query_list.has_item(consts::DATA_ITEM) ||
		   (!query_list.has_item(consts::TIME_ITEM) &&
		    !query_list.has_item(consts::KEY_ITEM)))
			throw std::invalid_argument("user, data, time or key");

		if(query_list.has_item(consts::KEY_ITEM)) {
			get_server()
			->get_provider()
			->add_log(query_list.item_value(consts::USER_ITEM),
			          query_list.item_value(consts::KEY_ITEM),
			          ioremap::elliptics::data_pointer::copy(query_list.item_value(consts::DATA_ITEM)),
			          std::bind(&on_add_log::on_finish,
			                    shared_from_this(),
			                    std::placeholders::_1));
		}
		else if(query_list.has_item("time")) {
			get_server()
			->get_provider()
			->add_log(query_list.item_value(consts::USER_ITEM),
			          boost::lexical_cast<uint64_t>(query_list.item_value(consts::TIME_ITEM)),
			          ioremap::elliptics::data_pointer::copy(query_list.item_value(consts::DATA_ITEM)),
			          std::bind(&on_add_log::on_finish,
			                    shared_from_this(),
			                    std::placeholders::_1));
		}
		else
			throw std::invalid_argument("Key and time are missed");
	}
	catch(ioremap::elliptics::error&) {
		get_reply()->send_error(ioremap::swarm::network_reply::internal_server_error);
	}
	catch(...) {
		get_reply()->send_error(ioremap::swarm::network_reply::bad_request);
	}
}
Esempio n. 17
0
int main(int argc, char *argv[])
{
   static char msg[] = "Throttling Enabled @ %u KB/s!";
   
   xbuf_xcat(get_reply(argv), msg, SPEED);
   
   throttle_reply(argv, SPEED, SPEED, 1); // 1: global setting, 0:this connection
   
   return 200; // return an HTTP code (200:'OK')
}
Esempio n. 18
0
void on_get_user_logs::on_request(const ioremap::swarm::http_request &req, const boost::asio::const_buffer &/*buffer*/)
{
	try {
		const auto &query = req.url().query();

		auto user_item = query.item_value(consts::USER_ITEM);
		if (!user_item)
			throw std::invalid_argument("user is missed");

		auto begin_time = query.item_value(consts::BEGIN_TIME_ITEM);
		auto end_time = query.item_value(consts::END_TIME_ITEM);

		if (auto keys_item = query.item_value(consts::KEYS_ITEM)) {
			std::vector<std::string> keys;
			boost::split(keys, *keys_item, boost::is_any_of(":"));
			server()
			->get_provider()
			->get_user_logs(*user_item,
			                keys,
			                std::bind(&on_get_user_logs::on_finished,
			                          shared_from_this(),
			                          std::placeholders::_1));
		} else if(begin_time && end_time) {
			server()
			->get_provider()
			->get_user_logs(*user_item,
			                boost::lexical_cast<uint64_t>(*begin_time),
			                boost::lexical_cast<uint64_t>(*end_time),
			                std::bind(&on_get_user_logs::on_finished,
			                          shared_from_this(),
			                          std::placeholders::_1));
		}
		else
			throw std::invalid_argument("something is missed");

	}
	catch(ioremap::elliptics::error& e) {
		get_reply()->send_error(ioremap::swarm::http_response::internal_server_error);
	}
	catch(...) {
		get_reply()->send_error(ioremap::swarm::http_response::bad_request);
	}
}
Esempio n. 19
0
File: mccli.c Progetto: eJon/common
int mc_store(mcContext *c, const item_data *item, int need_response, const char *store_type) {
  int ret;
  char cmd[512] = {'\0'};
  u_char *data = item->_buffer ;
  size_t data_len = item->_size;

  if ((data_len > MCCLI_MAX_VALUESIZE) || (data_len <= 0)) {
    //value size overflowing
    return MEM_SYSTEM_ERROR;
  }
  //socket send/recv failed count over, reconnect
  if (c->maxsrtimes <= c->srtimes) {
    if (MCCLI_OK != mc_reconnect(c)) {
      //socket reconnect failed count over
      if (c->maxrctimes <= c->rctimes) {
        if (MCCLI_OK != changetoslv(c)) {
          //change mc-server failed, continue connect to old server
          return MEM_SYSTEM_ERROR;
        }
      }
    }
  }
  if (!(c->fd)) {
    return MEM_SYSTEM_ERROR;
  }

  if (need_response == 0) {
    sprintf(cmd, "%s %s %d %lu %lu noreply\r\n", store_type, item->_key, item->_flag, item->_expire, data_len);
  } else {
    sprintf(cmd, "%s %s %d %lu %lu\r\n", store_type, item->_key, item->_flag, item->_expire, data_len);
  }

  if (MCCLI_OK != senddata(c, cmd, (int)strlen(cmd))) {
    __mcErrorErrorno(c, "send cmd");
    return MEM_SYSTEM_ERROR;
  }

  if (MCCLI_OK != senddata(c, (char *)data, data_len)) {
    __mcErrorErrorno(c, "send datalen");
    return MEM_SYSTEM_ERROR;
  }

  if (MCCLI_OK != senddata(c, "\r\n", 2)) {
    __mcErrorErrorno(c, "send \\r\\n");
    return MEM_SYSTEM_ERROR;
  }

  if (need_response != 0) {
    ret = get_reply(c, 0);
  } else {
    ret = MEM_NO_RESPONSE;
  }

  return ret;
}
Esempio n. 20
0
File: setup.c Progetto: akat1/impala
/*
 * Determine the current and maximum operating levels of the terminal
 */
static void
find_levels(void)
{
  char *report;

  set_tty_raw(TRUE);
  set_tty_echo(FALSE);

  da();
  report = get_reply();
  if (!strcmp(report, "\033/Z")) {
    cur_level =
    max_level = 0; /* must be a VT52 */
  } else if ((report = skip_csi(report)) == 0
   || strncmp(report, "?6", 2)
   || !isdigit(report[2])
   || report[3] != ';') {
    cur_level =
    max_level = 1; /* must be a VT100 */
  } else { /* "CSI ? 6 x ; ..." */
    cur_level =
    max_level = report[2] - '0'; /* VT220=2, VT320=3, VT420=4 */
    if (max_level >= 4) {
      decrqss("\"p");
      report = get_reply();
      if ((report = skip_dcs(report)) != 0
       && isdigit(*report++) /* 0 or 1 (by observation, though 1 is an err) */
       && *report++ == '$'
       && *report++ == 'r'
       && *report++ == '6'
       && isdigit(*report))
          cur_level = *report - '0';
    }
  }

  if (LOG_ENABLED) {
    fprintf(log_fp, "Max Operating Level: %d\n", max_level);
    fprintf(log_fp, "Cur Operating Level: %d\n", cur_level);
  }

  restore_ttymodes();
}
Esempio n. 21
0
int update_tilt_state_alt(freenect_device *dev)
{
	freenect_context *ctx = dev->parent;

	if (dev->usb_audio.dev == NULL)
	{
		FN_WARNING("Motor control failed: audio device missing");
		return -1;
	}

	int transferred = 0;
	int res = 0;
	fn_alt_motor_command cmd;
	cmd.magic = fn_le32(0x06022009);
	cmd.tag = fn_le32(tag_seq++);
	cmd.arg1 = fn_le32(0x68); // 104.  Incidentally, the number of bytes that we expect in the reply.
	cmd.cmd = fn_le32(0x8032);
    
	unsigned char buffer[256];
	memcpy(buffer, &cmd, 16);
    
	res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 16, &transferred, 250);
	if (res != 0)
	{
		return res;
	}
    
	res = libusb_bulk_transfer(dev->usb_audio.dev, 0x81, buffer, 256, &transferred, 250); // 104 bytes
	if (res != 0)
	{
		return res;
	}

	struct {
		int32_t x;
		int32_t y;
		int32_t z;
		int32_t tilt;
	} accel_and_tilt;

	memcpy(&accel_and_tilt, buffer + 16, sizeof(accel_and_tilt));
	FN_SPEW("Accelerometer state: X == %d \t Y == %d \t Z == %d \t Tilt == %d\n", accel_and_tilt.x, accel_and_tilt.y, accel_and_tilt.z, accel_and_tilt.tilt);

	dev->raw_state.accelerometer_x  = (int16_t)accel_and_tilt.x;
	dev->raw_state.accelerometer_y  = (int16_t)accel_and_tilt.y;
	dev->raw_state.accelerometer_z  = (int16_t)accel_and_tilt.z;

	// this is multiplied by 2 as the older 1414 device reports angles doubled and freenect takes this into account
	dev->raw_state.tilt_angle       = (int8_t)accel_and_tilt.tilt * 2;

	// Reply: skip four uint32_t, then you have three int32_t that give you acceleration in that direction, it seems.
	// Units still to be worked out.
	return get_reply(dev->usb_audio.dev, ctx);
}
Esempio n. 22
0
int main(int argc, char *argv[])
{ 
   xbuf_xcat(get_reply(argv), 
             "<br>"
             "<b>Servlet name</b>:<br>'%s'<br><br>"
             "<b>Client address</b>:<br>'%s'<br>",
             argv[-2],
             argv[-1]);

   return 200;
}
Esempio n. 23
0
/*############################# pop3_user() #############################*/
int
pop3_user(char *user)
{
   int reply;

   if ((reply = command(pop3_fd, "USER %s", user)) == SUCCESS)
   {
      reply = get_reply();
   }

   return(reply);
}
Esempio n. 24
0
/*############################# pop3_pass() #############################*/
int
pop3_pass(char *password)
{
   int reply;

   if ((reply = command(pop3_fd, "PASS %s", password)) == SUCCESS)
   {
      reply = get_reply();
   }

   return(reply);
}
Esempio n. 25
0
/*############################# pop3_dele() #############################*/
int
pop3_dele(unsigned int msg_number)
{
   int reply;

   if ((reply = command(pop3_fd, "DELE %u", msg_number)) == SUCCESS)
   {
      reply = get_reply();
   }

   return(reply);
}
Esempio n. 26
0
File: hellox.c Progetto: psfu/ULib
int main(int argc, char* argv[])
{
   unsigned char encoded[1024];

   char* reply = get_reply();

   (void) u_xml_encode(argv[1], strlen(argv[1]), encoded);

   (void) u__snprintf(reply, get_reply_capacity(), U_CONSTANT_TO_PARAM("<h1>Hello %s</h1>"), encoded);

   return 200;
}
Esempio n. 27
0
int update_tilt_state_alt(freenect_device *dev){
	freenect_context *ctx = dev->parent;

	int transferred = 0;
	int res = 0;
	fn_alt_motor_command cmd;
	cmd.magic = fn_le32(0x06022009);
	cmd.tag = fn_le32(tag_seq++);
	cmd.arg1 = fn_le32(0x68); // 104.  Incidentally, the number of bytes that we expect in the reply.
	cmd.cmd = fn_le32(0x8032);
    
	unsigned char buffer[256];
	memcpy(buffer, &cmd, 16);
    
	res = libusb_bulk_transfer(dev->usb_audio.dev, 0x01, buffer, 16, &transferred, 250);
	if (res != 0) {
		return res;
	}
    
	res = libusb_bulk_transfer(dev->usb_audio.dev, 0x81, buffer, 256, &transferred, 250); // 104 bytes
	if (res != 0) {
		return res;
	} else {
//		int i;
//		for(i = 0 ; i < transferred ; i += 4) {
//			int32_t j;
//			memcpy(&j, buffer + i, 4);
//			printf("\t%d\n", j);
//		}
//		printf("\n");
		struct {
			int32_t x;
			int32_t y;
			int32_t z;
            int32_t tilt;
		} accel_and_tilt;
        
		memcpy(&accel_and_tilt, buffer + 16, sizeof(accel_and_tilt));
		//printf("\tX: %d  Y: %d  Z:%d - tilt is %d\n", accel_and_tilt.x, accel_and_tilt.y, accel_and_tilt.z, accel_and_tilt.tilt);
        
    	dev->raw_state.accelerometer_x  = (int16_t)accel_and_tilt.x;
        dev->raw_state.accelerometer_y  = (int16_t)accel_and_tilt.y;
        dev->raw_state.accelerometer_z  = (int16_t)accel_and_tilt.z;
        
        //this is multiplied by 2 as the older 1414 device reports angles doubled and freenect takes this into account
        dev->raw_state.tilt_angle       = (int8_t)accel_and_tilt.tilt * 2;

	}
	// Reply: skip four uint32_t, then you have three int32_t that give you acceleration in that direction, it seems.
	// Units still to be worked out.
	return get_reply(dev->usb_audio.dev, ctx);
}
void
print_reply(const char *ifname, int count)
{
   unsigned char buf[512];
   size_t len;

   while(1) {
      len = sizeof(buf);
      if(get_reply(ifname, 5, buf, &len) == -1)
         break;
      print_console(buf, len);
   }
}
Esempio n. 29
0
void on_add_activity::on_request(const ioremap::swarm::http_request &req,
                                 const boost::asio::const_buffer &buffer)
{
	try {
		std::string request(boost::asio::buffer_cast<const char*>(buffer),
		                    boost::asio::buffer_size(buffer));
		ioremap::swarm::url_query query(request);

		auto user_item = query.item_value(consts::USER_ITEM);
		if (!user_item)
			throw std::invalid_argument("user is missed");

		if (auto key_item = query.item_value(consts::KEY_ITEM)) {
			server()
				->get_provider()
				->add_activity(*user_item,
				               *key_item,
				               std::bind(&on_add_activity::on_finished,
				                         shared_from_this(),
				                         std::placeholders::_1));
		} else if(auto time_item = query.item_value(consts::TIME_ITEM)) {
			server()
			->get_provider()
			->add_activity(*user_item,
			               boost::lexical_cast<uint64_t>(*time_item),
			               std::bind(&on_add_activity::on_finished,
			                         shared_from_this(),
			                         std::placeholders::_1));
		}
		else
			throw std::invalid_argument("key and time are missed");
	}
	catch(ioremap::elliptics::error& e) {
		get_reply()->send_error(ioremap::swarm::http_response::internal_server_error);
	}
	catch(...) {
		get_reply()->send_error(ioremap::swarm::http_response::bad_request);
	}
}
Esempio n. 30
0
int poll_status(libusb_device_handle* dev) {
	int transferred = 0;
	int res = 0;
	motor_command cmd;
	cmd.magic = le32(0x06022009);
	cmd.tag = le32(tag_seq++);
	cmd.arg1 = le32(0x68); // 104.  Incidentally, the number of bytes that we expect in the reply.
	cmd.cmd = le32(0x8032);
	unsigned char buffer[256];
	memcpy(buffer, &cmd, 16);
	// Send command to set LED to solid green
	LOG("About to send bulk transfer:");
	int i;
	for(i = 0; i < 16 ; i++) {
		LOG(" %02X", buffer[i]);
	}
	LOG("\n");
	res = libusb_bulk_transfer(dev, 0x01, buffer, 16, &transferred, 0);
	if (res != 0) {
		LOG("set_led(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
		return res;
	}

	res = libusb_bulk_transfer(dev, 0x81, buffer, 256, &transferred, 0); // 104 bytes
	if (res != 0) {
		LOG("set_led(): libusb_bulk_transfer failed: %d (transferred = %d)\n", res, transferred);
		return res;
	} else {
		LOG("poll_status():");
		int i;
		for(i = 0 ; i < transferred ; i += 4) {
			int32_t j;
			memcpy(&j, buffer + i, 4);
			LOG("\t%d", j);
		}
		LOG("\n");
		struct {
			int32_t x;
			int32_t y;
			int32_t z;
		} accel;
		memcpy(&accel, buffer + 16, sizeof(accel));
		LOG("X: %d\tY: %d\tZ:%d\n", accel.x, accel.y, accel.z);
	}
	// Reply: skip four uint32_t, then you have three int32_t that give you acceleration in that direction, it seems.
	// Units still to be worked out.
	return get_reply(dev);
}