void test_execute_Inquiry(char* path, int evpd, int page_code) { struct sg_io_hdr* p_hdr = init_io_hdr(); set_xfer_data(p_hdr, data_buffer, BLOCK_LEN * 256); set_sense_data(p_hdr, sense_buffer, SENSE_LEN); int status = 0; int fd = open(path, O_RDWR); if (fd > 0) { status = execute_Inquiry(fd, page_code, evpd, p_hdr); printf("the return status is %d\n", status); if (status != 0) { show_sense_buffer(p_hdr); } else { show_vendor(p_hdr); show_product(p_hdr); show_product_rev(p_hdr); } } else { printf("failed to open sg file %s\n", path); } close(fd); destroy_io_hdr(p_hdr); }
int show(void) { char *p; void (*cfunc)(int); void (*sfunc)(int); void (*bfunc)(int); struct natstr *natp; int tlev; char buf[1024]; int rlev; again: p = getstarg(player->argp[1], "Show what ('?' to list options)? ", buf); if (!p || !*p) return RET_SYN; if (*p == '?') { pr("bridge, item, land, news, nuke, plane, sect, ship, product, tower, updates\n"); goto again; } natp = getnatp(player->cnum); rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]); if (!player->argp[3]) { tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); if (player->god) tlev = 1000; } else { tlev = (int)atoi(player->argp[3]); if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god) tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); } if (player->god) rlev = 1000; switch (*p) { case 'b': show_bridge(99999); return RET_OK; case 't': show_tower(99999); return RET_OK; case 'i': show_item(99999); return RET_OK; case 'n': if (*(p + 1) == 'e') { show_news(99999); return RET_OK; } if (drnuke_const > MIN_DRNUKE_CONST) tlev = ((rlev / drnuke_const) > tlev ? tlev : (rlev / drnuke_const)); bfunc = show_nuke_build; cfunc = show_nuke_capab; sfunc = show_nuke_stats; break; case 'l': bfunc = show_land_build; sfunc = show_land_stats; cfunc = show_land_capab; break; case 'p': if (p[1] == 'r') { show_product(99999); return RET_OK; } bfunc = show_plane_build; sfunc = show_plane_stats; cfunc = show_plane_capab; break; case 's': if (*(p + 1) == 'e') { bfunc = show_sect_build; sfunc = show_sect_stats; cfunc = show_sect_capab; } else { bfunc = show_ship_build; sfunc = show_ship_stats; cfunc = show_ship_capab; } break; case 'u': show_updates(player->argp[2] ? atoi(player->argp[2]) : 8); return RET_OK; default: return RET_SYN; } p = getstarg(player->argp[2], "Build, stats, or capability data (b,s,c)? ", buf); if (!p || !*p) return RET_SYN; pr("Printing for tech level '%d'\n", tlev); if (*p == 'B' || *p == 'b') bfunc(tlev); else if (*p == 'C' || *p == 'c') cfunc(tlev); else if (*p == 'S' || *p == 's') sfunc(tlev); else return RET_SYN; return RET_OK; }
void show_serial_number(struct sg_io_hdr *hdr) { unsigned char *buffer = hdr->dxferp; int i; printf("serial number: "); for (i=0x80, } #endif #define SENSE_LEN 32 #define BLOCK_LEN 1 unsigned char sense_buffer[SENSE_LEN]; unsigned char data_buffer[BLOCK_LEN*256]; void test_execute_Inquiry(char * path, int evpd, int page_code) { struct sg_io_hdr * p_hdr = init_io_hdr(); set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256); set_sense_data(p_hdr, sense_buffer, SENSE_LEN); int status = 0; int fd = open(path, O_RDWR); if (fd>0) { status = execute_Inquiry(fd, page_code, evpd, p_hdr); printf("the return status is %d\n", status); if (status!=0) { show_sense_buffer(p_hdr); } else{ show_vendor(p_hdr); show_product(p_hdr); show_product_rev(p_hdr); show_xfer_data(p_hdr); } } else { printf("failed to open sg file %s\n", path); } close(fd); destroy_io_hdr(p_hdr); } void test_cmds(char *path, int evpd, int page_code) { struct sg_io_hdr * p_hdr = init_io_hdr(); set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256); set_sense_data(p_hdr, sense_buffer, SENSE_LEN); int status = 0; int fd = open(path, O_RDWR); if (fd>0) { status = execute_Inquiry(fd, page_code, evpd, p_hdr); printf("the return status is %d\n", status); //show_sense_buffer(p_hdr); show_xfer_data(p_hdr); } else { printf("failed to open sg file %s\n", path); } close(fd); destroy_io_hdr(p_hdr); } void get_rpm(char *path, int evpd, int page_code) { struct sg_io_hdr * p_hdr = init_io_hdr(); set_xfer_data(p_hdr, data_buffer, BLOCK_LEN*256); set_sense_data(p_hdr, sense_buffer, SENSE_LEN); int status = 0; unsigned char *xfer; int pdt, rpm; int fd = open(path, O_RDWR); if (fd>0) { status = execute_Inquiry(fd, page_code, evpd, p_hdr); printf("the return status is %d\n", status); //show_sense_buffer(p_hdr); //show_xfer_data(p_hdr); // 参考代码 sg3_utils: sg_vpd.c : decode_b1_vpd() xfer = p_hdr->dxferp; pdt = (int)xfer[0]; switch (pdt) { case 0: if (p_hdr->dxfer_len < 64) { printf("xfer is too short!\n"); } else { rpm = (xfer[4]<<8) | xfer[5]; printf("rpm of %s: %d rpm\n", path, rpm); } break; default: printf("unknown pdt\n"); break; } } else { printf("failed to open sg file %s\n", path); } close(fd); destroy_io_hdr(p_hdr); } int main(int argc, char * argv[]) { //test_execute_Inquiry(argv[1], 0, 0); //test_cmds(argv[1], 1, 0x86); get_rpm(argv[1], 1, 0xb1); // rpm // tested: // 0x80,0x83 return 0; }