FORGOT YOUR DETAILS?

CREATE ACCOUNT

Unison Help

  1. Unison Kernel
    1. Pthreads
      1. pthread_create()
      2. pthread_exit()
      3. pthread_self()
      4. pthread_equal()
      5. pthread_join()
      6. pthread_detach()
      7. pthread_setschedparam()
      8. pthread_getschedparam()
      9. pthread_attr_init()
      10. pthread_attr_destroy()
      11. pthread_attr_setstackaddr()
      12. pthread_attr_getstackaddr()
      13. pthread_attr_setstacksize()
      14. pthread_attr_getstacksize()
      15. pthread_attr_setschedparam()
      16. pthread_attr_getschedparam()
      17. pthread_attr_setdetachstate()
      18. pthread_attr_getdetachstate()
      19. pthread_stackinfo()
      20. pthread_setprio()
      21. pthread_getprio()
      22. sched_get_priority_max()
      23. sched_get_priority_min()
      24. sched_yield()
    2. Pthread Cancellation
      1. pthread_cleanup_pop()
      2. pthread_cleanup_push()
      3. pthread_cancel()
      4. pthread_setcanceltype()
      5. pthread_setcancelstate()
      6. pthread_testcancel()
    3. Mutex
      1. pthread_mutex_init()
      2. pthread_mutex_destroy()
      3. pthread_mutex_lock()
      4. pthread_mutex_trylock()
      5. pthread_mutex_unlock()
    4. Semaphores
      1. sem_open()
      2. sem_close()
      3. sem_unlink()
      4. sem_init()
      5. sem_destroy()
      6. sem_wait()
      7. sem_trywait()
      8. sem_timedwait()
      9. sem_post()
      10. sem_getvalue()
    5. Message Queues
      1. mq_open()
      2. mq_close()
      3. mq_unlink()
      4. mq_send()
      5. mq_receive()
      6. mq_notify()
      7. mq_setattr()
      8. mq_getattr()
      9. mq_timedreceive()
      10. mq_timedsend()
    6. Conditional Variables
      1. pthread_cond_init()
      2. pthread_cond_destroy()
      3. pthread_cond_wait()
      4. pthread_cond_timedwait()
      5. pthread_cond_signal()
      6. pthread_cond_broadcast()
      7. pthread_condattr_init()
      8. pthread_condattr_destroy()
    7. Barriers
      1. pthread_barrier_init()
      2. pthread_barrier_destroy()
      3. pthread_barrier_wait()
    8. Timers
      1. timer_create()
      2. timer_delete()
      3. timer_settime()
      4. timer_gettime()
      5. timer_getoverrun()
      6. timer_tick()
      7. nanosleep()
    9. Clocks
      1. time()
      2. uptime()
      3. sleep()
      4. clock_settime()
      5. clock_gettime()
      6. clock_getres()
      7. clock_init()
    10. Memory Allocation
      1. POSIX.1
        1. malloc()
        2. free()
      2. Variable Length (Pools)
        1. pool_create()
        2. pool_destroy()
        3. pool_alloc()
        4. pool_free()
      3. Fixed Length (Partitions)
        1. pt_create()
        2. pt_destroy()
        3. pt_getblock()
        4. pt_freeblock()
    11. Rendezvous
      1. mr_init()
      2. mr_send()
      3. mr_receive()
      4. mr_reply()
      5. mr_sigrecv()
      6. mr_sigpost()
    12. Interrupts
      1. interrupts
      2. i_disable()
      3. i_restore()
    13. Directory Services
      1. dir_register()
      2. dir_deregister()
      3. dir_lookup()
      4. dir_lookup_string()
    14. Miscellaneous
      1. checkIstack()
      2. NanoStart() or DSPexec_Start()
      3. _isrStackFill
      4. Kernel Scaling
      5. kfatal()
      6. kalloc()
      7. kfree()
      8. mpu or mmu
      9. pthreadStackFill
      10. thread_numb()
      11. thread_utilization_start()
      12. thread_utilization_stop()
      13. xprintf()
      14. xputs()
      15. xputchar()
  2. Unison I/O Library
    1. accept()
    2. bind()
    3. chmod()
    4. close()
    5. connect()
    6. creat()
    7. fstat()
    8. getpeername()
    9. getsockname()
    10. getsockopt()
    11. ioctl()
    12. link()
    13. listen()
    14. lseek()
    15. mkdir()
    16. mkfs()
    17. mount()
    18. open()
    19. read()
    20. recv()
    21. recvfrom()
    22. rename()
    23. renameat()
    24. rmdir()
    25. select()
    26. send()
    27. sendto()
    28. setsockopt()
    29. shutdown()
    30. socket()
    31. stat()
    32. sync()
    33. umount()
    34. unlink()
    35. write()
  3. Unison STDIO Library
    1. STDIO Library Calls
      1. clearerr()
      2. dprintf()
      3. fclose()
      4. fdopen()
      5. feof()
      6. ferror()
      7. fileno()
      8. fflush()
      9. fgetc()
      10. fgetpos()
      11. fgets()
      12. fopen()
      13. fprintf()
      14. fputc()
      15. fputs()
      16. fread()
      17. freopen()
      18. fscanf()
      19. fseek()
      20. fseeko()
      21. fsetpos()
      22. ftell()
      23. ftello()
      24. fwrite()
      25. getc()
      26. getc_unlocked()
      27. getchar()
      28. getchar_unlocked()
      29. getdelim()
      30. getline()
      31. gets()
      32. get_stderr_ptr()
      33. get_stdin_ptr()
      34. get_stdout_ptr()
      35. noperprintf()
      36. perprintf()
      37. perror()
      38. posix_compat()
      39. printf()
      40. putc()
      41. putc_unlocked()
      42. putchar()
      43. putchar_unlocked()
      44. puts()
      45. remove()
      46. rewind()
      47. scanf()
      48. setbuf()
      49. setvbuf()
      50. snprintf()
      51. sprintf()
      52. sscanf()
      53. stderr_init()
      54. stderr_close()
      55. stdin_init()
      56. stdin_close()
      57. stdout_init()
      58. stdout_close()
      59. vdprintf()
      60. vscanf()
      61. vsscanf()
      62. vfscanf()
      63. vprintf()
      64. vsnprintf()
      65. vsprintf()
      66. vfprintf()
      67. ungetc()
    2. Do-nothing Stubs
      1. ctermid()
      2. flockfile()
      3. fmemopen()
      4. ftrylockfile()
      5. open_memstream()
      6. pclose()
      7. popen()
      8. tempnam()
      9. tmpfile()
      10. tmpnam()
  4. Unison LIBC Library
    1. LIBC Library Calls
      1. assert()
      2. realloc()
      3. strcasecmp()
      4. strdup()
      5. strncasecmp()
      6. strftime()
    2. Do-nothing Stubs
      1. abort()
      2. execve()
      3. exit()
      4. _Exit()
      5. fork()
      6. getpid()
      7. isatty()
      8. kill()
      9. sbrk()
      10. times()
      11. wait()
    3. Do-nothing Wide-character Stubs
      1. <wchar.h>
      2. <wctype.h>
  5. Unison I/O Servers
    1. File Servers
      1. Multimedia File Server - fsys
      2. FAT File System - fatfs
      3. NAND File Server - nandfsys
      4. NOR File Server - norfsys
      5. Network File Server - nfs
  6. Graphics, Camera, Video, Audio
    1. Vendor Graphics
    2. Prism++ Graphics
    3. ADPCM Services - adpcmd
    4. Camera
  7. Network Protocols
    1. TCP and UDP Server - tcpd
      1. IPv4 only server
      2. IPv4/IPv6 server
    2. DHCP Client Service - dhcp client
    3. DHCP Server - dhcpd
    4. Telnet Server - telnetd
    5. Tiny FTP Server - tftpd
    6. Point to Point - pppd
    7. Network Translation - NAT with PAT
    8. Firewall
      1. Packet filter: pf
      2. Packet filter control: pfctl
      3. Fitler rules: pf.filtering
      4. Translation rules: pf.nat
    9. Tiny HTTP Server - thttpd
    10. Tiny HTTP Server with TLS
    11. POP3 Server
    12. Simple Mail Transfer Protocol Services (SMTP)
    13. Bootp Protocol
    14. File Transfer Protocol Server (FTP)
    15. File Transfer Client Services
    16. RPC / XDR
    17. DNS Client
    18. HTTP/HTTPS Client
    19. REST Client
    20. AutoIP Service - autoip client
    21. mDNS server - mdnsd
    22. SNTP Client
    23. SNMP Agent - Snmpd server
    24. SSL/TLS library
    25. SSH server
    26. IP security
      1. IPsec description
      2. IPsec administration: ipsecadm
      3. Virtual Private Network: VPN
    27. Power Control
      1. Motor and Motion Control Servers
      2. PWM, Encoders
    28. Serial I/O
      1. Asynchronous Serial I/O Server - ttyserver
      2. CAN Server - cand
      3. I2C Server - i2cd
      4. I2S Server - i2sd
    29. System Services
      1. Power Management Servers
      2. Login Service - login_services
      3. XML
      4. POSIX Shell and Login Service - posh
    30. Universal Serial Bus (USB)
      1. USB Server
      2. USB Device Server
      3. USB Embedded Host Server
    31. Wireless
      1. Wireless Servers and Drivers
      2. 802.15.4 Radio Servers
      3. TCP/v6 with 6loWPAN
      4. ZigBee
      5. BlueTooth Server
      6. 802.11 Wi-Fi
      7. GPRS, UHF and GPS Radio Servers
    32. Remedy Tools for Unison
      1. Remedy Data Logging and Event Display Tools
      2. Remedy Diagnostics
      3. Remedy Flash Downloader/Bootloader
      4. Remedy Power On Self Test - POST
      5. Remedy OS Object Viewer
      6. Remedy Remote Control Tools

