Pulse Oximeter (NONIN) communicates with mbed via Bluetooth dongle and sends Heart Rate and Oxygen Saturation via GPRS module
Dependencies: C12832 GPS GSM mbed
Fork of myBlueUSB_localfix by
Revision 3:55a622e3dbb5, committed 2015-04-14
- Comitter:
- samialshorman
- Date:
- Tue Apr 14 21:48:07 2015 +0000
- Parent:
- 2:9f25a7fa1a54
- Commit message:
- Nonin (Pulse Oximeter) connected to mbed lpc 1768 by Bluetooth dongle and sends SMS including Heart Rate and Oxygen saturation by GPRS module
Changed in this revision
--- a/AvailableMemory.lib Sun Dec 08 21:52:09 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/networker/code/AvailableMemory/#2b2aa11cebd7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Tue Apr 14 21:48:07 2015 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/chris/code/C12832/#7de323fa46fe
--- a/FATFileSystem.lib Sun Dec 08 21:52:09 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_unsupported/code/fatfilesystem/#333d6e93e58f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPS.lib Tue Apr 14 21:48:07 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/GPS/#15611c7938a3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GSM.lib Tue Apr 14 21:48:07 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/components/code/GSM/#24671d8aa0c9
--- a/TestShell.cpp Sun Dec 08 21:52:09 2013 +0000 +++ b/TestShell.cpp Tue Apr 14 21:48:07 2015 +0000 @@ -1,25 +1,4 @@ -/* -Copyright (c) 2010 Peter Barrett - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ #include "mbed.h" #include <vector> #include "Utils.h" @@ -32,36 +11,58 @@ #include "sdp.h" #include "btserial.h" #include "neighbourhood.h" +#include "GPS.h" +#include "GSM.h" +#include "C12832.h" +#include <string> + + +C12832 lcd(p5, p7, p6, p8, p11); +GPS gps(p28, p27); + /************************************************ -TODO: -mtu and credits are completely unhandled - in progress -multiple rfcomm sessions should be possible - done -SDP would be nice - beta -multiple rfcomm channels are untested -decoupling of rfcomm and application - much better -packets are not reassembled - some are (HCI and ft application level) -disconnect and timeouts +Dr.Faycal Bensaali, Dr.Fadi Jaber, Sami Alshorman ************************************************/ +// GSM PART +#define PHONE_NUMBER "0097455303701" + +#define SEND_SMS_TEST 1 +#define CALL_UP_TEST 0 +#define ANSWER_TEST 0 +#define READ_SMS_TEST 0 #define DEBUG 1 int state = 0; + +GSM gsm(p9, p10, 19200, PHONE_NUMBER); + +void messageHandle(void) +{ + __disable_irq(); + int messageType = gsm.loopHandle(); + if(MESSAGE_RING == messageType) { + gsm.answer(); + } else if(MESSAGE_SMS == messageType) { + char smsMessage[SMS_MAX_LENGTH]; + gsm.getSMS(smsMessage); + } + __enable_irq(); +} +// END OF GSM PART + + //int bulk = 0; void printf(const BD_ADDR* addr) { const u8* a = addr->addr; printf("%02X:%02X:%02X:%02X:%02X:%02X",a[5],a[4],a[3],a[2],a[1],a[0]); } -const char FtDevClass[3] = {0x00, 0x1F, 0x82 }; -const char SerDevClass[3] = {4, 1, 0x00}; -// Instance -//RFCOMMManager rfcomm_manager; class application : public HCI { BTDevice* devs[8]; int count, i, pending; public: - // We have connected to a device void ConnectionComplete(connection_info* info) { printf("ConnectionComplete "); BD_ADDR* a = &info->bdaddr; @@ -82,7 +83,6 @@ return; } } - //state = 1; //start the real application } void ConnectDevices() { @@ -112,8 +112,8 @@ void application::Callback(HCI_CALLBACK_EVENT evt, const u8* data, int len) {//these events are forwarded (in)directly from HCIRecv - unsigned char pin[] = "1234"; - unsigned char newaddr[] = {0x2c, 0x07, 0x54, 0x7b, 0x13, 0x00};//possible ft TX address (ROBO TX-277) + unsigned char pin[] = "681010"; + unsigned char newaddr[] = {0x14, 0xd4, 0x00, 0x05, 0x1c, 0x00};//possible ft TX address (ROBO TX-277) // unsigned char newaddr[] = {0x57, 0x0a, 0x3d, 0x83, 0x15, 0x00};//original address of the cheap round BT dongle printf("\x1b[%dm", 33); switch (evt) { @@ -130,7 +130,6 @@ printf("CALLBACK_INQUIRY_RESULT "); printf((BD_ADDR*)data); printf("\n");//data points to inquiry_info struct -// RemoteNameRequest((BD_ADDR*)data); break; case CALLBACK_INQUIRY_DONE: @@ -160,23 +159,19 @@ printf("Going to open sdp socket\n"); L2CAPAddr addr; memcpy(&addr.bdaddr, &ci->bdaddr, 6); - //int s = SDP.Open(&addr.hdr); } break; case CALLBACK_PIN_REQ: printf("Enter PIN for "); printf((BD_ADDR*)data); printf(" : submitting %s\n", pin); - //USBLoop(); wait(1.0); USBLoop(); - //for(int k=0; k<2000000;k++) USBLoop(); PinCodeReply(data, pin); break; case CALLBACK_VENDOR: printfBytes("Vendor Reply:", data, len); - //mbed_reset(); if (data[0] == 0xc2) csr_reset_device(false); - break; + break; default: printf("Unhandled HCI Callback %d\n", evt); }; @@ -265,52 +260,104 @@ } void TestShell() { - int n=0; + char newaddr[] = {0x14, 0xd4, 0x00, 0x05, 0x1c, 0x00}; + string n; + int x=0; + short int c[3], SPO2, HR; + int QEWS; + int SCORE_S; + int SCORE_H; + + USBInit(); - for (;;) { + + for( ; ;) { + switch (state) { case 0: //inquiry and low-level connection break; case 1: {//initialisation - printf("Ready to open ports\n"); - InitFtBtDeviceList(); - int n = GetNrOfFtBtDevices(); - printf("%d ft BT devices have been found\n", n); - if (n > 0) { - ftbtdev *d = GetFtUsbDeviceHandle(0); - if (d==0) printf("could not get device handle\n"); - int sock = OpenFtBtDevice(d); - } state = 2; - comm = Socket_Listen(SOCKET_RFCOM, 1, echo, 0); // uncomment - //incoming = new btserial(1); + incoming = new btserial(newaddr,1); + } break; case 2://main loop - /*if (incoming->readable()>0){ - int c= incoming->getc(); - putc(c, stderr); - incoming->putc(c); - } - else if (incoming->readable()<0){ - state = 3; - printf("end of session"); - delete incoming; - }*/ - break; + + + if (incoming->readable()>0) + { + c[x]= incoming->getc(); + + if (x==3) + { + SPO2 = c[2]; + HR = (c[1] & 0x7F) | ((c[0] & 0x03) << 7); + lcd.printf("HR is: %d \nSPo2 is: %d",HR, SPO2); + + if(SPO2 >= 0x60) SCORE_S=0; + else if((SPO2 >= 0x5D) && (SPO2 <= 0x5F)) SCORE_S=1; + else if((SPO2 >= 0x5A) && (SPO2 <= 0x5C)) SCORE_S=2; + else SCORE_S = 3; + + if(( HR >= 0x32)&& (HR <= 0x64)) SCORE_H=0; + else if((( HR >= 0x65)&& (HR <= 0x6E))|| (( HR >= 0x29)&& (HR <= 0x32)))SCORE_H=1; + else if((( HR >= 0x6F)&& (HR <= 0x81))|| (( HR >= 0x1F)&& (HR <= 0x28)))SCORE_H=2; + else SCORE_H = 3; + + QEWS=SCORE_S +SCORE_H; + + + + lcd.printf("\n QEWS is: %d",QEWS); + // wait(5); + + if ( QEWS>0) + { + while(gps.sample()==0); + + lcd.printf("I'm at %f, %f\n", gps.longitude, gps.latitude); + + + while(0 != gsm.init()) { + wait(2); + } + char buffer[100]; + // n=sprintf (buffer, "%s,%f,\n %s,%f", "long:",gps.longitude,"Alt:",gps.latitude); + n=sprintf (buffer, "%s \n %s %d %s \n %s %d %s \n %s %d \n %s \n %s %f \n %s %f", "Patient 1" ,"SPO2 is ", SPO2,"% ","HR is ",HR,"bpm","QEWS is ",QEWS,"GPS coordinates: ","Longitude is ",gps.longitude,"Latitude is ",gps.latitude); + + #if SEND_SMS_TEST + //gsm.sendSMS(PHONE_NUMBER, "salam from sami alshorman"); + gsm.sendSMS(PHONE_NUMBER,buffer); + + #endif + + #if CALL_UP_TEST + gsm.callUp(PHONE_NUMBER); + #endif + + #if ANSWER_TEST || READ_SMS_TEST + gsm.gsmSerial.attach(&messageHandle); + #endif + + } + + wait(5); + mbed_reset(); + + } + + x++; + + } + + + break; default: break; } - loop=1; - USBLoop(); - loop=0; - n++; - if (n>=500000) { - n=0; - led = !led; - } + + USBLoop(); } - //printf("Dropped out of main loop!\n"); } -//********************************************************************************************************************************
--- a/btserial.cpp Sun Dec 08 21:52:09 2013 +0000 +++ b/btserial.cpp Tue Apr 14 21:48:07 2015 +0000 @@ -70,7 +70,7 @@ } void btserial::baud(int br) { - int rates[] = {2400,4800,7200,9600,19200,38400,57600,115200,230400}; + int rates[] = {2400,4800,7200,9600,19200,38400,57600,115200,230400,460800}; if (!open) return; for (int i = 0; i < sizeof(rates)/sizeof(int);i++) if (rates[i] == br) {
--- a/btserial.h Sun Dec 08 21:52:09 2013 +0000 +++ b/btserial.h Tue Apr 14 21:48:07 2015 +0000 @@ -4,7 +4,7 @@ #include "RFCOMM.h" class btserial { - static const int bufsize = 350; + static const int bufsize = 4; int recbufsize, sndbufsize; int sock; unsigned char sendbuf[bufsize], recbuf[bufsize];
--- a/hci.cpp Sun Dec 08 21:52:09 2013 +0000 +++ b/hci.cpp Tue Apr 14 21:48:07 2015 +0000 @@ -55,9 +55,8 @@ MASK_CREATE_CONNECTION = 64 }; -static const u8 local_name[] = "MBED"; -//static const u8 local_name[] = "ROBO TX-599"; -//static const u8 local_name[] = "mbed-WP8 RFCOMM"; +//static const u8 local_name[] = "MBED"; +static const u8 local_name[] = "Nonin_Medical_Inc._681010"; int HCI::Open(HCITransport* transport, HCICallback callback) { _transport = transport; @@ -319,8 +318,8 @@ u8 b[6+1+16]; memset(b,0,sizeof(b)); memcpy(b,data,6); - b[6] = 4; - memcpy(b+7, pin, 4); + b[6] = 6; + memcpy(b+7, pin, 6); return SendCmd(HCI_OP_PIN_CODE_REPLY,b,sizeof(b)); }
--- a/myUSBHost.lib Sun Dec 08 21:52:09 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/networker/code/myUSBHost/#58c785c2b381