From 89d6b647476897e8110efddd829e7e32c93c62f6 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Thu, 22 Jan 2015 15:28:35 +0000 Subject: [PATCH] Treat signal level in network messages as a (RMS) amplitude, since that is what was previously done and it gives us better range for small signals. Means a sqrt() call on beast output, but this shouldn't be too bad as it's only done once per message. --- net_io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/net_io.c b/net_io.c index 9d94c98..c4265d5 100644 --- a/net_io.c +++ b/net_io.c @@ -293,7 +293,7 @@ void modesSendBeastOutput(struct modesMessage *mm) { if (0x1A == ch) {*p++ = ch; } } - *p++ = ch = (char) round(mm->signalLevel * 255); + *p++ = ch = (char) round(sqrt(mm->signalLevel) * 255); if (0x1A == ch) {*p++ = ch; } for (j = 0; j < msgLen; j++) { @@ -569,7 +569,8 @@ int decodeBinMessage(struct client *c, char *p) { } ch = *p++; // Grab the signal level - mm.signalLevel = 1e-5 + (unsigned char)ch / 256.0; + mm.signalLevel = ((unsigned char)ch / 256.0); + mm.signalLevel = mm.signalLevel * mm.signalLevel + 1e-5; if (0x1A == ch) {p++;} for (j = 0; j < msgLen; j++) { // and the data @@ -645,7 +646,8 @@ int decodeHexMessage(struct client *c, char *hex) { switch(hex[0]) { case '<': { - mm.signalLevel = 1e-5 + ((hexDigitVal(hex[13])<<4) | hexDigitVal(hex[14])) / 256.0; + mm.signalLevel = ((hexDigitVal(hex[13])<<4) | hexDigitVal(hex[14])) / 256.0; + mm.signalLevel = mm.signalLevel * mm.signalLevel + 1e-5; hex += 15; l -= 16; // Skip <, timestamp and siglevel, and ; break;}