7.31.5.BlueTooth Server #

NAME

Bluetooth Server (btd)

SYNOPSIS

#include <sys.h>
#include <fcntl.h>
#include <iorqst.h>
#include <stdio.h>
#include <bluetooth.h>

int _bt_server(char* bt_setup, char hw_port_num, char hw_type, void * callback);

DESCRIPTION

The btd is a small and fast Bluetooth server. The Bluetooth protocol stack is flexible and can be easily extending to support new protocols and profiles.

The current version supports the following protocols:

Host Controller Interface (HCI)
Logical Link Control and Adaptation Protocol ( L2CAP)
Service Discovery Protocol (SDP)
RFCOMM

Supported profiles

Generic Access Profile (GAP)
Serial Port Profile (SPP)
Hands Free Profile (HFP)
Headset Profile (HSP)

The btd is instantiated with the command:
_bt_server((char*)&bt_setup, portnum, dev_type, user_callback );

After Bluetooth server has started it can be accessed using standard POSIX open/close/ioctl commands.
To access to BT server user must register it in local directory database:
dir_register(“/dev/bt/root”, pid, TYPE_SERVER);

The default bluetooth server path is: “/dev/bt/root

. Default path to Bluetooth profiles is “/dev/bt”.

Example

bt0_fd = open("/dev/bt/root", O_RDWR, 0);

