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 Nobuaki Aoki

Committer:
samialshorman
Date:
Tue Apr 14 21:48:07 2015 +0000
Revision:
3:55a622e3dbb5
Parent:
0:003889bc474f
Nonin (Pulse Oximeter) connected to mbed lpc 1768 by Bluetooth dongle and sends SMS including Heart Rate and Oxygen saturation by GPRS module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nobukuma 0:003889bc474f 1 #include "Utils.h"
nobukuma 0:003889bc474f 2 #include "neighbourhood.h"
nobukuma 0:003889bc474f 3
nobukuma 0:003889bc474f 4 neighbourhood *neighbors = 0;
nobukuma 0:003889bc474f 5
nobukuma 0:003889bc474f 6 int neighbourhood::get(BD_ADDR *a, unsigned char *key) {
nobukuma 0:003889bc474f 7 for (list<item>::iterator i = keys.begin(); i != keys.end(); i++)
nobukuma 0:003889bc474f 8 if (memcmp(a, &(*i).a, sizeof(BD_ADDR)) == 0) {
nobukuma 0:003889bc474f 9 memcpy(key, (*i).lk, lksize);
nobukuma 0:003889bc474f 10 #ifdef STRICT_MRU
nobukuma 0:003889bc474f 11 if (i != keys.begin()) {
nobukuma 0:003889bc474f 12 keys.push_front(*i);
nobukuma 0:003889bc474f 13 keys.erase(i);
nobukuma 0:003889bc474f 14 dirty = true;
nobukuma 0:003889bc474f 15 }
nobukuma 0:003889bc474f 16 #endif
nobukuma 0:003889bc474f 17 return 1;
nobukuma 0:003889bc474f 18 }
nobukuma 0:003889bc474f 19 return 0;
nobukuma 0:003889bc474f 20 }
nobukuma 0:003889bc474f 21
nobukuma 0:003889bc474f 22 int neighbourhood::add(BD_ADDR *a, const unsigned char *key, bool init) {
nobukuma 0:003889bc474f 23 for (list<item>::iterator i = keys.begin(); i != keys.end(); i++)
nobukuma 0:003889bc474f 24 if (memcmp(a, &(*i).a, sizeof(BD_ADDR)) == 0) {
nobukuma 0:003889bc474f 25 memcpy((*i).lk, key, lksize); //assume key has changed, update key
nobukuma 0:003889bc474f 26 (*i).used = true;
nobukuma 0:003889bc474f 27 return 1;
nobukuma 0:003889bc474f 28 }
nobukuma 0:003889bc474f 29 //new key
nobukuma 0:003889bc474f 30 printf("Neighbourhood: "); printf(a); printf("\n");
nobukuma 0:003889bc474f 31 if (keys.size() < cap) {
nobukuma 0:003889bc474f 32 keys.push_back(item(a, key, !init));//append as long as there is space
nobukuma 0:003889bc474f 33 } else {
nobukuma 0:003889bc474f 34 keys.push_front(item(a, key, true));//otherwise prepend
nobukuma 0:003889bc474f 35 dirty = true;
nobukuma 0:003889bc474f 36 }
nobukuma 0:003889bc474f 37 return 0;
nobukuma 0:003889bc474f 38 }
nobukuma 0:003889bc474f 39
nobukuma 0:003889bc474f 40 void neighbourhood::write() {
nobukuma 0:003889bc474f 41 int n = 0;
nobukuma 0:003889bc474f 42 static const int maxkey = 11;
nobukuma 0:003889bc474f 43 unsigned char param[maxkey*(lksize+sizeof(BD_ADDR))+1];
nobukuma 0:003889bc474f 44 int k = keys.size()-cap;
nobukuma 0:003889bc474f 45 list<item>::iterator i = keys.begin();
nobukuma 0:003889bc474f 46 while (i != keys.end()) {
nobukuma 0:003889bc474f 47 if (k>0) {
nobukuma 0:003889bc474f 48 if (!(*i).used) {
nobukuma 0:003889bc474f 49 delete_link_key(&(*i).a);//try to make some room
nobukuma 0:003889bc474f 50 keys.erase(i);
nobukuma 0:003889bc474f 51 k--;
nobukuma 0:003889bc474f 52 } else
nobukuma 0:003889bc474f 53 i++;
nobukuma 0:003889bc474f 54 } else
nobukuma 0:003889bc474f 55 break;
nobukuma 0:003889bc474f 56 }
nobukuma 0:003889bc474f 57 //hci->delete_link_keys();
nobukuma 0:003889bc474f 58 unsigned char *p = &param[1];
nobukuma 0:003889bc474f 59 for (list<item>::iterator i = keys.begin(); i != keys.end() && n<maxkey; i++, n++) {
nobukuma 0:003889bc474f 60 memcpy(p, &(*i).a, sizeof(BD_ADDR));
nobukuma 0:003889bc474f 61 p += sizeof(BD_ADDR);
nobukuma 0:003889bc474f 62 memcpy(p, (*i).lk, lksize);
nobukuma 0:003889bc474f 63 p += lksize;
nobukuma 0:003889bc474f 64 }
nobukuma 0:003889bc474f 65 param[0] = n;
nobukuma 0:003889bc474f 66 if (n > 0)
nobukuma 0:003889bc474f 67 write_link_keys(param);
nobukuma 0:003889bc474f 68 }
nobukuma 0:003889bc474f 69