Beispiel #1
0
void menu_select_callback(MenuLayer *me, MenuIndex *cell_index, void *data) {
	if (current_level == 0 && feed_count == 0) return;
	if (current_level == 1 && item_count == 0) return;
	push_new_level();
	switch (current_level) {
		case 1:
			item_receive_idx = 0; item_count = 0;
			request_command(1091, cell_index->row);
			break;
		case 2:
			selected_item_id = cell_index->row;
			request_command(1092, selected_item_id);
			break;
	}
}
void M3LedX2XNEcShm::SetCommandFromSds(unsigned char * data)
{
  
  M3LedX2XNEcShmSdsCommand * sds = (M3LedX2XNEcShmSdsCommand *) data;
    request_command();
   memcpy(&command_from_sds, sds, GetCommandSdsSize()); 
    release_command();    
    
    int64_t dt = GetBaseStatus()->timestamp()-command_from_sds.timestamp; // microseconds
    bool shm_timeout = ABS(dt) > (timeout*1000);    

/*	if (tmp_cnt++ == 200)
	{
		M3_DEBUG("hi\n");
		tmp_cnt = 0;
	
	}*/

       
  if (led_x2xn != NULL)
  {
    if (shm_timeout)
    {
/*	if (tmp_cnt++ == 200)
	{
		M3_DEBUG("hi\n");
		tmp_cnt = 0;
	
	}*/

      ((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->set_enable_a(0);
      ((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->set_enable_b(0);            
    } else {
/*	if (tmp_cnt++ == 200)
	{
		M3_DEBUG("here\n");
		tmp_cnt = 0;
	
	}*/
	((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->set_enable_a(command_from_sds.enable_a);
        ((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->set_enable_b(command_from_sds.enable_b);  
	for (int i = 0; i < NUM_PER_BRANCH; i++)
	{	  
		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_a()->set_r(i,command_from_sds.r_a[i]);
		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_a()->set_g(i,command_from_sds.g_a[i]);
		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_a()->set_b(i,command_from_sds.b_a[i]);

		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_b()->set_r(i,command_from_sds.r_b[i]);
		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_b()->set_g(i,command_from_sds.g_b[i]);
		((M3LedX2XNEcCommand*)led_x2xn->GetCommand())->mutable_branch_b()->set_b(i,command_from_sds.b_b[i]);
	}

    }
  }
    
}
void M3TorqueShm::SetCommandFromSds(unsigned char * data)
{
  M3TorqueShmSdsCommand * sds = (M3TorqueShmSdsCommand *) data;
    request_command();
   memcpy(&command_from_sds, sds, GetCommandSdsSize()); 
    release_command();
       
    command.set_timestamp(command_from_sds.timestamp);
    
    int64_t dt = GetBaseStatus()->timestamp()-command.timestamp(); // microseconds
    bool shm_timeout = ABS(dt) > (timeout*1000);    
       
  for (int i = 0; i < bot->GetNdof(RIGHT_ARM); i++)
  { 
    command.mutable_right_arm()->set_tq_desired(i, command_from_sds.right_arm.tq_desired[i]);
    if (shm_timeout)
    {      
      bot->DisableTorqueShmRightArm();
    } else{
      bot->EnableTorqueShmRightArm();
      bot->SetTorqueSharedMem_mNm(RIGHT_ARM, i, command.right_arm().tq_desired(i));
    }
  }
  for (int i = 0; i < bot->GetNdof(LEFT_ARM); i++)
  { 
    command.mutable_left_arm()->set_tq_desired(i, command_from_sds.left_arm.tq_desired[i]);
    if (shm_timeout)
    {
      bot->DisableTorqueShmLeftArm();  
    } else{
      bot->EnableTorqueShmLeftArm();
      bot->SetTorqueSharedMem_mNm(LEFT_ARM, i, command.left_arm().tq_desired(i));    
    }
  }
  for (int i = 0; i < bot->GetNdof(TORSO); i++)
  { 
    command.mutable_torso()->set_tq_desired(i, command_from_sds.torso.tq_desired[i]);
    if (shm_timeout)
    {
      bot->DisableTorqueShmTorso();
    } else{
      bot->EnableTorqueShmTorso();
      bot->SetTorqueSharedMem_mNm(TORSO, i, command.torso().tq_desired(i));    
    }
  }
  
  
}
Beispiel #4
0
void handle_resend(void* data) {
	command_timer = NULL;
	request_command(current_slot, current_command);
}
Beispiel #5
0
void message_click(ClickRecognizerRef recognizer, void *context) {
	if (has_thumbnail && chunk_receive_idx == 0) {
		push_new_level();
		request_command(1094, selected_item_id);
	}
}
Beispiel #6
0
void item_long_click(ClickRecognizerRef recognizer, void *context) {
	if (chunk_receive_idx == 0)
		request_command(1093, selected_item_id);
}
Beispiel #7
0
/* void protocol1
 *   buffer* recv_buffer - buffer containing the message sent by the client to the proxy
 *   server_stat* status - status and general information from the server
 * Processes the recv_buf as the class protocol dictates
 */
void protocol1(buffer* recv_buf, server_stat* status){
    struct timeval timeout;
    struct timeval timeout_0;
    // timeouts
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    timeout_0.tv_sec = 0;
    timeout_0.tv_usec = 0;

    timeout_setup(status->udp_sock, timeout);

    // giant mess of conditionals
    fprintf(stdout, "\tversion 1 protocol\n");
    int error = 0;
    header msg_header = extract_header(recv_buf);
    if (status->connected == 0) {
        if (check_pass(&msg_header, 0)) {
            if (get_command(&msg_header) == CONNECT) {
                fprintf(stdout, "\tReplying with password\n");
                status->connected = 1;
                msg_header.data[1] = status->password;
                insert_header(recv_buf, msg_header);
                if (udp_send(recv_buf, status) < 0) {
                    fprintf(stderr, "sendto()\n");
                }
            } else {
                fprintf(stderr, "ERROR: Unexpected Command\n");
                error = -2;
            }
        } else {
            fprintf(stderr, "ERROR: Incorrect Password\n");
        }
    } else if (status->connected == 1) {
        if (check_pass(&msg_header, status->password)) {
            if (get_command(&msg_header) == CONNECT) {
                status->connected = 2;
                timeout_setup(status->udp_sock, timeout_0);
                fprintf(stdout, "\tConnected to a client\n");
            } else {
                fprintf(stderr, "ERROR: Unexpected Command\n");
                error = -2;
            }
        } else {
            fprintf(stderr, "ERROR: Incorrect Password\n");
            error = -2;
        }
    } else {
        if (!check_pass(&msg_header, status->password)) {
            fprintf(stderr, "ERROR: Incorrect Password\n");
                error = -2;
        } else {
            fprintf(stdout, "\t\tReceived Message:\n");
            print_header(recv_buf);
            switch (get_command(&msg_header)) {
                case CONNECT:
                    fprintf(stderr, "ERROR: Unexpected Command\n");
                error = -2;
                    break;
                case QUIT:
                    quit(recv_buf, status);
                    timeout_setup(status->udp_sock, timeout_0);
                    break;
                default:
                    error = request_command(recv_buf, status);
                    break;
            }
        }
    }
    if (error == -2) {
        fprintf(stderr, "ERROR: Invalid client request\n");
        send_error(status, CLIENT_ERROR);
    } else if (error == -1) {
        fprintf(stderr, "ERROR: Problem with http response\n");
        send_error(status, HTTP_ERROR);
    }
}
Beispiel #8
0
bool StarDictClient::parse(gchar *line)
{
    int result;
    if (waiting_banner_) {
        waiting_banner_ = false;
        result = parse_banner(line);
        g_free(line);
        if (!result)
            return false;
        request_command();
        return true;
    }
    STARDICT::Cmd* cmd = cmdlist.front();
    switch (cmd->command) {
        case STARDICT::CMD_CLIENT:
            result = parse_command_client(line);
            g_free(line);
            break;
        case STARDICT::CMD_AUTH:
            result = parse_command_auth(line);
            g_free(line);
            break;
        case STARDICT::CMD_REGISTER:
            result = parse_command_register(line);
            g_free(line);
            break;
        case STARDICT::CMD_GET_DICT_MASK:
            result = parse_command_getdictmask(cmd, line);
            break;
        case STARDICT::CMD_SET_DICT_MASK:
            result = parse_command_setdictmask(line);
            break;
        case STARDICT::CMD_DIR_INFO:
            result = parse_command_dirinfo(cmd, line);
            break;
        case STARDICT::CMD_DICT_INFO:
            result = parse_command_dictinfo(cmd, line);
            break;
        case STARDICT::CMD_MAX_DICT_COUNT:
            result = parse_command_maxdictcount(cmd, line);
            break;
        case STARDICT::CMD_DEFINE:
        case STARDICT::CMD_LOOKUP:
        case STARDICT::CMD_SELECT_QUERY:
        case STARDICT::CMD_SMART_QUERY:
            result = parse_dict_result(cmd, line);
            break;
        case STARDICT::CMD_PREVIOUS:
        case STARDICT::CMD_NEXT:
            result = parse_wordlist(cmd, line);
            break;
        case STARDICT::CMD_GET_ADINFO:
            result =  parse_command_getadinfo(cmd, line);
            break;
        case STARDICT::CMD_QUIT:
            result = parse_command_quit(line);
            g_free(line);
            break;
        default:
            result = 0;
            g_free(line);
            break;
    }
    if (result == 0)
        return false;
    if (result == 1) {
        delete cmd;
        cmdlist.pop_front();
        if (cmdlist.empty()) {
            cmdlist.push_back(new STARDICT::Cmd(STARDICT::CMD_QUIT));
        }
        request_command();
    }
    return true;
}
Beispiel #9
0
void handle_init(AppContextRef ctx) { 
  if (clock_is_24h_style()) {
    format_time = "%H:%M";
    format_date = "%d-%m-%Y";
  }
  else {
    format_time = "%I:%M";
    format_date = "%m/%d/%Y";
  }
  
  update_time();

  resource_init_current_app(&APP_RESOURCES);
  ubuntu_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_BOLD_50));
  ubuntu_date = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_16));
  ubuntu_text = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_10));

  window_init(&window, MY_NAME);
  window_stack_push(&window, true);

  text_layer_init(&layer_time, GRect(0, 20, 144, 54));
  text_layer_set_font(&layer_time, ubuntu_time);
  text_layer_set_text(&layer_time, (const char*)&string_time);
  text_layer_set_text_alignment(&layer_time, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(&window), &layer_time.layer);

  text_layer_init(&layer_date, GRect(0, 74, 144, 20));
  text_layer_set_font(&layer_date, ubuntu_date);
  text_layer_set_text(&layer_date, (const char*)&string_date);
  text_layer_set_text_alignment(&layer_date, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(&window), &layer_date.layer);
    
  bitmap_layer_init(&layer_battery, GRect(8, 140, 14, 8));
  bitmap_layer_set_bitmap(&layer_battery, &bitmap_battery.bmp);
  layer_add_child(window_get_root_layer(&window), &layer_battery.layer);

  bitmap_layer_init(&layer_signal, GRect(8, 150, 14, 8));
  bitmap_layer_set_bitmap(&layer_signal, &bitmap_signal.bmp);
  layer_add_child(window_get_root_layer(&window), &layer_signal.layer);
  
  bmp_init_container(RESOURCE_ID_PNG_CALL, &layer_call);
  layer_call.layer.layer.frame.origin.x = 142 - 8 - 9;
  layer_call.layer.layer.frame.origin.y = 140;
  layer_add_child(window_get_root_layer(&window), &layer_call.layer.layer);

  bmp_init_container(RESOURCE_ID_PNG_MESSAGE, &layer_message);
  layer_message.layer.layer.frame.origin.x = 142 - 8 - 9;
  layer_message.layer.layer.frame.origin.y = 150;
  layer_add_child(window_get_root_layer(&window), &layer_message.layer.layer);
  
  text_layer_init(&layer_numbercall, GRect(101, 138, 22, 10));
  text_layer_set_font(&layer_numbercall, ubuntu_text);
  text_layer_set_text(&layer_numbercall, (const char*)&string_call);
  text_layer_set_text_alignment(&layer_numbercall, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(&window), &layer_numbercall.layer);

  text_layer_init(&layer_numbermessage, GRect(101, 148, 22, 10));
  text_layer_set_font(&layer_numbermessage, ubuntu_text);
  text_layer_set_text(&layer_numbermessage, (const char*)&string_message);
  text_layer_set_text_alignment(&layer_numbermessage, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(&window), &layer_numbermessage.layer);  
  
  update_stats();
 
  request_command(REACTOR_COMMAND_REFRESH);
}