@@ -25,66 +25,74 @@ void BLECommunications(void *pvParameters)
25
25
// **********************************Client***************************************/
26
26
for (size_t x = 0 ; x < NUM_BLE_DEVICES; x++) // loop through discovered devices
27
27
{
28
- if (spinBLEClient.myBLEDevices [x].advertisedDevice ) // is device registered?
28
+ if (spinBLEClient.myBLEDevices [x].connectedClientID != BLE_HS_CONN_HANDLE_NONE)
29
29
{
30
- myAdvertisedBLEDevice myAdvertisedDevice = spinBLEClient.myBLEDevices [x];
31
- if ((myAdvertisedDevice. connectedClientID != BLE_HS_CONN_HANDLE_NONE) && (myAdvertisedDevice. doConnect == false )) // client must not be in connection process
30
+ // spinBLEClient.myBLEDevices[x].print() ;
31
+ if (spinBLEClient. myBLEDevices [x]. advertisedDevice ) // is device registered?
32
32
{
33
- if (NimBLEDevice::getClientByPeerAddress (myAdvertisedDevice.advertisedDevice ->getAddress ())) // nullptr check
33
+ // debugDirector("1",false);
34
+ SpinBLEAdvertisedDevice myAdvertisedDevice = spinBLEClient.myBLEDevices [x];
35
+ if ((myAdvertisedDevice.connectedClientID != BLE_HS_CONN_HANDLE_NONE) && (myAdvertisedDevice.doConnect == false )) // client must not be in connection process
34
36
{
35
- BLEClient *pClient = NimBLEDevice::getClientByPeerAddress (myAdvertisedDevice. advertisedDevice -> getAddress () );
36
- if ((myAdvertisedDevice.serviceUUID != BLEUUID (( uint16_t ) 0x0000 )) && (pClient-> isConnected ())) // Client connected with a valid UUID registered
37
+ // debugDirector("2",false );
38
+ if (NimBLEDevice::getClientByPeerAddress (myAdvertisedDevice.peerAddress )) // nullptr check
37
39
{
38
- // Write the recieved data to the Debug Director
40
+ // debugDirector("3",false);
41
+ BLEClient *pClient = NimBLEDevice::getClientByPeerAddress (myAdvertisedDevice.peerAddress );
42
+ if ((myAdvertisedDevice.serviceUUID != BLEUUID ((uint16_t )0x0000 )) && (pClient->isConnected ())) // Client connected with a valid UUID registered
43
+ {
44
+ // debugDirector("4");
45
+ // Write the recieved data to the Debug Director
39
46
40
- BLERemoteCharacteristic *pRemoteBLECharacteristic = pClient->getService (myAdvertisedDevice.serviceUUID )->getCharacteristic (myAdvertisedDevice.charUUID );
41
- std::string data = pRemoteBLECharacteristic->getValue ();
42
- uint8_t *pData = reinterpret_cast <uint8_t *>(&data[0 ]);
43
- int length = data.length ();
47
+ BLERemoteCharacteristic *pRemoteBLECharacteristic = pClient->getService (myAdvertisedDevice.serviceUUID )->getCharacteristic (myAdvertisedDevice.charUUID );
48
+ std::string data = pRemoteBLECharacteristic->getValue ();
49
+ uint8_t *pData = reinterpret_cast <uint8_t *>(&data[0 ]);
50
+ int length = data.length ();
44
51
45
- // 250 == Data(60), Spaces(Data/2), Arrow(4), SvrUUID(37), Sep(3), ChrUUID(37), Sep(3),
46
- // Name(10), Prefix(2), HR(8), SEP(1), CD(10), SEP(1), PW(8), SEP(1), SP(7), Suffix(2), Nul(1) - 225 rounded up
47
- char logBuf[250 ];
48
- char *logBufP = logBuf;
49
- for (int i = 0 ; i < length; i++)
52
+ // 250 == Data(60), Spaces(Data/2), Arrow(4), SvrUUID(37), Sep(3), ChrUUID(37), Sep(3),
53
+ // Name(10), Prefix(2), HR(8), SEP(1), CD(10), SEP(1), PW(8), SEP(1), SP(7), Suffix(2), Nul(1) - 225 rounded up
54
+ char logBuf[250 ];
55
+ char *logBufP = logBuf;
56
+ for (int i = 0 ; i < length; i++)
50
57
51
- {
52
- logBufP += sprintf (logBufP, " %02x " , pData[i]);
53
- }
54
- logBufP += sprintf (logBufP, " <- %s | %s" , myAdvertisedDevice.serviceUUID .toString ().c_str (), myAdvertisedDevice.charUUID .toString ().c_str ());
58
+ {
59
+ logBufP += sprintf (logBufP, " %02x " , pData[i]);
60
+ }
61
+ logBufP += sprintf (logBufP, " <- %s | %s" , myAdvertisedDevice.serviceUUID .toString ().c_str (), myAdvertisedDevice.charUUID .toString ().c_str ());
55
62
56
- std::shared_ptr<SensorData> sensorData = sensorDataFactory.getSensorData (pRemoteBLECharacteristic, pData, length);
57
-
58
- logBufP += sprintf (logBufP, " | %s:[" , sensorData->getId ().c_str ());
59
- if (sensorData->hasHeartRate ())
60
- {
61
- int heartRate = sensorData->getHeartRate ();
62
- userConfig.setSimulatedHr (heartRate);
63
- spinBLEClient.connectedHR |= true ;
64
- logBufP += sprintf (logBufP, " HR(%d)" , heartRate % 1000 );
65
- }
66
- if (sensorData->hasCadence ())
67
- {
68
- float cadence = sensorData->getCadence ();
69
- userConfig.setSimulatedCad (cadence);
70
- spinBLEClient.connectedCD |= true ;
71
- logBufP += sprintf (logBufP, " CD(%.2f)" , fmodf (cadence, 1000.0 ));
72
- }
73
- if (sensorData->hasPower ())
74
- {
75
- int power = sensorData->getPower ();
76
- userConfig.setSimulatedWatts (power);
77
- spinBLEClient.connectedPM |= true ;
78
- logBufP += sprintf (logBufP, " PW(%d)" , power % 10000 );
79
- }
80
- if (sensorData->hasSpeed ())
81
- {
82
- float speed = sensorData->getSpeed ();
83
- userConfig.setSimulatedSpeed (speed);
84
- logBufP += sprintf (logBufP, " SD(%.2f)" , fmodf (speed, 1000.0 ));
63
+ std::shared_ptr<SensorData> sensorData = sensorDataFactory.getSensorData (pRemoteBLECharacteristic, pData, length);
64
+
65
+ logBufP += sprintf (logBufP, " | %s:[" , sensorData->getId ().c_str ());
66
+ if (sensorData->hasHeartRate ())
67
+ {
68
+ int heartRate = sensorData->getHeartRate ();
69
+ userConfig.setSimulatedHr (heartRate);
70
+ spinBLEClient.connectedHR |= true ;
71
+ logBufP += sprintf (logBufP, " HR(%d)" , heartRate % 1000 );
72
+ }
73
+ if (sensorData->hasCadence ())
74
+ {
75
+ float cadence = sensorData->getCadence ();
76
+ userConfig.setSimulatedCad (cadence);
77
+ spinBLEClient.connectedCD |= true ;
78
+ logBufP += sprintf (logBufP, " CD(%.2f)" , fmodf (cadence, 1000.0 ));
79
+ }
80
+ if (sensorData->hasPower ())
81
+ {
82
+ int power = sensorData->getPower ();
83
+ userConfig.setSimulatedWatts (power);
84
+ spinBLEClient.connectedPM |= true ;
85
+ logBufP += sprintf (logBufP, " PW(%d)" , power % 10000 );
86
+ }
87
+ if (sensorData->hasSpeed ())
88
+ {
89
+ float speed = sensorData->getSpeed ();
90
+ userConfig.setSimulatedSpeed (speed);
91
+ logBufP += sprintf (logBufP, " SD(%.2f)" , fmodf (speed, 1000.0 ));
92
+ }
93
+ strcat (logBufP, " ]" );
94
+ debugDirector (String (logBuf), true , true );
85
95
}
86
- strcat (logBufP, " ]" );
87
- debugDirector (String (logBuf), true , true );
88
96
}
89
97
}
90
98
}
@@ -138,3 +146,4 @@ void BLECommunications(void *pvParameters)
138
146
#endif
139
147
}
140
148
}
149
+
0 commit comments