Changes in uspace/app/sportdmp/sportdmp.c [74017ce:f9b2cb4c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sportdmp/sportdmp.c
r74017ce rf9b2cb4c 27 27 */ 28 28 29 #include <char_dev_iface.h> 29 30 #include <errno.h> 30 #include <io/chardev.h> 31 #include <io/serial.h> 31 #include <ipc/serial_ctl.h> 32 32 #include <loc.h> 33 33 #include <stdio.h> 34 #include <stdlib.h>35 34 36 35 #define BUF_SIZE 1 … … 45 44 sysarg_t baud = 9600; 46 45 service_id_t svc_id; 47 chardev_t *chardev;48 serial_t *serial;49 size_t nread;50 46 51 47 int arg = 1; … … 117 113 async_sess_t *sess = loc_service_connect(svc_id, INTERFACE_DDF, 118 114 IPC_FLAG_BLOCKING); 119 if ( sess == NULL) {115 if (!sess) { 120 116 fprintf(stderr, "Failed connecting to service\n"); 121 return 2;122 117 } 123 118 124 rc = chardev_open(sess, &chardev); 125 if (rc != EOK) { 126 fprintf(stderr, "Failed opening character device\n"); 127 return 2; 128 } 119 async_exch_t *exch = async_exchange_begin(sess); 120 rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, baud, 121 SERIAL_NO_PARITY, 8, 1); 122 async_exchange_end(exch); 129 123 130 rc = serial_open(sess, &serial);131 if (rc != EOK) {132 fprintf(stderr, "Failed opening serial port\n");133 return 2;134 }135 136 rc = serial_set_comm_props(serial, baud, SERIAL_NO_PARITY, 8, 1);137 124 if (rc != EOK) { 138 125 fprintf(stderr, "Failed setting serial properties\n"); … … 147 134 148 135 while (true) { 149 rc = chardev_read(chardev, buf, BUF_SIZE, &nread); 150 for (size_t i = 0; i < nread; i++) { 136 ssize_t read = char_dev_read(sess, buf, BUF_SIZE); 137 if (read < 0) { 138 fprintf(stderr, "Failed reading from serial device\n"); 139 break; 140 } 141 ssize_t i; 142 for (i = 0; i < read; i++) { 151 143 printf("%02hhx ", buf[i]); 152 }153 if (rc != EOK) {154 fprintf(stderr, "\nFailed reading from serial device\n");155 break;156 144 } 157 145 fflush(stdout); … … 159 147 160 148 free(buf); 161 serial_close(serial);162 chardev_close(chardev);163 async_hangup(sess);164 149 return 0; 165 150 }
Note:
See TracChangeset
for help on using the changeset viewer.