Changes in uspace/app/sportdmp/sportdmp.c [4c73361:aa91105] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sportdmp/sportdmp.c
r4c73361 raa91105 37 37 static void syntax_print(void) 38 38 { 39 fprintf(stderr, "Usage: sportdmp [--baud=<baud>] [device_service]\n");39 fprintf(stderr, "Usage: sportdmp <baud> <device_service>\n"); 40 40 } 41 41 42 42 int main(int argc, char **argv) 43 43 { 44 const char* svc_path = "devices/\\hw\\pci0\\00:01.0\\com1\\a"; 44 45 sysarg_t baud = 9600; 45 service_id_t svc_id;46 46 47 int arg = 1; 48 int rc; 49 50 if (argc > arg && str_test_prefix(argv[arg], "--baud=")) { 51 size_t arg_offset = str_lsize(argv[arg], 7); 52 char* arg_str = argv[arg] + arg_offset; 53 if (str_length(arg_str) == 0) { 54 fprintf(stderr, "--baud requires an argument\n"); 55 syntax_print(); 56 return 1; 57 } 47 if (argc > 1) { 58 48 char *endptr; 59 baud = strtol(arg _str, &endptr, 10);49 baud = strtol(argv[1], &endptr, 10); 60 50 if (*endptr != '\0') { 61 51 fprintf(stderr, "Invalid value for baud\n"); … … 63 53 return 1; 64 54 } 65 arg++;66 55 } 67 56 68 if (argc > arg) { 69 rc = loc_service_get_id(argv[arg], &svc_id, 0); 70 if (rc != EOK) { 71 fprintf(stderr, "Cannot find device service %s\n", 72 argv[arg]); 73 return 1; 74 } 75 arg++; 76 } 77 else { 78 category_id_t serial_cat_id; 79 80 rc = loc_category_get_id("serial", &serial_cat_id, 0); 81 if (rc != EOK) { 82 fprintf(stderr, "Failed getting id of category " 83 "'serial'\n"); 84 return 1; 85 } 86 87 service_id_t *svc_ids; 88 size_t svc_count; 89 90 rc = loc_category_get_svcs(serial_cat_id, &svc_ids, &svc_count); if (rc != EOK) { 91 fprintf(stderr, "Failed getting list of services\n"); 92 return 1; 93 } 94 95 if (svc_count == 0) { 96 fprintf(stderr, "No service in category 'serial'\n"); 97 free(svc_ids); 98 return 1; 99 } 100 101 svc_id = svc_ids[0]; 102 free(svc_ids); 57 if (argc > 2) { 58 svc_path = argv[2]; 103 59 } 104 60 105 if (argc > arg) { 106 fprintf(stderr, "Too many arguments\n"); 61 if (argc > 3) { 107 62 syntax_print(); 108 63 return 1; 109 64 } 110 65 66 service_id_t svc_id; 67 int rc = loc_service_get_id(svc_path, &svc_id, IPC_FLAG_BLOCKING); 68 if (rc != EOK) { 69 fprintf(stderr, "Cannot find device service %s\n", svc_path); 70 return 1; 71 } 111 72 112 73 async_sess_t *sess = loc_service_connect(EXCHANGE_SERIALIZE, svc_id, 113 74 IPC_FLAG_BLOCKING); 114 75 if (!sess) { 115 fprintf(stderr, "Failed connecting to service \n");76 fprintf(stderr, "Failed connecting to service %s\n", svc_path); 116 77 } 117 78 … … 140 101 ssize_t i; 141 102 for (i = 0; i < read; i++) { 142 printf("%02hhx ", buf[i]); 103 if ((buf[i] >= 32) && (buf[i] < 128)) 104 putchar((wchar_t) buf[i]); 105 else 106 putchar('.'); 107 fflush(stdout); 143 108 } 144 fflush(stdout);145 109 } 146 110
Note:
See TracChangeset
for help on using the changeset viewer.