/** * @brief Display an NLM cowner * * @param[in/out] dspbuf display_buffer describing output string * @param[in] key The NLM owner * * @return the bytes remaining in the buffer. */ int display_nlm_owner(struct display_buffer *dspbuf, state_owner_t *owner) { int b_left; if (owner == NULL) return display_printf(dspbuf, "STATE_LOCK_OWNER_NLM <NULL>"); b_left = display_printf(dspbuf, "STATE_LOCK_OWNER_NLM %p: {", owner); if (b_left <= 0) return b_left; b_left = display_nlm_client(dspbuf, owner->so_owner.so_nlm_owner.so_client); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, "} oh="); if (b_left <= 0) return b_left; b_left = display_opaque_value(dspbuf, owner->so_owner_val, owner->so_owner_len); if (b_left <= 0) return b_left; return display_printf(dspbuf, " svid=%d refcount=%d", owner->so_owner.so_nlm_owner.so_nlm_svid, atomic_fetch_int32_t(&owner->so_refcount)); }
/** * @brief Display an NSM client * * @param[in/out] dspbuf display_buffer describing output string * @param[in] key The NSM client * * @return the bytes remaining in the buffer. */ int display_nsm_client(struct display_buffer *dspbuf, state_nsm_client_t *key) { int b_left; if (key == NULL) return display_printf(dspbuf, "NSM Client <NULL>"); b_left = display_printf(dspbuf, "NSM Client %p: ", key); if (b_left <= 0) return b_left; if (nfs_param.core_param.nsm_use_caller_name) b_left = display_printf(dspbuf, "caller_name="); else b_left = display_printf(dspbuf, "addr="); if (b_left <= 0) return b_left; b_left = display_len_cat(dspbuf, key->ssc_nlm_caller_name, key->ssc_nlm_caller_name_len); if (b_left <= 0) return b_left; return display_printf(dspbuf, " ssc_client=%p %s refcount=%d", key->ssc_client, atomic_fetch_int32_t(&key->ssc_monitored) ? "monitored" : "unmonitored", atomic_fetch_int32_t(&key->ssc_refcount)); }
int display_9p_owner(struct display_buffer *dspbuf, state_owner_t *owner) { int b_left; if (owner == NULL) return display_printf(dspbuf, "<NULL>"); b_left = display_printf(dspbuf, "STATE_LOCK_OWNER_9P %p", owner); if (b_left <= 0) return b_left; b_left = display_sockaddr(dspbuf, &owner->so_owner.so_9p_owner.client_addr); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, " proc_id=%u", owner->so_owner.so_9p_owner.proc_id); if (b_left <= 0) return b_left; return display_printf(dspbuf, " refcount=%d", atomic_fetch_int32_t(&owner->so_refcount)); }
/** * @brief Display an NLM client * * @param[in/out] dspbuf display_buffer describing output string * @param[in] key The NLM client * * @return the bytes remaining in the buffer. */ int display_nlm_client(struct display_buffer *dspbuf, state_nlm_client_t *key) { int b_left; if (key == NULL) return display_printf(dspbuf, "NLM Client <NULL>"); b_left = display_printf(dspbuf, "NLM Client %p: {", key); if (b_left <= 0) return b_left; b_left = display_nsm_client(dspbuf, key->slc_nsm_client); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, "} caller_name="); if (b_left <= 0) return b_left; b_left = display_len_cat(dspbuf, key->slc_nlm_caller_name, key->slc_nlm_caller_name_len); if (b_left <= 0) return b_left; return display_printf(dspbuf, " type=%s refcount=%d", xprt_type_to_str(key->slc_client_type), atomic_fetch_int32_t(&key->slc_refcount)); }
int check_stopping_event(int stopping_event) { if (stopping_event == STOP_BY_ET) { if (analog_et(ET_SENSOR) < 300) { return 1; } } else if (stopping_event == STOP_BY_TOPHAT) { display_printf(0, 0, "%4i", analog(L_TOPHAT)); if (analog(L_TOPHAT) > 750 || analog(R_TOPHAT) > 750) { return 1; } } else if (stopping_event == STOP_BY_CAMERA) { camera_update(); if (get_object_count(0) < 1) { display_printf(0, 0, "No Object Found"); return 0; } if (get_object_area(0, 0) > PINGPONG_THRESHOLD) { display_clear(); display_printf(0, 0, "Object Seen!"); if (get_object_center(0, 0).x > 90 && get_object_center(0, 0).x < 110) { display_printf(0, 1, "Object centered"); return 1; } } } else { printf("Stopping type is not defined!\n"); return -1; } return 0; }
/** * Zeigt die aktuelle Speicherbelegung an. * Achtung, die Stackgroesse bezieht sich auf den Stack *dieser* Funktion! * Die Heapgroesse stimmt nur, wenn es dort keine Luecken gibt (z.b. durch free()) */ void ram_display(void) { unsigned char * sp = (unsigned char *) SP; extern unsigned char __data_start; extern unsigned char __bss_start; extern unsigned char __heap_start; extern unsigned char * __brkval; #ifdef RC5_AVAILABLE #ifdef LOG_AVAILABLE extern unsigned char __data_end; extern unsigned char __bss_end; if (RC5_Code == RC5_CODE_1) { LOG_DEBUG("__data_start = 0x%04x", &__data_start); LOG_DEBUG("__data_end = 0x%04x", &__data_end); LOG_DEBUG("__bss_start = 0x%04x", &__bss_start); LOG_DEBUG("__bss_end = 0x%04x", &__bss_end); LOG_DEBUG("__heap_start = 0x%04x", &__heap_start); LOG_DEBUG("__heap_end = 0x%04x", __brkval); LOG_DEBUG("SP = 0x%04x", sp); LOG_DEBUG("RAMEND = 0x%04x", RAMEND); RC5_Code = 0; } #endif // RC5_AVAILABLE #endif // LOG_AVAILABLE size_t data_size = (size_t) (&__bss_start - &__data_start); size_t bss_size = (size_t) (&__heap_start - &__bss_start); display_cursor(1, 1); display_puts("bss/data:"); display_cursor(1, 10); display_printf("%5u/%5u", bss_size, data_size); display_cursor(2, 1); display_puts("heap:"); display_cursor(2, 16); size_t heap_size = __brkval == NULL ? 0 : (size_t) (__brkval - &__heap_start); display_printf("%5u", heap_size); display_cursor(3, 1); size_t ram_size = (size_t) ((unsigned char *) (RAMEND + 1) - &__data_start); size_t stack_size = (size_t) ((unsigned char *) RAMEND - sp); display_puts("stack:"); #ifdef OS_DEBUG size_t stack_size_max = ram_size - (os_stack_unused(__brkval + __malloc_margin) + data_size + bss_size + heap_size); display_cursor(3, 10); display_printf("%5u/%5u", stack_size, stack_size_max); #else display_cursor(3, 16); display_printf("%5u", stack_size); #endif // OS_DEBUG display_cursor(4, 1); size_t frei = ram_size - (data_size + bss_size + heap_size + stack_size); display_puts("free/ram:"); display_cursor(4, 10); display_printf("%5u/%5u", frei, ram_size); }
/** * Zeigt Informationen ueber Resets an */ void reset_info_display(void) { display_cursor(1, 1); display_printf("#Resets:%3u | (C)SR:", ctbot_eeprom_read_byte(&resetsEEPROM)); display_cursor(2, 1); display_printf("PORF :%d WDRF :%d", binary(mcucsr, 0), binary(mcucsr, 3)); display_cursor(3, 1); display_printf("EXTRF:%d JTRF :%d", binary(mcucsr, 1), binary(mcucsr, 4)); display_cursor(4, 1); display_printf("BORF :%d #SResets:%3u", binary(mcucsr, 2), soft_resets); }
int main() { int i, off=0, on=1, lports[]=LIGHT_PORTS, pcnt, w=40, m=5; float s; graphics_open(320,240); for(i=0;i<256;i+=5) { graphics_fill(i,i,i); graphics_update(); } SplashBG(320, 240); msleep(1000); graphics_close(); pcnt=NPORTS(lports); for(i=8;i<16;i++) { // change the digital ports to output set_digital_output(i,1); } srand(time(NULL)); // prime random number generation while(1) { table_lights(lports,pcnt,off); // shut off table lights setup(); // team setup (light calibration w/time out option) // setup done, including any time outs so proceed with judge's setup //get_shelf_positions(); // display orange/yellow block set up for judges - 2014 get_bgal_pod_positions(); // display left-right positions for Botgal & pod - 2015 set_a_button_text("QUIT"); set_b_button_text("-"); set_c_button_text("-"); graphics_close(); // close any open graphics graphics_open(3*w,62); display_clear(); display_printf(0,0,"************** BOTBALL 2015 **************"); display_printf(0,1," LIGHTS ON IN"); display_printf(0,2,"******************************************"); display_printf(0,9," Press QUIT to stop count down"); if (countdown_sd(5,1,BLUE,YELLOW,m,w)) continue; s=seconds(); // 2015 table_lights(lports,pcnt,on); // on for 115 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 5"); if (countdown(120,11,GREEN,BLUE,m,w)) continue; // end 2015 /* // 2014 table_lights(lports,pcnt,on); // on for 15 seconds display_printf(0,1," GAME CLOCK - LIGHTS ON TILL 105"); if (countdown(120,106,GREEN,BLUE,m,w)) continue; table_lights(lports,pcnt,off); // of for 100 seconds display_printf(0,1," GAME CLOCK - LIGHTS OFF TILL 5"); if (countdown(105,11,LTBLUE,RED,m,w)) continue; // end 2014 */ if (countdown(10,6,LTORANGE,BLUE,m,w)) continue; display_printf(0,1," GAME CLOCK - LIGHTS BLINK TILL 0"); i=5+(seconds()-s); if (blinkdown(5,0,RED,YELLOW,m,w,lports,pcnt)) continue; display_printf(0,1," GAME CLOCK - %d ",i); display_printf(0,9," ***** GAME OVER! ***** "); table_lights(lports,pcnt,off); // shut off table lights msleep(5000); // pause display } return 0; }
static void fsal_print_access_by_acl(int naces, int ace_number, fsal_ace_t *pace, fsal_aceperm_t perm, enum fsal_errors_t access_result, bool is_dir, struct user_cred *creds) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = { sizeof(str), str, str }; int b_left; if (!isFullDebug(COMPONENT_NFS_V4_ACL)) return; if (access_result == ERR_FSAL_NO_ERROR) b_left = display_cat(&dspbuf, "access granted"); else if (access_result == ERR_FSAL_PERM) b_left = display_cat(&dspbuf, "access denied (EPERM)"); else b_left = display_cat(&dspbuf, "access denied (EACCESS)"); if (b_left > 0) b_left = display_printf(&dspbuf, " uid %u gid %u Access req:", creds->caller_uid, creds->caller_gid); if (b_left > 0) b_left = display_fsal_v4mask(&dspbuf, perm, is_dir); if (b_left > 0 && (naces != ace_number)) b_left = display_fsal_ace(&dspbuf, ace_number, pace, is_dir); LogFullDebug(COMPONENT_NFS_V4_ACL, "%s", str); }
void move_until_line() { create_drive(100, FORWARDS); while (get_create_rfcliff_amt() > CREATE_THRESHOLD) { display_printf(0, 0, "%4i", get_create_rfcliff_amt()); } create_stop(); }
int display_fsal_ace(struct display_buffer *dspbuf, int ace_number, fsal_ace_t *pace, bool is_dir) { int b_left; if (!pace) return display_cat(dspbuf, "ACE: <NULL>"); /* Print the entire ACE. */ b_left = display_printf(dspbuf, "ACE %d:", ace_number); /* ACE type. */ if (b_left > 0) b_left = display_cat(dspbuf, IS_FSAL_ACE_ALLOW(*pace) ? " allow" : IS_FSAL_ACE_DENY(*pace) ? " deny" : IS_FSAL_ACE_AUDIT(*pace) ? " audit" : " ?"); /* ACE who and its type. */ if (b_left > 0 && IS_FSAL_ACE_SPECIAL_ID(*pace)) b_left = display_cat(dspbuf, IS_FSAL_ACE_SPECIAL_OWNER(*pace) ? " owner@" : IS_FSAL_ACE_SPECIAL_GROUP(*pace) ? " group@" : IS_FSAL_ACE_SPECIAL_EVERYONE(*pace) ? " everyone@" : ""); if (b_left > 0 && !IS_FSAL_ACE_SPECIAL_ID(*pace)) { if (IS_FSAL_ACE_SPECIAL_ID(*pace)) b_left = display_printf(dspbuf, " gid %d", pace->who.gid); else b_left = display_printf(dspbuf, " uid %d", pace->who.uid); } /* ACE mask. */ if (b_left > 0) b_left = display_fsal_v4mask(dspbuf, pace->perm, is_dir); /* ACE Inherit flags. */ if (b_left > 0 && IS_FSAL_ACE_INHERIT(*pace)) b_left = display_fsal_inherit_flags(dspbuf, pace); return b_left; }
bool vfs_valid_handle(struct gsh_buffdesc *desc) { xfs_handle_t *hdl = (xfs_handle_t *) desc->addr; bool fsid_type_ok = false; if ((desc->addr == NULL) || (desc->len != sizeof(xfs_handle_t))) return false; if (isMidDebug(COMPONENT_FSAL)) { char buf[256]; struct display_buffer dspbuf = {sizeof(buf), buf, buf}; display_printf(&dspbuf, "Handle len %d: " " fsid=0x%016"PRIx32".0x%016"PRIx32 " fid_len=%"PRIu16 " fid_pad=%"PRIu16 " fid_gen=%"PRIu32 " fid_ino=%"PRIu64, (int) desc->len, hdl->ha_fsid.val[0], hdl->ha_fsid.val[1], hdl->ha_fid.fid_len, hdl->ha_fid.fid_pad, hdl->ha_fid.fid_gen, hdl->ha_fid.fid_ino); LogMidDebug(COMPONENT_FSAL, "%s", buf); } if (hdl->ha_fid.fid_pad != 0) { switch ((enum fsid_type) (hdl->ha_fid.fid_pad - 1)) { case FSID_NO_TYPE: case FSID_ONE_UINT64: case FSID_MAJOR_64: case FSID_TWO_UINT64: case FSID_TWO_UINT32: case FSID_DEVICE: fsid_type_ok = true; break; } if (!fsid_type_ok) { LogDebug(COMPONENT_FSAL, "FSID Type %02"PRIu16" invalid", hdl->ha_fid.fid_pad - 1); return false; } if (hdl->ha_fid.fid_gen != 0) return false; } return hdl->ha_fid.fid_len == (sizeof(xfs_handle_t) - sizeof(xfs_fsid_t) - sizeof(hdl->ha_fid.fid_len)); }
int display_session(struct display_buffer *dspbuf, nfs41_session_t *session) { int b_left = display_printf(dspbuf, "session %p {", session); if (b_left > 0) b_left = display_session_id(dspbuf, session->session_id); if (b_left > 0) b_left = display_cat(dspbuf, "}"); return b_left; }
/*! * Display zum Setzen und Anfahren der Stackpunkte */ void drive_stack_display(void) { display_cursor(1, 1); display_printf("Stack %5d %5d", pos.x, pos.y); display_cursor(2, 1); display_puts("Save/Del : 3/8"); display_cursor(3, 1); display_puts("GoBack/Forward: 4/7"); display_cursor(4, 1); display_puts("Start WayPushPos: 5"); drivestack_disp_key_handler(); // Aufruf des Key-Handlers }
struct session *activate_session(struct session *ses) { check_all_events(gtd->ses, SUB_ARG|SUB_SEC, 0, 1, "SESSION DEACTIVATED", gtd->ses->name); gtd->ses = ses; display_printf(ses, "#SESSION '%s' ACTIVATED.", ses->name); check_all_events(ses, SUB_ARG|SUB_SEC, 0, 1, "SESSION ACTIVATED", ses->name); return ses; }
int display_fsal_inherit_flags(struct display_buffer *dspbuf, fsal_ace_t *pace) { if (!pace) return display_cat(dspbuf, "NULL"); return display_printf(dspbuf, "Inherit:%s%s%s%s", IS_FSAL_ACE_FILE_INHERIT(*pace) ? " file" : "", IS_FSAL_ACE_DIR_INHERIT(*pace) ? " dir" : "", IS_FSAL_ACE_INHERIT_ONLY(*pace) ? " inherit_only" : "", IS_FSAL_ACE_NO_PROPAGATE(*pace) ? " no_propagate" : ""); }
void cleanup_session(struct session *ses) { push_call("cleanup_session(%p)",ses); if (ses == gtd->update) { gtd->update = ses->next; } UNLINK(ses, gts->next, gts->prev); if (ses->socket) { if (close(ses->socket) == -1) { syserr("close in cleanup"); } if (HAS_BIT(ses->flags, SES_FLAG_RUN)) { kill(ses->pid, SIGKILL); } DEL_BIT(ses->flags, SES_FLAG_CONNECTED); } check_all_events(ses, SUB_ARG|SUB_SEC, 0, 3, "SESSION DISCONNECTED", ses->name, ses->command, ntos(ses->pid)); display_printf(gtd->ses, "#SESSION '%s' DIED.", ses->name); if (ses == gtd->ses) { gtd->ses = newactive_session(); } if (ses->logfile) { fclose(ses->logfile); } if (ses->logline) { fclose(ses->logline); } LINK(ses, gtd->dispose_next, gtd->dispose_prev); pop_call(); return; }
void get_bgal_pod_positions() { // screen size (scols,srows), box size (bxcols,bxcols), separator m pixels // random block positions p1, p2 set by function picks int srows=120,scols=160, bpos, ppos; graphics_close(); // close any existing graphics window display_clear(); // prep screen set_a_button_text("COUNTDOWN"); set_b_button_text("-"); set_c_button_text("-"); graphics_open(scols,srows); graphics_fill(WHITE); bpos=rand()%2; if (bpos==0) ppos=1; else ppos=0; // draw field graphics_rectangle(3,3,157,117,BLACK); // outline graphics_rectangle(3,3,70,50,BLACK); // quads graphics_rectangle(90,3,157,50,BLACK); graphics_rectangle(3,70,70,117,BLACK); graphics_rectangle(90,70,157,117,BLACK); graphics_rectangle_fill(70,3,90,50,LTBROWN); // mesa graphics_rectangle(70,3,90,50,BLACK); graphics_rectangle_fill(70,70,90,117,LTBROWN); graphics_rectangle(70,70,90,117,BLACK); graphics_rectangle_fill(72,50,88,70,LTGRAY); // caldera graphics_rectangle(72,50,88,70,BLACK); graphics_rectangle_fill(20,3,25,50,TEAL); // lines graphics_rectangle_fill(135,3,140,50,TEAL); graphics_rectangle_fill(20,70,25,117,PINK); graphics_rectangle_fill(135,70,140,117,PINK); if (bpos==0) { draw_bg(73,13,0.2); graphics_rectangle_fill(74,87,86,102,GREEN); } else { draw_bg(73,82,0.2); graphics_rectangle_fill(74,18,86,32,GREEN); } graphics_update(); display_printf(2,0,"Set Botgal and Botpod "); while(a_button()==0); while(a_button()==1); // debounce }
void display_xfs_handle(struct display_buffer *dspbuf, struct vfs_file_handle *fh) { xfs_handle_t *hdl = (xfs_handle_t *) fh->handle_data; display_printf(dspbuf, "Handle len %hhu:" " fsid=0x%016"PRIx32".0x%016"PRIx32 " fid_len=%"PRIu16 " fid_pad=%"PRIu16 " fid_gen=%"PRIu32 " fid_ino=%"PRIu64, fh->handle_len, hdl->ha_fsid.val[0], hdl->ha_fsid.val[1], hdl->ha_fid.fid_len, hdl->ha_fid.fid_pad, hdl->ha_fid.fid_gen, hdl->ha_fid.fid_ino); }
//************************************************************** // main läßt LED am Port P30 für ca. 1 Minute mit 1 Hz blinken //************************************************************** int main(){ AT91C_BASE_PMC->PMC_PCER = (1<<AT91C_ID_PIOA); // wichtig; unsigned char ucB=0; // lokale Variable ucB char buf[10]; display_init(); while(1) { ucB++; unsigned int t = getTaste(); sprintf(buf,"%u", t); display_set_cursor(0,0); display_putstr(buf); display_set_cursor(0,1); display_printf("%d", t); } while (1); // Endlosschleife nach eigentlichem // Programm: niemals vergessen! }
void lego_spin_until(int direction, int speed, int sensor, int (*comparator)(int, int), int threshold) { int left_ticks_traveled = 0; int right_ticks_traveled = 0; float right_error; float left_error; float desired_value; int left_multiplier; int right_multiplier; clear_motor_position_counter(LEFT_MOTOR); clear_motor_position_counter(RIGHT_MOTOR); motor(LEFT_MOTOR, speed * direction); motor(RIGHT_MOTOR, -speed * direction); while(TRUE) { if (comparator(analog(sensor), threshold)) { break; } display_printf(0, 0, "%4i", analog(sensor)); left_ticks_traveled = abs(get_motor_position_counter(LEFT_MOTOR)); right_ticks_traveled = abs(get_motor_position_counter(RIGHT_MOTOR)); desired_value = (left_ticks_traveled + right_ticks_traveled) / 2.0; left_error = desired_value - left_ticks_traveled; right_error = desired_value - right_ticks_traveled; left_multiplier = (int) ((left_error * spin_l_kP) + 0.5); right_multiplier = (int) ((right_error * spin_r_kP) + 0.5); motor(LEFT_MOTOR, (speed * direction) + left_multiplier); motor(RIGHT_MOTOR, (-speed * direction) + right_multiplier); } freeze(LEFT_MOTOR); freeze(RIGHT_MOTOR); }
int display_sockaddr(struct display_buffer *dspbuf, sockaddr_t *addr) { const char *name = NULL; char ipname[SOCK_NAME_MAX]; int port; int b_left = display_start(dspbuf); if (b_left <= 0) return b_left; switch (addr->ss_family) { case AF_INET: name = inet_ntop(addr->ss_family, &(((struct sockaddr_in *)addr)->sin_addr), ipname, sizeof(ipname)); port = ntohs(((struct sockaddr_in *)addr)->sin_port); break; case AF_INET6: name = inet_ntop(addr->ss_family, &(((struct sockaddr_in6 *)addr)->sin6_addr), ipname, sizeof(ipname)); port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); break; case AF_LOCAL: return display_cat(dspbuf, ((struct sockaddr_un *)addr)->sun_path); } if (name == NULL) return display_cat(dspbuf, "<unknown>"); else return display_printf(dspbuf, "%s:%d", name, port); }
/** * Zeigt ein paar Infos an, die man nicht naeher zuordnen kann */ void misc_display(void) { /* Anzeige der Bot-Adresse (aenderbar) */ display_cursor(1, 1); display_puts("bot_addr="); #ifdef KEYPAD_AVAILABLE if (RC5_Code == RC5_CODE_MUTE) { gui_keypad_request(change_bot_addr_callback, 1, 1, 10); #ifdef PC display_cursor(1, 10); #endif display_puts(" "); // clean new_address = 1; RC5_Code = 0; } if (new_address == 0) #endif // KEYPAD_AVAILABLE { #ifdef PC display_cursor(1, 10); #endif display_printf("0x%x", get_bot_address()); } #ifdef BEHAVIOUR_AVAILABLE display_cursor(2, 1); display_printf("TS=%+4d %+4d", target_speed_l, target_speed_r); #endif #ifdef SRF10_AVAILABLE display_cursor(2, 15); display_printf("US%4u", sensSRF10); #endif display_cursor(3, 1); display_printf("RC=%+4d %+4d", sensEncL, sensEncR); display_cursor(4, 1); display_printf("Speed=%+4d", v_center); display_cursor(4, 12); display_printf("%4u:%03u", timer_get_s(), timer_get_ms()); }
int nfs4_op_create_session(struct nfs_argop4 *op, compound_data_t *data, struct nfs_resop4 *resp) { /* Result of looking up the clientid in the confirmed ID table */ nfs_client_id_t *conf = NULL; /* XXX these are not good names */ /* Result of looking up the clientid in the unconfirmed ID table */ nfs_client_id_t *unconf = NULL; /* The found clientid (either one of the preceding) */ nfs_client_id_t *found = NULL; /* The found client record */ nfs_client_record_t *client_record; /* The created session */ nfs41_session_t *nfs41_session = NULL; /* Client supplied clientid */ clientid4 clientid = 0; /* The client address as a string, for gratuitous logging */ const char *str_client_addr = "(unknown)"; /* The client name, for gratuitous logging */ char str_client[CLIENTNAME_BUFSIZE]; /* Display buffer for client name */ struct display_buffer dspbuf_client = { sizeof(str_client), str_client, str_client }; /* The clientid4 broken down into fields */ char str_clientid4[DISPLAY_CLIENTID_SIZE]; /* Display buffer for clientid4 */ struct display_buffer dspbuf_clientid4 = { sizeof(str_clientid4), str_clientid4, str_clientid4 }; /* Return code from clientid calls */ int i, rc = 0; /* Component for logging */ log_components_t component = COMPONENT_CLIENTID; /* Abbreviated alias for arguments */ CREATE_SESSION4args * const arg_CREATE_SESSION4 = &op->nfs_argop4_u.opcreate_session; /* Abbreviated alias for response */ CREATE_SESSION4res * const res_CREATE_SESSION4 = &resp->nfs_resop4_u.opcreate_session; /* Abbreviated alias for successful response */ CREATE_SESSION4resok * const res_CREATE_SESSION4ok = &res_CREATE_SESSION4->CREATE_SESSION4res_u.csr_resok4; /* Make sure str_client is always printable even * if log level changes midstream. */ display_printf(&dspbuf_client, "(unknown)"); display_reset_buffer(&dspbuf_client); if (op_ctx->client != NULL) str_client_addr = op_ctx->client->hostaddr_str; if (isDebug(COMPONENT_SESSIONS)) component = COMPONENT_SESSIONS; resp->resop = NFS4_OP_CREATE_SESSION; res_CREATE_SESSION4->csr_status = NFS4_OK; clientid = arg_CREATE_SESSION4->csa_clientid; display_clientid(&dspbuf_clientid4, clientid); if (data->minorversion == 0) return res_CREATE_SESSION4->csr_status = NFS4ERR_INVAL; LogDebug(component, "CREATE_SESSION client addr=%s clientid=%s -------------------", str_client_addr, str_clientid4); /* First try to look up unconfirmed record */ rc = nfs_client_id_get_unconfirmed(clientid, &unconf); if (rc == CLIENT_ID_SUCCESS) { client_record = unconf->cid_client_record; found = unconf; } else { rc = nfs_client_id_get_confirmed(clientid, &conf); if (rc != CLIENT_ID_SUCCESS) { /* No record whatsoever of this clientid */ LogDebug(component, "%s clientid=%s", clientid_error_to_str(rc), str_clientid4); if (rc == CLIENT_ID_EXPIRED) rc = CLIENT_ID_STALE; res_CREATE_SESSION4->csr_status = clientid_error_to_nfsstat_no_expire(rc); return res_CREATE_SESSION4->csr_status; } client_record = conf->cid_client_record; found = conf; } PTHREAD_MUTEX_lock(&client_record->cr_mutex); inc_client_record_ref(client_record); if (isFullDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_record(&dspbuf, client_record); LogFullDebug(component, "Client Record %s cr_confirmed_rec=%p cr_unconfirmed_rec=%p", str, client_record->cr_confirmed_rec, client_record->cr_unconfirmed_rec); } /* At this point one and only one of conf and unconf is * non-NULL, and found also references the single clientid * record that was found. */ LogDebug(component, "CREATE_SESSION clientid=%s csa_sequence=%" PRIu32 " clientid_cs_seq=%" PRIu32 " data_oppos=%d data_use_drc=%d", str_clientid4, arg_CREATE_SESSION4->csa_sequence, found->cid_create_session_sequence, data->oppos, data->use_drc); if (isFullDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, found); LogFullDebug(component, "Found %s", str); } data->use_drc = false; if (data->oppos == 0) { /* Special case : the request is used without use of * OP_SEQUENCE */ if ((arg_CREATE_SESSION4->csa_sequence + 1 == found->cid_create_session_sequence) && (found->cid_create_session_slot.cache_used)) { data->use_drc = true; data->cached_res = &found->cid_create_session_slot.cached_result; res_CREATE_SESSION4->csr_status = NFS4_OK; dec_client_id_ref(found); LogDebug(component, "CREATE_SESSION replay=%p special case", data->cached_res); goto out; } else if (arg_CREATE_SESSION4->csa_sequence != found->cid_create_session_sequence) { res_CREATE_SESSION4->csr_status = NFS4ERR_SEQ_MISORDERED; dec_client_id_ref(found); LogDebug(component, "CREATE_SESSION returning NFS4ERR_SEQ_MISORDERED"); goto out; } } if (unconf != NULL) { /* First must match principal */ if (!nfs_compare_clientcred(&unconf->cid_credential, &data->credential)) { if (isDebug(component)) { char *unconfirmed_addr = "(unknown)"; if (unconf->gsh_client != NULL) unconfirmed_addr = unconf->gsh_client->hostaddr_str; LogDebug(component, "Unconfirmed ClientId %s->'%s': Principals do not match... unconfirmed addr=%s Return NFS4ERR_CLID_INUSE", str_clientid4, str_client_addr, unconfirmed_addr); } dec_client_id_ref(unconf); res_CREATE_SESSION4->csr_status = NFS4ERR_CLID_INUSE; goto out; } } if (conf != NULL) { if (isDebug(component) && conf != NULL) display_clientid_name(&dspbuf_client, conf); /* First must match principal */ if (!nfs_compare_clientcred(&conf->cid_credential, &data->credential)) { if (isDebug(component)) { char *confirmed_addr = "(unknown)"; if (conf->gsh_client != NULL) confirmed_addr = conf->gsh_client->hostaddr_str; LogDebug(component, "Confirmed ClientId %s->%s addr=%s: Principals do not match... confirmed addr=%s Return NFS4ERR_CLID_INUSE", str_clientid4, str_client, str_client_addr, confirmed_addr); } /* Release our reference to the confirmed clientid. */ dec_client_id_ref(conf); res_CREATE_SESSION4->csr_status = NFS4ERR_CLID_INUSE; goto out; } /* In this case, the record was confirmed proceed with CREATE_SESSION */ } /* We don't need to do any further principal checks, we can't * have a confirmed clientid record with a different principal * than the unconfirmed record. */ /* At this point, we need to try and create the session before * we modify the confirmed and/or unconfirmed clientid * records. */ /* Check flags value (test CSESS15) */ if (arg_CREATE_SESSION4->csa_flags & ~(CREATE_SESSION4_FLAG_PERSIST | CREATE_SESSION4_FLAG_CONN_BACK_CHAN | CREATE_SESSION4_FLAG_CONN_RDMA)) { LogDebug(component, "Invalid create session flags %" PRIu32, arg_CREATE_SESSION4->csa_flags); dec_client_id_ref(found); res_CREATE_SESSION4->csr_status = NFS4ERR_INVAL; goto out; } /* Record session related information at the right place */ nfs41_session = pool_alloc(nfs41_session_pool); if (nfs41_session == NULL) { LogCrit(component, "Could not allocate memory for a session"); dec_client_id_ref(found); res_CREATE_SESSION4->csr_status = NFS4ERR_SERVERFAULT; goto out; } nfs41_session->clientid = clientid; nfs41_session->clientid_record = found; nfs41_session->refcount = 2; /* sentinel ref + call path ref */ nfs41_session->fore_channel_attrs = arg_CREATE_SESSION4->csa_fore_chan_attrs; nfs41_session->back_channel_attrs = arg_CREATE_SESSION4->csa_back_chan_attrs; nfs41_session->xprt = data->req->rq_xprt; nfs41_session->flags = false; nfs41_session->cb_program = 0; PTHREAD_MUTEX_init(&nfs41_session->cb_mutex, NULL); PTHREAD_COND_init(&nfs41_session->cb_cond, NULL); for (i = 0; i < NFS41_NB_SLOTS; i++) PTHREAD_MUTEX_init(&nfs41_session->slots[i].lock, NULL); /* Take reference to clientid record on behalf the session. */ inc_client_id_ref(found); /* add to head of session list (encapsulate?) */ PTHREAD_MUTEX_lock(&found->cid_mutex); glist_add(&found->cid_cb.v41.cb_session_list, &nfs41_session->session_link); PTHREAD_MUTEX_unlock(&found->cid_mutex); /* Set ca_maxrequests */ nfs41_session->fore_channel_attrs.ca_maxrequests = NFS41_NB_SLOTS; nfs41_Build_sessionid(&clientid, nfs41_session->session_id); res_CREATE_SESSION4ok->csr_sequence = arg_CREATE_SESSION4->csa_sequence; /* return the input for wanting of something better (will * change in later versions) */ res_CREATE_SESSION4ok->csr_fore_chan_attrs = nfs41_session->fore_channel_attrs; res_CREATE_SESSION4ok->csr_back_chan_attrs = nfs41_session->back_channel_attrs; res_CREATE_SESSION4ok->csr_flags = 0; memcpy(res_CREATE_SESSION4ok->csr_sessionid, nfs41_session->session_id, NFS4_SESSIONID_SIZE); /* Create Session replay cache */ data->cached_res = &found->cid_create_session_slot.cached_result; found->cid_create_session_slot.cache_used = true; LogDebug(component, "CREATE_SESSION replay=%p", data->cached_res); if (!nfs41_Session_Set(nfs41_session)) { LogDebug(component, "Could not insert session into table"); /* Release the session resources by dropping our reference * and the sentinel reference. */ dec_session_ref(nfs41_session); dec_session_ref(nfs41_session); /* Decrement our reference to the clientid record */ dec_client_id_ref(found); /* Maybe a more precise status would be better */ res_CREATE_SESSION4->csr_status = NFS4ERR_SERVERFAULT; goto out; } /* Make sure we have a reference to the confirmed clientid record if any */ if (conf == NULL) { conf = client_record->cr_confirmed_rec; if (isDebug(component) && conf != NULL) display_clientid_name(&dspbuf_client, conf); /* Need a reference to the confirmed record for below */ if (conf != NULL) inc_client_id_ref(conf); } if (conf != NULL && conf->cid_clientid != clientid) { /* Old confirmed record - need to expire it */ if (isDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(component, "Expiring %s", str); } /* Expire clientid and release our reference. */ nfs_client_id_expire(conf, false); dec_client_id_ref(conf); conf = NULL; } if (conf != NULL) { /* At this point we are updating the confirmed * clientid. Update the confirmed record from the * unconfirmed record. */ display_clientid(&dspbuf_clientid4, conf->cid_clientid); LogDebug(component, "Updating clientid %s->%s cb_program=%u", str_clientid4, str_client, arg_CREATE_SESSION4->csa_cb_program); if (unconf != NULL) { /* unhash the unconfirmed clientid record */ remove_unconfirmed_client_id(unconf); /* Release our reference to the unconfirmed entry */ dec_client_id_ref(unconf); } if (isDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(component, "Updated %s", str); } } else { /* This is a new clientid */ if (isFullDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogFullDebug(component, "Confirming new %s", str); } rc = nfs_client_id_confirm(unconf, component); if (rc != CLIENT_ID_SUCCESS) { res_CREATE_SESSION4->csr_status = clientid_error_to_nfsstat_no_expire(rc); /* Need to destroy the session */ if (!nfs41_Session_Del(nfs41_session->session_id)) LogDebug(component, "Oops nfs41_Session_Del failed"); /* Release our reference to the unconfirmed record */ dec_client_id_ref(unconf); goto out; } nfs4_chk_clid(unconf); conf = unconf; unconf = NULL; if (isDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(component, "Confirmed %s", str); } } conf->cid_create_session_sequence++; /* Bump the lease timer */ conf->cid_last_renew = time(NULL); /* Release our reference to the confirmed record */ dec_client_id_ref(conf); if (isFullDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_record(&dspbuf, client_record); LogFullDebug(component, "Client Record %s cr_confirmed_rec=%p cr_unconfirmed_rec=%p", str, client_record->cr_confirmed_rec, client_record->cr_unconfirmed_rec); } /* Handle the creation of the back channel, if the client requested one. */ if (arg_CREATE_SESSION4->csa_flags & CREATE_SESSION4_FLAG_CONN_BACK_CHAN) { nfs41_session->cb_program = arg_CREATE_SESSION4->csa_cb_program; if (nfs_rpc_create_chan_v41( nfs41_session, arg_CREATE_SESSION4->csa_sec_parms.csa_sec_parms_len, arg_CREATE_SESSION4->csa_sec_parms.csa_sec_parms_val) == 0) { res_CREATE_SESSION4ok->csr_flags |= CREATE_SESSION4_FLAG_CONN_BACK_CHAN; } } if (isDebug(component)) { char str[LOG_BUFF_LEN]; struct display_buffer dspbuf = {sizeof(str), str, str}; display_session(&dspbuf, nfs41_session); LogDebug(component, "success %s csa_flags 0x%X csr_flags 0x%X", str, arg_CREATE_SESSION4->csa_flags, res_CREATE_SESSION4ok->csr_flags); } /* Release our reference to the session */ dec_session_ref(nfs41_session); /* Successful exit */ res_CREATE_SESSION4->csr_status = NFS4_OK; out: PTHREAD_MUTEX_unlock(&client_record->cr_mutex); /* Release our reference to the client record and return */ dec_client_record_ref(client_record); return res_CREATE_SESSION4->csr_status; }
void follow_black_line(int normal_speed, int minimum_speed, int maximum_speed, int left_desired_value, int right_desired_value, float left_kP, float right_kP, float left_kD, float right_kD, int (*stopping_function)()) { int left_sensor_current_value, right_sensor_current_value; int left_error, right_error; int left_previous_error, right_previous_error; float left_speed, right_speed, raw_left_speed, raw_right_speed; int left_error_delta, right_error_delta; int count = 0; int LEFT_LINE_SENSOR, RIGHT_LINE_SENSOR; LEFT_LINE_SENSOR = LEFT_TOPHAT; RIGHT_LINE_SENSOR = RIGHT_TOPHAT; left_previous_error = 0; right_previous_error = 0; // Turn on the left and right motors. NEGATIVE since backwards. motor(LEFT_MOTOR, normal_speed); motor(RIGHT_MOTOR, normal_speed); while (TRUE) { if (stopping_function()) { break; } // Determine the "errors" -- how far the sensors are from their desired values. left_sensor_current_value = analog(LEFT_LINE_SENSOR); right_sensor_current_value = analog(RIGHT_LINE_SENSOR); left_error = left_desired_value - left_sensor_current_value; right_error = right_desired_value - right_sensor_current_value; left_error_delta = left_error - left_previous_error; right_error_delta = right_error - right_previous_error; // Adjust the motor speeds proportionately to the errors. raw_left_speed = normal_speed + (left_error * left_kP) + (left_error_delta * left_kD); left_speed = raw_left_speed; if (left_speed < minimum_speed) { left_speed = minimum_speed; } else if (left_speed > maximum_speed) { left_speed = maximum_speed; } raw_right_speed = normal_speed + (right_error * right_kP) + (right_error_delta * right_kD); right_speed = raw_right_speed; if (right_speed < minimum_speed) { right_speed = minimum_speed; } else if (right_speed > maximum_speed) { right_speed = maximum_speed; } motor(LEFT_MOTOR, (int) left_speed); motor(RIGHT_MOTOR, (int) right_speed); if (count % 100 == 0) { display_printf(0, 0, "Raw speeds (l, r): %4f, %4f", raw_left_speed, raw_right_speed); display_printf(0, 1, " Speeds (l, r): %4f, %4f", left_speed, right_speed); display_printf(0, 2, " Values (l, r): %4i, %4i", left_sensor_current_value, right_sensor_current_value); display_printf(0, 3, " Errors (l, r): %4i, %4i", left_error, right_error); } count++; left_previous_error = left_error; right_previous_error = right_error; } freeze(LEFT_MOTOR); freeze(RIGHT_MOTOR); }
void lego_spin_onto_black_line(int direction, int speed, int low_threshold, int high_threshold) { int left_ticks_traveled = 0; int right_ticks_traveled = 0; float right_error; float left_error; float desired_value; int left_multiplier; int right_multiplier; int i; clear_motor_position_counter(LEFT_MOTOR); clear_motor_position_counter(RIGHT_MOTOR); motor(LEFT_MOTOR, speed * direction); motor(RIGHT_MOTOR, -speed * direction); for (i = 0; i < 3; i++) { while(TRUE) { if (analog_et(RIGHT_ET) >= low_threshold) { break; } left_ticks_traveled = abs(get_motor_position_counter(LEFT_MOTOR)); right_ticks_traveled = abs(get_motor_position_counter(RIGHT_MOTOR)); desired_value = (left_ticks_traveled + right_ticks_traveled) / 2.0; left_error = desired_value - left_ticks_traveled; right_error = desired_value - right_ticks_traveled; left_multiplier = (int) ((left_error * spin_l_kP) + 0.5); right_multiplier = (int) ((right_error * spin_r_kP) + 0.5); motor(LEFT_MOTOR, (speed * direction) + left_multiplier); motor(RIGHT_MOTOR, (-speed * direction) + right_multiplier); display_printf(0, 0, "L: %4i", ((speed * direction) + left_multiplier)); display_printf(0, 1, "R: %4i", ((speed * direction) + right_multiplier)); } msleep(10); while(TRUE) { if (analog_et(RIGHT_ET) <= high_threshold) { break; } left_ticks_traveled = abs(get_motor_position_counter(LEFT_MOTOR)); right_ticks_traveled = abs(get_motor_position_counter(RIGHT_MOTOR)); desired_value = (left_ticks_traveled + right_ticks_traveled) / 2.0; left_error = desired_value - left_ticks_traveled; right_error = desired_value - right_ticks_traveled; left_multiplier = (int) ((left_error * spin_l_kP) + 0.5); right_multiplier = (int) ((right_error * spin_r_kP) + 0.5); motor(LEFT_MOTOR, (-speed * direction) + left_multiplier); motor(RIGHT_MOTOR, (speed * direction) + right_multiplier); display_printf(0, 0, "L: %4i", ((speed * direction) + left_multiplier)); display_printf(0, 1, "R: %4i", ((speed * direction) + right_multiplier)); } } freeze(LEFT_MOTOR); freeze(RIGHT_MOTOR); }
int nfs4_op_setclientid_confirm(struct nfs_argop4 *op, compound_data_t *data, struct nfs_resop4 *resp) { SETCLIENTID_CONFIRM4args * const arg_SETCLIENTID_CONFIRM4 = &op->nfs_argop4_u.opsetclientid_confirm; SETCLIENTID_CONFIRM4res * const res_SETCLIENTID_CONFIRM4 = &resp->nfs_resop4_u.opsetclientid_confirm; nfs_client_id_t *conf = NULL; nfs_client_id_t *unconf = NULL; nfs_client_record_t *client_record; clientid4 clientid = 0; char str_verifier[NFS4_VERIFIER_SIZE * 2 + 1]; const char *str_client_addr = "(unknown)"; /* The client name, for gratuitous logging */ char str_client[CLIENTNAME_BUFSIZE]; /* Display buffer for client name */ struct display_buffer dspbuf_client = { sizeof(str_client), str_client, str_client}; /* The clientid4 broken down into fields */ char str_clientid4[DISPLAY_CLIENTID_SIZE]; /* Display buffer for clientid4 */ struct display_buffer dspbuf_clientid4 = { sizeof(str_clientid4), str_clientid4, str_clientid4}; int rc; /* Make sure str_client is always printable even * if log level changes midstream. */ display_printf(&dspbuf_client, "(unknown)"); display_reset_buffer(&dspbuf_client); resp->resop = NFS4_OP_SETCLIENTID_CONFIRM; res_SETCLIENTID_CONFIRM4->status = NFS4_OK; clientid = arg_SETCLIENTID_CONFIRM4->clientid; display_clientid(&dspbuf_clientid4, clientid); if (data->minorversion > 0) { res_SETCLIENTID_CONFIRM4->status = NFS4ERR_NOTSUPP; return res_SETCLIENTID_CONFIRM4->status; } if (op_ctx->client != NULL) str_client_addr = op_ctx->client->hostaddr_str; if (isDebug(COMPONENT_CLIENTID)) { sprint_mem(str_verifier, arg_SETCLIENTID_CONFIRM4->setclientid_confirm, NFS4_VERIFIER_SIZE); } else { str_verifier[0] = '\0'; } LogDebug(COMPONENT_CLIENTID, "SETCLIENTID_CONFIRM client addr=%s clientid=%s setclientid_confirm=%s", str_client_addr, str_clientid4, str_verifier); /* First try to look up unconfirmed record */ rc = nfs_client_id_get_unconfirmed(clientid, &unconf); if (rc == CLIENT_ID_SUCCESS) { client_record = unconf->cid_client_record; if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogFullDebug(COMPONENT_CLIENTID, "Found %s", str); } } else { rc = nfs_client_id_get_confirmed(clientid, &conf); if (rc != CLIENT_ID_SUCCESS) { /* No record whatsoever of this clientid */ LogDebug(COMPONENT_CLIENTID, "%s clientid = %s", clientid_error_to_str(rc), str_clientid4); res_SETCLIENTID_CONFIRM4->status = clientid_error_to_nfsstat_no_expire(rc); return res_SETCLIENTID_CONFIRM4->status; } client_record = conf->cid_client_record; if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogFullDebug(COMPONENT_CLIENTID, "Found %s", str); } } PTHREAD_MUTEX_lock(&client_record->cr_mutex); inc_client_record_ref(client_record); if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_record(&dspbuf, client_record); LogFullDebug(COMPONENT_CLIENTID, "Client Record %s cr_confirmed_rec=%p cr_unconfirmed_rec=%p", str, client_record->cr_confirmed_rec, client_record->cr_unconfirmed_rec); } /* At this point one and only one of pconf and punconf is non-NULL */ if (unconf != NULL) { /* First must match principal */ if (!nfs_compare_clientcred(&unconf->cid_credential, &data->credential) || op_ctx->client == NULL || unconf->gsh_client == NULL || op_ctx->client != unconf->gsh_client) { if (isDebug(COMPONENT_CLIENTID)) { char *unconfirmed_addr = "(unknown)"; if (unconf->gsh_client != NULL) unconfirmed_addr = unconf->gsh_client->hostaddr_str; LogDebug(COMPONENT_CLIENTID, "Unconfirmed ClientId %s->'%s': Principals do not match... unconfirmed addr=%s Return NFS4ERR_CLID_INUSE", str_clientid4, str_client_addr, unconfirmed_addr); } res_SETCLIENTID_CONFIRM4->status = NFS4ERR_CLID_INUSE; dec_client_id_ref(unconf); goto out; } else if (unconf->cid_confirmed == CONFIRMED_CLIENT_ID && memcmp(unconf->cid_verifier, arg_SETCLIENTID_CONFIRM4->setclientid_confirm, NFS4_VERIFIER_SIZE) == 0) { /* We must have raced with another SETCLIENTID_CONFIRM */ if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = { sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogDebug(COMPONENT_CLIENTID, "Race against confirm for %s", str); } res_SETCLIENTID_CONFIRM4->status = NFS4_OK; dec_client_id_ref(unconf); goto out; } else if (unconf->cid_confirmed != UNCONFIRMED_CLIENT_ID) { /* We raced with another thread that dealt * with this unconfirmed record. Release our * reference, and pretend we didn't find a * record. */ if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = { sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogDebug(COMPONENT_CLIENTID, "Race against expire for %s", str); } res_SETCLIENTID_CONFIRM4->status = NFS4ERR_STALE_CLIENTID; dec_client_id_ref(unconf); goto out; } } if (conf != NULL) { if (isDebug(COMPONENT_CLIENTID) && conf != NULL) display_clientid_name(&dspbuf_client, conf); /* First must match principal */ if (!nfs_compare_clientcred(&conf->cid_credential, &data->credential) || op_ctx->client == NULL || conf->gsh_client == NULL || op_ctx->client != conf->gsh_client) { if (isDebug(COMPONENT_CLIENTID)) { char *confirmed_addr = "(unknown)"; if (conf->gsh_client != NULL) confirmed_addr = conf->gsh_client->hostaddr_str; LogDebug(COMPONENT_CLIENTID, "Confirmed ClientId %s->%s addr=%s: Principals do not match... confirmed addr=%s Return NFS4ERR_CLID_INUSE", str_clientid4, str_client, str_client_addr, confirmed_addr); } res_SETCLIENTID_CONFIRM4->status = NFS4ERR_CLID_INUSE; } else if (memcmp( conf->cid_verifier, arg_SETCLIENTID_CONFIRM4->setclientid_confirm, NFS4_VERIFIER_SIZE) == 0) { /* In this case, the record was confirmed and * we have received a retry */ if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = { sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(COMPONENT_CLIENTID, "Retry confirm for %s", str); } res_SETCLIENTID_CONFIRM4->status = NFS4_OK; } else { /* This is a case not covered... Return * NFS4ERR_CLID_INUSE */ if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = { sizeof(str), str, str}; char str_conf_verifier[NFS4_VERIFIER_SIZE * 2 + 1]; sprint_mem(str_conf_verifier, conf->cid_verifier, NFS4_VERIFIER_SIZE); display_client_id_rec(&dspbuf, conf); LogDebug(COMPONENT_CLIENTID, "Confirm verifier=%s doesn't match verifier=%s for %s", str_conf_verifier, str_verifier, str); } res_SETCLIENTID_CONFIRM4->status = NFS4ERR_CLID_INUSE; } /* Release our reference to the confirmed clientid. */ dec_client_id_ref(conf); goto out; } /* We don't need to do any further principal checks, we can't * have a confirmed clientid record with a different principal * than the unconfirmed record. Also, at this point, we have * a matching unconfirmed clientid (punconf != NULL and pconf * == NULL). */ /* Make sure we have a reference to the confirmed clientid * record if any */ if (conf == NULL) { conf = client_record->cr_confirmed_rec; if (isDebug(COMPONENT_CLIENTID) && conf != NULL) display_clientid_name(&dspbuf_client, conf); /* Need a reference to the confirmed record for below */ if (conf != NULL) inc_client_id_ref(conf); } if (conf != NULL && conf->cid_clientid != clientid) { /* Old confirmed record - need to expire it */ if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(COMPONENT_CLIENTID, "Expiring %s", str); } /* Expire clientid and release our reference. */ nfs_client_id_expire(conf, false); dec_client_id_ref(conf); conf = NULL; } if (conf != NULL) { /* At this point we are updating the confirmed * clientid. Update the confirmed record from the * unconfirmed record. */ if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogFullDebug(COMPONENT_CLIENTID, "Updating from %s", str); } /* Copy callback information into confirmed clientid record */ memcpy(conf->cid_cb.v40.cb_client_r_addr, unconf->cid_cb.v40.cb_client_r_addr, sizeof(conf->cid_cb.v40.cb_client_r_addr)); conf->cid_cb.v40.cb_addr = unconf->cid_cb.v40.cb_addr; conf->cid_cb.v40.cb_program = unconf->cid_cb.v40.cb_program; conf->cid_cb.v40.cb_callback_ident = unconf->cid_cb.v40.cb_callback_ident; nfs_rpc_destroy_chan(&conf->cid_cb.v40.cb_chan); memcpy(conf->cid_verifier, unconf->cid_verifier, NFS4_VERIFIER_SIZE); /* unhash the unconfirmed clientid record */ remove_unconfirmed_client_id(unconf); /* Release our reference to the unconfirmed entry */ dec_client_id_ref(unconf); if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, conf); LogDebug(COMPONENT_CLIENTID, "Updated %s", str); } /* Check and update call back channel state */ if (nfs_param.nfsv4_param.allow_delegations && nfs_test_cb_chan(conf) != RPC_SUCCESS) { set_cb_chan_down(conf, true); LogCrit(COMPONENT_CLIENTID, "setclid confirm: Callback channel is down"); } else { set_cb_chan_down(conf, false); LogDebug(COMPONENT_CLIENTID, "setclid confirm: Callback channel is UP"); } /* Release our reference to the confirmed clientid. */ dec_client_id_ref(conf); } else { /* This is a new clientid */ if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogFullDebug(COMPONENT_CLIENTID, "Confirming new %s", str); } rc = nfs_client_id_confirm(unconf, COMPONENT_CLIENTID); if (rc != CLIENT_ID_SUCCESS) { res_SETCLIENTID_CONFIRM4->status = clientid_error_to_nfsstat_no_expire(rc); LogEvent(COMPONENT_CLIENTID, "FAILED to confirm client"); /* Release our reference to the unconfirmed record */ dec_client_id_ref(unconf); goto out; } /* check if the client can perform reclaims */ nfs4_chk_clid(unconf); if (isDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_id_rec(&dspbuf, unconf); LogDebug(COMPONENT_CLIENTID, "Confirmed %s", str); } /* Check and update call back channel state */ if (nfs_param.nfsv4_param.allow_delegations && nfs_test_cb_chan(unconf) != RPC_SUCCESS) { set_cb_chan_down(unconf, true); LogCrit(COMPONENT_CLIENTID, "setclid confirm: Callback channel is down"); } else { set_cb_chan_down(unconf, false); LogDebug(COMPONENT_CLIENTID, "setclid confirm: Callback channel is UP"); } /* Release our reference to the now confirmed record */ dec_client_id_ref(unconf); } if (isFullDebug(COMPONENT_CLIENTID)) { char str[LOG_BUFF_LEN] = "\0"; struct display_buffer dspbuf = {sizeof(str), str, str}; display_client_record(&dspbuf, client_record); LogFullDebug(COMPONENT_CLIENTID, "Client Record %s cr_confirmed_rec=%p cr_unconfirmed_rec=%p", str, client_record->cr_confirmed_rec, client_record->cr_unconfirmed_rec); } /* Successful exit */ res_SETCLIENTID_CONFIRM4->status = NFS4_OK; out: PTHREAD_MUTEX_unlock(&client_record->cr_mutex); /* Release our reference to the client record and return */ dec_client_record_ref(client_record); return res_SETCLIENTID_CONFIRM4->status; }
/** * @brief Display NFSv4 owner * * @param[in] owner The state owner * @param[out] str Output string * * @return the bytes remaining in the buffer. */ int display_nfs4_owner(struct display_buffer *dspbuf, state_owner_t *owner) { int b_left; if (owner == NULL) return display_cat(dspbuf, "<NULL>"); b_left = display_printf(dspbuf, "%s %p:", state_owner_type_to_str(owner->so_type), owner); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, " clientid={"); if (b_left <= 0) return b_left; b_left = display_client_id_rec(dspbuf, owner->so_owner.so_nfs4_owner .so_clientrec); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, "} owner="); if (b_left <= 0) return b_left; b_left = display_opaque_value(dspbuf, owner->so_owner_val, owner->so_owner_len); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, " confirmed=%u seqid=%u", owner->so_owner.so_nfs4_owner.so_confirmed, owner->so_owner.so_nfs4_owner.so_seqid); if (b_left <= 0) return b_left; if (owner->so_owner.so_nfs4_owner.so_related_owner != NULL) { b_left = display_printf(dspbuf, " related_owner={"); if (b_left <= 0) return b_left; b_left = display_nfs4_owner(dspbuf, owner->so_owner .so_nfs4_owner.so_related_owner); if (b_left <= 0) return b_left; b_left = display_printf(dspbuf, "}"); if (b_left <= 0) return b_left; } return display_printf(dspbuf, " refcount=%d", atomic_fetch_int32_t(&owner->so_refcount)); }
/*! * @brief Drehzahlregelung fuer die Motoren des c't-Bots * @author Benjamin Benz ([email protected] * @date 01.05.06 * Getrennte Drehzahlregelung fuer linken und rechten Motor sorgt fuer konstante Drehzahl und somit annaehernd * fuer Geradeauslauf * Feintuning von Kp, Ki, Kd verbessert die Genauigkeit und Schnelligkeit der Regelung * Querkopplung der Motoren verbessert Gleichlauf, beispielsweise x*(sensEncL - sensEncR) * in jeden Regler einbauen */ void speed_control(void){ int8 Kp=0; int8 Ki=0; int16 StellwertL=motor_left; /*!< Stellwert links*/ int16 StellwertR=motor_right; /*!< Stellwert rechts*/ volatile static int16 lastEncoderL=0; /*!< vorhergehender Wert von sensEncL */ volatile static int8 lastErrL=0; /*!< letzter Drehzahlfehler links */ volatile static int8 last2ErrL=0; /*!< vorletzter Drehzahlfehler links */ volatile static int16 lastEncoderR=0; /*!< vorhergehender Wert von sensEncR */ volatile static int8 lastErrR=0; /*!< letzter Drehzahlfehler rechts */ volatile static int8 last2ErrR=0; /*!< vorletzter Drehzahlfehler rechts */ int16 err=0; // aktuelle Abweichung vom Soll-Wert int16 encoderRate=0; // IST-Wert [Encoder-ticks/Aufruf] // Wir arbeiten mit verschiedenen PID-Parametern fuer verschiedene Geschwindigkeitsabschnitte if (encoderTargetRateL <= PID_LOW_RATE){ Kp=PID_LOW_Kp; Ki=PID_LOW_Ki; } else { if (encoderTargetRateL >= PID_HIGH_RATE) { Kp=PID_HIGH_Kp; Ki=PID_HIGH_Ki; } else { Kp=(PID_HIGH_Kp+PID_LOW_Kp)/2; Ki=(PID_HIGH_Ki+PID_LOW_Ki)/2; } } //Regler links if (encoderTargetRateL == 0){ StellwertL=0; err=0; lastErrL = 0; } else { encoderRate = sensEncL-lastEncoderL; // aktuelle Ist-Wert berechnen [Encoder-ticks/aufruf] lastEncoderL = sensEncL; // Anzahl der Encoderpulse merken fuer naechsten Aufruf merken err = encoderTargetRateL - encoderRate; // Regelabweichung links // Stellwert Berechnen StellwertL += (Kp * (err - lastErrL)) / 10; // P-Beitrag StellwertL += (Ki * (err + lastErrL)/2 ) /10; // I-Beitrag // StellwertL += Kd * (errL - 2 * lastErrL + last2ErrL); // D-Beitrag //berechneten Stellwert auf zulaessige Groesse begrenzen if (StellwertL > PWMMAX) StellwertL = PWMMAX; if (StellwertL < -PWMMAX) StellwertL = -PWMMAX; #ifdef DISPLAY_REGELUNG_AVAILABLE if (display_screen==DISPLAY_REGELUNG_AVAILABLE){ display_cursor(1,1); display_printf("%03d/%03d ",encoderRate,encoderTargetRateL); display_cursor(2,1); display_printf("e =%03d ",err); display_cursor(3,1); display_printf("L =%04d ", StellwertL); } #endif } last2ErrL = lastErrL; // alten N-2 Fehler merken lastErrL = err; // alten N-1 Fehler merken //Regler rechts if (encoderTargetRateR == 0){ StellwertR=0; err=0; lastErrR=0; } else { encoderRate = sensEncR-lastEncoderR; // aktuelle Ist-Wert berechnen [Encoder-ticks/aufruf] lastEncoderR = sensEncR; // Anzahl der Encoderpulse merken fuer naechsten Aufruf merken err = encoderTargetRateR - encoderRate; // Regelabweichung links // Stellwert Berechnen StellwertR += (Kp * (err - lastErrR))/10; // P-Beitrag StellwertR += (Ki * (err + lastErrR)/2)/10; // I-Beitrag // StellwertR += Kd * (err - 2 * lastErrR + last2ErrR); // D-Beitrag //berechneten Stellwert auf zulaessige Groesse begrenzen if (StellwertR > PWMMAX) StellwertR = PWMMAX; if (StellwertR < -PWMMAX) StellwertR = -PWMMAX; #ifdef DISPLAY_REGELUNG_AVAILABLE if (display_screen==DISPLAY_REGELUNG_AVAILABLE){ display_cursor(1,10); display_printf("%03d/%03d ",encoderRate,encoderTargetRateR); display_cursor(2,10); display_printf("e =%03d ",err); display_cursor(3,10); display_printf("R =%04d ", StellwertR); } #endif } last2ErrR = lastErrR; // alten N-2 Fehler merken lastErrR = err; // alten N-1 Fehler merken #ifdef DISPLAY_REGELUNG_AVAILABLE if (display_screen==DISPLAY_REGELUNG_AVAILABLE){ display_cursor(4,1); display_printf("Kp=%03d Ki=%03d", Kp, Ki); } #endif // Und nun den Wert setzen bot_motor(StellwertL,StellwertR); }
int display_fsal_v4mask(struct display_buffer *dspbuf, fsal_aceperm_t v4mask, bool is_dir) { int b_left = display_printf(dspbuf, "0x%06x", v4mask); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_READ_DATA)) b_left = display_cat(dspbuf, " READ"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_DATA) && is_dir) b_left = display_cat(dspbuf, " ADD_FILE"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_DATA) && !is_dir) b_left = display_cat(dspbuf, " WRITE"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_APPEND_DATA) && is_dir) b_left = display_cat(dspbuf, " ADD_SUBDIR"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_APPEND_DATA) && !is_dir) b_left = display_cat(dspbuf, " APPEND"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_READ_NAMED_ATTR)) b_left = display_cat(dspbuf, " READ_NAMED"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_NAMED_ATTR)) b_left = display_cat(dspbuf, " WRITE_NAMED"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_EXECUTE)) b_left = display_cat(dspbuf, " EXECUTE"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_DELETE_CHILD)) b_left = display_cat(dspbuf, " DELETE_CHILD"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_READ_ATTR)) b_left = display_cat(dspbuf, " READ_ATTR"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_ATTR)) b_left = display_cat(dspbuf, " WRITE_ATTR"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_DELETE)) b_left = display_cat(dspbuf, " DELETE"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_READ_ACL)) b_left = display_cat(dspbuf, " READ_ACL"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_ACL)) b_left = display_cat(dspbuf, " WRITE_ACL"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_WRITE_OWNER)) b_left = display_cat(dspbuf, " WRITE_OWNER"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE_PERM_SYNCHRONIZE)) b_left = display_cat(dspbuf, " SYNCHRONIZE"); if (b_left > 0 && IS_FSAL_ACE_BIT(v4mask, FSAL_ACE4_PERM_CONTINUE)) b_left = display_cat(dspbuf, " CONTINUE"); return b_left; }