]> rtime.felk.cvut.cz Git - mirosot.git/blob - testapp/main.c
Added a script from connecting to robot wia bluetooth.
[mirosot.git] / testapp / main.c
1 /*******************************************************************
2   bluetooth test aplication - bth chat 
3
4   bth_h8s2638.h - bth chat - write a recieve data to RS232 link
5                   as recieve data include char is 'a' aplication
6                   send 'ahoj'
7
8   Copyright (C) 2006 by Petr Kovacik petr_kovacik@gmail.com
9
10  *******************************************************************/
11 #ifdef BTH_LX
12 #include <types.h>
13 #include <cpu_def.h>
14 #include <h8s2638h.h>
15 #include <periph/sci_channels.h>
16 #include <periph/sci_rs232.h>
17 #include <system_def.h>
18 #include <assert.h>
19 #include "bth_h8s2638.h"
20
21
22 #else
23 #include "types.h"
24 #include <stdio.h>
25 #endif
26
27 #include "bth_inface.h"
28 #include "bth_fce_out.h"
29
30 #ifdef BTH_LX
31 //*******************************************************
32
33 void  unhandled_exception(void) __attribute__ ((interrupt_handler));
34 /**
35  * init - shaddow registers, outputs..
36  *
37  * Initializes P1 and P3 shaddow registers,
38  * sets PJ.1, PJ.2, PJ.3 LED as outputs,
39  * initialises interrupt vector.
40  */
41 void init()
42 {
43   /* initialises interrupt vector */
44   excptvec_initfill(unhandled_exception, 0);
45 }
46
47 /*Interrupt routines*/
48 void  unhandled_exception(void)
49 {
50 };
51 //***************************************#define _USE_EXR_LEVELS 1*****************
52 #endif
53
54
55
56 int main()
57 {
58   int zz,zn_bth;
59   
60
61   /********************************************************************************/
62 #ifdef BTH_LX
63 //  *SYS_SYSCR|=(SYSCR_INTM1m);
64 //  *INT_IPRH=0x34;
65 //  *INT_IPRK=0x67;                       /*highest priority SCI 1 and 2*/
66
67   *DIO_PEDDR=0xff;                      /*output gate*/
68   *DIO_PEDR=0x60;                       /*0x0-LED - light all; 0x6 -ENA,ENB=1, LE33CD=0*/
69   
70   cli();
71   init();
72   sti();
73
74   sci_rs232_setmode(115200, 0, 0, 2);   //bth
75   sci_rs232_setmode(19200, 0, 0, sci_rs232_chan_default); //PC
76   
77 #endif
78   bth_inface_setup(0);      /*init I/O data buffer for bluetooth*/
79   bth_init();               /*init bth device*/
80   
81   
82   bth_init_pkt_controll();
83   bth_parametr_slave();     /* set up bluetooth device to slave*/
84   bth_start_TPU_counter();
85
86   do{
87     zn_bth=sci_rs232_recch(2);
88   }while(bth_get_timer()<3);
89   bth_start();
90
91   /*
92  do{
93    zn=sci_rs232_recch(sci_rs232_chan_default);
94    zn_bth=sci_rs232_recch(2);
95  }while (zn==-1);
96   */   
97   
98
99  do{
100    zn_bth=sci_rs232_recch(2);
101    if(zn_bth!=-1)
102    {
103      bth_conv_char_text(zn_bth);
104      bth_recieve_packet(zn_bth);
105    };
106
107    if((zz=bth_inface_recch(0))>-1)
108    {
109      if(zz=='a')
110      {
111        bth_inface_sendch('a',0); bth_inface_sendch('h',0); bth_inface_sendch('o',0);
112        bth_inface_sendch('j',0); bth_inface_sendch('\n',0);
113      };
114      l2cap_send_data(0, 0);
115      sci_rs232_sendch(zz,sci_rs232_chan_default);
116    };
117    bth_send_queue();
118 //   sci_rs232_sendch('.',sci_rs232_chan_default);
119  }while(1);
120   return 0;
121 };