The _bt_server required parameters:

 

  • bt_setup – parameters for initialization of the hardware bluetooth interface. bt_setup has callback function named read_init_file. This function used by BT stack to load init file to BT chip. If initialisation is not needed – write NULL to read_init_file.

 

int (*read_init_file)(char *data, int size, int * pos, void * arg);

data - pointer to read data buffer
size - size requested to be read
pos - current position in read file
arg - addition command depending of chip driver (for example "-o" for open or "-r" for read initialization  file)

 

  • portnum – port selection for the bluetooth module.
  • dev_type – selection of the hardware transport for current module. The current version supports a UART (ebt_hw_uart) and SPI (ebt_hw_spi) transport. For other versions contact the factory.
  • user_callback – User callback function for handling events from the Bluetooth server.

 

prototype of user_callback function:

int user_callback(tbt_evt * evt, int * resp, int evt_type);

parameters:

 

  • * evt – struct which holds data for the user (depends on the evt_type)
  • * resp – depending on the evt_type, the user must change this information to send response data.
  • evt_type – type of event.

 

List of available event types:

1. BT_CONNECT_REQ – request connect from remote peer
evt->con_evt.name – name of remote peer (e.g. “BTPC_1”)
evt->con_evt.bdaddr – BDADDR of remote peer (e.g. 123456)
evt->con_evt.svc_name – connecting service name (“SPP” for “SPP1” )
evt->con_evt.svc_port – connecting service port ( (1) for “SPP1” )
user response:
*resp = (-1) – reject connection
*resp = (1) – accept connection

