Skip to content

Commit

Permalink
Now able to build and run under Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stephendade committed Apr 9, 2017
1 parent 1f709f9 commit d2201e1
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cuav/image/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,9 +1201,13 @@ scanner_thermal_convert(PyObject *self, PyObject *args)

for (uint32_t i=0; i<width*height; i++) {
uint16_t value = data[i];
#ifndef __MINGW32__
if (__BYTE_ORDER == __LITTLE_ENDIAN) {
swab(&value, &value, 2);
}
#else
swab(&value, &value, 2);
#endif
value >>= 2;
mask |= value;
if (value > maxv) maxv = value;
Expand All @@ -1214,9 +1218,13 @@ scanner_thermal_convert(PyObject *self, PyObject *args)

for (uint32_t i=0; i<width*height; i++) {
uint16_t value = data[i];
#ifndef __MINGW32__
if (__BYTE_ORDER == __LITTLE_ENDIAN) {
swab(&value, &value, 2);
}
#else
swab(&value, &value, 2);
#endif
value >>= 2;
uint8_t map_value(float v, const float threshold) {
if (v > threshold) {
Expand Down
3 changes: 2 additions & 1 deletion cuav/uav/uav.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from numpy import array, linalg, eye, zeros, dot, transpose
from numpy import sin, cos, pi
from matplotlib import pyplot

#def rotationMatrix(phi, theta, psi):
# out = zeros((3,3))
Expand Down Expand Up @@ -91,6 +90,8 @@ def __init__(self, fu=200, fv=200, cu=512, cv=480):


if __name__ == '__main__':
from matplotlib import pyplot

xfer = uavxfer()
xfer.setCameraParams(200.0, 200.0, 512, 480)
xfer.setCameraOrientation(0.0, 0.0, -pi/2)
Expand Down
48 changes: 48 additions & 0 deletions windows/createChangelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python
'''
Create a user readable changelog
Requires the gitpython package via pip install gitpython
Stephen Dade
November 2016
'''

from git import Repo
import os
import time

#Get the parent (..\) directory. ie the root cuav dir
path = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
repo = Repo(path)
assert not repo.bare

#get list of all commits
all_commits = list(repo.iter_commits('master'))

#open the changelog for writing
f = open("changelog.txt","w")

#go through all the commits
for comm in all_commits:
#if it's a version raise, add a special message
if "raise version" in comm.message:
commit_date = time.strftime("%d-%m-%Y", time.gmtime(comm.committed_date))
tree = comm.tree
#get setup.py and grab the version number from the file
blob = tree['setup.py']
data = blob.data_stream.read()
curversion = ""
for line in data.split('\n'):
if "version = " in line:
curversion = line[11:len(line)-1]
break

f.write("\n")
f.write("CUAV " + curversion + " (" + commit_date + ")\n")
else:
#just print the summary (1st line) of the commit message
comm.message.split('\n', 1)[0]
f.write("-" + comm.summary + "\n")

f.close()
print("Done")
103 changes: 103 additions & 0 deletions windows/cuav.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# -*- mode: python -*-
# spec file for pyinstaller to build cuav for windows
geotagAny = Analysis(['.\\cuav\\tools\\geotag.py'],
pathex=[os.path.abspath('.')],
# for some unknown reason these hidden imports don't pull in
# all the needed pieces, so we also import them in mavproxy.py
hiddenimports=['UserList', 'UserString',
'pymavlink.mavwp', 'pymavlink.mavutil', 'pymavlink.dialects.v20.ardupilotmega',
'pymavlink.dialects.v10.ardupilotmega',
'pymavlink.dialects.v20.common', 'pymavlink.dialects.v10.common',
'pymavlink.dialects.v20.ASLUAV', 'pymavlink.dialects.v10.ASLUAV',
'pymavlink.dialects.v20.autoquad', 'pymavlink.dialects.v10.autoquad',
'pymavlink.dialects.v20.matrixpilot', 'pymavlink.dialects.v10.matrixpilot',
'pymavlink.dialects.v20.minimal', 'pymavlink.dialects.v10.minimal',
'pymavlink.dialects.v20.paparazzi', 'pymavlink.dialects.v10.paparazzi',
'pymavlink.dialects.v20.slugs', 'pymavlink.dialects.v10.slugs',
'pymavlink.dialects.v20.standard', 'pymavlink.dialects.v10.standard',
'pymavlink.dialects.v20.ualberta', 'pymavlink.dialects.v10.ualberta',
'pymavlink.dialects.v20.uAvionix', 'pymavlink.dialects.v10.uAvionix'],
excludes=['tcl', 'tk', 'Tkinter', 'tkinter', '_tkinter'],
hookspath=None,
runtime_hooks=None)
pgmconvertAny = Analysis(['.\\cuav\\tools\\pgm_convert.py'],
pathex=[os.path.abspath('.')],
# for some unknown reason these hidden imports don't pull in
# all the needed pieces, so we also import them in mavproxy.py
hiddenimports=['UserList', 'UserString'],
excludes=['tcl', 'tk', 'Tkinter', 'tkinter', '_tkinter'],
hookspath=None,
runtime_hooks=None)
geosearchAny = Analysis(['.\\cuav\\tools\\geosearch.py'],
pathex=[os.path.abspath('.')],
# for some unknown reason these hidden imports don't pull in
# all the needed pieces, so we also import them in mavproxy.py
hiddenimports=['UserList', 'UserString',
'pymavlink.mavwp', 'pymavlink.mavutil', 'pymavlink.dialects.v20.ardupilotmega',
'pymavlink.dialects.v10.ardupilotmega',
'pymavlink.dialects.v20.common', 'pymavlink.dialects.v10.common',
'pymavlink.dialects.v20.ASLUAV', 'pymavlink.dialects.v10.ASLUAV',
'pymavlink.dialects.v20.autoquad', 'pymavlink.dialects.v10.autoquad',
'pymavlink.dialects.v20.matrixpilot', 'pymavlink.dialects.v10.matrixpilot',
'pymavlink.dialects.v20.minimal', 'pymavlink.dialects.v10.minimal',
'pymavlink.dialects.v20.paparazzi', 'pymavlink.dialects.v10.paparazzi',
'pymavlink.dialects.v20.slugs', 'pymavlink.dialects.v10.slugs',
'pymavlink.dialects.v20.standard', 'pymavlink.dialects.v10.standard',
'pymavlink.dialects.v20.ualberta', 'pymavlink.dialects.v10.ualberta',
'pymavlink.dialects.v20.uAvionix', 'pymavlink.dialects.v10.uAvionix'],
excludes=[],
hookspath=None,
runtime_hooks=None)

MERGE( (geotagAny, 'geotag', 'geotag'), (pgmconvertAny, 'pgmconvert', 'pgmconvert'), (geosearchAny, 'geosearch', 'geosearch') )

geotag_pyz = PYZ(geotagAny.pure)
geotag_exe = EXE(geotag_pyz,
geotagAny.scripts,
exclude_binaries=True,
name='geotag.exe',
debug=False,
strip=None,
upx=True,
console=True )
geotag_coll = COLLECT(geotag_exe,
geotagAny.binaries,
geotagAny.zipfiles,
geotagAny.datas,
strip=None,
upx=True,
name='geotag')

pgmconvert_pyz = PYZ(pgmconvertAny.pure)
pgmconvert_exe = EXE(pgmconvert_pyz,
pgmconvertAny.scripts,
exclude_binaries=True,
name='pgmconvert.exe',
debug=False,
strip=None,
upx=True,
console=True )
pgmconvert_coll = COLLECT(pgmconvert_exe,
pgmconvertAny.binaries,
pgmconvertAny.zipfiles,
pgmconvertAny.datas,
strip=None,
upx=True,
name='pgmconvert')

geosearch_pyz = PYZ(geosearchAny.pure)
geosearch_exe = EXE(geosearch_pyz,
geosearchAny.scripts,
exclude_binaries=True,
name='geosearch.exe',
debug=False,
strip=None,
upx=True,
console=True )
geosearch_coll = COLLECT(geosearch_exe,
geosearchAny.binaries,
geosearchAny.zipfiles,
geosearchAny.datas,
strip=None,
upx=True,
name='geosearch')
43 changes: 43 additions & 0 deletions windows/cuavWinBuild.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
rem build the standalone Cuav tools for Windows.
rem This assumes Python is installed in C:\Python27
rem If it is not, change the PYTHON_LOCATION environment variable accordingly
rem This assumes InnoSetup is installed in C:\Program Files (x86)\Inno Setup 5
rem If it is not, change the INNOSETUP environment variable accordingly
rem This requires the MinGW compiler and libjpeg-turbo development files (libjpeg-turbo-1.5.1-gcc.exe)
rem This requires Pyinstaller==2.1, setuptools==19.2 and packaging==14.2
rem also requires pyexiv2 - https://launchpad.net/pyexiv2
SETLOCAL enableextensions

if "%PYTHON_LOCATION%" == "" (set "PYTHON_LOCATION=C:\Python27")
if "%INNOSETUP%" == "" (set "INNOSETUP=C:\Program Files (x86)\Inno Setup 5")

rem get the version
for /f "tokens=*" %%a in (
'"%PYTHON_LOCATION%\python" returnVersion.py'
) do (
set VERSION=%%a
)

rem -----build the changelog-----
"%PYTHON_LOCATION%\python" createChangelog.py

rem -----Build CUAV-----
cd ..\
"%PYTHON_LOCATION%\python" setup.py clean build --compiler=mingw32 install
"%PYTHON_LOCATION%\Scripts\pyinstaller" -y --clean .\windows\cuav.spec

rem ----Copy the files and scanner.pyd----
mkdir .\dist\cuav
xcopy .\dist\pgmconvert\* .\dist\cuav /Y /E
xcopy .\dist\geotag\* .\dist\cuav /Y /E
xcopy .\dist\geosearch\* .\dist\cuav /Y /E
xcopy .\build\lib.win32-2.7\cuav\image\scanner.pyd .\dist\cuav\cuav.image.scanner.pyd /Y

rem -----Create version Info-----
@echo off
@echo %VERSION%> .\windows\version.txt
@echo on



pause
12 changes: 12 additions & 0 deletions windows/returnVersion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This script reads the setup.py and returns the current version number
# Used as part of building the WIndows setup file (cuavWinBuild.bat)
# It assumes there is a line like this:
# version = "12344"

# glob supports Unix style pathname extensions
with open("../setup.py") as f:
searchlines = f.readlines()
for i, line in enumerate(searchlines):
if "version = " in line:
print line[11:len(line)-2]
break

0 comments on commit d2201e1

Please sign in to comment.