mirror of
https://github.com/lumapu/ahoy.git
synced 2025-05-27 15:56:11 +02:00
switched to dynamic payload mode, added a pretender
This commit is contained in:
parent
c0abc8daae
commit
122e4567b1
5 changed files with 168 additions and 10 deletions
45
tools/rpi/discover/common.cpp
Normal file
45
tools/rpi/discover/common.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "common.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/** Convert given 5-byte address to human readable hex string */
|
||||
string prettyPrintAddr(string &a)
|
||||
{
|
||||
ostringstream o;
|
||||
o << hex << setw(2)
|
||||
<< setfill('0') << setw(2) << int(a[0])
|
||||
<< ":" << setw(2) << int(a[1])
|
||||
<< ":" << setw(2) << int(a[2])
|
||||
<< ":" << setw(2) << int(a[3])
|
||||
<< ":" << setw(2) << int(a[4]) << dec;
|
||||
return o.str();
|
||||
}
|
||||
|
||||
|
||||
/** Convert a Hoymiles inverter/DTU serial number into its
|
||||
* corresponding NRF24 address byte sequence (5 bytes).
|
||||
*
|
||||
* The inverters use a BCD representation of the last 8
|
||||
* digits of their serial number, in reverse byte order,
|
||||
* followed by \x01.
|
||||
*/
|
||||
string serno2shockburstaddrbytes(uint64_t n)
|
||||
{
|
||||
char b[5];
|
||||
b[3] = (((n/10)%10) << 4) | ((n/1)%10);
|
||||
b[2] = (((n/1000)%10) << 4) | ((n/100)%10);
|
||||
b[1] = (((n/100000)%10) << 4) | ((n/10000)%10);
|
||||
b[0] = (((n/10000000)%10) << 4) | ((n/1000000)%10);
|
||||
b[4] = 0x01;
|
||||
|
||||
string s = string(b, sizeof(b));
|
||||
|
||||
cout << dec << "ser# " << n << " --> addr "
|
||||
<< prettyPrintAddr(s) << endl;
|
||||
return s;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue