[問題] 請問提取外部程式變數的問題

看板C_and_CPP (C/C++)作者 (kiwi90310)時間11年前 (2015/03/04 17:14), 11年前編輯推噓2(206)
留言8則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) 樹莓派(應該是Linux,但用C寫) 問題(Question): 不好意思第一次PO文 小弟接觸程式不久 想請問各位版上的高手一點問題 小弟主要是正在做BTdongle用藍芽連接2個HC-05來接收資料做運算 也在網路上找到程式碼如下 原本想把程式改成可以同時連接2個藍芽HC-05 但小弟程式太爛自己試了幾次沒成功 所以想說用&開2個背景程式 在用第三個程式去提取程式1和2的變數 想請問這樣的話是要用什麼函式或方法才可以呢? 餵入的資料(Input): 藍芽HC-05所送過來的字串資料 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <errno.h> #include <stdlib.h> #include <unistd.h> #include <bluetooth/bluetooth.h> #include <bluetooth/sdp.h> #include <bluetooth/sdp_lib.h> #include <sys/socket.h> #include <bluetooth/rfcomm.h> int main(int argc, char **argv) { struct sockaddr_rc addr = { 0 }; int status, len, rfcommsock; char rfcommbuffer[255]; //char dest[18] = "01:22:03:04:55:06"; // HC-05, slave, WORK!! char dest[18] = "10:14:07:10:29:52"; // allocate a socket rfcommsock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); // set the connection parameters (who to connect to) addr.rc_family = AF_BLUETOOTH; addr.rc_channel = 1; str2ba( dest, &addr.rc_bdaddr ); // connect to server status = connect(rfcommsock, (struct sockaddr *)&addr, sizeof(addr)); //------------------------------------------------------------------------------ // send/receive messages if( status == 0 ) { // say hello to client side status = send(rfcommsock, "hello!", 6, 0); if( status < 0 ) { perror( "rfcomm send " ); close(rfcommsock); return -1; } while(1) { btRecvHandle( rfcommsock, rfcommbuffer ); //------------------------------------- float l; l = atof(rfcommbuffer); printf("l = %f\n",l); //-------------------------------------- } } else if( status < 0 ) { perror("uh oh"); } close(rfcommsock); return 0; } 補充說明(Supplement): 感謝各位大大 抱歉忘了說 是要提取float l在第三個程式去做運算 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.125.20.81 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1425460493.A.4D5.html

03/04 17:27, , 1F
shared lib ?
03/04 17:27, 1F

03/04 17:28, , 2F
推錯 shared memory...
03/04 17:28, 2F

03/04 18:31, , 3F
shared memory, pipeline, 或者直接開一個file在tmp
03/04 18:31, 3F

03/04 18:31, , 4F
做資料傳遞之用,socket....方法滿多的
03/04 18:31, 4F

03/04 18:32, , 5F
藍牙位置要錯開
03/04 18:32, 5F

03/04 18:32, , 6F
用IPC當關鍵字找吧(Inter-Process Communication)
03/04 18:32, 6F

03/04 18:33, , 7F
傳資料沒問題,但無法傳音頻訊號
03/04 18:33, 7F
※ 編輯: kiwi90310 (140.125.20.81), 03/04/2015 18:41:47

03/30 17:06, , 8F
感謝各位大大的建議~
03/30 17:06, 8F
文章代碼(AID): #1KziqDJL (C_and_CPP)
文章代碼(AID): #1KziqDJL (C_and_CPP)