Skip to content

Commit

Permalink
Merge pull request #68 from n-peugnet/signal-average
Browse files Browse the repository at this point in the history
Add signal strength average to StationInfo struct
  • Loading branch information
SuperQ committed May 21, 2024
2 parents e031f90 + c75d970 commit 7baef12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ func (info *StationInfo) parseAttributes(attrs []netlink.Attribute) error {
// * @NL80211_STA_INFO_SIGNAL: signal strength of last received PPDU (u8, dBm)
// Should just be cast to int8, see code here: https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/station.c#n378
info.Signal = int(int8(a.Data[0]))
case unix.NL80211_STA_INFO_SIGNAL_AVG:
info.SignalAverage = int(int8(a.Data[0]))
case unix.NL80211_STA_INFO_RX_PACKETS:
info.ReceivedPackets = int(nlenc.Uint32(a.Data))
case unix.NL80211_STA_INFO_TX_PACKETS:
Expand Down
3 changes: 3 additions & 0 deletions client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) {
ReceivedPackets: 10,
TransmittedPackets: 20,
Signal: -50,
SignalAverage: -53,
TransmitRetries: 5,
TransmitFailed: 2,
BeaconLoss: 3,
Expand All @@ -291,6 +292,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) {
ReceivedPackets: 20,
TransmittedPackets: 40,
Signal: -25,
SignalAverage: -27,
TransmitRetries: 10,
TransmitFailed: 4,
BeaconLoss: 6,
Expand Down Expand Up @@ -493,6 +495,7 @@ func (s *StationInfo) attributes() []netlink.Attribute {
{Type: unix.NL80211_STA_INFO_TX_BYTES, Data: nlenc.Uint32Bytes(uint32(s.TransmittedBytes))},
{Type: unix.NL80211_STA_INFO_TX_BYTES64, Data: nlenc.Uint64Bytes(uint64(s.TransmittedBytes))},
{Type: unix.NL80211_STA_INFO_SIGNAL, Data: []byte{byte(int8(s.Signal))}},
{Type: unix.NL80211_STA_INFO_SIGNAL_AVG, Data: []byte{byte(int8(s.SignalAverage))}},
{Type: unix.NL80211_STA_INFO_RX_PACKETS, Data: nlenc.Uint32Bytes(uint32(s.ReceivedPackets))},
{Type: unix.NL80211_STA_INFO_TX_PACKETS, Data: nlenc.Uint32Bytes(uint32(s.TransmittedPackets))},
{Type: unix.NL80211_STA_INFO_TX_RETRIES, Data: nlenc.Uint32Bytes(uint32(s.TransmitRetries))},
Expand Down
5 changes: 4 additions & 1 deletion wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ type StationInfo struct {
// The current data transmit bitrate, in bits/second.
TransmitBitrate int

// The signal strength of this station's connection, in dBm.
// The signal strength of the last received PPDU, in dBm.
Signal int

// The average signal strength, in dBm.
SignalAverage int

// The number of times the station has had to retry while sending a packet.
TransmitRetries int

Expand Down

0 comments on commit 7baef12

Please sign in to comment.