mirror of https://github.com/ARMmbed/mbed-os.git
new units
parent
7b4439567d
commit
57e4cdd732
|
@ -42,7 +42,7 @@ void clamp(T& value, const R& min, const R& max) {
|
|||
}
|
||||
}
|
||||
|
||||
template<typename LayoutType, size_t microseconds, size_t min, size_t max>
|
||||
template<typename LayoutType, size_t in_microseconds, size_t value_min, size_t value_max>
|
||||
class unit_t {
|
||||
public:
|
||||
unit_t() : _value(0) { }
|
||||
|
@ -50,23 +50,33 @@ public:
|
|||
unit_t(LayoutType value) : _value(value) { }
|
||||
|
||||
void clamp() {
|
||||
clamp(_value, min, max);
|
||||
clamp(_value, value_min, value_max);
|
||||
}
|
||||
|
||||
const LayoutType& value() const {
|
||||
return _value;
|
||||
}
|
||||
|
||||
uint32_t microseconds() const {
|
||||
return _value * in_microseconds;
|
||||
}
|
||||
|
||||
bool operator>(unit_t const& other) const {
|
||||
return _value > other._value;
|
||||
}
|
||||
|
||||
bool operator=(unit_t const& other) {
|
||||
return _value = other._value;
|
||||
}
|
||||
|
||||
private:
|
||||
LayoutType _value;
|
||||
};
|
||||
|
||||
typedef unit_t<uint32_t, 625, 0x20, 0xFFFFFF> unit_adv_interval_t;
|
||||
typedef unit_t<uint16_t, 10000, 0x01, 0xFFFF> unit_adv_duration_t;
|
||||
typedef unit_t<uint16_t, 10000, 0x01, 0xFFFF> unit_scan_duration_t;
|
||||
typedef unit_t<uint16_t, 1280, 0x01, 0xFFFF> unit_scan_period_t;
|
||||
typedef unit_t<uint16_t, 625, 0x04, 0xFFFF> unit_scan_interval_t;
|
||||
typedef unit_t<uint16_t, 625, 0x04, 0xFFFF> unit_scan_window_t;
|
||||
typedef unit_t<uint16_t, 1250, 0x06, 0x0C80> unit_conn_interval_t;
|
||||
|
|
|
@ -530,6 +530,8 @@ public:
|
|||
|
||||
typedef ble::unit_adv_interval_t UnitAdvInterval_t;
|
||||
typedef ble::unit_adv_duration_t UnitAdvDuration_t;
|
||||
typedef ble::unit_scan_duration_t UnitScanDuration_t;
|
||||
typedef ble::unit_scan_period_t UnitScanPeriod_t;
|
||||
typedef ble::unit_scan_interval_t UnitScanInterval_t;
|
||||
typedef ble::unit_scan_window_t UnitScanWindow_t;
|
||||
typedef ble::unit_conn_interval_t UnitConnInterval_t;
|
||||
|
@ -1259,7 +1261,7 @@ public:
|
|||
ble::advertising_sid_t SID;
|
||||
ble::advertising_power_t txPower;
|
||||
ble::rssi_t rssi;
|
||||
int16_t periodicInterval;
|
||||
UnitPeriodicInterval_t periodicInterval;
|
||||
PeerAddressType_t directAddressType;
|
||||
const ble::address_t &directAddress;
|
||||
mbed::Span<const uint8_t> advertisingData;
|
||||
|
@ -1361,10 +1363,10 @@ public:
|
|||
const ble::address_t &peerAddress;
|
||||
const ble::address_t &localResolvablePrivateAddress;
|
||||
const ble::address_t &peerResolvablePrivateAddress;
|
||||
uint16_t connectionInterval_us;
|
||||
uint16_t connectionLatency;
|
||||
uint16_t supervisionTimeout_ms;
|
||||
uint16_t masterClockAccuracy_ppm;
|
||||
UnitConnInterval_t connectionInterval;
|
||||
UnitConnInterval_t connectionLatency;
|
||||
UnitSupervisionTimeout_t supervisionTimeout;
|
||||
uint16_t masterClockAccuracy /* parts per million */;
|
||||
};
|
||||
|
||||
void onConnectionComplete(
|
||||
|
@ -2340,8 +2342,8 @@ public:
|
|||
*/
|
||||
virtual ble_error_t startScan(
|
||||
ble::scanning_filter_duplicates_t filtering = ble::SCAN_FILTER_DUPLICATES_DISABLED,
|
||||
uint16_t duration = 0,
|
||||
uint16_t period = 0
|
||||
UnitScanDuration_t duration = 0,
|
||||
UnitScanPeriod_t period = 0
|
||||
) {
|
||||
use_non_deprecated_scan_api();
|
||||
/* Requesting action from porter(s): override this API if this capability is supported. */
|
||||
|
@ -2361,8 +2363,8 @@ public:
|
|||
PeerAddressType_t peerAddressType,
|
||||
Address_t peerAddress,
|
||||
uint8_t sid,
|
||||
uint16_t maxPacketSkip,
|
||||
uint32_t timeoutMs
|
||||
UnitSlaveLatency_t maxPacketSkip,
|
||||
UnitSyncTimeout_t timeout
|
||||
) {
|
||||
/* Requesting action from porter(s): override this API if this capability is supported. */
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
|
@ -2375,8 +2377,8 @@ public:
|
|||
* @return
|
||||
*/
|
||||
virtual ble_error_t createSync(
|
||||
uint16_t maxPacketSkip,
|
||||
uint32_t timeoutMs
|
||||
UnitSlaveLatency_t maxPacketSkip,
|
||||
UnitSyncTimeout_t timeout
|
||||
) {
|
||||
/* Requesting action from porter(s): override this API if this capability is supported. */
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -50,54 +50,41 @@ public:
|
|||
/* setters */
|
||||
|
||||
GapExtendedConnectParameters_t& setScanParameters(
|
||||
uint32_t scanInterval_us,
|
||||
uint32_t scanWindow_us,
|
||||
ble::unit_scan_interval_t scanInterval,
|
||||
ble::unit_scan_window_t scanWindow,
|
||||
ble::phy_t phy = ble::phy_t::LE_1M
|
||||
) {
|
||||
uint8_t phy_index = handlePhyToggle(phy, true);
|
||||
|
||||
_scanInterval[phy_index] = scanInterval_us / 625;
|
||||
_scanWindow[phy_index] = scanWindow_us / 625;
|
||||
|
||||
ble::clamp(_scanInterval[phy_index], 0x0004, 0xFFFF);
|
||||
ble::clamp(_scanWindow[phy_index], 0x0004, 0xFFFF);
|
||||
_scanInterval[phy_index] = scanInterval.value();
|
||||
_scanWindow[phy_index] = scanWindow.value();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
GapExtendedConnectParameters_t& setConnectionParameters(
|
||||
uint16_t minConnectionInterval_ms,
|
||||
uint16_t maxConnectionInterval_ms,
|
||||
uint16_t slaveLatency,
|
||||
uint16_t connectionSupervisionTimeout_ms,
|
||||
ble::unit_conn_interval_t minConnectionInterval,
|
||||
ble::unit_conn_interval_t maxConnectionInterval,
|
||||
ble::unit_slave_latency_t slaveLatency,
|
||||
ble::unit_supervision_timeout_t connectionSupervisionTimeout,
|
||||
ble::phy_t phy = ble::phy_t::LE_1M,
|
||||
uint32_t _minEventLength_us = 0,
|
||||
uint32_t _maxEventLength_us = 0xFFFF
|
||||
ble::unit_conn_event_length_t minEventLength = 0,
|
||||
ble::unit_conn_event_length_t maxEventLength = 0xFFFF
|
||||
) {
|
||||
uint8_t phy_index = handlePhyToggle(phy, true);
|
||||
|
||||
_minConnectionInterval[phy_index] = (((uint32_t)minConnectionInterval_ms) * 1000) / 1250;
|
||||
_maxConnectionInterval[phy_index] = (((uint32_t)maxConnectionInterval_ms) * 1000) / 1250;
|
||||
_slaveLatency[phy_index] = slaveLatency;
|
||||
|
||||
ble::clamp(_minConnectionInterval[phy_index], 0x0006, 0x0C80);
|
||||
ble::clamp(_maxConnectionInterval[phy_index], 0x0006, 0x0C80);
|
||||
ble::clamp(_slaveLatency[phy_index], 0x0000, 0x01F3);
|
||||
|
||||
/* avoid overlfow */
|
||||
uint32_t connectionSupervisionTimeout_10ms = connectionSupervisionTimeout_ms * 10;
|
||||
ble::clamp(connectionSupervisionTimeout_10ms, 0x000A, 0x0C80);
|
||||
_connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout_10ms;
|
||||
_minConnectionInterval[phy_index] = minConnectionInterval.value();
|
||||
_maxConnectionInterval[phy_index] = maxConnectionInterval.value();
|
||||
_slaveLatency[phy_index] = slaveLatency.value();
|
||||
_connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout.value();
|
||||
|
||||
/* avoid overflows and truncation */
|
||||
_minEventLength_us = _minEventLength_us / 625;
|
||||
_maxEventLength_us = _maxEventLength_us / 625;
|
||||
if (minEventLength > maxEventLength) {
|
||||
minEventLength = maxEventLength;
|
||||
}
|
||||
|
||||
ble::clamp(_minEventLength_us, 0x0000, 0xFFFF);
|
||||
ble::clamp(_maxEventLength_us, 0x0000, 0xFFFF);
|
||||
|
||||
_minEventLength[phy_index] = _minEventLength_us;
|
||||
_maxEventLength[phy_index] = _maxEventLength_us;
|
||||
_minEventLength[phy_index] = minEventLength.value();
|
||||
_maxEventLength[phy_index] = maxEventLength.value();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -116,8 +116,8 @@ public:
|
|||
|
||||
virtual ble_error_t setPeriodicAdvertisingParameters(
|
||||
AdvHandle_t handle,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMinMs,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMaxMs,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMin,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMax,
|
||||
bool advertiseTxPower
|
||||
);
|
||||
|
||||
|
@ -136,19 +136,22 @@ public:
|
|||
|
||||
virtual ble_error_t startScan(
|
||||
scanning_filter_duplicates_t filtering,
|
||||
uint16_t duration_ms,
|
||||
uint16_t period_ms
|
||||
UnitScanDuration_t duration,
|
||||
UnitScanPeriod_t period
|
||||
);
|
||||
|
||||
virtual ble_error_t createSync(
|
||||
PeerAddressType_t peerAddressType,
|
||||
uint8_t *peerAddress,
|
||||
uint8_t sid,
|
||||
uint16_t maxPacketSkip,
|
||||
uint32_t timeoutMs
|
||||
Gap::UnitSlaveLatency_t maxPacketSkip,
|
||||
Gap::UnitSyncTimeout_t timeout
|
||||
);
|
||||
|
||||
virtual ble_error_t createSync(uint16_t maxPacketSkip, uint32_t timeoutMs);
|
||||
virtual ble_error_t createSync(
|
||||
Gap::UnitSlaveLatency_t maxPacketSkip,
|
||||
Gap::UnitSyncTimeout_t timeout
|
||||
);
|
||||
|
||||
virtual ble_error_t cancelCreateSync();
|
||||
|
||||
|
|
|
@ -1931,7 +1931,7 @@ ble_error_t GenericGap::startAdvertising(
|
|||
if (maxDuration.value()) {
|
||||
_advertising_timeout.attach_us(
|
||||
mbed::callback(this, &GenericGap::on_advertising_timeout),
|
||||
maxDuration.value()
|
||||
maxDuration.microseconds()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -2009,12 +2009,12 @@ bool GenericGap::isAdvertisingActive(AdvHandle_t handle) {
|
|||
|
||||
ble_error_t GenericGap::setPeriodicAdvertisingParameters(
|
||||
Gap::AdvHandle_t handle,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMinMs,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMaxMs,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMin,
|
||||
UnitPeriodicInterval_t periodicAdvertisingIntervalMax,
|
||||
bool advertiseTxPower
|
||||
)
|
||||
{
|
||||
if (periodicAdvertisingIntervalMinMs > periodicAdvertisingIntervalMaxMs) {
|
||||
if (periodicAdvertisingIntervalMin > periodicAdvertisingIntervalMax) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
@ -2032,8 +2032,8 @@ ble_error_t GenericGap::setPeriodicAdvertisingParameters(
|
|||
|
||||
return _pal_gap.set_periodic_advertising_parameters(
|
||||
handle,
|
||||
periodicAdvertisingIntervalMinMs.value(),
|
||||
periodicAdvertisingIntervalMaxMs.value(),
|
||||
periodicAdvertisingIntervalMin.value(),
|
||||
periodicAdvertisingIntervalMax.value(),
|
||||
advertiseTxPower
|
||||
);
|
||||
}
|
||||
|
@ -2388,8 +2388,8 @@ ble_error_t GenericGap::setScanParameters(const GapScanParameters ¶ms)
|
|||
|
||||
ble_error_t GenericGap::startScan(
|
||||
scanning_filter_duplicates_t filtering,
|
||||
uint16_t duration,
|
||||
uint16_t period
|
||||
UnitScanDuration_t duration,
|
||||
UnitScanPeriod_t period
|
||||
)
|
||||
{
|
||||
use_non_deprecated_scan_api();
|
||||
|
@ -2399,11 +2399,11 @@ ble_error_t GenericGap::startScan(
|
|||
return _pal_gap.extended_scan_enable(
|
||||
/* enable */true,
|
||||
(pal::duplicates_filter_t::type) filtering,
|
||||
duration,
|
||||
period
|
||||
duration.value(),
|
||||
period.value()
|
||||
);
|
||||
} else {
|
||||
if (period != 0) {
|
||||
if (period.value() != 0) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
@ -2417,10 +2417,10 @@ ble_error_t GenericGap::startScan(
|
|||
}
|
||||
|
||||
_scan_timeout.detach();
|
||||
if (duration) {
|
||||
if (duration.value()) {
|
||||
_scan_timeout.attach_us(
|
||||
mbed::callback(this, &GenericGap::on_scan_timeout),
|
||||
duration * 10 /* ms */ * 1000 /* us */
|
||||
duration.microseconds()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2432,8 +2432,8 @@ ble_error_t GenericGap::createSync(
|
|||
Gap::PeerAddressType_t peerAddressType,
|
||||
uint8_t *peerAddress,
|
||||
uint8_t sid,
|
||||
uint16_t maxPacketSkip,
|
||||
uint32_t timeoutMs
|
||||
UnitSlaveLatency_t maxPacketSkip,
|
||||
UnitSyncTimeout_t timeout
|
||||
)
|
||||
{
|
||||
if (is_extended_advertising_available() == false) {
|
||||
|
@ -2450,47 +2450,31 @@ ble_error_t GenericGap::createSync(
|
|||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (maxPacketSkip > 0x1F3) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint32_t timeout = timeoutMs / 10;
|
||||
if (timeout < 0x000A || timeout > 0x4000) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return _pal_gap.periodic_advertising_create_sync(
|
||||
/* use advertiser list */ false,
|
||||
sid,
|
||||
(peer_address_type_t::type) peerAddressType.value(),
|
||||
peerAddress,
|
||||
maxPacketSkip,
|
||||
timeout
|
||||
maxPacketSkip.value(),
|
||||
timeout.value()
|
||||
);
|
||||
}
|
||||
|
||||
ble_error_t GenericGap::createSync(uint16_t maxPacketSkip, uint32_t timeoutMs)
|
||||
{
|
||||
ble_error_t GenericGap::createSync(
|
||||
UnitSlaveLatency_t maxPacketSkip,
|
||||
UnitSyncTimeout_t timeout
|
||||
) {
|
||||
if (is_extended_advertising_available() == false) {
|
||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
if (maxPacketSkip > 0x1F3) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
uint32_t timeout = timeoutMs / 10;
|
||||
if (timeout < 0x000A || timeout > 0x4000) {
|
||||
return BLE_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
return _pal_gap.periodic_advertising_create_sync(
|
||||
/* use advertiser list */ true,
|
||||
/* sid - not used */ 0x00,
|
||||
/* N/A */ peer_address_type_t::PUBLIC,
|
||||
/* N/A */ ble::address_t(),
|
||||
maxPacketSkip,
|
||||
timeout
|
||||
maxPacketSkip.value(),
|
||||
timeout.value()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue