|
From: Mattias A. <mat...@us...> - 2001-03-21 19:03:10
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bttest.c 1.2 1.3=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
replaced code with functions in bt_xxx files
lots of cleanup
The diff of the modified file(s):
--- bttest.c 2001/03/10 12:49:32 1.2
+++ bttest.c 2001/03/21 19:03:09 1.3
@@ -39,12 +39,6 @@
*
*/
=20
-/*=20
- * FIXME !!!
- * THIS FILE HAS NOT BEEN TESTED AFTER SPLIT UP OF BTD=20
- * AND SHOULD NOT BE USED AS IS
- */
-
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -76,12 +70,10 @@
#include "bt_if.h"
#include "bt_misc.h"
#include "bt_conf.h"
+#include "bt_vendor.h"
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
=20
-#define START_PPP 1
-#define QUIT_BTD 2
-
#define BTD_HISTORY_FILE "/tmp/btd_history"
=20
char* menu[] =3D
@@ -97,9 +89,7 @@
" readbd", /* read module bd address */
" reset", /* reset board */
" role_switch <xx:xx:xx:xx:xx:xx> <role> (0=3Dmaster, 1=3Dslave)",
-#ifdef BT_USERSTACK
" stat ", /* similar to reading the /proc/bt */
-#endif
#ifdef ECS_TEST_FUNCTIONS
" ecs_entertest <handle> (hex)",
" ecs_testctrl <par1,par2,...,par9> (hex)",
@@ -107,7 +97,6 @@
" ecs_testcon <xx:xx:xx:xx:xx:xx> (hex)",=20=20
" enable_dut", /* enable device under test mode */
#endif
- " ppp",
" quit",
#ifdef BT_USERSTACK
"",
@@ -150,27 +139,21 @@
}=20=20=20=20=20=20=20=20=20
}
=20
-void=20
-testmain(void)
+int
+main(void)
{
- int start_ppp =3D 0;
int bt_cfd;=20=20
=20
- if ((bt_cfd =3D open_device(BT_CTRL_TTY, O_RDWR, 0)) < 0)
+ /* First of all check that stack is running */
+ if (!bt_isinitiated())
{
- perror("Could not open BT control TTY\n");
+ printf("Stack not initiated, exit\n");
exit(1);
}
-
-// if (enter_cmd_mode)
- {
- read_history(BTD_HISTORY_FILE);
=20
-#ifdef BT_USERSTACK
- sleep(2); /* temp fix - wait for last command response to be returned =
*/
-#endif
+ bt_cfd =3D bt_openctrl();
=20
- printf("Now entering cmd line mode\n");
+ read_history(BTD_HISTORY_FILE);=20=20
=20
show_menu();
=20=20=20=20=20
@@ -178,62 +161,37 @@
{
int tmp;
char *line =3D (char*) readline("> ");
-
- if (!line)
- {
- start_ppp =3D 0;
- break;
- }
-
add_history(line);
=20=20=20=20=20=20=20
tmp =3D process_cmd(line, bt_cfd);
=20
- if (tmp =3D=3D START_PPP)
- {
- start_ppp =3D 1;
- break;
- }
- else if (tmp =3D=3D QUIT_BTD)
+ if (tmp =3D=3D QUIT_BTD)
{
- start_ppp =3D 0;
break;
}
free(line);
}
write_history(BTD_HISTORY_FILE);
- }=20=20
+ exit(0);
}
=20
int
process_cmd(char *buf, int bt_cfd)
{
- int bd[6];
- unsigned char my_bd_addr[6];
unsigned int tmp[11];
int repeat;
int i, line;
-#ifdef BT_USERSTACK
- unsigned char tmp_bd[6]; /* used for byte swapping */
- int server_channel, profile;
-#endif
=20=20
if (!strncmp(buf, "quit", 4))
{
return QUIT_BTD;
}
- else if (!strncmp(buf, "ppp", 3))
- {
- return START_PPP;
- }
-
- if (sscanf(buf, "rf_conn %x:%x:%x:%x:%x:%x %d %d",
+ else if (sscanf(buf, "rf_conn %x:%x:%x:%x:%x:%x %d %d",
&tmp[0], &tmp[1], &tmp[2],
&tmp[3], &tmp[4], &tmp[5],
&tmp[6], &tmp[7]) =3D=3D 8)
{
- int i;
- unsigned int con_id;
+ unsigned int con_id, i;
unsigned short srv_ch, line;
unsigned char tmp_bd[6];
=20
@@ -268,118 +226,33 @@
}
else if (sscanf(buf, "rf_send %d %d %d", &i, &repeat, &line) =3D=3D 3)
{
-#define MAXSIZE (4096*2)
- struct timeval start_t, stop_t;
- int bytes_tot =3D i*repeat;
- int avg_speed =3D 0; /* bps */
- unsigned int ms;
- char tmp[MAXSIZE];
+ int btfd;
char dev[20];
- int fd;
- int j;
-
sprintf(dev, "/dev/ttyBT%d",line);
-
-#ifndef BT_USERSTACK=20=20=20=20
- printf("Opening %s\n", dev);
- if ((fd =3D open_device(dev, O_RDWR, CLIENT)) < 0)
- {
- perror("open_device");
- return 0;
- }=20=20=20=20
- printf("Done.\n");
-
- bt_waitconnection(fd, line);
-
-#else
- /* FIXME -- currently only uses line 0 */
- if (line !=3D 0) {
- printf("No support for sending data on line %d, use line 0 instead !=
(userstack only)\n", line);
- fd=3D-1;
- return 0;
- }
-#endif
-
- if (i > MAXSIZE)
- {
- printf("Max 8192 bytes per write!\n");
- i =3D MAXSIZE;
- bytes_tot =3D i*repeat; /* update this aswell */
- }
-
- /* fill them with letters... */
- for(j =3D 0; j < i; j++)
- {
- tmp[j] =3D (j % 25) + 65;
+ btfd =3D open(dev, O_RDWR | O_NOCTTY);
+ bt_send(bt_cfd, i, repeat);
+ close(btfd);
}
-=20=20=20=20
- printf("\nNow sending %d %d-bytes packet (%d kB) on line %d\n",=20
- repeat, i, bytes_tot/1000, line);
-
- gettimeofday(&start_t, NULL);
-=20
- while (repeat)
+ else if (sscanf(buf, "setbd %x:%x:%x:%x:%x:%x",
+ &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]) =
=3D=3D 6)
{
- int n =3D 0;
-#ifndef BT_USERSTACK
- n =3D write(fd, tmp, i);=20=20=20
-#else
- n =3D bt_write_top(tmp, i, line);
-#endif
+ unsigned char tmp_bd[6];
=20=20=20=20=20=20=20
- if (n <=3D0)
+ for (i =3D 0; i < 6; i++)
{
- printf("couldn't write any more data...\n\n");
- bytes_tot =3D bytes_tot-repeat*i;
- break;
- }
-
- repeat--;
- printf("%6d kB left to send... \r",
- ((repeat*i)/1000));
- fflush(stdout);
+ tmp_bd[i] =3D (unsigned char)tmp[i];
}
- gettimeofday(&stop_t, NULL);
- printf("\ndone.\n");
=20
- ms =3D (stop_t.tv_sec-start_t.tv_sec)*1000 +=20
- (stop_t.tv_usec-start_t.tv_usec)/1000;
- if (ms)
- avg_speed =3D ((8*bytes_tot)/ms);
- printf("Average TX rate : %d kbps (%d kB/s)\n", avg_speed, avg_speed/8=
);
-#ifndef BT_USERSTACK
- printf("Closing %s\n", dev);
- close_device(fd);
-#endif
- }
- else if (sscanf(buf, "setbd %x:%x:%x:%x:%x:%x",
- &bd[0], &bd[1], &bd[2], &bd[3], &bd[4], &bd[5]) =3D=3D 6)
- {
- bt_set_bd_addr(bt_cfd, &bd[0]);
+ bt_set_bd_addr(bt_cfd, &tmp_bd[0]);
}
else if (strncmp(buf, "readbd", 6) =3D=3D 0)
{
+ unsigned char my_bd_addr[6];=20=20
read_local_bd(bt_cfd, my_bd_addr);
}
- else if (strncmp(buf, "reset", 5) =3D=3D 0)
- {
- /* FIXME */
-#if 0
-
- close_device(bt_cfd);
- close_device(phys_fd);
- bt_cfd =3D -1;
- phys_fd =3D -1;
- reset_hw();
-#ifdef RESTART_ENABLED
- /* must set baud rate to default for hw again... */
- siglongjmp(jmpbuffer, 1);
-#endif
-
-#endif
- }
else if(sscanf(buf, "role_switch %x:%x:%x:%x:%x:%x %d ",
- &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5], &tmp[6]) =3D=3D 7)
+ &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4],=20
+ &tmp[5], &tmp[6])=3D=3D 7)
{
unsigned char tmp_bd[6];
=20
@@ -422,22 +295,16 @@
ericsson_tx_test(&tmp[0]);
}
#endif
-
-/*
- * Non usermode stack functions for the stuff=20
- * below will be added later on
- */
-
-#ifdef BT_USERSTACK
else if (strncmp(buf, "stat", 4) =3D=3D 0)
{
-
- char tmp[4096];
- int len;
- len =3D bt_read_internal(tmp);
- tmp[len] =3D 0;
- printf("%s", tmp);
+ bt_showstatus();
}
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
+/* FIXME !!! -- make this work for both kernel / usermode stack */
+/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
+
+
+#ifdef BT_USERSTACK
else if (sscanf(buf, "ping %x:%x:%x:%x:%x:%x",
&bd[0], &bd[1], &bd[2], &bd[3], &bd[4], &bd[5]) =3D=3D 6)
{
@@ -575,7 +442,6 @@
printf("> error: command not recognized or wrong syntax\n");
show_menu();
}
-
return 0;
}
=20
|