mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
sx1276: Initial implementation
This driver was developed using an SX1276 based shield on the Galileo G2. It requires 3.3v of operation. It does not work with Edison, due to SPI issues. Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
4de9734f0a
commit
2a1af1399a
@ -155,6 +155,8 @@ add_executable (bma220-example bma220.cxx)
|
||||
add_executable (dfrph-example dfrph.cxx)
|
||||
add_executable (mcp9808-example mcp9808.cxx)
|
||||
add_executable (groveultrasonic-example groveultrasonic.cxx)
|
||||
add_executable (sx1276-lora-example sx1276-lora.cxx)
|
||||
add_executable (sx1276-fsk-example sx1276-fsk.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -274,6 +276,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/bma220)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/dfrph)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mcp9808)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/groveultrasonic)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/sx1276)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -430,3 +433,5 @@ target_link_libraries (bma220-example bma220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (dfrph-example dfrph ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mcp9808-example mcp9808 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveultrasonic-example groveultrasonic ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (sx1276-lora-example sx1276 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (sx1276-fsk-example sx1276 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
121
examples/c++/sx1276-fsk.cxx
Normal file
121
examples/c++/sx1276-fsk.cxx
Normal file
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "sx1276.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Specify an argument to go into receive mode. Default is transmit"
|
||||
<< endl;
|
||||
|
||||
bool rx = false;
|
||||
if (argc > 1)
|
||||
rx = true;
|
||||
|
||||
// Instantiate an SX1276 using default parameters
|
||||
upm::SX1276 *sensor = new upm::SX1276();
|
||||
|
||||
// 915Mhz
|
||||
sensor->setChannel(915000000);
|
||||
|
||||
// FSK configuration (rx and tx must be configured the same):
|
||||
// Tx output power = 14 dBm
|
||||
// FSK freq deviation = 25000 Hz
|
||||
// FSK bandwidth = 50000 bps
|
||||
// FSK AFC bandwidth = 83333 Hz
|
||||
// FSK datarate = 50000 bps
|
||||
// FSK preamble len = 5
|
||||
// FSK fixed length payload = false
|
||||
// FSK CRC check = true
|
||||
// FSK (rx) continuous Rx mode = false
|
||||
|
||||
sensor->setTxConfig(sensor->MODEM_FSK, 14, 25000, 0,
|
||||
50000, 0, 5, false, true, false, 0, false);
|
||||
|
||||
sensor->setRxConfig(sensor->MODEM_FSK, 50000, 50000,
|
||||
0, 83333, 5, 0, false, 0, true,
|
||||
false, 0, false, true);
|
||||
|
||||
int count = 0;
|
||||
int buflen = 64;
|
||||
char buffer[buflen];
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
if (!rx)
|
||||
{
|
||||
snprintf(buffer, buflen, "Ping %d", count++);
|
||||
cout << "Sending..." << std::string(buffer) << endl;
|
||||
sensor->sendStr(string(buffer), 3000);
|
||||
|
||||
sensor->setSleep();
|
||||
sleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// receiving
|
||||
cout << "Attempting to receive..." << endl;
|
||||
int rv;
|
||||
if (rv = sensor->setRx(3000))
|
||||
{
|
||||
cout << "setRx returned " << rv << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Received Buffer: " << sensor->getRxBufferStr() << endl;
|
||||
}
|
||||
|
||||
// go back to sleep when done
|
||||
sensor->setSleep();
|
||||
usleep(250000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
119
examples/c++/sx1276-lora.cxx
Normal file
119
examples/c++/sx1276-lora.cxx
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "sx1276.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
//! [Interesting]
|
||||
cout << "Specify an argument to go into receive mode. Default is transmit"
|
||||
<< endl;
|
||||
|
||||
bool rx = false;
|
||||
if (argc > 1)
|
||||
rx = true;
|
||||
|
||||
// Instantiate an SX1276 using default parameters
|
||||
upm::SX1276 *sensor = new upm::SX1276();
|
||||
|
||||
// 915Mhz
|
||||
sensor->setChannel(915000000);
|
||||
|
||||
// LORA configuration (rx and tx must be configured the same):
|
||||
// Tx output power = 14 dBm
|
||||
// LORA bandwidth = 125000 (can also be 250K and 500K)
|
||||
// LORA spreading factor = 7
|
||||
// LORA coding rate = 1 (4/5)
|
||||
// LORA preamble len = 8
|
||||
// LORA symbol timeout = 5
|
||||
// LORA fixed payload = false
|
||||
// LORA IQ inversion = false
|
||||
// LORA (rx) continuous Rx mode = true
|
||||
|
||||
sensor->setTxConfig(sensor->MODEM_LORA, 14, 0, 125000,
|
||||
7, 1, 8, false, true, false, 0, false);
|
||||
|
||||
sensor->setRxConfig(sensor->MODEM_LORA, 125000, 7,
|
||||
1, 0, 8, 5, false, 0, true, false, 0, false, true);
|
||||
|
||||
int count = 0;
|
||||
int buflen = 64;
|
||||
char buffer[buflen];
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
if (!rx)
|
||||
{
|
||||
snprintf(buffer, buflen, "Ping %d", count++);
|
||||
cout << "Sending..." << std::string(buffer) << endl;
|
||||
sensor->sendStr(string(buffer), 3000);
|
||||
sensor->setSleep();
|
||||
sleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// receiving
|
||||
cout << "Attempting to receive..." << endl;
|
||||
int rv;
|
||||
if (rv = sensor->setRx(3000))
|
||||
{
|
||||
cout << "setRx returned " << rv << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Received Buffer: " << sensor->getRxBufferStr() << endl;
|
||||
}
|
||||
|
||||
// go back to sleep when done
|
||||
sensor->setSleep();
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
112
examples/javascript/sx1276-fsk.js
Normal file
112
examples/javascript/sx1276-fsk.js
Normal file
@ -0,0 +1,112 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
var sensorObj = require('jsupm_sx1276');
|
||||
|
||||
var count = 0;
|
||||
var interval;
|
||||
|
||||
/************** Functions **************/
|
||||
function transmit(sensor)
|
||||
{
|
||||
var buffer = "Ping " + count;
|
||||
count++;
|
||||
console.log("Sending... " + buffer);
|
||||
|
||||
sensor.sendStr(buffer, 3000);
|
||||
sensor.setSleep();
|
||||
}
|
||||
|
||||
function receive(sensor)
|
||||
{
|
||||
console.log("Attempting to receive... ");
|
||||
var rv = 0;
|
||||
rv = sensor.setRx(3000);
|
||||
|
||||
if (rv)
|
||||
{
|
||||
console.log("setRx returned " + rv);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Received Buffer: " + sensor.getRxBufferStr());
|
||||
}
|
||||
|
||||
sensor.setSleep();
|
||||
}
|
||||
|
||||
/************** Main code **************/
|
||||
// Instantiate an SX1276 using default parameters
|
||||
|
||||
var sensor = new sensorObj.SX1276();
|
||||
|
||||
console.log("Specify an argument to go into receive mode. Default is transmit");
|
||||
|
||||
// 915Mhz
|
||||
sensor.setChannel(915000000)
|
||||
|
||||
// FSK configuration (rx and tx must be configured the same):
|
||||
// Tx output power = 14 dBm
|
||||
// FSK freq deviation = 25000 Hz
|
||||
// FSK bandwidth = 50000 bps
|
||||
// FSK AFC bandwidth = 83333 Hz
|
||||
// FSK datarate = 50000 bps
|
||||
// FSK preamble len = 5
|
||||
// FSK fixed length payload = false
|
||||
// FSK CRC check = true
|
||||
// FSK (rx) continuous Rx mode = False
|
||||
|
||||
sensor.setTxConfig(sensorObj.SX1276.MODEM_FSK, 14, 25000, 0,
|
||||
50000, 0, 5, false, true, false, 0, false);
|
||||
|
||||
sensor.setRxConfig(sensorObj.SX1276.MODEM_FSK, 50000, 50000,
|
||||
0, 83333, 5, 0, false, 0, true,
|
||||
false, 0, false, true);
|
||||
|
||||
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
// receive mode
|
||||
interval = setInterval(function() { receive(sensor); }, 250);
|
||||
}
|
||||
else
|
||||
{
|
||||
// transmit mode
|
||||
interval = setInterval(function() { transmit(sensor); }, 1000);
|
||||
}
|
||||
|
||||
|
||||
/************** Exit code **************/
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
110
examples/javascript/sx1276-lora.js
Normal file
110
examples/javascript/sx1276-lora.js
Normal file
@ -0,0 +1,110 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
var sensorObj = require('jsupm_sx1276');
|
||||
|
||||
var count = 0;
|
||||
var interval;
|
||||
|
||||
/************** Functions **************/
|
||||
function transmit(sensor)
|
||||
{
|
||||
var buffer = "Ping " + count;
|
||||
count++;
|
||||
console.log("Sending... " + buffer);
|
||||
|
||||
sensor.sendStr(buffer, 3000);
|
||||
sensor.setSleep();
|
||||
}
|
||||
|
||||
function receive(sensor)
|
||||
{
|
||||
console.log("Attempting to receive... ");
|
||||
var rv = 0;
|
||||
rv = sensor.setRx(3000);
|
||||
|
||||
if (rv)
|
||||
{
|
||||
console.log("setRx returned " + rv);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("Received Buffer: " + sensor.getRxBufferStr());
|
||||
}
|
||||
|
||||
sensor.setSleep();
|
||||
}
|
||||
|
||||
/************** Main code **************/
|
||||
// Instantiate an SX1276 using default parameters
|
||||
|
||||
var sensor = new sensorObj.SX1276();
|
||||
|
||||
console.log("Specify an argument to go into receive mode. Default is transmit");
|
||||
|
||||
// 915Mhz
|
||||
sensor.setChannel(915000000)
|
||||
|
||||
// LORA configuration (rx and tx must be configured the same):
|
||||
// Tx output power = 14 dBm
|
||||
// LORA bandwidth = 125000 (can also be 250K and 500K)
|
||||
// LORA spreading factor = 7
|
||||
// LORA coding rate = 1 (4/5)
|
||||
// LORA preamble len = 8
|
||||
// LORA symbol timeout = 5
|
||||
// LORA fixed payload = false
|
||||
// LORA IQ inversion = false
|
||||
// LORA (rx) continuous Rx mode = true
|
||||
|
||||
sensor.setTxConfig(sensorObj.SX1276.MODEM_LORA, 14, 0, 125000,
|
||||
7, 1, 8, false, true, false, 0, false);
|
||||
|
||||
sensor.setRxConfig(sensorObj.SX1276.MODEM_LORA, 125000, 7,
|
||||
1, 0, 8, 5, false, 0, true, false, 0, false, true);
|
||||
|
||||
if (process.argv.length > 2)
|
||||
{
|
||||
// receive mode
|
||||
interval = setInterval(function() { receive(sensor); }, 250);
|
||||
}
|
||||
else
|
||||
{
|
||||
// transmit mode
|
||||
interval = setInterval(function() { transmit(sensor); }, 1000);
|
||||
}
|
||||
|
||||
|
||||
/************** Exit code **************/
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
89
examples/python/sx1276-fsk.py
Normal file
89
examples/python/sx1276-fsk.py
Normal file
@ -0,0 +1,89 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_sx1276 as sensorObj
|
||||
|
||||
# Instantiate an SX1276 using default parameters
|
||||
sensor = sensorObj.SX1276()
|
||||
|
||||
## Exit handlers ##
|
||||
# This stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
print "Specify an argument to go into receive mode. Default is transmit"
|
||||
|
||||
# 915Mhz
|
||||
sensor.setChannel(915000000)
|
||||
|
||||
# FSK configuration (rx and tx must be configured the same):
|
||||
# Tx output power = 14 dBm
|
||||
# FSK freq deviation = 25000 Hz
|
||||
# FSK bandwidth = 50000 bps
|
||||
# FSK AFC bandwidth = 83333 Hz
|
||||
# FSK datarate = 50000 bps
|
||||
# FSK preamble len = 5
|
||||
# FSK fixed length payload = false
|
||||
# FSK CRC check = true
|
||||
# FSK (rx) continuous Rx mode = False
|
||||
|
||||
sensor.setTxConfig(sensor.MODEM_FSK, 14, 25000, 0,
|
||||
50000, 0, 5, False, True, False, 0, False)
|
||||
|
||||
sensor.setRxConfig(sensor.MODEM_FSK, 50000, 50000,
|
||||
0, 83333, 5, 0, False, 0, True,
|
||||
False, 0, False, True)
|
||||
|
||||
count = 0
|
||||
|
||||
while True:
|
||||
if (len(sys.argv) > 1):
|
||||
# receive mode
|
||||
print "Attempting to receive..."
|
||||
rv = sensor.setRx(3000)
|
||||
if (rv):
|
||||
print "setRx returned ", rv
|
||||
else:
|
||||
print "Received Buffer: ", sensor.getRxBufferStr();
|
||||
# go back to sleep when done
|
||||
|
||||
sensor.setSleep()
|
||||
time.sleep(.25)
|
||||
else:
|
||||
# transmit mode
|
||||
buffer = "Ping " + str(count)
|
||||
count += 1
|
||||
print "Sending..." + buffer
|
||||
sensor.sendStr(buffer, 3000)
|
||||
sensor.setSleep();
|
||||
time.sleep(1);
|
88
examples/python/sx1276-lora.py
Normal file
88
examples/python/sx1276-lora.py
Normal file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2015 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_sx1276 as sensorObj
|
||||
|
||||
# Instantiate an SX1276 using default parameters
|
||||
sensor = sensorObj.SX1276()
|
||||
|
||||
## Exit handlers ##
|
||||
# This stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
print "Specify an argument to go into receive mode. Default is transmit"
|
||||
|
||||
# 915Mhz
|
||||
sensor.setChannel(915000000)
|
||||
|
||||
# LORA configuration (rx and tx must be configured the same):
|
||||
# Tx output power = 14 dBm
|
||||
# LORA bandwidth = 125000 (can also be 250K and 500K)
|
||||
# LORA spreading factor = 7
|
||||
# LORA coding rate = 1 (4/5)
|
||||
# LORA preamble len = 8
|
||||
# LORA symbol timeout = 5
|
||||
# LORA fixed payload = false
|
||||
# LORA IQ inversion = false
|
||||
# LORA (rx) continuous Rx mode = true
|
||||
|
||||
sensor.setTxConfig(sensor.MODEM_LORA, 14, 0, 125000,
|
||||
7, 1, 8, False, True, False, 0, False)
|
||||
|
||||
sensor.setRxConfig(sensor.MODEM_LORA, 125000, 7,
|
||||
1, 0, 8, 5, False, 0, True, False, 0, False, True)
|
||||
|
||||
count = 0
|
||||
|
||||
while True:
|
||||
if (len(sys.argv) > 1):
|
||||
# receive mode
|
||||
print "Attempting to receive..."
|
||||
rv = sensor.setRx(3000)
|
||||
if (rv):
|
||||
print "setRx returned ", rv
|
||||
else:
|
||||
print "Received Buffer: ", sensor.getRxBufferStr();
|
||||
# go back to sleep when done
|
||||
|
||||
sensor.setSleep()
|
||||
time.sleep(.25)
|
||||
else:
|
||||
# transmit mode
|
||||
buffer = "Ping " + str(count)
|
||||
count += 1
|
||||
print "Sending..." + buffer
|
||||
sensor.sendStr(buffer, 3000)
|
||||
sensor.setSleep();
|
||||
time.sleep(1);
|
5
src/sx1276/CMakeLists.txt
Normal file
5
src/sx1276/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set (libname "sx1276")
|
||||
set (libdescription "SZ1276 LoRa/FSK/OOK radio")
|
||||
set (module_src ${libname}.cxx)
|
||||
set (module_h ${libname}.h)
|
||||
upm_module_init()
|
25
src/sx1276/LICENSE.txt
Normal file
25
src/sx1276/LICENSE.txt
Normal file
@ -0,0 +1,25 @@
|
||||
--- Revised BSD License ---
|
||||
Copyright (c) 2013, SEMTECH S.A.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Semtech corporation nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
src/sx1276/javaupm_sx1276.i
Normal file
36
src/sx1276/javaupm_sx1276.i
Normal file
@ -0,0 +1,36 @@
|
||||
%module(directors="1") javaupm_sx1276
|
||||
%include "../upm.i"
|
||||
%include "cpointer.i"
|
||||
%include "typemaps.i"
|
||||
%include "arrays_java.i";
|
||||
%include "../java_buffer.i"
|
||||
|
||||
%feature("director") IsrCallback;
|
||||
|
||||
%ignore generic_callback_isr;
|
||||
%include "../IsrCallback.h"
|
||||
|
||||
%apply int {mraa::Edge};
|
||||
%apply float *INOUT { float *x, float *y, float *z };
|
||||
|
||||
%typemap(jni) float* "jfloatArray"
|
||||
%typemap(jstype) float* "float[]"
|
||||
%typemap(jtype) float* "float[]"
|
||||
|
||||
%typemap(javaout) float* {
|
||||
return $jnicall;
|
||||
}
|
||||
|
||||
%typemap(out) float *getAccelerometer {
|
||||
$result = JCALL1(NewFloatArray, jenv, 3);
|
||||
JCALL4(SetFloatArrayRegion, jenv, $result, 0, 3, $1);
|
||||
delete [] $1;
|
||||
}
|
||||
|
||||
%ignore getAccelerometer(float *, float *, float *);
|
||||
|
||||
%{
|
||||
#include "sx1276.h"
|
||||
%}
|
||||
|
||||
%include "sx1276.h"
|
9
src/sx1276/jsupm_sx1276.i
Normal file
9
src/sx1276/jsupm_sx1276.i
Normal file
@ -0,0 +1,9 @@
|
||||
%module jsupm_sx1276
|
||||
%include "../upm.i"
|
||||
%include "cpointer.i"
|
||||
|
||||
%include "sx1276.h"
|
||||
%{
|
||||
#include "sx1276.h"
|
||||
%}
|
||||
|
15
src/sx1276/pyupm_sx1276.i
Normal file
15
src/sx1276/pyupm_sx1276.i
Normal file
@ -0,0 +1,15 @@
|
||||
%module pyupm_sx1276
|
||||
%include "../upm.i"
|
||||
%include "cpointer.i"
|
||||
|
||||
%include "stdint.i"
|
||||
|
||||
%feature("autodoc", "3");
|
||||
|
||||
%pointer_functions(float, floatp);
|
||||
|
||||
%include "sx1276.h"
|
||||
%{
|
||||
#include "sx1276.h"
|
||||
%}
|
||||
|
2160
src/sx1276/sx1276.cxx
Normal file
2160
src/sx1276/sx1276.cxx
Normal file
File diff suppressed because it is too large
Load Diff
2035
src/sx1276/sx1276.h
Normal file
2035
src/sx1276/sx1276.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user