Changeset 13326
- Timestamp:
- May 9, 2007, 6:31:51 PM (19 years ago)
- Location:
- trunk/Ohana/src/libkapa
- Files:
-
- 2 edited
-
include/kapa.h (modified) (1 diff)
-
src/IOfuncs.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libkapa/include/kapa.h
r12892 r13326 92 92 /* IOfuncs.c */ 93 93 int KiiSendMessage (int device, char *format, ...); 94 int KiiScanMessage (int device, char *format, ...); 94 95 int KiiSendCommand (int device, int length, char *format, ...); 95 96 int KiiSendCommandV (int device, int length, char *format, va_list argp); 96 int KiiScan Message (int device, char *format, ...);97 int KiiScanCommand (int device, int length, char *format, ...); 97 98 int KiiSendData (int device, char *data, int Nbytes); 98 99 char *KiiRecvData (int device); -
trunk/Ohana/src/libkapa/src/IOfuncs.c
r5852 r13326 51 51 } 52 52 53 int KiiSendCommand (int device, int length, char *format, ...) {54 55 int status;56 va_list argp;57 58 va_start (argp, format);59 status = KiiSendCommandV (device, length, format, argp);60 va_end (argp);61 62 return (status);63 }64 65 int KiiSendCommandV (int device, int length, char *format, va_list argp) {66 67 char *string;68 69 /* string is sent WITHOUT ending NULL char */70 /* allocate and zero length + 1 extra byte */71 ALLOCATE (string, char, length + 1);72 memset (string, 0, length + 1);73 vsnprintf (string, length + 1, format, argp);74 75 write (device, string, length);76 free (string);77 return (TRUE);78 }79 80 53 /* scan a message of arbitrary size, accepting the size first */ 81 54 int KiiScanMessage (int device, char *format, ...) { … … 106 79 return (status); 107 80 } 81 82 /* send a command of fixed size */ 83 int KiiSendCommand (int device, int length, char *format, ...) { 84 85 int status; 86 va_list argp; 87 88 va_start (argp, format); 89 status = KiiSendCommandV (device, length, format, argp); 90 va_end (argp); 91 92 return (status); 93 } 94 95 int KiiSendCommandV (int device, int length, char *format, va_list argp) { 96 97 char *string; 98 99 /* string is sent WITHOUT ending NULL char */ 100 /* allocate and zero length + 1 extra byte */ 101 ALLOCATE (string, char, length + 1); 102 memset (string, 0, length + 1); 103 vsnprintf (string, length + 1, format, argp); 104 105 write (device, string, length); 106 free (string); 107 return (TRUE); 108 } 109 110 /* scan a command of fixed size */ 111 int KiiScanCommand (int device, int length, char *format, ...) { 112 113 int Nbytes, status; 114 char *buffer, *message; 115 va_list argp; 116 117 ALLOCATE (message, char, length + 1); 118 119 /* read Nbytes from the device */ 120 status = read (device, message, Nbytes); 121 if (status != Nbytes) fprintf (stderr, "Kii/Kapa comm error\n"); 122 message[status] = 0; 123 /* make the string easy to parse */ 124 125 /* scan the incoming message */ 126 va_start (argp, format); 127 Nbytes = vsscanf (message, format, argp); 128 va_end (argp); 129 130 return (status); 131 }
Note:
See TracChangeset
for help on using the changeset viewer.
