int main(void) { struct items { char *up; char *load; char *fan; char *temp; char *mem; char *swap; char *diskio; char *fs_root; char *fs_home; char *fs_storage; char *net_speed; char *batt; char *vol; char *time; char *status; }; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "dwmstatus: cannot open display.\n"); return 1; } struct items *i = malloc(sizeof(struct items)); while(1) { i->up = get_up(); i->load = get_load(); i->fan = get_fan(); i->temp = get_temp(); i->mem = get_mem(); i->swap = get_swap(); i->diskio = get_diskio("sda"); i->fs_root = get_space("/"); i->fs_home = get_space("/home"); i->net_speed = get_net_speed(); i->batt = get_batt(); i->vol = get_vol(); i->time = mktimes("%m/%d/%Y %a %H:%M", tzkiev); i->status = smprintf( "up:%s la:%s fan:%s temp:%s m:%s s:%s io:%s /:%s " "~/:%s net:%s bat:%s vol:%s %s", i->up, i->load, i->fan, i->temp, i->mem, i->swap, i->diskio, i->fs_root, i->fs_home, i->net_speed, i->batt, i->vol, i->time); setstatus(i->status); sleep(INTERVAL); } free(i); XCloseDisplay(dpy); return EXIT_SUCCESS; }
void bc_perspective_camera::get_extend_points(extend& p_points) const { auto l_fov_tan = 2 * std::tanf(m_field_of_view / 2); auto l_near_clip_height = l_fov_tan * get_near_clip(); auto l_near_clip_width = l_near_clip_height * m_aspect_ratio; auto l_far_clip_height = l_fov_tan * get_far_clip(); auto l_far_clip_width = l_far_clip_height * m_aspect_ratio; auto l_near_clip_center = get_position() + get_forward() * get_near_clip(); auto l_far_clip_center = get_position() + get_forward() * get_far_clip(); p_points[0] = l_near_clip_center + get_left() * (l_near_clip_width / 2) + get_down() * (l_near_clip_height / 2); p_points[1] = l_near_clip_center + get_left() * (l_near_clip_width / 2) + get_up() * (l_near_clip_height / 2); p_points[2] = l_near_clip_center + get_right() * (l_near_clip_width / 2) + get_up() * (l_near_clip_height / 2); p_points[3] = l_near_clip_center + get_right() * (l_near_clip_width / 2) + get_down() * (l_near_clip_height / 2); p_points[4] = l_far_clip_center + get_left() * (l_far_clip_width / 2) + get_down() * (l_far_clip_height / 2); p_points[5] = l_far_clip_center + get_left() * (l_far_clip_width / 2) + get_up() * (l_far_clip_height / 2); p_points[6] = l_far_clip_center + get_right() * (l_far_clip_width / 2) + get_up() * (l_far_clip_height / 2); p_points[7] = l_far_clip_center + get_right() * (l_far_clip_width / 2) + get_down() * (l_far_clip_height / 2); }
struct gmi_set* gmi_base_adjacent(struct gmi_model* m, struct gmi_ent* e, int dim) { int from_dim; struct agm_ent a; a = agm_from_gmi(e); from_dim = agm_dim_from_type(a.type); if (dim == from_dim - 1) return get_down(to_base(m)->topo, a); else if (dim == from_dim + 1) return get_up(to_base(m)->topo, a); gmi_fail("only one-level adjacencies supported"); return 0; }
glm::mat4 view_matrix(){ return glm::lookAt(get_position(), get_gaze(), get_up()); }
core::bc_vector3f bc_icamera::get_down() const noexcept { return get_up() * -1; }
void bc_free_camera::update(core_platform::bc_clock::update_param p_clock_update_param, const platform::bc_pointing_device& p_pointing_device, const platform::bc_key_device& p_key_device) { core::bc_vector3f l_position = get_position(); bcFLOAT l_move_speed = m_shift_pressed ? m_move_speed * 6 : m_ctrl_pressed ? m_move_speed * 0.25 : m_move_speed; bcFLOAT l_rotate_speed = m_rotate_speed; l_move_speed *= p_clock_update_param.m_elapsed_second; l_rotate_speed *= p_clock_update_param.m_elapsed_second; if (m_w_pressed) { l_position += get_forward() * l_move_speed; } if (m_s_pressed) { l_position += get_back() * l_move_speed; } if (m_a_pressed) { l_position += get_left() * l_move_speed; } if (m_d_pressed) { l_position += get_right() * l_move_speed; } if (m_e_pressed) { l_position += get_down() * l_move_speed; } if (m_q_pressed) { l_position += get_up() * l_move_speed; } core::bc_vector3f l_direction = get_direction(); if (m_rmb_pressed) { bcFLOAT l_pi = 3.14159265358979323846 / 2; auto l_dx = -m_dx * l_rotate_speed; auto l_dy = m_dy * l_rotate_speed; if (m_dy > l_pi) { m_dy = l_pi; } if (m_dy < -l_pi) { m_dy = -l_pi; } core::bc_matrix3f l_rotation_y; core::bc_matrix3f l_rotation_x; core::bc_matrix3f l_rotation; core::bc_vector3f l_right = get_right(); core::bc_vector3f l_up = get_up(); if(graphic::bc_render_api_info::is_left_handed()) { l_rotation_y.rotation_euler_lh(l_up, -l_dx); l_rotation_x.rotation_euler_lh(l_right, l_dy); } else { l_rotation_y.rotation_euler_rh(l_up, -l_dx); l_rotation_x.rotation_euler_rh(l_right, l_dy); } l_rotation = l_rotation_y * l_rotation_x; l_direction = l_rotation * l_direction; l_direction.normalize(); } auto l_lookat = l_position + l_direction; set_look_at(l_position, l_lookat, core::bc_vector3f(0, 1, 0)); m_dx = 0; m_dy = 0; }
void FlyingCamera::roll(GLfloat angle) { glm::fquat quaternion = create_quaternion(get_forward_dir(),angle); set_up(quaternion*get_up()); set_forward(quaternion * get_forward()); }
void FlyingCamera::pitch(GLfloat angle) { glm::fquat quaternion = create_quaternion(glm::cross(get_forward_dir(),get_up_dir()),angle); set_forward(quaternion*get_forward()); set_up(quaternion*get_up()); }
void mob_is_standing( CHAR_DATA * ch ) { short dir; CHAR_DATA *vch; CHAR_DATA *tch; list<CHAR_DATA *>::iterator li; bool ready = TRUE; bool prey_still_exist = FALSE; int number_got_up = 0; int number_of_group = 1; int number_of_other_group = 1; /* * get a light source */ if ( ch->in_room->light <= 0 ) { if ( ch->mana >= mana_cost( ch, skill_lookup( "continual light" ) ) ) { do_cast( ch, "'continual light'" ); do_get( ch, "all" ); do_wear( ch, "all" ); return; } } if ( ( IS_AFFECTED( ch, AFF_POISON ) ) || ( IS_AFFECTED( ch, AFF_BLIND ) ) ) { if ( IS_AFFECTED( ch, AFF_POISON ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure poison" ) ) ) do_cast( ch, "'cure poison'" ); if ( IS_AFFECTED( ch, AFF_BLIND ) ) if ( ch->mana >= mana_cost( ch, skill_lookup( "cure blindness" ) ) ) do_cast( ch, "'cure blindness'" ); return; } /* * is anyone in group being attacked? if so, assist! */ /* * -leaders will be forced to rescue in the 'mob_is_fighting' function * * already so no need to check for it here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( ch, vch ) ) && ( vch->fighting != NULL ) && ( vch != ch ) ) { do_assist( ch, "" ); return; } } if ( ch->leader == NULL ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( is_same_group( ch, vch ) && ( ch != vch ) ) { number_of_group = number_of_group + 1; } } if ( number_of_group < 4 ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( vch->leader != NULL ) continue; if ( ( vch != ch ) && ( IS_NPC( vch ) ) && ( AI_MOB(vch) ) && ( !is_same_group( ch, vch ) ) && ( vch->position == POS_STANDING ) && ( ( vch->get_level("psuedo") - ch->get_level("psuedo") <= 20 && vch->get_level("psuedo") - ch->get_level("psuedo") >= -20 ) || ( ch->get_level("psuedo") - vch->get_level("psuedo") <= 20 && ch->get_level("psuedo") - vch->get_level("psuedo") >= -20 ) ) && ( can_see( vch, ch ) ) && ( can_see( ch, vch ) ) ) { if ( vch->leader == NULL ) { for ( tch = vch->in_room->first_person; tch != NULL; tch = tch->next_in_room ) { if ( is_same_group( tch, vch ) && ( tch != vch ) ) { number_of_other_group = number_of_other_group + 1; } } } if ( number_of_group + number_of_other_group <= 4 ) { get_mob_group( ch, vch ); return; } } } } } /* * do you need to heal? */ if ( ch->hit < ch->max_hit * 85 / 100 ) { if ( ( ch->mana >= mana_cost( ch, skill_lookup( "heal" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure critical" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure serious" ) ) ) ) mob_regen_check( ch, NULL, FALSE ); /* * if leader is ready to move, just keep standing */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->leader->position == POS_STANDING ) && ( ch->leader->mana >= ch->leader->max_mana * 85 / 100 ) && ( ch->leader->hit >= ch->leader->max_hit * 85 / 100 ) ) return; else { if ( ch->mana >= ch->max_mana * 75 / 100 ) ready = ready_heal_room( ch ); if ( ready == TRUE ) do_sleep( ch, "" ); return; } } if ( ch->mana < ch->max_mana * 85 / 100 ) { do_sleep( ch, "" ); return; } /* * do you need to level? if you have a group leader, have the leader * * find a the trainer. if you are the leader just go and find the * * trainer */ // ZEN FIX Have them recall then hunt the room if ( able_to_level( ch ) ) { char_from_room( ch ); char_to_room( ch, get_room_index( 3758 ) ); gain_level( ch ); return; /* dir = h_find_dir ( get_room_index(ch->in_room->vnum), get_room_index(ROOM_VNUM_INT_HEAL), ch->hunt_flags ); if ( dir == -1 ) gain_level ( ch ); else { if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) ) { hunt_move ( ch->leader, dir ); end_hunt ( ch->leader ); return; } else { hunt_move ( ch, dir ); return; } } */ } /* * if you're leader and you don't need to gain level, does anyone else * * in the group? */ /* * actually, the above function will force the leader to find a trainer * * already. but since i don't want the leader to select a new target * * until the group gains the needed level, i'll put this check here */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( vch, ch ) ) && ( vch->in_room == ch->in_room ) && ( vch->leader == ch ) && ( able_to_level( vch ) ) ) { dir = h_find_dir( get_room_index( ch->in_room->vnum ), get_room_index( ROOM_VNUM_INT_HEAL ), ch->hunt_flags ); hunt_move( ch, dir ); return; } } /* * if noone needs to heal or gain level, then let's hunt! */ /* * by the way, only leaders will hunt. followers will just follow and * * assist when needed */ if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting != NULL ) ) { end_hunt( ch ); } else if ( ( ch->leader != NULL ) && ( ch->leader->in_room == ch->in_room ) && ( ch->hunting == NULL ) ) { return; } else if ( is_group_leader( ch ) ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( vch != ch ) && ( is_same_group( vch, ch ) ) && ( vch->position != POS_STANDING ) ) { get_up( vch, vch->position ); number_got_up = number_got_up + 1; } } if ( number_got_up != 0 ) return; } else { if ( ch->hunting != NULL ) { for ( li = char_list.begin(); li != char_list.end(); li++ ) { vch = *li; if ( vch == ch->hunting ) { prey_still_exist = TRUE; return; } } if ( prey_still_exist == FALSE ) { ch->hunting = NULL; } } if ( ch->hunting == NULL && ch->leader == NULL ) { select_target( ch ); return; } } /* * power_up_mob ( ch ); */ /* * if ( ch->leader != NULL * && ch->in_room != ch->leader->in_room ) * { * do_follow( ch, ch->name ); * } */ return; }
/* checks to see if mob needs to stand up for any reason, if so then stand. */ void need_to_stand( CHAR_DATA * ch ) { int current_state; CHAR_DATA *vch; current_state = ch->position; /* * if someone in your group is fighting, get up */ for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( is_same_group( ch, vch ) ) && ( vch->position == POS_FIGHTING ) ) { get_up( ch, current_state ); return; } } /* * if your leader is up and ready to move, get up */ if ( ( ch->leader != NULL ) && ( ch->in_room == ch->leader->in_room ) && ( ch->leader->position == POS_STANDING ) && ( ch->leader->hit >= ch->leader->max_hit * 85 / 100 ) && ( ch->leader->mana >= ch->leader->max_mana * 85 / 100 ) ) { get_up( ch, current_state ); return; } /* * Do you need heal? if so, can you heal? */ if ( ch->hit < ch->max_hit * 85 / 100 ) { if ( ( ch->mana >= mana_cost( ch, skill_lookup( "heal" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure critical" ) ) ) || ( ch->mana >= mana_cost( ch, skill_lookup( "cure serious" ) ) ) ) { get_up( ch, current_state ); return; } } /* * if there is an int mob in the room stand so that you can group with * * it */ if ( ch->leader == NULL ) { for ( vch = ch->in_room->first_person; vch != NULL; vch = vch->next_in_room ) { if ( ( AI_MOB( vch ) ) && ( vch->leader == NULL ) && ( !is_same_group( vch, ch ) ) && ( AI_MOB(vch) ) && ( vch != ch ) && ( ( vch->get_level("psuedo") - ch->get_level("psuedo") <= 20 ) && ( vch->get_level("psuedo") - ch->get_level("psuedo") >= -20 ) ) ) { get_up( ch, current_state ); return; } } } /* * if you're ready to move, stand */ if ( ( ch->hit >= ch->max_hit * 85 / 100 ) && ( ch->mana >= ch->max_mana * 85 / 100 ) ) get_up( ch, current_state ); return; }
void Camera::adjust_yaw(const float &theta) { orientation = Quaternion::Axis_Angle(get_up(), theta) * orientation; }
int main(void) { /* USER CODE BEGIN 1 */ // create pointer to MX_SPI_Init() function in order to use it in utility functions MX_SPI1_Init_Pointer = &MX_SPI1_Init; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); //MX_SPI1_Init(); MX_TIM16_Init(); MX_TIM17_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_WWDG_Init(); /* USER CODE BEGIN 2 */ // delete MX_SPI1_Init(); up there after regenerating code with mx cube //================================================================================= /// some basic setups //================================================================================= // input is up // output is down uart_queue_initialize(&uart_input_queue); uart_queue_initialize(&uart_output_queue); uart_queue_initialize(&uart_command_queue); // load setup_data from flash to struct: config_data_flash_struct setup_data; get_from_Flash(); LED_init(); if(setup_data.initied_0xAA!=0xAA) { reset_joint(); } part_init(); /// FIND DIRECTION = WAIT FOR FIRST 'R' DIRECTION_SET = 0; PROGRAMM_SENSOR = 0; SET_FLASH = 0; UP_STATE = IDLE; DOWN_STATE = IDLE; // init some huart stuff huart_DOWN = &huart1; huart_UP = &huart2; uint16_t si = 0; data_mode = 0; HAL_StatusTypeDef status; // create empty messages Line empty_command_line; empty_command_line.text[0] = empty; for(si=1; si < DOWN_MESSAGE_LENGTH-1; si++) { empty_command_line.text[si] = si; } empty_command_line.text[DOWN_MESSAGE_LENGTH-1] = ComputeCRCN(empty_command_line.text, DOWN_MESSAGE_LENGTH-1); empty_command_line.length = DOWN_MESSAGE_LENGTH; Line empty_up_line; empty_up_line.text[0] = empty; for(si=1; si < UP_MESSAGE_LENGTH-1; si++) { empty_up_line.text[si] = si; } empty_up_line.text[UP_MESSAGE_LENGTH-1] = ComputeCRCN(empty_up_line.text, UP_MESSAGE_LENGTH-1); empty_up_line.length = UP_MESSAGE_LENGTH; // start timer HAL_TIM_Base_Start(&htim16); HAL_TIM_Base_Start(&htim17); // send some initial init messages uart_queue_push_line(&uart_input_queue, &init_message_line); if(is_splitter(setup_data.type)) { for(si = 0; si < 8; si++) { if(setup_data.splitter_outputs[si]==1) { uart_queue_push_line(&uart_input_queue, &splitter_message_lines[si]); skc[si] = 1; } } } int redled_timeout_timer = __HAL_TIM_GetCounter(&htim16); int init_timout_timer = __HAL_TIM_GetCounter(&htim16); interrupt_up_timeout_time = __HAL_TIM_GetCounter(&htim16); interrupt_down_timeout_time = __HAL_TIM_GetCounter(&htim16); int new_sensor_timer = __HAL_TIM_GetCounter(&htim16); int up_timeout_timer = __HAL_TIM_GetCounter(&htim16); int kids_timer[] = {-1,-1,-1,-1,-1,-1,-1,-1}; transmittedUP=0; receivedUP=0; transmittedDOWN=0; receivedDOWN=0; uint8_t TIMEDOUT = 0; update_sensor_messages(); HAL_HalfDuplex_EnableTransmitterReceiver(huart_DOWN); HAL_HalfDuplex_EnableTransmitterReceiver(huart_UP); HAL_UART_Receive_DMA(huart_UP, up_buffer, DOWN_MESSAGE_LENGTH + 1); HAL_UART_Receive_DMA(huart_DOWN, down_buffer, DOWN_MESSAGE_LENGTH + 1); led_set(1, 1, 0); //while(1); //if(is_splitter(setup_data.type)) HAL_WWDG_Start(&hwwdg); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ get_up_time = __HAL_TIM_GetCounter(&htim16); uint8_t WDGO = 0; uint8_t WDSET = 0; while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ // if((WD_UP && WD_DOWN) || DIRECTION_SET==0) // { // WD_UP = 0; // WD_DOWN = 0; // // for up and dwn we have own flags // // HAL_WWDG_Refresh(&hwwdg, 127); // } if(DIRECTION_SET && WDSET==0) { HAL_WWDG_Start(&hwwdg); WDSET = 1; up_timeout_timer = __HAL_TIM_GetCounter(&htim16); } if(WDGO==0 || is_splitter(setup_data.type)==0) { HAL_WWDG_Refresh(&hwwdg, 127); } // if there was no poll from above a certain time = reset! if(__HAL_TIM_GetCounter(&htim16) - interrupt_up_timeout_time > 250) { WDGO = 1; get_up(1); interrupt_up_timeout_time = __HAL_TIM_GetCounter(&htim16); UP_STATE = IDLE; } // if there was no interrupt call for data from below if(__HAL_TIM_GetCounter(&htim16) - interrupt_down_timeout_time > 250) { WDGO = 1; HAL_UART_DMAStop(huart_DOWN); HAL_UART_DMAResume(huart_DOWN); if(!DIRECTION_SET) { HAL_HalfDuplex_EnableTransmitterReceiver(huart_DOWN); HAL_UART_Receive_DMA(huart_DOWN, down_buffer, DOWN_MESSAGE_LENGTH + 1); } interrupt_down_timeout_time = __HAL_TIM_GetCounter(&htim16); DOWN_STATE = IDLE; } // wait for directions to be set if(!DIRECTION_SET) { led_set(8, 1, 8); continue; } led_set(8, 0, 8); if(__HAL_TIM_GetCounter(&htim16) - get_up_time > 20 && receivedUP == 0) { get_up(0); } // red blinking led if(__HAL_TIM_GetCounter(&htim16) - redled_timeout_timer > 250) { HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); redled_timeout_timer = __HAL_TIM_GetCounter(&htim16); } if(__HAL_TIM_GetCounter(&htim16) - up_timeout_timer > 500) { WDGO = 1; } // sent init messages if(__HAL_TIM_GetCounter(&htim16) - init_timout_timer > 1000) { uart_queue_replace_push_line(&uart_input_queue, &init_message_line, setup_data.id); if(is_splitter(setup_data.type)) { for(si = 0; si < 8; si++) { if(setup_data.splitter_outputs[si]==1) { uart_queue_push_line(&uart_input_queue, &splitter_message_lines[si]); } } } init_timout_timer = __HAL_TIM_GetCounter(&htim16); } if(SET_FLASH && UP_STATE == IDLE && DOWN_STATE == IDLE) { HAL_HalfDuplex_EnableTransmitter(huart_UP); set_in_Flash(&setup_data); SET_FLASH = 0; get_up(1); } if(PROGRAMM_SENSOR && UP_STATE == IDLE && DOWN_STATE == IDLE) { HAL_HalfDuplex_EnableTransmitter(huart_UP); if(setup_data.hardware == 2) init_2D(hspi1, GPIOA, GPIO_PIN_3); else init_2D(hspi1, GPIOB, GPIO_PIN_1); PROGRAMM_SENSOR = 0; get_up(1); } /// UP_STATE_MACHINE switch(UP_STATE) { case IDLE: if(SET_FLASH || PROGRAMM_SENSOR) { UP_STATE = IDLE; break; } if(receivedUP) { receivedUP = 0; if(up_buffer[0] == poll_receive /*&& __HAL_TIM_GetCounter(&htim16) - receivedUPtime < 5*/) { if(UP_RESEND_MESSAGE==0) { //update_sensor_messages(); uint8_t n_up_messages = 0; while(uart_queue_is_empty(&uart_input_queue)==0 && (n_up_messages < UP_MESSAGES_MAX)) { uart_queue_pop_line(&uart_input_queue, &send_up_line); memcpy(&poll_up_buffer[n_up_messages*(UP_MESSAGE_LENGTH)], send_up_line.text, UP_MESSAGE_LENGTH); n_up_messages++; } while(n_up_messages < UP_MESSAGES_MAX) { memcpy(&poll_up_buffer[n_up_messages*(UP_MESSAGE_LENGTH)], empty_up_line.text, UP_MESSAGE_LENGTH); n_up_messages++; } poll_up_size = n_up_messages*UP_MESSAGE_LENGTH; } UP_RESEND_MESSAGE = 0; UP_STATE = SENDING; HAL_HalfDuplex_EnableTransmitter(huart_UP); HAL_UART_Transmit_DMA(huart_UP, poll_up_buffer, poll_up_size); int something_else = __HAL_TIM_GetCounter(&htim16); if(up_buffer[1]!=empty) { memcpy(command_in_line.text, &up_buffer[1], DOWN_MESSAGE_LENGTH); command_in_line.length = DOWN_MESSAGE_LENGTH; uint8_t checksum = ComputeCRCN(command_in_line.text, DOWN_MESSAGE_LENGTH-1); if(checksum == command_in_line.text[DOWN_MESSAGE_LENGTH-1]) { if(command_in_line.text[0] == poll_direct || getIDfromMessage(command_in_line.text)==setup_data.id) { uart_queue_push_line(&uart_command_queue, &command_in_line); if((command_in_line.text[0] == poll_send) && (setup_data.type==NODE_JOINT_TUT_TU)) uart_queue_push_line(&uart_output_queue, &command_in_line); } else if(getIDfromMessage(command_in_line.text)==BROADCAST_ID) { uart_queue_push_line(&uart_command_queue, &command_in_line); uart_queue_push_line(&uart_output_queue, &command_in_line); } else { uart_queue_push_line(&uart_output_queue, &command_in_line); } } } if(is_splitter(setup_data.type)) { /*__disable_irq(); delayUS(10000); __enable_irq();*/ } else { update_sensor_messages(); } up_timeout_time = __HAL_TIM_GetCounter(&htim16); } else { //HAL_UART_DMAStop(huart_UP); //HAL_UART_DMAResume(huart_UP); // HAL_UART_Receive(huart_UP, &up_buffer[1], DOWN_MESSAGE_LENGTH, 2); get_up(1); } } break; case SENDING: if(transmittedUP) { UP_STATE = END; transmittedUP = 0; } else if(__HAL_TIM_GetCounter(&htim16) - up_timeout_time > 10) { HAL_UART_DMAStop(huart_UP); HAL_UART_DMAResume(huart_UP); UP_STATE = END; } break; case END: WD_UP = 1; up_timeout_timer = __HAL_TIM_GetCounter(&htim16); // work on commands UP_STATE = IDLE; get_up(1); break; } uint8_t s=0; switch(DOWN_STATE) { case DELAY: if(is_splitter(setup_data.type) || (__HAL_TIM_GetCounter(&htim16) - down_timeout_time > 7) /* && TIMEDOUT==0 */) DOWN_STATE = IDLE; /*else if (__HAL_TIM_GetCounter(&htim16) - down_timeout_time > 5) DOWN_STATE = IDLE;*/ break; case IDLE: // do nothing if(SET_FLASH || PROGRAMM_SENSOR) { DOWN_STATE = IDLE; break; } if(is_splitter(setup_data.type)) { if(splitter_kids_counter[i_p_splitter] > 10) { splitter_kids_counter[i_p_splitter] = 9; kids_timer[i_p_splitter] = __HAL_TIM_GetCounter(&htim16) + 200; } if(kids_timer[i_p_splitter]!=-1 && kids_timer[i_p_splitter] > __HAL_TIM_GetCounter(&htim16)) { interrupt_down_timeout_time = __HAL_TIM_GetCounter(&htim16); DOWN_STATE = END; break; } if(skc[i_p_splitter] == 0) { send_down_line = send_down_line_now; } else { send_down_line = empty_command_line; } } if(skc[0]+skc[1]+skc[2]+skc[3]+skc[4]+skc[5]+skc[6]+skc[7] >= n_splitter) { if(uart_queue_is_empty(&uart_output_queue)==0) { uart_queue_pop_line(&uart_output_queue, &send_down_line_now); send_down_line = send_down_line_now; for(s=0; s<n_splitter; s++) skc[s] = 0; } else { send_down_line = empty_command_line; for(s=0; s<n_splitter; s++) skc[s] = 1; } } //send_down_line = empty_command_line; if(is_splitter(setup_data.type)) { MPX_UART_Open(i_p_splitter); } DOWN_STATE = RECEIVING; //__disable_irq(); HAL_HalfDuplex_EnableTransmitter(huart_DOWN); status = HAL_UART_Transmit(huart_DOWN, "R", 1, 3); status = HAL_UART_Transmit(huart_DOWN, send_down_line.text, DOWN_MESSAGE_LENGTH, 5); //__enable_irq(); // DMA Receive for 3 HAL_HalfDuplex_EnableTransmitterReceiver(huart_DOWN); HAL_UART_Receive_DMA(huart_DOWN, poll_down_buffer, UP_MESSAGE_LENGTH*UP_MESSAGES_MAX); down_timeout_time = __HAL_TIM_GetCounter(&htim16); break; case RECEIVING: if(receivedDOWN) { receivedDOWN = 0; splitter_kids_counter[i_p_splitter] = 0; skc[i_p_splitter] = 1; kids_timer[i_p_splitter] = -1; // no more transmitting checksum, only calculating uint8_t checksum = ComputeCRCN(&poll_down_buffer[poll_down_size-UP_MESSAGE_LENGTH], UP_MESSAGE_LENGTH-1); uint8_t i = 0; for(i=0; i<UP_MESSAGES_MAX; i++) { // check checksum if(1 /*checksum == poll_down_buffer[i*UP_MESSAGE_LENGTH-1]*/) { Line sensor_message_line; memcpy(sensor_message_line.text, &poll_down_buffer[i*UP_MESSAGE_LENGTH], UP_MESSAGE_LENGTH); sensor_message_line.length = UP_MESSAGE_LENGTH; if(sensor_message_line.text[0]==empty) break; // delete messages from T joint but the answer_data, there update angles[3] if(getIDfromMessage(sensor_message_line.text)==setup_data.id && setup_data.type == NODE_JOINT_TUT_TU && data_mode!=2) { if(sensor_message_line.text[0] == answer_data) angles[3] = ((sensor_message_line.text[15] << 8) & 0xFF00) + sensor_message_line.text[16]; } else // for the other kinds (splitter, init, data from other) replace them if already in queue, ack messages always add to queue { // if it's from own child, add own id if(sensor_message_line.text[5]==0) { sensor_message_line.text[5] = (setup_data.id >> 24) & 0xFF; sensor_message_line.text[6] = (setup_data.id >> 16) & 0xFF; sensor_message_line.text[7] = (setup_data.id >> 8) & 0xFF; sensor_message_line.text[8] = setup_data.id & 0xFF; // add splitter branch number if(is_splitter(setup_data.type)) sensor_message_line.text[5] |= ((i_p_splitter << 4) & 0xF0); } UpdateCRCLine(&sensor_message_line); if(sensor_message_line.text[0] == answer_ack || sensor_message_line.text[0] == splitter) uart_queue_push_line(&uart_input_queue, &sensor_message_line); else uart_queue_replace_push_line(&uart_input_queue, &sensor_message_line, getIDfromMessage(sensor_message_line.text)); } } } DOWN_STATE = END; TIMEDOUT = 0; } else if(__HAL_TIM_GetCounter(&htim16) - down_timeout_time > 13)