Example:
——————————————————-

  xprintf("Connect request from \"%s\", bdaddr %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",evt->con_evt.name,
  evt->con_evt.bdaddr->addr[5],
  evt->con_evt.bdaddr->addr[4],
  evt->con_evt.bdaddr->addr[3],
  evt->con_evt.bdaddr->addr[2],
  evt->con_evt.bdaddr->addr[1],
  evt->con_evt.bdaddr->addr[0]);
  xprintf("Service %s%d\n",evt->con_evt.svc_name, evt->con_evt.svc_port);
  *resp = 1;  //accepting connect request. Send -1 to reject connect request

——————————————————-
2. BT_CONNECT_EVT – request event. Sent when connection established
evt->con_evt.name – name of remote peer (e.g. “BTPC_1”)
evt->con_evt.bdaddr – BDADDR of remote peer (e.g. 123456)
evt->con_evt.svc_name – connecting service name ( “SPP” for “SPP1”)
evt->con_evt.svc_port – connecting service port ( (1) for “SPP1”)
user response: NONE

3. BT_DISCONNECT_EVT – request event. Sent when connction broken
evt->discon_evt.name – name of remote peer (e.g. “BTPC_1”)
evt->discon_evt.bdaddr – BDADDR of remote peer (e.g. 123456)
evt->discon_evt.svc_name – connecting service name (“SPP” for “SPP1”)
evt->discon_evt.svc_port – connecting service port ( (1) for “SPP1”)
user response: NONE

4. BT_CONNECT_ERR – error establishing a connection.
evt->con_err.name – name of remote peer (e.g. “BTPC_1”)
evt->con_err.bdaddr – BDADDR of remote peer (e.g. 123456)
evt->con_err.svc_name – connecting service name (e.g. “SPP”)

5. BT_PIN_REQ – remote peer requested pin
evt->pin_req.name – name of remote peer (e.g. “0000”). Max 4 symbols
evt->pin_req.bdaddr – BDADDR of remote peer (e.g. 123456)

user response
*resp = -1 – reject pin request
*resp = “XXXX” – send pin (“XXXX”)

Example:
——————————————————-

  xprintf("Pin request event \"%s\", BDADDR %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n\n",evt->pin_req.name,
  evt->pin_req.bdaddr->addr[5],
  evt->pin_req.bdaddr->addr[4],
  evt->pin_req.bdaddr->addr[3],
  evt->pin_req.bdaddr->addr[2],
  evt->pin_req.bdaddr->addr[1],
  evt->pin_req.bdaddr->addr[0]);
  memcpy((char *)evt->pin_req.pin, "0000", 5);

——————————————————-

6. BT_KEY_NOT – Link Key Notification event
The Link Key Notification event is used to indicate that a new Link Key has been created for the connection with the device specified in evt->key_evt.bdaddr

evt->key_evt.bdaddr – Remote device BDADDR
evt->key_req.key – Created link key
The Host can save this new Link Key in its own storage for future use

Example:
——————————————————-

  xprintf("Key notification event \"%s\", BDADDR %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",evt->key_evt.name,
  evt->key_evt.bdaddr->addr[5],
  evt->key_evt.bdaddr->addr[4],
  evt->key_evt.bdaddr->addr[3],
  evt->key_evt.bdaddr->addr[2],
  evt->key_evt.bdaddr->addr[1],
  evt->key_evt.bdaddr->addr[0]);
  memcpy(key, evt->key_evt.key, 16);
  key_set = 1;
  *resp = 0;	//send 1 if you want to store link key to local BT chip database (stored key count is limited)

