Skip to content

Commit 969c630

Browse files
committed
Various fixes regarding typos, dead code and consistency.
1 parent 453045a commit 969c630

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xGattServer.cpp

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -532,35 +532,27 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
532532
long_write_request_t* req = findLongWriteRequest(conn_handle);
533533
if (!req) {
534534
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_reply);
535-
releaseLongWriteRequest(conn_handle);
536535
return;
537536
}
538537

539538
// initialize the first request by setting the offset
540539
if (req->length == 0) {
541540
req->attr_handle = input_req.handle;
542541
req->offset = input_req.offset;
543-
}
544-
545-
// it is disalowed to write backward
546-
if (input_req.offset < req->offset) {
547-
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_offset_reply);
548-
releaseLongWriteRequest(conn_handle);
549-
return;
550-
}
551-
552-
// it should be the subsequent write
553-
if ((req->offset + req->length) != input_req.offset) {
554-
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_offset_reply);
555-
releaseLongWriteRequest(conn_handle);
556-
return;
557-
}
542+
} else {
543+
// it should be the subsequent write
544+
if ((req->offset + req->length) != input_req.offset) {
545+
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_offset_reply);
546+
releaseLongWriteRequest(conn_handle);
547+
return;
548+
}
558549

559-
// it is not allowed to write multiple characteristic with the same request
560-
if (input_req.handle != req->attr_handle) {
561-
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_reply);
562-
releaseLongWriteRequest(conn_handle);
563-
return;
550+
// it is not allowed to write multiple characteristic with the same request
551+
if (input_req.handle != req->attr_handle) {
552+
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_reply);
553+
releaseLongWriteRequest(conn_handle);
554+
return;
555+
}
564556
}
565557

566558
// start the copy of what is in input
@@ -595,7 +587,6 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
595587
long_write_request_t* req = findLongWriteRequest(conn_handle);
596588
if (!req) {
597589
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_reply);
598-
releaseLongWriteRequest(conn_handle);
599590
return;
600591
}
601592

@@ -615,7 +606,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
615606
// just leave here.
616607
if (write_authorization != AUTH_CALLBACK_REPLY_SUCCESS) {
617608
// report the status of the operation in any cases
618-
sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &write_auth_invalid_reply);
609+
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_invalid_reply);
619610
releaseLongWriteRequest(conn_handle);
620611
return;
621612
}
@@ -633,7 +624,7 @@ void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
633624
return;
634625
}
635626

636-
sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &write_auth_succes_reply);
627+
sd_ble_gatts_rw_authorize_reply(conn_handle, &write_auth_succes_reply);
637628

638629
GattWriteCallbackParams writeParams = {
639630
.connHandle = conn_handle,
@@ -751,7 +742,7 @@ uint16_t nRF5xGattServer::getBiggestCharacteristicSize() const {
751742
}
752743

753744
nRF5xGattServer::long_write_request_t* nRF5xGattServer::allocateLongWriteRequest(uint16_t connection_handle) {
754-
for (size_t i = 0; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST; ++i) {
745+
for (size_t i = 0; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS; ++i) {
755746
long_write_request_t& req = long_write_requests[i];
756747
if (req.data == NULL) {
757748
uint16_t block_size = getBiggestCharacteristicSize();
@@ -780,7 +771,7 @@ bool nRF5xGattServer::releaseLongWriteRequest(uint16_t connection_handle) {
780771
}
781772

782773
nRF5xGattServer::long_write_request_t* nRF5xGattServer::findLongWriteRequest(uint16_t connection_handle) {
783-
for (size_t i = 0; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST; ++i) {
774+
for (size_t i = 0; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS; ++i) {
784775
long_write_request_t& req = long_write_requests[i];
785776
if (req.data != NULL && req.conn_handle == connection_handle) {
786777
return &req;
@@ -791,7 +782,7 @@ nRF5xGattServer::long_write_request_t* nRF5xGattServer::findLongWriteRequest(uin
791782
}
792783

793784
void nRF5xGattServer::releaseAllWriteRequests() {
794-
for (size_t i = 0; i < TOTAL_CONCURENT_LONG_WRITE_REQUEST; ++i) {
785+
for (size_t i = 0; i < TOTAL_CONCURRENT_LONG_WRITE_REQUESTS; ++i) {
795786
long_write_request_t& req = long_write_requests[i];
796787
if (req.data != NULL) {
797788
free(req.data);

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xGattServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class nRF5xGattServer : public GattServer
4545
private:
4646
const static unsigned BLE_TOTAL_CHARACTERISTICS = 20;
4747
const static unsigned BLE_TOTAL_DESCRIPTORS = 8;
48-
const static unsigned TOTAL_CONCURENT_LONG_WRITE_REQUEST = 3;
48+
const static unsigned TOTAL_CONCURRENT_LONG_WRITE_REQUESTS = 3;
4949

5050
private:
5151
struct long_write_request_t {
@@ -124,7 +124,7 @@ class nRF5xGattServer : public GattServer
124124

125125
/**
126126
* Find a long write request from a characteristic handle
127-
* @param connection_handle The connection handle associated with the reauest.
127+
* @param connection_handle The connection handle associated with the request.
128128
* @return a pointer to the request if found otherwise NULL.
129129
*/
130130
long_write_request_t* findLongWriteRequest(uint16_t connection_handle);
@@ -140,7 +140,7 @@ class nRF5xGattServer : public GattServer
140140
GattAttribute *p_descriptors[BLE_TOTAL_DESCRIPTORS];
141141
uint8_t descriptorCount;
142142
uint16_t nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS];
143-
long_write_request_t long_write_requests[TOTAL_CONCURENT_LONG_WRITE_REQUEST];
143+
long_write_request_t long_write_requests[TOTAL_CONCURRENT_LONG_WRITE_REQUESTS];
144144

145145
/*
146146
* Allow instantiation from nRF5xn when required.

0 commit comments

Comments
 (0)