From ee61e3f582cb400a66be85d2bd4cb0570ba24b9b Mon Sep 17 00:00:00 2001 From: Russ Handorf Date: Sat, 13 Feb 2016 16:14:55 -0500 Subject: [PATCH] Added files, directories and comments. --- README | 47 +++++ sdrninja-client/sdr.html | 2 + sdrninja-client/sdr.js | 144 ++++++++++++++++ sdrninja-client/sdrninja.init | 47 +++++ sdrninja-client/sdrninja/server.py | 110 ++++++++++++ sdrninja-client/sdrninja/start.sh | 4 + sdrninja-server/.waterfall.py.swp | Bin 0 -> 16384 bytes sdrninja-server/client.py | 267 +++++++++++++++++++++++++++++ sdrninja-server/radio_math.py | 204 ++++++++++++++++++++++ sdrninja-server/radio_math.pyc | Bin 0 -> 7648 bytes sdrninja-server/sdrninja.initd | 47 +++++ sdrninja-server/start.sh | 4 + 12 files changed, 876 insertions(+) create mode 100644 sdrninja-client/sdr.html create mode 100644 sdrninja-client/sdr.js create mode 100755 sdrninja-client/sdrninja.init create mode 100644 sdrninja-client/sdrninja/server.py create mode 100755 sdrninja-client/sdrninja/start.sh create mode 100644 sdrninja-server/.waterfall.py.swp create mode 100644 sdrninja-server/client.py create mode 100644 sdrninja-server/radio_math.py create mode 100644 sdrninja-server/radio_math.pyc create mode 100755 sdrninja-server/sdrninja.initd create mode 100755 sdrninja-server/start.sh diff --git a/README b/README index e69de29..ebfa13b 100644 --- a/README +++ b/README @@ -0,0 +1,47 @@ +Howdy do neighbor! + +If you're reading this, then pour yourself a tasty beverage. The history of this was so that I could learn the basics of websockets, html js canvasas, integration with wordpress, and some python coding for rtlsdr bits. All the code contained within is basically what you would need to do in order to mimic what is live on http://sdr.ninja. + +Firstly, lets get the licensing out of the way... + +############################################################################### +# The MIT License (MIT) +# Copyright (c) Russell Handorf +# Other copyrights noted where code modification is located +# +# 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. +# +############################################################################### + +In all cases for scripts, replace all instances of 'YOURSERVER' with your server's domainname, ip, or some other identifier. To make your life easier, just grep for this. + +sdrninja-client +-sdr.html : This is the HTML code for your web page to include the canvas +-sdr.js : This is the JS that is called to connect to the websocket and render the canvas. This has a YOURSERVER config requirement. +-sdrninja.init : This is an init.d script for making it an automagical process if you'd like. Copy the sdrninja dir into /etc/ to make that happen more easily +-sdrninja/start.sh : This is the script that the init script calls +-sdrninja/server.py : This is what creates the python websocket. You'll have some dependencies to install laddy! +-sdrninja/logs : If you want logs, dump 'em here + +sdrninja-server +-client.py : A fairly modified script origionally written by Tavendo GmbH. I've added web socket handling, frequency range mapping, and a few other minor fixes to make this work. This is a great script to learn from for doing basif FFT in python. Tip of the hat to Tavendo GmbH! +-radio_math.py/radio_math.pyc : Math dependencies for client.py. Tau for the win. +-sdrninja.init : This is an init.d script for making it an automagical process if you'd like. Copy the sdrninja dir into /etc/ to make that happen more easily +-logs : If you want logs, dump 'em here + diff --git a/sdrninja-client/sdr.html b/sdrninja-client/sdr.html new file mode 100644 index 0000000..97489d7 --- /dev/null +++ b/sdrninja-client/sdr.html @@ -0,0 +1,2 @@ + + diff --git a/sdrninja-client/sdr.js b/sdrninja-client/sdr.js new file mode 100644 index 0000000..236b4e9 --- /dev/null +++ b/sdrninja-client/sdr.js @@ -0,0 +1,144 @@ +var canvas = document.getElementById("sdr"); +var canvasWidth = canvas.width; +var canvasHeight = canvas.height; +var ctx = canvas.getContext("2d"); + +ctx.imageSmoothingEnabled = false; +ctx.mozImageSmoothingEnabled = false; +var canvasData = ctx.getImageData(0, 0, canvasWidth, canvasHeight); + +//test +var buffer = document.createElement('canvas'); +buffer.width = canvas.width; +buffer.height = canvas.height; + + +//init pixels +var pixels = new Array(canvasHeight*canvasWidth); + +//generate static +var pixelCounter=0; + +for (y=0; ycanvasWidth; x--) { + var offset = x-canvasWidth; + arr[x].r = arr[offset].r; + arr[x].g = arr[offset].g; + arr[x].b = arr[offset].b; + } + //insert the new row + var newrow = JSON.parse(newrowJSON); + padding=(canvasWidth-newrow.length)/2; + for (var x=0; x 1 and sys.argv[1] == 'debug': + log.startLogging(sys.stdout) + debug = True + else: + debug = False + + ServerFactory = BroadcastServerFactory + # ServerFactory = BroadcastPreparedServerFactory + + factory = ServerFactory("ws://localhost:9000", + debug=debug, + debugCodePaths=debug) + + factory.protocol = BroadcastServerProtocol + factory.setProtocolOptions(allowHixie76=True) + listenWS(factory) + + reactor.run() + diff --git a/sdrninja-client/sdrninja/start.sh b/sdrninja-client/sdrninja/start.sh new file mode 100755 index 0000000..88bf935 --- /dev/null +++ b/sdrninja-client/sdrninja/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash +PWD=`pwd` +script=$PWD'/server.py' +/usr/bin/python $script & diff --git a/sdrninja-server/.waterfall.py.swp b/sdrninja-server/.waterfall.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..b1af671ff6ec21abec586bb0b0fb7aade2c24122 GIT binary patch literal 16384 zcmeHOON<;x8Lrp~Z$mI}AVN`jE!f#*c4lX69BgGEmJ>oEdqLjV7P6vIPj_{9#XVh3 zRrNfU*NsGohX5h*5OB-^B#t~T$eb*}0r3#x0^9;Z!T}Bhp%A{ms%K_rABJ!OsayW0 zXY2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lGX9)%|uY0>4T%{+lq z&G!YF*)t7O3QDiv<9im;ScN42iv5*OTIYUYFdzUpxqGm?D&M_4xJ0;_XcfjcMwnB!mtoFd0PX42vem&>`<<(%3!A z+fr2RZ`Fxs;WQT?nsEl0=WrHgL6WHfoG{NYvuInS7#ax$u$V~O==yH?-QEg`gb8V0 zBf;1eMg_ZM7hDDc#hB|^M%f|Xr*q!v1f^A>(pns%6=o8diSiDzQ{obd$dGgPnH%VU zhUU^+5It2I>$VpA^a8EbnBNdnLn+8v-cf4E8zz;p-vkU~k{}e(_rk30Gax2zKY5Pt zegm1G?Vc59_}NpN;>^Ap7*ywh!+=58Ys@eRpWO?%XpK-^ANxq*w2;_$*WW&koD&lUC%8*T-` z9?M`ioUd9wR{91O0c6h$NR`#^#F zDMy;8`TX9622wkQJ`$M#`eRP`86yy?!|g&o#5@#==MP7ZIO>q+ome-GJ5|1HlD|y2k7}9kIC-3 zh3EKZfv15_0x8f1jskyy?w_kVx2axz)eO`O)C|-N)C|-N)C|-N)C|-N)C|-N)C~O3 zF;G392Sw4+WsZZ`svyKc!;O}~abHy8$3u5IFbcAUI|A&Raex!O2k@KNzft$6<4xXa zZMLf;WE?nEr^z_QbqB3II=f#Sqxqv?uU(xuw$MM3N4|A`Oy?vxhFsPw6n^sZ3M(Q0 j4?S057#JLW;Jf?nAqZ{hzPpnXXJpmzp%~)0Wrh61: + Pxy = Pxy.mean(axis=1) + return Pxy, freqs + + +#This is a helper function that implements the commonality between the +#psd, csd, and spectrogram. It is *NOT* meant to be used outside of mlab +def _spectral_helper(x, y, NFFT=256, Fs=2, detrend=detrend_none, + window=window_hanning, noverlap=0, pad_to=None, sides='default', + scale_by_freq=True): + #The checks for if y is x are so that we can use the same function to + #implement the core of psd(), csd(), and spectrogram() without doing + #extra calculations. We return the unaveraged Pxy, freqs, and t. + same_data = y is x + + #Make sure we're dealing with a numpy array. If y and x were the same + #object to start with, keep them that way + x = numpy.asarray(x) + if not same_data: + y = numpy.asarray(y) + else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