——————————————————-

7. BT_KEY_REQ – The Link Key Request event is used to indicate that a Link Key is required for
the connection with the device specified in evt->key_req.bdaddr.
If key exists – return *resp = 0 and key, in evt->key_req.key, else return *resp = -1

Example:

-------------------------------------------------------
if (key_set == 1) {
  memcpy(evt->key_req.key, key, 16);
  *resp = 0; 
}else 
  *resp = -1;
-------------------------------------------------------

8. BT_KEY_DELETE – Request to delete existing link key (received from already paired device) from database
evt->key_delete_evt.name – paired device name
evt->key_delete_evt.bdaddr – paired device BDADDR

9. BT_INQ_COMPLEATE
– indicates that the Inquiry is finished. Return status Inquiry process.
evt->inq_evt.devnum – status of Inquiry process. Return founded devices number or (-1) if the process failed.

All communication with Bluetooth server takes with open/close/ioctl functions.

To start the BT module, the user must call the open function:

bt0_fd = open("/dev/bt/root", O_RDWR, 0);

Now the user can use ioctl(bt0_fd) command to communicate with the bluetooth server.

ioctl(fd, CMD, cmd_param);

where:

  • fd – opened BT device file descriptor
  • CMD – command class (BTIOCTL)
  • cmd_param – pointer to the command parameters;

    Example:
    //========================================================

      int bt_fd;
      BT_IO_CMD bt_cmd;
      if((bt0_fd = open("/dev/bt/root", O_RDWR, 0)) == -1) {
        xprintf("Can't open bluetooth hardware\n");	//opening BT device descriptor
        pthread_exit(0);
      }
      bt_cmd.cmd = BTSNAME;
      bt_cmd.io_set_name.name =  "Rowebots BT";
      xprintf("BT name: %s\n", bt_cmd.io_set_name.name );	//set local name
      ioctl(bt0_fd, BTIOCTL, &bt_cmd);

    //========================================================
    // Command list
    //========================================================

    BTSDISC – set discoverable mode

    struct BT_STDISCOVER_st {
      int cmd;		//BTSDISC
      int mode;		//discover set (int)
      //DISCOVER_GENERAL - all devices can see module
      //DISCOVER_NONE - all devices can't see module
    };

    BTSCOD – set local device COD (ClassOfDevice)

    struct BT_SCOD_st {
      int cmd;		//BTSCOD
      int COD;		//set class of device. Valid values for this parameter are specified in the
      //Bluetooth Assigned Numbers Document www.bluetooth.com.
    };

    BTGLNAME – get local device name

    struct BT_GLNAME_st {
      int cmd;		//BTGLNAME
      char * name;	//name
    };

    BTSNAME – set local device name

    struct BT_SNAME_st {
      int cmd;		//BTSNAME
      char * name;	//name
    };

    GETLADDR – get local BD addr

    struct BT_GETLADDR_st {
      int cmd;					//BDADDR
      struct bd_addr * bdaddr;	//local BD addr
    };

    Example:

    bt_cmd.cmd = GETLADDR;
    ioctl(bt0_fd, BTIOCTL, &bt_cmd);
    fprintf(tty_file,"New bdaddr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
    		bt_cmd.io_get_local_addr.bdaddr->addr[5],
    		bt_cmd.io_get_local_addr.bdaddr->addr[4],
    		bt_cmd.io_get_local_addr.bdaddr->addr[3],
    		bt_cmd.io_get_local_addr.bdaddr->addr[2],
    		bt_cmd.io_get_local_addr.bdaddr->addr[1],
    		bt_cmd.io_get_local_addr.bdaddr->addr[0]);
    

    BTSETLADDR – set local BD addr

    struct BT_SETLADDR_st {
    	int cmd;
    	struct bd_addr * bdaddr;
    };

    Example:

    bt_cmd.cmd = BTSETLADDR;
    bt_cmd.io_set_local_addr.bdaddr->addr[0] = 0x11;
    bt_cmd.io_set_local_addr.bdaddr->addr[1] = 0x22;
    bt_cmd.io_set_local_addr.bdaddr->addr[2] = 0x33;
    bt_cmd.io_set_local_addr.bdaddr->addr[3] = 0x44;
    bt_cmd.io_set_local_addr.bdaddr->addr[4] = 0x55;
    bt_cmd.io_set_local_addr.bdaddr->addr[5] = 0x66;
    if (ioctl(bt0_fd, BTIOCTL, &bt_cmd))
    	fprintf(tty_file,"Error\n");
    else
    	fprintf(tty_file,"OK\n");
    

    BTDISCOVER – Performs device discovery

    struct BT_DISCOVER_st {
      int cmd;       //BTDISCOVER
      int timeout;   //time for device discovery (typically >= 20 sec)
    };

    BTGPLIST – Get total discovered peers cnt

    struct BT_GPLIST_st {
      int cmd;       //BTGPLIST
      int peer_cnt;  //discovered peers count
    };

    BTGPBDADDR – Get peer BD addr

    struct BT_GPBDADDR_st {
      int cmd;                   //BTGPBDADDR
      int dev_index;             //Device index (dev_index <= peer_cnt)
      struct bd_addr * bdaddr;   //return peer BDADDR
    };

    BTGPNAME – Get peer name

    struct BT_GPNAME_st {
      int cmd;          //BTGPNAME
      int dev_index;    //Device index (dev_index <= peer_cnt)<
      char * name;      //return peer name
    };

    BTGADDRNAME – Get peer name bt BDADDR

    struct BT_GADDRNAME_st {
      int cmd;                   //BTGADDRNAME
      struct bd_addr * bdaddr;   //peer BDADDR
      char * name;               //return peer name
    };
    

    BTGCOD – Get peer COD (class of device)

    struct BT_GCOD_st {
      int cmd;          //BTGCOD
      int dev_index;    //Device index (dev_index <= peer_cnt)
      int COD;          //return peer class of device
    };

    BTSVCDISC – Device service discovery

    struct BT_SVCDISC_st {
      int cmd;         //BTSVCDISC
      int dev_index;   //Device index (dev_index <= peer_cnt)
    };

    BTSVCMDISC – Device service discovery by bdaddr

    struct BT_SVCMDISC_st {
      int cmd;                  //BTSVCMDISC
      struct bd_addr * bdaddr;  //peer BDADDR
    };

    BTNSVCCNT – Get device servise cnt

    struct BT_NSVCCNT_st {
      int cmd;          //BTNSVCCNT
      int dev_index;    //Device index (dev_index < peer_cnt)
      int service_cnt;  //Return service count of device
    };

    BTSVCPROP – Get service name and port count

    struct BT_SVCPROP_st {
      int cmd;             //BTSVCPROP
      int dev_index;       //Device index (dev_index <= peer_cnt)
      int service_index;   //Service index (service_index < service_cnt)
      char * name;         //Service name ("SPP", "HFP"...)
      int port_cnt;        //Service port count
    };

    BTGETSVCONCNT – Get connected services count

    struct BT_GETSVCONCNT_st {
      int cmd;           //BTGETSVCONCNT
      int dev_index;     //Device index (dev_index < peer_cnt)
      int service_cnt;   //Get already connected services count
    };

    BTGETSVCCONPROP – Get service properties

      struct BT_GETSVCCONPROP_st {
      int cmd;              //BTGETSVCCONPROP
      int dev_index;        /Device index (dev_index < peer_cnt)
      int service_index;    //Service index (service_index < service_cnt)
      char * svc_name;      //Service name ("SPP", "HFP"...)
      char svc_fd;          //connected service index: (0) for HFP0, (1) for SPP1...
      char out;             //connect direction (1 - OUT, 0 - IN)
      char svc_ch;          //channel on which connection is established.
      char * name;
    };

    BTCONNECT – Connect to remote peer service

      struct BT_CONNECT_st {
      int cmd;          //BTCONNECT
      int dev_index;    //Device index (dev_index < peer_cnt)
      char *svc_name;   //Service name ("SPP", "HFP"...)
      int svc_port;     //Service port
    };

    To connect to the SPP1 service set:
    *svc_name = “SPP”;
    svc_port = 1;

    BTDISCON – Disconnect from peer service

    struct BT_DISCON_st {
      int cmd;          //BTDISCON
      char *svc_name;   //Service name ("SPP", "HFP"...)
      int  svc_port;    //Local connected service port
    };

    BTDEVRM – Remove selected device from list with all connected services

    struct BT_DEVRM_st {
      int cmd;         //BTDISCON
      int dev_index;   //Device index (dev_index < peer_cnt)
    };

    BTGHWVER – Get Hardware version

    struct BT_GHWVER_st {
    	int cmd;
    	char hci_ver;
    	short hci_rev;
    	char lmp_ver;
    	short lmp_subver;
    	short manufacturer;
    };

    BTSCOROUTING – set SCO routing (PCM or SCO)

    struct BT_SCOROUTINGst {
    	int cmd;
    #define	SCO_HCI		0
    #define	SCO_PCM 	1
    	int routing;
    };
    

    BTWRVOICESETTINGS – set voice settings (for all connections)
    BTRDVOICESETTINGS – get current voice settings

    struct BT_VOICE_SETTINGS_st{
    	int cmd;
    	char icf;     //Input Coding
    	char idf;     //Input Data Format
    	char iss;     //Input Sample Size
    	char acf;     //Air Coding Format
    	char lbp;     //Linear_PCM_Bit_Pos
    
    };
    

    BTSETPWRMOD– set power safe mode

    struct BT_SETPWRMODE_st {
    	int cmd;
    	int mode;     //power safe mode type. 
                      //One of: BT_PWR_ACTIVE, BT_PWR_SLEEP, BT_PWR_DEEP_SLEEP, BT_PWR_OFF
    	void * param; //additional parameter. Typically timeout for enter to sleep mode in msec
    };

    BTSETSLEEPENA – set sleep enable

    struct BT_SETSLEEPENA_st {
    	int cmd;
    	int ena;       //activate/deactivate power safe mode
    };

    BTGETPOWERSTATE– get current power state

    struct BT_GETPWRSTATE_st {
    	int cmd;
    	int ena;        //power safe mode activated/deactivated
    	int state;      //actual power safe state (1-active/0-sleep)
    	int mode;       //power safe mode type. 
    };
    

    Power mode setting example:

    BT_IO_CMD bt_cmd;
    .....
    i = 2000;          //timeout in msec to enter sleep mode when no activity
    on HCI interface
    
    /*Setup power mode*/
    bt_cmd.cmd = BTSETPWRMODE;
    bt_cmd.io_set_pwr_mode.mode = BT_PWR_DEEP_SLEEP; //deep sleep power mode.
    bt_cmd.io_set_pwr_mode.param = &i;
    ioctl(bt0_fd, BTIOCTL, &bt_cmd);
    .....
    /*Activate power safe mechanism*/
    bt_cmd.cmd = BTSETSLEEPENA;
    bt_cmd.io_sleep_ena.ena = 1;    // enable sleep mode (0 - disable)
    ioctl(bt0_fd, BTIOCTL, &bt_cmd);
    .....
    /*Getting current powersafe state*/
    bt_cmd.cmd = BTGETPOWERSTATE;
    ioctl(bt0_fd, BTIOCTL, &bt_cmd);
            
    fprintf(tty_file, "We in power safe mode \"%d\"\n", bt_cmd.io_pwr_state.mode);
    fprintf(tty_file, "   --Power manage %s \n", bt_cmd.io_pwr_state.ena ? "enabled" : "disabled");
    fprintf(tty_file, "   --BT in %s state\n", bt_cmd.io_pwr_state.state ? "Active" : "Power Safe");
    

    BTSTAT – get stack staticstics

    struct BT_STATst {	
    	int cmd;
    
    	uint_32 ACL_pkt_in;
    	uint_32 ACL_data_in;
    	uint_32 ACL_pkt_out;
    	uint_32 ACL_data_out;
    
    	uint_32 SCO_pkt_in;
    	uint_32 SCO_data_in;
    	uint_32 SCO_pkt_out;
    	uint_32 SCO_data_out;
    
    	uint_32	EVT_pkt;
    	uint_32 EVT_data;
    	uint_32 CMD_pkt;
    	uint_32 CMD_data;
    };

    After the connection is established (receive by callback function event BT_CONNECT_REQ or BT_CONNECT_EVT) – then user can open the connected service. The name of the service is stored in evt->con_evt.svc_name and evt->con_evt.svc_port which was received in the callback function.fd_spp = open(“/dev/bt/SPP0”, O_RDWR, 0); //open “SPP0” service.

    Now the user may use the read or write command to send and receive data:

    n = read(fd_spp, &temp_buf , 1);
    if (n!= -1)
    write(fd_spp,&temp_buf,n);
    ///////////////////////////////////////////////////////////////////////////////
    ////////////////////////////Bluetooth SPP demo/////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////
    

    1. Open demo project “bt_spp_XXXXX” in your demo directory, where XXXXX – is the name of your Bluetooth hardware.

    For example: bt_spp_PAN1315 for PAN1315 module.

    2. Compile and run demo.
    3. After the demo runs you can see the following messages:

    Main here!
    Start Unison Bluetooth core ver. 1.3.8
    TTY Server version = 2.4.0
    SPP server ver 0.97
    TTY Server version = 2.4.0
    Starting Bluetooth
    Vendor bdaddr: c0:e4:22:8c:f1:8a
    Setting new bdaddr...OK
    New bdaddr: 11:22:33:44:55:66
    BT name: Rowebots BT
    Type 'h' for help
    
    

    Enter ‘h’ command

      h
    =========help=======
    Type: "l" for print discovered devices
    Type: "s" for discovery bluetooth devices
    Type: "p n" for discovery device service
             n - device number in device list(l)
    Type: "c dev svc port" for connect to peer
            dev - device number in discovery list
            svc - Service name
            port remote service port
    Type: "d svc port" for disconnect from peer
            svc - service name
            port connected port
    

    After entering the command ‘s’ the result is displayed, for example:

      s
      Discovery devices. Wait some time...
      Discovery devices complete.
      Found 1 devices
    

    Enter ‘l’ command:

      l
      ========================
      0. Dev name: "TEST_BT-PC", bdaddr: 00:15:83:3d:0a:57
      found 0 services
      Connected 0 services
      ========================
    

    Now – searching for available “SPP” service in remote devices.
    To search for a Profile on device which is named “RwBt-PC” enter the command

      p 0
      Discovery device 0 profiles...
      profile discovery OK
      
      l
      ========================
      0. Dev name: "TEST_BT-PC", bdaddr: 00:15:83:3d:0a:57
      found 1 services
      services:
      -SPP has 2 ports
      Connected 0 services
      ========================
    

    The device found “TEST_BT-PC” and has 2 “SPP” ports. Try to connect to the port “SPP0”

      c 0 SPP 
      Connecting to peer 0
      Connect event from "RwBt-PC", bdaddr 00:15:83:3d:0a:57
      Service SPP0
      connect OK
      
      l
      ========================
      0. Dev name: "TEST_BT-PC", bdaddr: 00:15:83:3d:0a:57
      found 1 service
      services:
     	-SPP has 2 ports
      Connected 1 service
    	service SPP0 - was connected to Remote port SPP0
      ========================
    

    Now we can communicate with the remote device using standard open/close/read/write instructions

      Example: 
      fd_spp = open("/dev/bt/SPP0", O_RDWR, 0);
      n = read(fd_spp, &temp_buf , 8);
      if (n!= -1)
      write(fd_spp,&temp_buf,n);
    

    to close the communication channel “SPP0” enter the command

      d SPP 0
      Disconnecting SPP0
      Disconnect event from "TEST_BT-PC", bdaddr 00:15:83:3d:0a:57
      Service SPP0<
      l
      ========================
      0. Dev name: "TEST_BT-PC", bdaddr: 00:15:83:3d:0a:57
      found 1 service
      services:
      -SPP has 2 ports
      Connected 0 services
      ========================
    

    SEE ALSO

    HSP_server, HFP_server, SPP server

 

Suggest Edit

CONTACT US

TO GET YOUR PROJECT STARTED

TOP