Skip to content

Commit

Permalink
Make standard scan clear services.
Browse files Browse the repository at this point in the history
Rationale: services can still be examined after disconnect
AND, on reconnect, one can avoid the scan and just get right to
it if one wishes. That would be a "little well dodge" though if
one didn't take a great deal of care.
  • Loading branch information
Edward Rosten committed Jan 4, 2017
1 parent f743d61 commit 102aea2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
29 changes: 17 additions & 12 deletions bluetooth.cc
Expand Up @@ -24,13 +24,14 @@
#include <iostream>
#include <sstream>
#include <iomanip>
#include <libattgatt/blestatemachine.h>
#include <libattgatt/float.h>
#include <blepp/blestatemachine.h>
#include <blepp/float.h>
#include <deque>
#include <sys/time.h>
#include <unistd.h>
#include "cxxgplot.h" //lolzworthy plotting program
using namespace std;
using namespace BLEPP;

void bin(uint8_t i)
{
Expand Down Expand Up @@ -119,9 +120,17 @@ int main(int argc, char **argv)
//This particular device sends 16 bit integers.
//Extract them and both print them in binary and send them to the plotting program
const uint8_t* d = n.value().first;
int val = ((0+d[1] *256 + d[0])>>0) ;

int16_t bv = d[6] | (d[7] << 8);
for(int i=0; i < 7; i++)
{
int val = ((0+d[1 + 2*i] *256 + d[0 + 2*i])>>0) ;
//Format the points and send the results to the plotting program.
points.push_back(val);
if(points.size() > 300)
points.pop_front();
}

uint32_t seq = d[14] | (d[15]<<8) | (d[16]<<16) | (d[17]<<8);
int16_t bv = d[18] | (d[19] << 8);

if(bv != -32768)
voltage = bv / 1000.0;
Expand All @@ -133,15 +142,11 @@ int main(int argc, char **argv)

//cout << endl;

//Format the points and send the results to the plotting program.
points.push_back(val);
if(points.size() > 100)
points.pop_front();

plot.newline("line lw 10 lt 0 title \"\"");
plot.newline("line lw 3 lt 1 title \"\"");
plot.addpts(points);
ostringstream os;
os << "set title \"Voltage: " << voltage << "\"";
os << "set title \"Voltage: " << voltage << " Seq: " << seq << "\"";
plot.add_extra(os.str());

plot.draw();
Expand All @@ -166,7 +171,7 @@ int main(int argc, char **argv)

for(auto& service: gatt.primary_services)
for(auto& characteristic: service.characteristics)
if(service.uuid == UUID("7309203e-349d-4c11-ac6b-baedd1819764") && characteristic.uuid == UUID("53f72b8c-ff27-4177-9eee-30ace844f8f2"))
if(service.uuid == UUID("7309203e-349d-4c11-ac6b-baedd1819764") && characteristic.uuid == UUID("e5f49879-6ee1-479e-bfec-3d35e13d3b88"))
{
cout << "woooo\n";
characteristic.cb_notify_or_indicate = notify_cb;
Expand Down
1 change: 1 addition & 0 deletions lescan.cc
Expand Up @@ -30,6 +30,7 @@ void catch_function(int)

int main()
{
log_level = LogLevels::Debug;
HCIScanner scanner;

//Catch the interrupt signal. If the scanner is not
Expand Down
2 changes: 2 additions & 0 deletions src/blestatemachine.cc
Expand Up @@ -790,6 +790,8 @@ namespace BLEPP
{
ENTER();

primary_services.clear();

cb_services_read = [this]()
{
this->find_all_characteristics();
Expand Down

0 comments on commit 102aea2

Please sign in to comment.