Skip to contentSkip to conversation

rctest DUMP mode with data dump

PATCH New Hartmut Schimmel 1 participant 1 message Oct 2, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rctest DUMP mode with data dump

Hello,

the attached patch extendes rctest.c with a cmd line switch -D, which writes the data recived in DUMP mode to stdout.

Install:
cd bluez-utils-2.21
patch -p0 < rcdump_2.21.patch
make distclean
./configure --enable-test
make

Why I made it:
For me it is usefull as a very simple client program, which waits for incoming connections and dumps the incoming data. It can be used from script languages like perl.

In real I receive mesurements from a sensor (bluetooth equiped with PicoPlug) out there, which wake up from time to time, send measure value via SPP to the host, where the pachted rctest runs and sleeps again.

sml@Amadeus:~> rctest -P 5 -d -D
rctest[12071]: Waiting for connection on channel 5 ... rctest[12072]: Can't get RFCOMM connection information: Protocol not available
(92)
rctest[12072]: Connect from 00:80:37:15:1A:A9 [handle 0, class 0x000000] rctest[12072]: Receiving ...
this is line the data payload
rctest[12072]: Disconnect: Connection timed out

Please give me feedback, if this is usefull for anybody else.

Hartmut

test/rctest.c renamed from bluez-utils-2.21/test/rctest.c +23 -5
diff -Naur ../bluez-utils-2.21/test/rctest.c ./test/rctest.c
@@ -75,6 +75,7 @@
 static int secure = 0;
 static int socktype = SOCK_STREAM;
 static int linger = 0;
+static int dump_data = 0;
 
 static float tv2fl(struct timeval tv)
 {
@@ -265,11 +266,23 @@
 
 static void dump_mode(int sk)
 {
-	int len;
+	int len, count;
 
 	syslog(LOG_INFO, "Receiving ...");
-	while ((len = read(sk, buf, data_size)) > 0)
-		syslog(LOG_INFO, "Recevied %d bytes", len);
+
+	if ( !dump_data ) {
+		count = data_size;
+	} else {
+		count = 1;
+	}
+
+	while ((len = read(sk, buf, count)) > 0) {
+		if ( !dump_data ) {
+			syslog(LOG_INFO, "Recevied %d bytes", len);
+		} else {
+			printf("%s", buf);
+		}
+	}
 }
 
 static void recv_mode(int sk)
@@ -407,7 +420,8 @@
 		"\t[-A] request authentication\n"
 		"\t[-E] request encryption\n"
 		"\t[-S] secure connection\n"
-		"\t[-M] become master\n");
+		"\t[-M] become master\n"
+		"\t[-D] dump incoming data (only in dump mode)\n");
 }
 
 int main(int argc ,char *argv[])
@@ -417,7 +431,7 @@
 
 	bacpy(&bdaddr, BDADDR_ANY);
 
-	while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:N:MAESL:")) != EOF) {
+	while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:N:MAESL:D")) != EOF) {
 		switch (opt) {
 		case 'r':
 			mode = RECV;
@@ -483,6 +497,10 @@
 			encrypt = 1;
 			break;
 
+		case 'D':
+			dump_data = 1;
+			break;
+
 		case 'S':
 			secure = 1;
 			break;