Skip to content

Commit

Permalink
RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
solasolo committed May 25, 2022
1 parent 2e85363 commit c589b0a
Show file tree
Hide file tree
Showing 16 changed files with 16,363 additions and 8,496 deletions.
27 changes: 27 additions & 0 deletions Host/DataFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
import os

class DataFile:
def __init__(self):
base_path = os.path.dirname(__file__)

self.File = None
self.File = open( base_path + "/data/data.csv", "a+")


def __del__(self):
if self.File != None:
self.File.flush()
self.File.close()


def Write(self, data):
if len(data) >= 6:
for i in range(6):
if i > 0: self.File.write("\t")
self.File.write(str(data[i]))

self.File.write("\n")



36 changes: 36 additions & 0 deletions Host/SensorChart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from OpenGL import GLUT, GLU, GL

AxisColor = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
BarScale = [0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.0015, 0.0015, 0.0015]

class SensorChart:
def __init__(self):
GLUT.glutInit()
GLUT.glutInitDisplayMode(GLUT.GLUT_SINGLE | GLUT.GLUT_RGBA)
GLUT.glutInitWindowSize(600, 600)
GLUT.glutCreateWindow("3D")


def Run(self, proc):
GLUT.glutDisplayFunc(self.Draw)
GLUT.glutIdleFunc(proc)

GLUT.glutMainLoop()


def Draw(self, data=None):
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
GL.glBegin(GL.GL_LINES)

if data != None:
for i in range(len(data)):
x = i * 0.1 - 0.9
y = 0.75 + data[i] / 4 * 0.00001
c = AxisColor[i % 3]

GL.glColor3f(c[0], c[1], c[2])
GL.glVertex3f(x, 0.75, 0)
GL.glVertex3f(x, y, 0)

GL.glEnd()
GL.glFlush()
99 changes: 32 additions & 67 deletions Host/SensorProcess.py
Original file line number Diff line number Diff line change
@@ -1,105 +1,70 @@
from asyncio.windows_events import NULL
import socket
import struct

from OpenGL import GLUT, GLU, GL

from PerformanceCounter import PerformanceCounter

from SensorChart import SensorChart
from DataFile import DataFile

raw_data = []


AxisColor = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
BarScale = [0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.00005, 0.0015, 0.0015, 0.0015]

class UdpServer:
def __init__(self):
self.Counter = PerformanceCounter()
self.Chart = SensorChart()
self.DataFile = DataFile()

self.Server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.Server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
self.Server.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 65536 * 16)
self.Server.bind(("192.168.10.13", 8000))

def Run(self):
GLUT.glutInit()
GLUT.glutInitDisplayMode(GLUT.GLUT_SINGLE | GLUT.GLUT_RGBA)
GLUT.glutInitWindowSize(600, 600)
GLUT.glutCreateWindow("3D")
GLUT.glutDisplayFunc(self.Draw)
GLUT.glutIdleFunc(self.Recv)
self.Server.settimeout(1)

ip = self.GetLocalIP("192.168.10")
print(ip)
self.Server.bind((ip, 8000))


GLUT.glutMainLoop()
def Run(self):
self.Chart.Run(self.Recv)
self.DataFile = NULL


def Recv(self):
raw_data = [0]*9
delta = 0
raw_count = 0
raw_data = [0] * 9

try:
data, address = self.Server.recvfrom(44)
data, address = self.Server.recvfrom(36)

#print(len(data), data)
reader = lambda p: int.from_bytes(data[p:p + 2], byteorder="little", signed=True)


reader = lambda p: int.from_bytes(data[p:p + 4], byteorder="little", signed=True)

for i in range(9):
raw_data[i] = reader(i * 2)
'''
q0 = struct.unpack("f", data[20:24])[0]
q1 = struct.unpack("f", data[24:28])[0]
q2 = struct.unpack("f", data[28:32])[0]
q3 = struct.unpack("f", data[32:36])[0]
'''
#delta = struct.unpack("f", data[36:40])[0]
#raw_count = int.from_bytes(data[40:44], byteorder="little", signed=False)
raw_data[i] = reader(i * 4)

except socket.timeout:
raw_data = []

except Exception as e:
raw_data = []
print("error", e.args)

# t = count / (now_time - last_tick)
[count, t] = self.Counter.Frame()
#print(count, t, raw_data)

self.Draw(raw_data)


def Draw(self, data=None):
glClear(GL_COLOR_BUFFER_BIT)
print(count, t, raw_data)

'''
glPushMatrix()
glColor3f(1, 1, 1)
#glRotate(180, 0, 0, 1)
if q != None:
v = q.getVector()
angle = q.getAngle() * 180 / 3.14 * 2 # 四元数角 * 2
self.DataFile.Write(raw_data)
self.Chart.Draw(raw_data)

glRotate(angle, v[0], v[2], v[1])

glutWireTeapot(0.4)
glPopMatrix()
'''
glBegin(GL_LINES)
def GetLocalIP(self, mask):
host_name = socket.gethostname()
ips = socket.gethostbyname_ex(host_name)[2]

if data != None:
for i in range(len(data)):
x = i * 0.1 - 0.9
y = 0.75 + data[i] / 4 * BarScale[i]
c = AxisColor[i % 3]
for ip in ips:
if ip.startswith(mask):
ret = ip

glColor3f(c[0], c[1], c[2])
glVertex3f(x, 0.75, 0)
glVertex3f(x, y, 0)
return ret

glEnd()
glFlush()


if __name__ == '__main__':
Server = UdpServer()
Server.Run()
Server.Run()
10 changes: 0 additions & 10 deletions Host/data/flex.csv

This file was deleted.

10 changes: 0 additions & 10 deletions Host/data/punch.csv

This file was deleted.

Loading

0 comments on commit c589b0a

Please sign in to comment.