// // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++ ++ // +++++ When UwTerminal downloads the app it will store it as a filenname ++ // +++++ which consists of all characters up to the first . and excluding ++ // +++++ excluding it ++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // BT900.BEACON.sb // // This app provides for a command interface over the uart for testing SPP and // the protocol is as follows:- // //---------------------------------------------------------------------------- //**************************************************************************** // Global Variable Declarations //**************************************************************************** // GPIOBINDEVENT (EventNum(0..3), SIO_NR, Polarity) //------------------------------------------------------------------------ // Where SIO_NR On BT900 only can be SIO 0, 3, 5, 8, 13, 20 or 22. // And SIO0 and SIO3 can only be used as bind or assign events, // if they are not being used as UART pins, i.e. // that the UartClose() function has been called // and the UART has not been reopened. //------------------------------------------------------------------------ // Where Polarity // 0 - Low to high transition, // 1 - High to low transition, // 2 - Either a low to high or high to low transition //------------------------------------------------------------------------ // GPIOASSIGNEVENT EVDETECTCHAN(0..3) // SIO: 0, 3, 5, 8, 13, 20 or 22 // GpioSetFunc(SIO_xx, MainFunction, SubFunction) //----------------------------------------------- #define EVENTNUM0 0 #define EVENTNUM1 1 #define EVENTNUM2 2 #define EVENTNUM3 3 //------------------------------------- // MainFunction //------------------------------------- #define DIGITAL_IN 1 #define DIGITAL_OUT 2 #define ANALOG_IN 3 //--------------------------------------------------------- // SubFunction DIGITAL_IN //------------------------------------- #define D_IN_PU 2 // or 4 #define D_IN_WakeUpLow 0x10 // 16 #define D_IN_WakeUpHigh 0x20 // 32 #define D_IN_WakeUpCH 0x30 // 48 //--------------------------------------------------------- // SubFunction DIGITAL_OUT //------------------------------------- #define D_OUT_LOW 0 #define D_OUT_HIGH 1 #define D_OUT_PWM 2 #define D_OUT_FREQ 3 //---------------------------------------------------------------------------- // Defining SIO //------------------------------------- #define SIO_00 0 //PIN 44 SIO_00 DIO UART_RX or WKUP2 EVENT #define SIO_01 1 //PIN 45 SIO_01 DIO UART_TX #define SIO_02 2 //PIN 46 SIO_02 DIO UART_RTS #define SIO_03 3 //PIN 01 SIO_03 DIO UART_CTS or WKUP4 or Ext Interrupt #define SIO_04 4 //PIN 02 SIO_04 DIO #define SIO_05 5 //PIN 04 SIO_05 DIO Ext Interrupt EVENT #define SIO_06 6 //PIN 07 SIO_06 DIO SPI MISO #define SIO_07 7 //PIN 08 SIO_07 DIO SPI MOSI #define SIO_08 8 //PIN 09 SIO_08 DIO Ext Interrupt EVENT #define SIO_09 9 //PIN 10 SIO_09 DIO SPI CLK #define SIO_10 10//PIN 11 SIO_10 DIO I2C SDA #define SIO_11 11//PIN 12 SIO_11 DIO I2C SCL //---------------------------------------------------------------------------- // GPIO_BUZZER #define SIO_12 12//PIN 14 SIO_12 DIO FREQ or PWM //---------------------------------------------------------------------------- // GPIO_BTN0 13 #define SIO_13 13//PIN 15 SIO_13 DIO FREQ or PWM EVENT //---------------------------------------------------------------------------- #define SIO_14 14//PIN 17 SIO_14 DIO #define SIO_15 15//PIN 18 SIO_15 DIO #define SIO_16 16//PIN 19 SIO_16 DIO //---------------------------------------------------------------------------- // GPIO_LED0 17 #define SIO_17 17//PIN 20 SIO_17 DIO FREQ or PWM //---------------------------------------------------------------------------- // GPIO_LED1 18 #define SIO_18 18//PIN 21 SIO_18 DIO #define SIO_19 19//PIN 22 SIO_19 DIO VSP //---------------------------------------------------------------------------- // GPIO_BTN1, GPIO_TRIM_POT #define SIO_20 20//PIN 24 SIO_20 DIO AIN (ADC01) // or WKUP1 or Ext Interrupt EVENT //---------------------------------------------------------------------------- // GPIO_TEMP_SENSOR #define SIO_21 21//PIN 25 SIO_21 DIO AIN (ADC00) //---------------------------------------------------------------------------- #define SIO_22 22//PIN 03 SIO_22 nAutoRUN // or Ext Interrupt EVENT //---------------------------------------------------------------------------- #define EBTCAUTHKEYTYPE_NONE 0 #define EBTCAUTHKEYTYPE_PASSKEY 1 #define EBTCAUTHKEYTYPE_OOB 2 #define EBTCAUTHKEYTYPE_PIN 3 //**************************************************************************** // Definitions //**************************************************************************** //**************************************************************************** AssertBT900() //This is to make sure the application doesn't compile //if this sblib file is #included for the wrong module //**************************************************************************** #define GPIO_BUZZER 12 #define GPIO_LED0 17 #define GPIO_LED1 18 #define LED_DUR_TIMER 0 #define LED_INTVL_TIMER 1 dim n dim scale[7] dim text$[7] //**************************************************************************** //Default BT Friendly Name - name of device seen by other devices #define FRIENDLY_NAME "BT900.BEACON" dim beacon$ : beacon$ = "BEACON" //**************************************************************************** // Global Variable Declarations //**************************************************************************** //--------------------------------------------------------- #define DISCOV_TIMEOUT 120 //--------------------------------------------------------- //Number of connections #define NUM_OF_CONNS 8 //--------------------------------------------------------- //APP RUN MODES #define NORMAL_MODE 0 //CMD_MODE #define BRIDGE_MODE 1 //BRIDGE_SPP_MODE //--------------------------------------------------------- //Size of index_arr[] #define NUM_OF_I_PARAMS (5) //Size of str_arr$[] #define NUM_OF_S_PARAMS (5) //#define NUM_OF_SCAN 8 //--------------------------------------------------------- dim rc dim stRsp$ as string //Uart rx data is stored here dim ok$,er$,pr$, nc$, uc$, t$, e$, p$ dim index_arr[NUM_OF_I_PARAMS] //Index used for return values index_arr[5], str_arr$[5] dim str_arr$[NUM_OF_S_PARAMS] //Must be at least 8 elements dim ConnectionHandler[NUM_OF_CONNS+1]//Contains connection handles dim urtcmd$ //CMD line from uart dim tkn$,tlen //Used by command parser dim carCnt //Count variable for number of times '^' entered dim SppPortHandler //Handler of spp port that a peer will connect to dim SppConHandler //Handler of ssp connecction dim StreamBridgeHandler //Handler of UART sB bridge dim handler //Handler of other things dim buffer dim string_buffer$ //UART buffer dim index dim name$ //Local device name dim addr$ //Address of device being connected to dim fname$ dim mac$ dim devName$ dim RemoteName$ dim string$ dim NUM_OF_SCAN dim discoverable //--------------------------------------------------------- DIM arr_pointer DIM mac_array$[8] dim adr_array$[8] //------------------------------------- //Predefined array list //------------------------------------- mac_array$[0] = "0016A4707E25" mac_array$[1] = "0016A4707F0E" mac_array$[2] = "0016A4707BFF" mac_array$[3] = "0016A4707E31" mac_array$[4] = "0016A4707C06" mac_array$[5] = "0016A41313A3" mac_array$[6] = "0016A40FBEEB" //Module //------------------------------------- dim module$ module$ = "0016A40FBEEB" dim board$ board$ = "0016A4707F0E" //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- #define UART_BAUDRATE (115200) //---------------------------------------------------------------------------- // Inquiry config parameters (See description for BtcInquiryConfig() // in BT900 Extention user manual) #define INQR_TMT 30 //Inquiry timeout in seconds #define INQR_TYPE 0 //Inquiry type - general inquiry #define INQR_MODE 2 //Inquiry mode - extended inquiry #define MAX_DEVS_REC_RESP 100 //Max number of devices to receive //inquiry responses //---------------------------------------------------------------------------- dim Response$ //**************************************************************************** //**************************************************************************** // Initialisse Global Variable //**************************************************************************** index = 0 string_buffer$ = "" Response$ = "Here I am\n" discoverable = 0 NUM_OF_SCAN = 8 //============================================================================ //---------------------------------------------------------------------------- // Display the error message //---------------------------------------------------------------------------- sub AssertRc(ResCode) if (rc < 0)|| (rc > 1) then print "error: ";integer.h' ResCode;"\n" endif endsub //---------------------------------------------------------------------------- //============================================================================ //---------------------------------------------------------------------------- // For debugging // --- rc = result code // --- ln = line number //---------------------------------------------------------------------------- Sub AssertRCLn(rc,ln) if (rc < 0)|| (rc > 1) then print "\nFail :";integer.h' rc;" at line: ";ln; "\n" //else //print "\nOk: line ";ln endif EndSub //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // For debugging // --- rc = result code // --- ln = line number //---------------------------------------------------------------------------- Sub AssertRcStr(rc, byval str$ ) if (rc < 0)|| (rc > 1) then print "\nFail :";integer.h' rc;" with msg: ";str$; "\n" //else //print "\nOk: line ";ln endif EndSub //---------------------------------------------------------------------------- // For debugging // --- rc = result code // --- ln = line number //---------------------------------------------------------------------------- Sub AssertStrRc(byval str$,rc ) if (rc < 0)||(rc > 1) then print "Fail: ";str$; " with :";integer.h'rc; "\n" endif EndSub //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // For debugging // --- rc = result code // --- ln = line number //---------------------------------------------------------------------------- sub UartRsp(rsp as integer) if rsp == 0 then print ok$;pr$ elseif rsp == -2 then print pr$ elseif rsp == -3 then print ok$ elseif rsp == -4 then print uc$;pr$ elseif rsp > 0 then print er$;integer.h' rsp;pr$ endif endsub //---------------------------------------------------------------------------- function ExtractIntTokens(string_buffer$,stIdx,num) while num>0 tlen = ExtractIntToken(string_buffer$,index_arr[stIdx]) if tlen == 0 then exitfunc 4 endif num=num-1 stIdx = stIdx+1 endwhile endfunc 1 //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- function ExtractStrTokens(string_buffer$,stIdx,num) while num>0 tlen = ExtractStrToken(string_buffer$,str_arr$[stIdx]) if tlen == 0 then exitfunc 3 endif num=num-1 stIdx = stIdx+1 endwhile endfunc 1 //---------------------------------------------------------------------------- //------------------------------------------------------------------------- // Process a carrat character ^ do decide whether or not to switch to command mode // - When the carCnt value is 3, end func with 1 to switch to command mode // - Think of it like a boolean value //------------------------------------------------------------------------- function SwitchToCmd() //If ^ was sent after the delay time (valid) increment the counter if TimerRunning(0)==0 then carCnt = carCnt + 1 if carCnt<3 then TimerStart(0,1000,0) else exitfunc 1 endif else //Invalid press TimerCancel(0) carCnt = 0 endif endfunc 1 //Don't give response to user //------------------------------------------------------------------------- //============================================================================ // TURN GPIO LED0 ON //============================================================================ function TURN_GPIO_LED0_ON() as integer print "TURN_GPIO_LED0_ON Begin \n" GpioWrite(GPIO_LED0, 1) print "TURN_GPIO_LED0_ON End \n" endfunc 1 //Don't give response to user //============================================================================ //============================================================================ // TURN GPIO LED0 ON //============================================================================ function TURN_GPIO_LED0_Off() as integer print "TURN_GPIO_LED0_Off Begin \n" GpioWrite(GPIO_LED0, 0) print "TURN_GPIO_LED0_Off End \n" endfunc 1 //Don't give response to user //============================================================================ //============================================================================ // AT I 2003 -> 8 (0-7) antal timere //============================================================================ function HandlerTimer6() print "Timer 6, has expired."; "\n" endfunc 0 //============================================================================ //============================================================================ // AT I 2003 -> 8 (0-7) antal timere //============================================================================ SUB timer_7(time) PRINT "\nWait Begin\n" PRINT integer.h'time;"\n" TimerStart(7,time,0) while TimerRunning(7) !=0 endwhile PRINT "Waiting for timer 7 is Over\n" ENDSUB //============================================================================ //============================================================================ // AT I 2003 -> 8 (0-7) antal timere //============================================================================ SUB timer_6(time) PRINT "\nWait Begin\n" TimerStart(6,time,0) ONEVENT EVTMR6 CALL HandlerTimer6 WAITEVENT PRINT "\nWaiting is Over\n" ENDSUB //============================================================================ //============================================================================ //============================================================================ // Initialise all connection handles //============================================================================ sub InitConnHandles() dim z for z=0 to (NUM_OF_CONNS) ConnectionHandler[z]=-1 next endsub //============================================================================ //============================================================================ // Initialise all connection handles //============================================================================ sub ResetAddrArray() dim z for z=0 to (7) //0601: RUN_INDEX_TOO_LARGE: //The array index provided is too large for the array. adr_array$[z]= "" next endsub //============================================================================ //============================================================================ // Add the connection handle to the list of connection handles //============================================================================ function AcqConnHandle(hConn) dim z for z=1 to (NUM_OF_CONNS) if ConnectionHandler[z] == -1 then ConnectionHandler[z]=hConn exitfunc z endif next endfunc 1 //============================================================================ //============================================================================ function exit() as integer print "function exit()\n" endfunc 1 //============================================================================ //============================================================================ FUNCTION HandlerTimer0() PRINT "\nTimer 0 has expired\n" endfunc 1 //remain blocked in WAITEVENT //============================================================================ //============================================================================ FUNCTION HandlerTimer1() as integer PRINT "\nTimer 1 has expired \n" endfunc 1 //remain blocked in WAITEVENT //============================================================================ //============================================================================ // TIMERRUNNING (number) TIMERCANCEL (number) //============================================================================ FUNCTION StartTimer0(time, reuse) PRINT "\nStart Timer 0 \n" // A valid time in milliseconds, between 1 and 1,000,000,000 (11.6 days). // reuse AS INTEGER // Set to 0 for a once-only timer // Set to 1 for reuse timer. //TimerStart( Timer-number, interval_ms, repeat) TimerStart(0,time,reuse) PRINT "\nWaiting for Timer 0 \n" endfunc 1 //remain blocked in WAITEVENT //============================================================================ //============================================================================ // TIMERRUNNING (number) TIMERCANCEL (number) //============================================================================ FUNCTION StartTimer1(time, reuse) PRINT "\nStart Timer 1 \n" TimerStart(1,time,reuse) PRINT "\nWaiting for Timer 1 \n" endfunc 1 //remain blocked in WAITEVENT //============================================================================ //============================================================================ FUNCTION HandlerTimerRescan() as integer PRINT "\nTimer 1 has expired \n" if StrLen(mac$) == 0 then //rc = scan() endif PRINT "\nHandlerTimerRescan Return \n" endfunc 1 //remain blocked in WAITEVENT //============================================================================ //============================================================================ // Find out whether in a connection or not = think of it like a boolean //============================================================================ function InConnection() print "InConnection() Begin \n" dim bdAddr$ //Will fail if invalid handle - no connection if BtcGetBDAddrFromHandle(SppPortHandler,bdAddr$)!=0 then exitfunc -1 endif //Length of 'bdAddr$' will be zero if no connection if StrLen(bdAddr$)==0 then exitfunc -1 endif print "InConnection() End \n" endfunc 1 //============================================================================ //============================================================================ // Called after a pairing attempt //============================================================================ function HandlerAuthReq(reqType) print "Authentication type: " if reqType == EBTCAUTHKEYTYPE_NONE then print "NONE\n" elseif reqType == EBTCAUTHKEYTYPE_PASSKEY then print "PASSKEY\n" elseif reqType == EBTCAUTHKEYTYPE_OOB then print "OOB\n" elseif reqtype == EBTCAUTHKEYTYPE_PIN then print "PIN\n" else print "UNKNOWN\n" endif endfunc 1 //============================================================================ //============================================================================ // //============================================================================ sub sound() GpioWrite(GPIO_BUZZER,scale[n]) endsub //============================================================================ //============================================================================ // //============================================================================ sub quit() timercancel(0) GpioWrite(GPIO_BUZZER,0) endsub //============================================================================ //============================================================================ // //============================================================================ FUNCTION HandlerBuzTimer0() as integer n=n+1 if n>6 then quit() // Print "\nExit HandlerBuzTimer app\n" EXITFUNC 0 else sound() //Print text$[n];"\n" endif endfunc 1 //============================================================================ //============================================================================ // //============================================================================ function buzzer() // as integer print "Begin of Buzzer\n" scale[0] = 262 //Do scale[1] = 294 //Re scale[2] = 330 //Mi scale[3] = 349 //Fa scale[4] = 392 //So scale[5] = 440 //La scale[6] = 494 //Si text$[0] = "Do" text$[1] = "Re" text$[2] = "Mi" text$[3] = "Fa" text$[4] = "So" text$[5] = "La" text$[6] = "Si" rc=GpioSetFunc(GPIO_BUZZER,2,3) //Configure the SIO for the buzzer // print "\n\n" TIMERSTART(0,500,1) n=0 sound() //Print text$[n];"\n" ONEVENT EVTMR0 CALL handlerBuzTimer0 WAITEVENT print "End of Buzzer\n" endfunc 1 //============================================================================ //============================================================================ //#CMD#// ath OR disconnect //============================================================================ function disconnect() as integer print "function disconnect()\n" //rc=BtcInquiryCancel() //AssertRcStr(rc, "BtcInquiryCancel") //------------------------------------------------------------------------ rc = BtcSppClose(SppPortHandler) AssertStrRc("BtcSppClose with SppPortHandler in disconnect()", Rc) print "BtcSppClose(SppPortHandler): ";integer.h'SppPortHandler; "\n" //------------------------------------------------------------------------ rc = BtcSppDisconnect(SppConHandler)//SppConHandler AssertStrRc("BtcSppDisconnect in disconnect()", Rc) print "BtcSppDisconnect(with SppConHandler): ";integer.h'SppConHandler; "\n" SppConHandler = 0 SppPortHandler = 0 //------------------------------------------------------------------------ rc = BtcSetDiscoverable(1, DISCOV_TIMEOUT) AssertStrRc("BtcSetDiscoverable in disconnect()", Rc) if rc!=0 then print "BtcSetDiscoverable(FAIL)\n" exitfunc rc endif //------------------------------------------------------------------------ print "End of disconnect()\n" endfunc -3 //Don't give response to user //============================================================================ //============================================================================ //#CMD#// at+bti OR inquiry //============================================================================ function Scan() as integer print "Scan Begin \n" dim ret if discoverable == 0 then rc = BtcInquiryStart(INQR_TMT)//30s AssertStrRc("Scan(): ", rc) endif print "scan(ENDIF) \n" // // 5701: BTC_ALREADY_INQUIRING: // A classic Bluetooth inquiry is already in progress // // 6339: BTS_SS1_ERROR_INVALID_MODE: // The specified mode for the Bluetooth stack is not valid. // //------------------------------------------------------------------------ // rc = BtcInquiryStart(INQR_TMT) // AssertRc(rc) //------------------------------------------------------------------------ //BtcInquiryGetReport(addr$, inqData$, nDiscarded, nRssi) // //When an inquiry is in progress (after having called BtcInquiryStart() //for report), the information is cached in a queue buffer and a //EVINQRESP event is thrown to the smartBASIC application. //This function is used by the smartBASIC application to extract it from //the queue for further processing in the handler for the EVINQRESP event. //------------------------------------------------------------------------ print "Scan End \n" endfunc 1 //Don't give response to user //============================================================================ //============================================================================ // rfcomm connect //============================================================================ function rfcommConnect(byval mac_addr$) as integer print "rfcommConnect Begin \n" rc=BtcInquiryCancel() AssertStrRc("BtcInquiryCancel in RfcommConnect",rc) //Connect to SPP device rc = BtcSppConnect(mac_addr$) AssertStrRc("BtcSppConnect",rc) //---------------------------------------------------------------------------- // Possible error's: // 5701: BTC_ALREADY_INQUIRING: // A classic Bluetooth inquiry is already in progress // 5706: BTC_INV_MAC_ADDRESS: // The specified Bluetooth address is not valid. //---------------------------------------------------------------------------- if rc == 0 then print "Connecting to ";StrHexize$(mac_addr$); " \n" else print "Not Connecting ... \n" endif rc = BtcGetPairRequestBDAddr(mac$) print "rfcommConnect End\n" endfunc 1 //============================================================================ //============================================================================ // This is my attemp to send message //============================================================================ function HandleSendingMessage(byval message$) //------------------------------------- dim len //------------------------------------------------------------------- print "HandleSendingMessage Begin \n" len = strlen(message$) rc=BtcSppWrite(SppConHandler, message$, len) AssertStrRc("BtcSppWrite in HandleSendingMessage()",rc) if rc==0 then print "Wrote ";len;" bytes: ";message$; "\n" else print "Error: "; integer.h'rc ; "\n" endif print "HandleSendingMessage End \n" //------------------------------------------------------------------- //------------------------------------------------------------------- endfunc 1 //============================================================================ //============================================================================ // This handler is called when there at least one inquiry response waiting to // be read //============================================================================ function HandlerInqResp(respType) as integer print "\n--------------------------------\n" print "HandlerInqResp Begin \n" dim ad$,dta$,rsi,nme$,ndx, temp$ index = 0 //rc=BtcInquiryCancel() //---------------------------------------------------------WHILE..B while BtcInquiryGetReport(ad$,dta$,ndx,rsi)==0 //Get and print name of device //rc = BtcGetEIRByTag(dta$,0x09,nme$) //print "Inquiry result: "; StrHexize$(ad$), rsi, nme$; "\n" print "Inquiry result: "; StrHexize$(ad$); "\n" temp$ = StrHexize$(ad$) //------------------------------------------------------------------- print "Examine a match: "; temp$; "\n" //---------------------------------------------------------FOR..POINTER.B for arr_pointer = 0 to 6 //---------------------------------------------------------FOR.. //if StrPos(temp$, module$,0) >= 0 then if Strcmp(temp$, mac_array$[arr_pointer]) == 0 then print "Found a match: "; temp$; "\n" index = index +1 BREAK endif print "arr_pointer = "; arr_pointer //---------------------------------------------------------FOR.. next //---------------------------------------------------------FOR..POINTER.E if index > 0 then BREAK endif //--------------------------------------------------------- endwhile //---------------------------------------------------------WHILE..E print "index = "; index; "\n" //--------------------------------------------------------- if index > 0 then rc = rfcommConnect(ad$) AssertStrRc("rfcommConnect()",rc) mac$ = "" endif //--------------------------------------------------------- print "HandlerInqResp End\n" print "--------------------------------\n\n" endfunc 1 //============================================================================ //============================================================================ // //============================================================================ function OnUartCmd() as integer print "\n----OnUartCmd Begin----\n" rc = -2 //Assume there is no error tlen = ExtractStrToken(urtcmd$,tkn$) //Get first token //---------------------------------------------------------------------------- if tlen > 0 then //---------------------------------------------------------------------------- if strcmp(tkn$,"at")==0 then // rc = _at() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"reset")==0 then reset(0) //---------------------------------------------------------------------------- elseif strcmp(tkn$,"spp")==0 then // rc = _spp() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"atd")==0 || strcmp(tkn$,"connect")==0 then // rc = _connect() //---------------------------------------------------------------------------- elseif StrCmp(tkn$,"ato")==0 || StrCmp(tkn$,"bridge")==0 then // _bridge() // rc = -1 //Don't give response to user //---------------------------------------------------------------------------- elseif strcmp(tkn$,"at+btd")==0 then // rc = _delete() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"inquiry")==0 then // rc = _inquiry() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"pair")==0 then // rc = _pair() //---------------------------------------------------------------------------- elseif StrCmp(tkn$,"ato")==0 || StrCmp(tkn$,"bridge")==0 then print "OnUartCmd: Now in BRIDGE_MODE \n" rc = SendMsgApp(0,BRIDGE_MODE) AssertStrRc("SendMsgApp in OnUartCmd() ",rc) rc = -1 //Don't give response to user //---------------------------------------------------------------------------- elseif StrCmp(tkn$,"ath")==0 || StrCmp(tkn$,"disconnect")==0 then // rc = _disconnect() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"misc")==0 then // rc = _misc() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"stop")==0 then rc = BtcInquiryCancel() //---------------------------------------------------------------------------- elseif strcmp(tkn$,"quit")==0 || strcmp(tkn$,"exit")==0 then rc = BtcSppDisconnect(SppConHandler) AssertStrRc("BtcSppDisconnect OnUartCmd()",rc) //Fail: BtcSppDisconnect OnUartCmd() with :00005708 // 5708: BTC_SPP_INV_HANDLE: // The supplied SPP handle is not valid. rc = BtcSppClose(SppPortHandler) AssertStrRc("BtcSppClose in OnUartCmd()" ,rc) //Fail: BtcSppClose in OnUartCmd() with :00005708 exitfunc 0 //---------------------------------------------------------------------------- elseif strcmp(tkn$,"setdiscoverable")==0 then //Extract 2 : (#INTenable# #INTtimeout#) and store starting at index_arr[1] rc = ExtractIntTokens(urtcmd$,1,2) if rc != 0 then exitfunc rc endif rc = BtcSetDiscoverable(index_arr[1], index_arr[2]) print "BtcSetDiscoverable: "; integer.h'index_arr[1]; " and "; integer.h'index_arr[2]; AssertRc(rc) //---------------------------------------------------------------------------- elseif strcmp(tkn$,"setpairable")==0 then //Extract 1 : (#INTenable#) and store starting at index_arr[1] rc = ExtractIntTokens(urtcmd$,1,1) if rc != 0 then exitfunc rc endif rc = BtcSetPairable(index_arr[1]) AssertStrRc("BtcSetPairable",rc) //---------------------------------------------------------------------------- elseif strcmp(tkn$,"bdaddr")==0 then str_arr$[1] = SysInfo$(4) StrShiftLeft(str_arr$[1],1) print "\n";StrHexize$(str_arr$[1]) endif //---------------------------------------------------------------------------- endif //---------------------------------------------------------------------------- //Send a response back to the user UartRsp(rc) print "\n----OnUartCmd End----\n" endfunc 1 //============================================================================ //============================================================================ // This handler is called when there is an inquiry timeout //============================================================================ function HandlerBtcInqTimOut() as integer print "Handler inquiry timeout() \n" print "This handler is called when there is an inquiry timeout \n" print "End of Handler inquiry timeout() \n" endfunc 1 //============================================================================ //============================================================================ // Called on a PIN request from another device //============================================================================ function HandlerPinReq() print "HandlerPinReq Begin \n" // BtcGetPINRequestBDAddr(strBDAddr$) strBDAddr$ AS STRING // On return, this string contains the Bluetooth address of the device requesting a PIN. // Get the Bluetooth address of the device requesting a pairing using Legacy PIN. rc = BtcGetPinRequestBDAddr(addr$) AssertStrRc("BtcGetPinRequestBDAddr",rc) if rc==0 then print "\nPIN requested from device: "; StrHexize$(mac$) ; " \n" print "\nSending PIN respose with PIN '1234'" ; " \n" rc = BtcSendPINResp("1234") AssertRc(rc) else print "\nErr: "; integer.h'rc ; " \n" endif // BtcGetPINRequestBDAddr(strBDAddr$) strBDAddr$ AS STRING // On return, this string contains the Bluetooth address of the device requesting a PIN. // Get the Bluetooth address of the device requesting a pairing using Legacy PIN. rc = BtcBondingEraseKey(addr$) //Erase link key for this bluetooth //device incase already bonded with it AssertStrRc("BtcBondingEraseKey",rc) print "PIN Req: "; StrHexize$(addr$); " \n" // UartFlush(1) //Flush the uart rx buffer // onevent evuartrx call exit//call HandlerUartRxPIN //------------------------------------------------------------------- print "HandlerPinReq End \n" //------------------------------------------------------------------- endfunc 1 //============================================================================ //============================================================================ // Called after a pairing attempt //============================================================================ function HandlerPairRes(pair_result) dim my_mac$ print "\n--------------------------------\n" print "HandlerPairRes Begin \n" //------------------------------------------------------------------- if pair_result == 0 then // BtcGetPINRequestBDAddr(strBDAddr$) strBDAddr$ AS STRING // On return, this string contains the Bluetooth address of the device requesting a PIN. // Get the Bluetooth address of the device requesting a pairing using Legacy PIN. rc = BtcGetPAIRRequestBDAddr(my_mac$) //rc = BtcGetPinRequestBDAddr(my_mac$) AssertStrRc("BtcGetPAIRRequestBDAddr",rc) print "Pair request from device: "; StrHexize$(my_mac$); " \n" //------------------------------------------------------------------- else print "--- Pairing attempt error: (";integer.h'pair_result;") \n" endif //------------------------------------------------------------------- print "HandlerPairRes End \n" print "--------------------------------\n" endfunc 1 //============================================================================ //============================================================================ // Called after an SPP connection attempt //============================================================================ function HandlerSppConn(hConn, result) as integer //------------------------------------------------------------------- print "HandlerSppConn Begin \n" //------------------------------------------------------------------- dim port_handler, remote_mac$ dim len //------------------------------------------------------------------- if result == 0 then //------------------------------------------------------------------- SppConHandler = hConn //print "HandlerSppConn: Now in BRIDGE_MODE \n" //rc = SendMsgApp(0,BRIDGE_MODE) //AssertStrRc("SendMsgApp in HandlerSppConn()",rc) //Set not discoverable or connectable to prevent multiple connections //------------------------------------------------------------------- //rc = BtcInquiryCancel() rc = BtcSetDiscoverable(0,DISCOV_TIMEOUT) AssertStrRc("BtcSetDiscoverable in HandlerSppConn()",rc) rc = BtcSetConnectable(0) AssertStrRc("BtcSetConnectable in HandlerSppConn()",rc) //------------------------------------------------------------------- //Now we are getting somewhere rc = BtcGetBDAddrFromHandle(SppConHandler,remote_mac$) AssertStrRc("BtcGetBDAddrFromHandle in HandlerSppConn()",rc) print "--- Successfully Connected to Remote device: ";strhexize$(remote_mac$); "\n" //------------------------------------------------------------------- print "BtcQueryRemoteFriendlyName \n" rc = BtcQueryRemoteFriendlyName(remote_mac$) AssertStrRc("BtcQueryRemoteFriendlyName in HandlerSppConn()",rc) //------------------------------------------------------------------- endif // result //------------------------------------------------------------------- rc = Turn_GPIO_LED0_On() AssertStrRc("Turn_GPIO_LED0_ON in HandlerSppCon",rc) //------------------------------------------------------------------- print "HandlerSppConn End \n" endfunc 1 //============================================================================ //============================================================================ // Called when a connection attempt to an SPP device times out //============================================================================ function HandlerSppConnTimOut() as integer print "\n--SPP Conn Attempt Timeout\n\n" endfunc 1 //============================================================================ //============================================================================ // Called when data is received via SPP //============================================================================ function HandlerSppData() print "\n--------------------------------\n" print "HandlerSppData Begin\n" //--------------------------------------------------------- //When receiving SPP data just print it to terminal dim hPort, data$, rLen ,exit$ exit$ = "exit" //Read and print data while there is data available to read while BtcSppRead(hPort, data$, rLen) == 0 if rLen>0 then print "BtcSppRead:\n"; data$; "\n" endif endwhile //--------------------------------------------------------- rc = HandleSendingMessage("OK") AssertStrRc("Send Message in HandlerSppData()", rc) //--------------------------------------------------------- if rc == 0 then rc = disconnect() endif //--------------------------------------------------------- print "HandlerSppData End\n" print "--------------------------------\n\n" endfunc 1 //============================================================================ //============================================================================ // //============================================================================ function HandlerRemoteName(nStatus) PRINT "HandlerRemoteName Begin \n" //--------------------------------------------------------- // // BTCGETREMOTEFRIENDLYNAME(address$, name$, nStatus) // byREF address$ AS STRING: // Address of the remote device that the refiendly name relates to. // Returned from the query. // name$ byREF name$ AS STRING // Friendly name of the remote device, returned from the query. // nStatus byREF nStatus AS INTEGER // Status code of the query. // The name string is only valid on a success status of 0. //--------------------------------------------------------- dim raddress$, rname$, stat // is nStatus valid? if (nStatus == 0) then //rc = BtcGetRemoteFriendlyName(address$, name$, nStatus)//pdf //Manual code: rc = BtcGetRemoteFriendlyName(rname$, raddress$, stat) endif PRINT "HandlerRemoteName: ";rname$;" \n" PRINT "HandlerRemoteAddr: ";strhexize$(raddress$);" \n" //--------------------------------------------------------- // nIndex = nIndex + 1 // if (nIndex < 10) & (StrLen(addr$[nIndex]) == 6) then // rc = BtcQueryRemoteFriendlyName(addr$[nIndex]) // nContinue = 1 // else // nCOntinue = 0 // endif //--------------------------------------------------------- // if strcmp(RemoteName$,rname$)==0 then // print "Remote Name is accepted. \n" // // print "EVBTC_SPP_DATA_RECEIVED is active \n" // else // print "Remote Name is not recognized. \n" // //exitfunc 0 // endif //--------------------------------------------------------- // rc = disconnect() // AssertstrRc("Trying to disconnect in HandlerRemoteName", rc) PRINT "HandlerRemoteName End \n" endfunc 1 //============================================================================ //============================================================================ // This handler is called when data has arrived at the serial port //============================================================================ function HandlerUartRx() as integer print "\nHandlerUartRx Begin\n" dim nMatch : nMatch = 0 //Check if CR has been received nMatch=UartReadMatch(stRsp$,13) if nMatch!=0 then //CR exists in the input buffer urtcmd$ = strsplitleft$(stRsp$,nMatch) print "exitfunc\nHandlerUartRx End \n" exitfunc OnUartCmd() endif print "HandlerUartRx End \n" endfunc 1 //============================================================================ //============================================================================ // Called when data is received via UART when bridged to SPP //============================================================================ function HandlerUartRxSpp() print "HandlerUartRxSpp Begin \n" dim uLen, wLen if buffer ==0 then //Read data that has arrived through dia the UART uLen = UartRead(string_buffer$) print "HandlerUartRxSpp(-UartRead-)\n" if uLen > 0 then if StrCmp(string_buffer$,"^")==0 then //Parse the ^ entry if SwitchToCmd() == 1 then print "SwitchToCmd(-1-)\n" rc = SendMsgApp(0,NORMAL_MODE) AssertStrRc("SendMsgApp in HandlerUartRxSpp()", rc) endif else //Write data to most recent spp connection print "HandlerUartRxSpp(-BtcSppWrite-) \n" rc = BtcSppWrite(SppConHandler, string_buffer$, wLen) AssertStrRc("BtcSppWrite in HandlerUartRxSpp()", rc) if wLen != uLen then buffer = 1 strshiftleft(string_buffer$,wLen) else string_buffer$ = "" endif endif endif endif print "HandlerUartRxSpp End \n" endfunc 1 //============================================================================ //============================================================================ // Called when txbuffer is empty //============================================================================ function HandlerSppTxEmpty(i) print "HandlerSppTxEmpty Begin \n" dim Read_Length, Write_Length if buffer == 1 then print "buffer == 1\n" Read_Length = strlen(string_buffer$) rc = BtcSppWrite(SppConHandler, string_buffer$, Write_Length) AssertstrRc("BtcSppWrite in HandlerSppTxEmpty(First)", rc) //--------------------------------------------------------- if Write_Length != Read_Length then //--------------------------------------------------------- buffer = 1 //Remove the first Write_Length char of string stringbuffer strshiftleft(string_buffer$,Write_Length) else buffer=0 string_buffer$ = "" Read_Length = UartRead(string_buffer$) //--------------------------------------------------------- if Read_Length > 0 then //--------------------------------------------------------- rc = BtcSppWrite(SppConHandler, string_buffer$, Write_Length) AssertstrRc("BtcSppWrite in HandlerSppTxEmpty(Second)", rc) //--------------------------------------------------------- if Write_Length != Read_Length then buffer = 1 strshiftleft(string_buffer$,Write_Length) else string_buffer$="" endif //--------------------------------------------------------- endif //if Read_Length > 0 then //--------------------------------------------------------- endif //if Write_Length //--------------------------------------------------------- else //if buffer == 1 //--------------------------------------------------------- rc = HandlerUartRxSpp() AssertStrRc("HandlerSppTxEmpty", rc) //--------------------------------------------------------- endif //if buffer == 1 //--------------------------------------------------------- rc=BtcSppDisconnect(SppConHandler) if rc==0 then print "\nDisconnecting...\n" else print "\nError:", integer.h'rc endif //--------------------------------------------------------- print "HandlerSppTxEmpty End\n" //--------------------------------------------------------- endfunc 1 //============================================================================ //============================================================================ //============================================================================ // Initialise the Bluetooth device // Set the device to be discoverable, connectible, pairable, // Set the inquiry type to be general, inquiry mode to be extended //============================================================================ sub InitBtDevice() print "InitBtDevice Begin \n" //dim SppPortHandler //Set device name //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Get the device's bdaddr and display it in hex format dim local_name$ : local_name$ = SYSINFO$(4) local_name$ = right$(local_name$, 6) local_name$ = StrHexize$(local_name$) print "This Address: "; local_name$; "\n" print "Configure classic BT radio \n" // Configure classic BT radio //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Set device is discoverable with 300s discoverability timeout // nTimeout AS INTEGER // The length of time in seconds that the module is discoverable. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ rc = BtcSetDiscoverable(1, DISCOV_TIMEOUT) //1 – Discoverable //rc = (0, 000) //0 – Not discoverable,time ignored AssertStrRc("BtcSetDiscoverable", rc) //Set device to be connectable rc = BtcSetConnectable(1) AssertStrRc("BtcSetConnectable", rc) //Set the device to be pairable rc = BtcSetPairable(1) AssertStrRc("BtcSetPairable", rc) //Save subsequent pairings -bond rc = BtcSavePairings(1) AssertStrRc("BtcSavePairings", rc) //Set inquiry type to be general //Inquiry Type (0 for General Inquiry, 1 for Limited Inquiry) rc = BtcInquiryConfig(0,INQR_TYPE)//0 AssertStrRc("BtcInquiryConfig 0", rc) //Set inquiry mode to be extended //Inquiry Mode (0 for Standard, 1 for with RSSI, 2 for Extended) rc = BtcInquiryConfig(1,INQR_MODE)//2 AssertStrRc("BtcInquiryConfig 1", rc) //Max number of inquiry responses to receive (Range is from 0-255) rc = BtcInquiryConfig(2,MAX_DEVS_REC_RESP)//100 AssertStrRc("BtcInquiryConfig 2", rc) //3 Inquiry Tx Power (Range is from -70 to 20 dBm) not used //------------------------------------------------------------------------ // Open Spp rc = btcSppOpen(SppPortHandler)//SppPortHandler AS INTEGER // On return this will contain the handle for the SPP service. AssertStrRc("btcSppOpen", rc) print "btcSppOpen(SppPortHandler): ";integer.h' SppPortHandler;"\n" //------------------------------------------------------------------------ // 0 None; also known as Just Works (unauthenticated pairing) // 1 Display with Yes/No input capability (authenticated pairing) // 2 Keyboard Only (authenticated pairing) // 3 Display Only (authenticated pairing – if other end has input cap) // Set the IO capability to Just works print "Set the IO capability to Just works \n" rc = BtcSecMngrIoCap(0) AssertStrRc("BtcSecMngrIoCap", rc) //------------------------------------------------------------------------ // Set the JustWorks configuration to 0 so that pairing works by itself // using BtcSendPAIRResp to respond. rc = BtcSecMngrJustWorksConf(0) AssertStrRc("BtcSecMngrJustWorksConf", rc) //------------------------------------------------------------------------ //Send user prompt for uart based command interface UartRsp(0) //------------------------------------------------------------------------ print "InitBtDevice End \n" endsub //============================================================================ //============================================================================ // //============================================================================ function DiscoveryConfig() print "DiscoveryConfig Begin \n" rc=BtcDiscoveryConfig(0,0) //general AssertStrRc("BtcDiscoveryConfig 0", rc) rc=BtcDiscoveryConfig(1,0x320) //inquiry scan interval of 500ms (0x0320) AssertStrRc("BtcDiscoveryConfig 1", rc) rc=BtcDiscoveryConfig(2,0x190) //inquiry scan interval of 250ms (0x0190) AssertStrRc("BtcDiscoveryConfig 2", rc) print "DiscoveryConfig End \n" endfunc 1 //============================================================================ // //============================================================================ //============================================================================ // This is the first subroutine called when the program starts //============================================================================ sub Initialise() print "Initialise Begin \n" // Setup print "Friendly name: "; FRIENDLY_NAME; "\n" rc = BtcSetFriendlyName(FRIENDLY_NAME) AssertStrRc("BtcSetFriendlyName in App",rc) //------------------------------------------------------------------------ //------------------------------------------------------------------------ //Configure the SIO for the LED0 rc=GpioSetFunc(GPIO_LED0, DIGITAL_OUT, D_OUT_HIGH) AssertStrRc("GpioSetFunc(GPIO_LED0, DIGITAL_OUT, D_OUT_HIGH)",rc) GpioWrite(GPIO_LED0, 0) rc=GpioSetFunc(GPIO_LED1, DIGITAL_OUT, D_OUT_HIGH) AssertStrRc("GpioSetFunc(GPIO_LED1, DIGITAL_OUT, D_OUT_HIGH)",rc) GpioWrite(GPIO_LED1, 0) //--------------------------------------------------------- //rc=GpioSetFunc(GPIO_LED0, 2, 1) //GpioWrite(GPIO_LED0, 0) //rc = GpioWrite(GPIO_LED0, 1) //AssertStrRc("GpioWrite in Initialise()" ,rc) //rc = TimerCancel(LED_DUR_TIMER) //AssertStrRc("TimerCancel in Initialise()" ,rc) //rc = TimerCancel(LED_INTVL_TIMER) //AssertStrRc("TimerCancel in Initialise()" ,rc) //--------------------------------------------------------- rc = UartOpen(UART_BAUDRATE, 0, 0, "CN81H") AssertStrRc("UartOpen",rc) //Set device to be discoverable, connectible, and pairable //--------------------------------------------------------- InitBtDevice() //Initialise connection handles ResetAddrArray() //Initialise connection handles //InitConnHandles() rc = DiscoveryConfig() //Display the following lines as soon as the program starts //--------------------------------------------------------- print name$; "\n" //print "Sysinfo timer: "; sysinfo(2002); "\n"//Sysinfo timer: 12 print "Initialise End \n" endsub //============================================================================ //============================================================================ // //============================================================================ function HandlerBtcDiscTimOut() as integer print "\n---- No longer discoverable ----\n" //discoverable = 1 rc = BtcSetDiscoverable(1, DISCOV_TIMEOUT)//DISCOV_TIMEOUT default 30sec endfunc 1 //============================================================================ //============================================================================ // //============================================================================ function nn() endfunc 1 //============================================================================ //============================================================================ // Called on a Pairing request from another device //============================================================================ function HandlerPairReq() print "HandlerPairReq Begin \n" dim req_mac$ rc=BtcGetPairRequestBDAddr(req_mac$) AssertStrRc("BtcGetPairRequestBDAddr in HandlerPairReq()",rc) if rc==0 then print "\nPairing requested from device: "; StrHexize$(req_mac$); " \n" print "\nAccepting pair request \n" // Decline 0, Accept 1 rc = BtcSendPairResp(1) AssertStrRc("BtcSendPairResp(1) in HandlerPairReq()",rc) else print "\nErr: "; integer.h'rc // From req.. endif //Erase link key for this bluetooth device incase already bonded with it rc = BtcBondingEraseKey(req_mac$) AssertStrRc("BtcBondingEraseKey in HandlerPairReq()",rc) print "HandlerPairReq End \n" endfunc 1 //============================================================================ //============================================================================ //============================================================================ // Called when SPP disconnection occurs //============================================================================ function HandlerSppDiscon(hConn) print "\n------------------------------\n" print "----HandlerSppDiscon Begin----\n" RC = Buzzer() AssertStrRc("Buzzer in HandlerSppDiscon",rc) rc = BtcSetConnectable(1) //29.12.2018 AssertStrRc("BtcSetConnectable in HandlerSppDiscon",rc) //Set discoverable if spp port open //if SppPortHandler!=0 then rc = BtcSetDiscoverable(1, DISCOV_TIMEOUT) //29.12.2018 AssertStrRc("BtcSetDiscoverable in HandlerSppDiscon",rc) //endif RC = Turn_GPIO_LED0_Off() AssertStrRc("Turn_GPIO_LED0_Off in HandlerSppDiscon",rc) print "----HandlerSppDiscon End------\n" print "------------------------------\n\n" //---------------------------------------------------------------------------- //Wait(2000) //---------------------------------------------------------------------------- Initialise() //---------------------------------------------------------------------------- endfunc 1 //============================================================================ //============================================================================ //============================================================================ // EVBTC_REMOTENAME_RECEIVED // This event is thrown when the module receives a response to a // BtcQueryRemoteFriendlyName command, after this event has been received // the values can be read by issuing BtcGetRemoteFriendlyName. // OnEvent EVBTC_REMOTENAME_RECEIVED call HandlerRemoteName //---------------------------------------------------------------------------- // Enable synchronous event handlers //---------------------------------------------------------------------------- OnEvent EVUARTRX call HandlerUartRx //---------------------------------------------------------------------------- // rfcomm related events //---------------------------------------------------------------------------- // EVBTC_DISCOV_TIMEOUT: // This event is thrown when the module is no longer discoverable. // This will be after the time specified with BtcSetDiscoverable(), // otherwise it will be after the default value of 60 seconds. // OnEvent EVBTC_DISCOV_TIMEOUT call HandlerBtcDiscTimOut //---------------------------------------------------------------------------- // This event is thrown when an SPP disconnection occurs. // The message contains nHandle, the handle of the connection. OnEvent EVSPPDISCON call HandlerSppDiscon //---------------------------------------------------------------------------- // EVBTC_SPP_DATA_RECEIVED: // This event is thrown when data is received via the Serial Port Profile. // OnEvent EVBTC_SPP_DATA_RECEIVED call HandlerSppData //---------------------------------------------------------------------------- // EVSPPCONN: // This event is thrown when a new SPP connection has been established or // an error has occured. // The message is passed to a handler, which should be registered in the // smartBASIC application, and contains nHandle (the handle of the connection) // and result (a result code). // nHandle is only valid on a successful result code (0). // OnEvent EVSPPCONN call HandlerSppConn //---------------------------------------------------------------------------- // EVBTC_SPP_CONN_TIMEOUT: // This event is thrown when a connection attempt to an SPP device times out. // OnEvent EVBTC_SPP_CONN_TIMEOUT call HandlerSppConnTimOut //---------------------------------------------------------------------------- // EVSPPTXEMPTY: // This event is generated when the last byte in the SPP Tx buffer is // transmitted. See example for BtcSppWrite(). // OnEvent EVSPPTXEMPTY call HandlerSppTxEmpty //---------------------------------------------------------------------------- // EVBTC_PIN_REQUEST: // This event is thrown on a PIN request from another device during pairing. // See examples given for EVBTC_PAIR_RESULT and BtcPair. // onevent EVBTC_PIN_REQUEST call HandlerPinReq //---------------------------------------------------------------------------- // EVBTC_PAIR_REQUEST: // This event is thrown on a pairing request from another device. // OnEvent EVBTC_PAIR_REQUEST call HandlerPairReq //---------------------------------------------------------------------------- // EVBTC_PAIR_RESULT: // This message is thrown after a pairing attempt and comes with one parameter // which is the result code. // OnEvent EVBTC_PAIR_RESULT call HandlerPairRes //---------------------------------------------------------------------------- // Events and Messages EVINQRESP // This event is thrown when there is an BTC inquiry report waiting to be read. // The message, which is passed to a handler which should be registered in the // smartBASIC application, contains respType, // the type of inquiry response received. // It is one of the following values: // 0 Standard, 1 With RSSI, 2 Extended (contains EIR data) // OnEvent EVINQRESP call HandlerInqResp //---------------------------------------------------------------------------- // EVBTC_AUTHREQ // This message is thrown after a Secure Simple Pairing or Legacy // authentication request comes. // Its parameter denotes the type of authentication from the following list. // AuthType Description // 0 A device is requesting Secure Simple Pairing - JustWorks, // use BtcSendPAIRResp to respond. // 1 A device is requesting Secure Simple Pairing - Passkey, // use BtcSecMngrPasskey to respond. // 2 A device is requesting Secure Simple Pairing - OOB, // use BtcSecMngrOOBKey to respond. // 3 A device is requesting Legacy PIN entry, // use BtcSendPINResp to respond. OnEvent EVBTC_AUTHREQ call HandlerAuthReq //---------------------------------------------------------------------------- // This event is thrown when an inquiry times out. // When an inquiry times out this doesn’t necessarily mean that there are // no more responses waiting, so you can obtain the remaining responses // after a timeout by calling BtcInquiryGetReport(). // OnEvent EVBTC_INQUIRY_TIMEOUT call HandlerBtcInqTimOut //---------------------------------------------------------------------------- // EVBTC_MODE_CHANGE // This message from the LMP indicates that a link has changed its power mode. // The mode change must be queried with BtcQueryModeChange to return the // address of the device that is associated with that link. // Status returns 0 on success. // On a non-zero value, the link mode parameter is invalid. // //OnEvent EVBTC_MODE_CHANGE call HandlerModeChanged //---------------------------------------------------------------------------- //Initialise the device //---------------------------------------------------------------------------- Initialise() //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- print "\n--Module restarted--\n" print "\nFilename: $autorun$.BT900.BEACON\n" //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // Wait for a synchronous event. //---------------------------------------------------------------------------- // 0682: NON-FATAL TAR ERROR 0x02 (2): There has been a non-fatal error. //---------------------------------------------------------------------------- WaitEvent print "We ended here for some reason.\n" //SystemStateSet(0) //============================================================================ //============================================================================ // //============================================================================ //============================================================================ //============================================================================ //============================================================================ //============================================================================ //============================================================================