Skip to content

Commit f272c41

Browse files
committed
基本框架入库
0 parents  commit f272c41

33 files changed

+2251
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Directories
2+
.idea/
3+
.gradle/
4+
app/build/
5+
build/
6+
7+
# Files
8+
*.properties
9+
*.iml

ServerExample/streamReceiver.py

+137
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
'''
2+
Eample of simple PNG frame stream receiver server
3+
4+
5+
Note: uses PIL, the library Pillow is recommended
6+
https://pypi.python.org/pypi/Pillow
7+
'''
8+
9+
import socket
10+
import sys
11+
from threading import Thread
12+
from io import BytesIO
13+
from PIL import Image, ImageTk
14+
try:
15+
import tkinter
16+
except ImportError:
17+
import Tkinter
18+
tkinter = Tkinter
19+
20+
21+
22+
23+
HOST = '' # Symbolic name meaning all available interfaces
24+
PORT = 12345 # Arbitrary non-privileged port
25+
26+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27+
print('Socket created')
28+
29+
#Bind socket to local host and port
30+
try:
31+
s.bind((HOST, PORT))
32+
except socket.error as msg:
33+
print('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
34+
sys.exit()
35+
36+
print('Socket bind complete')
37+
38+
39+
#Start listening on socket
40+
s.listen(10)
41+
print('Socket now listening')
42+
print(socket.gethostbyname(socket.gethostname())+":"+str(PORT))
43+
44+
#Function for handling connections. This will be used to create threads
45+
def clientthread(conn):
46+
headerPending = True
47+
expectedData = 6
48+
bufferedData = ""
49+
rotation = 0
50+
#infinite loop so that function do not terminate and thread do not end.
51+
while True:
52+
if headerPending:
53+
bufferedData = ""
54+
expectedData = 6
55+
#Receiving from client
56+
try:
57+
data = conn.recv(expectedData)
58+
except:
59+
print('Error receiving data')
60+
break
61+
if not data:
62+
break
63+
if headerPending:
64+
size = (ord(data[0]) << 24) + (ord(data[1]) << 16) + (ord(data[2]) << 8) + ord(data[3])
65+
rotation = (ord(data[4]) << 8) + ord(data[5])
66+
#print('size of frame: '+str(size))
67+
expectedData = size
68+
headerPending = False
69+
else:
70+
# check that we got all the data, otherwise buffer, subtract from expectedData and loop again
71+
expectedData = expectedData - len(data)
72+
bufferedData += data
73+
74+
if expectedData == 0:
75+
# we got more than we expected
76+
memoryFile = BytesIO(bufferedData)
77+
# rotation is only supported in multiples of 90
78+
rotation = -1*int(round(float(rotation)/90)*90)
79+
#imgSize = (480,640) if rotation == 0 or rotation == 180 else (640,480)
80+
img = Image.open(memoryFile).resize((480,640),Image.BICUBIC).rotate(rotation)
81+
82+
try:
83+
tkpi = ImageTk.PhotoImage(img)
84+
imageLabel.config(image=tkpi);
85+
except:
86+
pass
87+
window.after_idle(updateImageLabel, True);
88+
headerPending = True
89+
90+
#came out of loop
91+
conn.close()
92+
def listenForConnections():
93+
#now keep talking with the client
94+
while 1:
95+
96+
print('Waiting for connection')
97+
#wait to accept a connection - blocking call
98+
conn, addr = s.accept()
99+
print('Connected with ' + addr[0] + ':' + str(addr[1]))
100+
101+
#start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
102+
103+
t = Thread(target=clientthread,args=(conn,))
104+
t.daemon = True
105+
t.start()
106+
107+
108+
109+
110+
def updateImageLabel(direct=False):
111+
imageLabel.config()
112+
if direct != True:
113+
window.after(100,updateImageLabel)
114+
115+
def onQuit():
116+
print('Quitting...')
117+
imageLabel.destroy()
118+
window.destroy()
119+
120+
window = tkinter.Tk()
121+
window.geometry('{}x{}'.format(640,640))
122+
window.title('Frame Viewer')
123+
window.protocol("WM_DELETE_WINDOW", onQuit)
124+
imageLabel = tkinter.Label(window,text="Waiting...");
125+
imageLabel.pack()
126+
imageLabel.place(x=0,y=0,width=640,height=640)
127+
128+
129+
130+
t = Thread(target=listenForConnections)
131+
t.daemon = True
132+
t.start()
133+
134+
window.after(100,updateImageLabel)
135+
window.mainloop()
136+
137+
sys.exit(0)

app/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.application'
2+
android {
3+
compileSdkVersion 24
4+
buildToolsVersion "24.0.0"
5+
6+
defaultConfig {
7+
applicationId "com.flir.flironeexampleapplication"
8+
minSdkVersion 18
9+
targetSdkVersion 24
10+
versionCode 16
11+
versionName "1.2.6"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
20+
}
21+
dependencies {
22+
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
compile(name:'flironesdk', ext:'aar')
24+
compile 'com.android.support:appcompat-v7:24.2.1'
25+
compile 'com.android.support:support-v4:24.2.1'
26+
}
27+
28+
repositories{
29+
flatDir{
30+
dirs 'libs'
31+
}
32+
}

app/libs/flironesdk.aar

4.74 MB
Binary file not shown.

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Applications/ADT/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.flir.flironeexampleapplication;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.flir.flironeexampleapplication" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme"
10+
android:versionCode="3"
11+
android:versionName="0.3">
12+
<activity android:name=".EditorActivity"
13+
android:screenOrientation="portrait">
14+
<intent-filter>
15+
<action android:name="android.intent.action.VIEW" />
16+
<action android:name="android.intent.action.EDIT" />
17+
<action android:name="android.intent.action.PICK" />
18+
<action android:name="android.intent.action.SEND"/>
19+
<category android:name="android.intent.category.DEFAULT" />
20+
<data android:mimeType="image/jpeg" />
21+
</intent-filter>
22+
</activity>
23+
<activity
24+
android:name=".PreviewActivity"
25+
android:screenOrientation="portrait"
26+
android:configChanges="orientation|keyboardHidden|screenSize"
27+
android:label="@string/app_name_cn"
28+
android:launchMode="singleTask"
29+
android:theme="@style/FullscreenTheme" >
30+
<intent-filter>
31+
<action android:name="android.intent.action.MAIN" />
32+
33+
<category android:name="android.intent.category.LAUNCHER" />
34+
</intent-filter>
35+
36+
37+
<intent-filter>
38+
<action android:name="android.intent.action.MAIN" />
39+
40+
<category android:name="android.intent.category.LAUNCHER" />
41+
</intent-filter>
42+
43+
<intent-filter>
44+
<action android:name="android.intent.action.MAIN" />
45+
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
46+
<category android:name="android.intent.category.LAUNCHER" />
47+
</intent-filter>
48+
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
49+
android:resource="@xml/device_filter" />
50+
</activity>
51+
52+
</application>
53+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
54+
<uses-permission android:name="android.permission.INTERNET"/>
55+
</manifest>

app/src/main/ic_launcher-web.png

44.6 KB
Loading

0 commit comments

Comments
 (0)