版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、11 / 11文檔可自由編輯打印嵌入式系統(tǒng)實(shí)驗(yàn)報(bào)告姓名:寧昭義組數(shù):第5組 學(xué)號:6 專業(yè):信息與通信工程 日期:2015年12月20日綜合實(shí)驗(yàn)(藍(lán)牙電話網(wǎng)關(guān)系統(tǒng)綜合開發(fā)案例)一、實(shí)驗(yàn)?zāi)康?熟練建立交叉編譯環(huán)境。2了解藍(lán)牙電話網(wǎng)關(guān)實(shí)現(xiàn)的原理。3通過編程實(shí)現(xiàn)通過建立的藍(lán)牙鏈接實(shí)現(xiàn)對GSM模塊功能的控制。二、實(shí)驗(yàn)內(nèi)容前言在藍(lán)牙電話網(wǎng)關(guān)系統(tǒng)中,嵌入式主機(jī)起到主控作用,Bluetooth模塊則向N個藍(lán)牙電話終端設(shè)備提供語音接入功能,GSM/GPRS模塊提供語音呼出服務(wù),使得任何一個藍(lán)牙電話終端的呼叫請求都能夠連接到公眾語音網(wǎng)絡(luò),從而實(shí)現(xiàn)本系統(tǒng)內(nèi)部的藍(lán)牙電話終端與外部公眾語音通信網(wǎng)絡(luò)用戶的通信。本開發(fā)案
2、例構(gòu)建了完整的藍(lán)牙電話網(wǎng)關(guān)系統(tǒng),系統(tǒng)組成結(jié)構(gòu)如上圖所示。嵌入式藍(lán)牙電話網(wǎng)關(guān)是本系統(tǒng)的核心設(shè)備,主要使用了本產(chǎn)品中的ARM9嵌入式主機(jī)、Bluetooth和GSM/GPRS通信模塊。本實(shí)驗(yàn)通過藍(lán)牙建立無線連接,控制板載GSM模塊撥打電話,示意圖如下所示。具體任務(wù)1) 開發(fā)板1的藍(lán)牙與開發(fā)板2的藍(lán)牙建立語音和數(shù)據(jù)鏈路。2) 設(shè)置開發(fā)板1,使開發(fā)板1能控制GSM模塊撥打電話。3) 開發(fā)板2通過建好的藍(lán)牙鏈路控制開發(fā)板1的GSM模塊撥打電話。實(shí)驗(yàn)設(shè)備與軟件環(huán)境硬件:SemitARM9200開發(fā)板、PC機(jī)PIII800MHz,256MB以上、串口線(公母)1根、網(wǎng)線1根,音頻線一對,7.5V電源1個,以
3、上設(shè)備均需2套。軟件:RedHat 9.0 Linux操作系統(tǒng),SemitARM9200實(shí)驗(yàn)開發(fā)軟件。三、實(shí)驗(yàn)步驟 分別將開發(fā)板1與開發(fā)板2的DEBUG COM與PC1和PC2的串口相連,開發(fā)板的網(wǎng)口與PC的網(wǎng)口相連。開發(fā)板接7.5V電源。啟動開發(fā)板1與開發(fā)板2,并建立交叉編譯環(huán)境。在開發(fā)板1上插入SIM卡,打開開發(fā)板1上GSM開關(guān),按下GSM RESET鍵復(fù)位GSM,等到GSM MODE燈閃爍之后說明GSM模塊已經(jīng)啟動成功。開發(fā)板1與開發(fā)板2分別輸入sh /etc/scripts_arm.sh啟動藍(lán)牙輸入hciconfig顯示藍(lán)牙地址在開發(fā)板1:輸入cd /mnt/SEMIT_Project
4、/Bluetooth_Cellphone/Bluetooth_Cellphone_Server進(jìn)入文件夾輸入./server開發(fā)板2:輸入cd /mnt/SEMIT_Project/Bluetooth_Cellphone/Bluetooth_Cellphone_Client進(jìn)入文件夾輸入./client 00:06:6e:17:1c:30 開發(fā)板2將通過藍(lán)牙與開發(fā)板1建立鏈接,屏幕上將出現(xiàn)please select the function字樣代表已經(jīng)可以控制開發(fā)板2的板載GSM模塊撥打電話,按操作界面提示信息進(jìn)行操作。四、附錄(程序)Client端#ifdef HAVE_CONFIG_H#i
5、nclude #endif#define DEBUG#include #include #include #include #include #include #include #include #include #include #include #include #include bluetooth/bluetooth.h#include bluetooth/hci.h#include bluetooth/hci_lib.h#include bluetooth/l2cap.h#include bluetooth/sdp.h#include bluetooth/sdp_lib.h#inclu
6、de bluetooth/sco.h#include bluetooth/tcs.hvoid bas *dst, const bdaddr_t *src) register unsigned char *d = (unsigned char *) dst; register const unsigned char *s = (const unsigned char *) src; register int i; for (i = 0; i 6; i+) di = s5-i;int ba2str(const bdaddr_t *ba, char *str) uint8_t b6; baswap(
7、bdaddr_t *) b, ba); return sprintf(str, %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X, b0, b1, b2, b3, b4, b5);int str2ba(const char *str, bdaddr_t *ba) uint8_t b6; const char *ptr = str; int i; for (i = 0; i 6; i+) bi = (uint8_t) strtol(ptr, NULL, 16); if (i != 5 & !(ptr = strchr(ptr, :) ptr = :00:00:00:00:0
8、0; ptr+; bas, (bdaddr_t *) b); return 0;For debug#ifdef DEBUG void debug(char * str) printf(str); #else#define debug(str)#endif#define MAX_LEN 32VARIABLEint flag_process = 0;int flag_sco = 0;int flag_dial = 0;int flag_called = 0;int fd_tty;unsigned char command; unsigned int phonenum_len; unsigned c
9、har phonenumMAX_LEN+1 = 0; unsigned char msgType;unsigned char send_msg672;struct sockaddr_l2 addr = 0; /for l2cap socketint s;int status;char *dest;int bytes_read;unsigned char buf1024;struct sockaddr_sco sco_addr=0; /for sco linkint sco_s;int sco_status; void dt_add_sco(/*tcs_con_bt *tcs*/) debug(
10、n =NOW DT CONNECT SCO TO GW!=n);/ allocate a socket sco_s=socket(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_SCO); if(sco_s0) perror(create socket error); exit(1); else debug(create sco socket done!n); / set the connection parameters sco_addr.sco_family=AF_BLUETOOTH; str2ba(dest,&sco_addr.sco_bdaddr); / con
11、nect to server debug(connectting.n); sco_status=connect(sco_s,(struct sockaddr *)&sco_addr,sizeof(sco_addr);if(sco_status=0) debug(connect sco success!n);/after_sco_menu(tcs); else debug(connet sco Fail!n);close(sco_s); exit(1);void tcs_dt_init(int argc,char*argv) char c,ch; char cmd_line50; int nwr
12、ite; if(argc = 2) dest = argv1; else printf(usage:clinet addrn);exit(1); /unsigned char* addr; debug(n|= get tcs_dt initialized =|n); debug(1) dt opening l2cap socket.n); /allocate socket printf(s = %dn,s); s = socket(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_L2CAP); printf(s = %dn,s); if(s 0) printf(crea
13、te socket in dt failed.n); exit(1); else debug( dt open socket success!n); /bind socket to port 0x1001 of the first available bluetooth adaptor addr.l2_family = AF_BLUETOOTH; addr.l2_psm = htobs(0x1001); str2ba(dest,&addr.l2_bdaddr); /ba2str(&(loc_addr.l2_bdaddr), addr); /printf(local address is %cn
14、,addr); debug(2) connecting to gateway.n); printf(status = %d n,status); status = connect(s,(struct sockaddr*)&addr, sizeof(addr); printf(status = %d n,status); if(status ); memset(cmd_line,0,50); scanf(%s,cmd_line); ch = cmd_line0; switch(ch) case 1:printf(please enter the number to calln);memset(p
15、honenum,0,sizeof(phonenum) );scanf(%s,phonenum); phonenumstrlen(phonenum) = 0;phonenum_len = strlen(phonenum);memcpy(cmd_line+1,phonenum,phonenum_len);nwrite = write( s, cmd_line, sizeof(cmd_line) ); sleep(1); break;case 2: nwrite = write(s,2,1); sleep(1); close(sco_s); break; case 3: nwrite = write
16、(s,3,1);printf(exiting .n); exit(0); default: break; int main(int argc, char*argv) memset(phonenum,0,sizeof(phonenum); debug(begining.now.n); /tcs_con_bt* tcs; /tcs-tcs_cur_state = STATE_NULL; tcs_dt_init(argc,argv); return 0;Server端#ifdef HAVE_CONFIG_H#include #endif#define DEBUG#include #include #
17、include #include #include #include #include #include /* definitions */#include /* Error number definitions */#include /* POSIX terminal control definitions */#include /* Mluti-programming definitions*/#include bluetooth/bluetooth.h#include bluetooth/hci.h#include bluetooth/hci_lib.h#include bluetoot
18、h/l2cap.h#include bluetooth/sdp.h#include bluetooth/sdp_lib.h#include bluetooth/sco.h#include bluetooth/tcs.h#define MAX_LEN 32For debug#ifdef DEBUG void debug(char * str) printf(str); #else#define debug(str)#endifvoid bas *dst, const bdaddr_t *src)register unsigned char *d = (unsigned char *) dst;r
19、egister const unsigned char *s = (const unsigned char *) src;register int i;for (i = 0; i 6; i+)di = s5-i;int ba2str(const bdaddr_t *ba, char *str)uint8_t b6;baswap(bdaddr_t *) b, ba);return sprintf(str, %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X,b0, b1, b2, b3, b4, b5);struct termios options; pthread_t th
20、;int thread_flag;tcs_states tcs_state;unsigned char option;unsigned char command; unsigned char phonenumMAX_LEN+1 = 0; unsigned int phonenum_len; / for proceed from scratchunsigned char send_cmd50;unsigned char msgType;unsigned char* send_msg;struct sockaddr_l2 loc_addr=0, rem_addr = 0; / for l2capi
21、nt s;int result;int client;int bytes_read;char buf50;int opt = sizeof(rem_addr);char addr18;struct sockaddr_sco sco_loc_addr =0,sco_rem_addr=0; /for sco ;int sco_s;int sco_client;int sco_bytes_read;int sco_result;int sco_opt = sizeof(sco_rem_addr);extern int open_port(int fd, int comport);int fd;/*c
22、lean() : make a string empty*/void clean(char *s)int i=strlen(s);int j;for(j=0;ji;j+)*(s+j)=0;convert string to hexvoid string2hex(char *chr) /changed for form command_pic by ff 0720 int Length = strlen(chr); int i, n; char *tmp = chr; for ( i = 0; i Length; i+) *tmp -= 0x30;tmp+; int open_port(int
23、fd, int comport) char *dev=/dev/ttyS0,/dev/ttyS1,/dev/ttyS2; long vdisable; switch(comport) case 1: fd=open(/dev/ttyS0,O_RDWR|O_NOCTTY|O_NDELAY); break; case 2:fd=open(/dev/ttyS1,O_RDWR|O_NOCTTY|O_NDELAY); break; case 3:fd=open(/dev/ttyS2,O_RDWR|O_NOCTTY|O_NDELAY); break; case 4:fd=open(/dev/ttyS3,O
24、_RDWR|O_NOCTTY|O_NDELAY); break; case 5:fd=open(/dev/ttyS4,O_RDWR|O_NOCTTY|O_NDELAY); break; if(fd=-1) printf(open serial port %d failed!n,comport); return -1; if(fcntl(fd,F_SETFL,0)0) printf(fcntl failsn); else printf(fcntl=%dn,fcntl(fd,F_SETFL,0); if(isatty(STDIN_FILENO)=0) printf(standard input i
25、s not a terminal devicen); else printf(isatty successn); printf(fd-open=%dn,fd); return fd;int set_opt(int fd,int nSpeed, int nBits, char nEvent, int nStop) struct termios newtio,oldtio; if(tcgetattr(fd,&oldtio)!=0) perror(Setup Serial 1); return -1; bzero(&newtio, sizeof(newtio); newtio.c_cflag|=CL
26、OCAL|CREAD; newtio.c_cflag&=CSIZE;/setting stop bits switch(nBits) case 7: newtio.c_cflag|=CS7; break; case 8: newtio.c_cflag|=CS8; break; switch(nEvent) case O: newtio.c_cflag |= PARENB; newtio.c_cflag |= PARODD; newtio.c_iflag |= (INPCK|ISTRIP); break; case E: newtio.c_iflag|=(INPCK|ISTRIP); newti
27、o.c_cflag|=PARENB; newtio.c_cflag&=PARODD; break; case N: newtio.c_cflag &= PARENB; break; switch(nSpeed)case 9600: cfsetispeed(&newtio,B9600); cfsetospeed(&newtio,B9600); break; case 19200: cfsetispeed(&newtio,B19200); cfsetospeed(&newtio,B19200); break; case 38400: cfsetispeed(&newtio,B38400); cfs
28、etospeed(&newtio,B38400); break; case 57600: cfsetispeed(&newtio,B57600); cfsetospeed(&newtio,B57600); break;case 115200: cfsetispeed(&newtio,B115200); cfsetospeed(&newtio,B115200); break; /setting stop bits if(nStop=1) newtio.c_cflag&=CSTOPB; else newtio.c_cflag|=CSTOPB;/deng dai shi jian & min jie
29、shou fu newtio.c_ccVTIME=0; newtio.c_ccVMIN=0;/handle byes time+out tcflush(fd,TCIFLUSH);/activate newtio if( (tcsetattr(fd,TCSANOW,&newtio)!=0) perror(com set errorn); return -1; printf(set donen); return 0;*gw_add_scovoid gw_add_sco(void) debug(n=gw add sco=n); /allocate socket debug(Creating sco
30、socket.n); sco_s =socket(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_SCO); if(sco_s0) perror(create socket error); exit(1); else debug(creat sco socket success!n); sco_loc_addr.sco_family=AF_BLUETOOTH; sco_loc_addr.sco_bdaddr=*BDADDR_ANY; debug(Binding sco socket.n); sco_result=bind(sco_s,(struct sockaddr *
31、)&sco_loc_addr, sizeof(sco_loc_addr); if(sco_result0) perror(bind socket error:); exit(1); else debug(binding sco socket success!n); debug(Listen. ); sco_result=listen(sco_s,1); if(sco_result0) printf(error:%dn:,result); perror(listen error:); exit(1); else debug(gw sco requested!n); debug(Accepting
32、.n); sco_client= accept(sco_s,(struct sockaddr *)&sco_rem_addr,&sco_opt); if(sco_client0) perror(accept error); exit(1); else debug(gw accept sco OK!n); *EXPORT FUNCITON DEFINATION(FOR GATEWAY) void tcs_init(void) /unsigned char* addr; debug(n|= get tcs initialized =|n); debug(1) tcs init: opening l
33、2cap socket.n); /allocate socket s = socket(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_L2CAP); if(s 0) printf(create socket in gateway failed.n); exit(1); else debug( open socket success!n); /bind socket to port 0x1001 of the first available bluetooth adaptor loc_addr.l2_family = AF_BLUETOOTH; loc_addr.l2_
34、psm = htobs(0x1001); loc_addr.l2_bdaddr = *BDADDR_ANY; /ba2str(&loc_addr.l2_bdaddr,addr); ba2str(&(*BDADDR_ANY),addr); printf(local address is %sn,addr); debug(2) binding socket.n); result = bind(s,(struct sockaddr*)&loc_addr, sizeof(loc_addr); if(result 0) printf(bind socket error.n); close(s); exit(1); else debug( binding socket success!n); pri
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- GB/T 12417.1-2024無源外科植入物骨接合與關(guān)節(jié)置換植入器械第1部分:骨接合植入器械特殊要求
- 二零二五年度鋼材水泥市場調(diào)研與風(fēng)險評估合同2篇
- 二零二五年度變壓器節(jié)能補(bǔ)貼申請與使用合同范本3篇
- 二零二五版加工承攬合同全文詳盡規(guī)定承攬物、報(bào)酬及質(zhì)量標(biāo)準(zhǔn)3篇
- 二零二五版合伙人業(yè)務(wù)拓展合同范本3篇
- 二零二五年度貨物包裝合同范本3篇
- 2025年度森林防火物資儲備與供應(yīng)標(biāo)準(zhǔn)植樹承包合同示范文本3篇
- 2024版權(quán)轉(zhuǎn)讓合同轉(zhuǎn)讓價格及支付方式
- 2024版環(huán)保設(shè)備生產(chǎn)與安裝合同
- 二零二五年房產(chǎn)分割公證合同書3篇
- 河南省鄭州外國語高中-【高二】【上期中】【把握現(xiàn)在 蓄力高三】家長會【課件】
- 天津市武清區(qū)2024-2025學(xué)年八年級(上)期末物理試卷(含解析)
- 2025年中煤電力有限公司招聘筆試參考題庫含答案解析
- 企業(yè)內(nèi)部控制與財(cái)務(wù)風(fēng)險防范
- 高端民用航空復(fù)材智能制造交付中心項(xiàng)目環(huán)評資料環(huán)境影響
- 建設(shè)項(xiàng)目施工現(xiàn)場春節(jié)放假期間的安全管理方案
- 胃潴留護(hù)理查房
- 植物細(xì)胞中氨基酸轉(zhuǎn)運(yùn)蛋白的一些已知或未知的功能
- 山東省高等學(xué)校精品課程
- 三菱張力控制器LE-40MTA-E說明書
- 生活垃圾填埋場污染控制標(biāo)準(zhǔn)
評論
0/150
提交評論