Compare commits

..

6 Commits

Author SHA1 Message Date
peterlu14 0386cf1847 Merge remote-tracking branch 'origin/release/update_eis_cali_fomula' into dev/scheduler_folder 2023-04-06 10:52:17 +08:00
peterlu14 62d8610191 - fix UnboundLocalError : 'project_meta_id' 2023-04-06 10:51:43 +08:00
Roy 991f5d06ea [update] use 4hstia calibration down 2023-04-06 09:06:05 +08:00
peterlu14 55711285e6 - update create meta project info change from data-server to control-server 2023-03-31 13:14:33 +08:00
peterlu14 3ec5fee43b - update create collection table
- init project then create folder
2023-03-31 13:14:29 +08:00
Roy 614a9c0b0f [update] hstia pA->nA & hsrtia_b is 8bytes 2023-03-31 10:16:50 +08:00
10 changed files with 270 additions and 220 deletions
+60
View File
@@ -0,0 +1,60 @@
from sqlalchemy import Table, Column, String, MetaData, ForeignKey, JSON
from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB
from biopro.db.base import Session
from .base import Base
class Collection(Base):
__tablename__ = "collections"
id = Column(Integer, primary_key=True)
name = Column(String(255))
parent = Column(JSONB)
controller_id = Column(Integer)
type = Column(String(255))
description = Column(String(255))
deleted = Column(Boolean)
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
@classmethod
def create_collection(cls, collection_name, parent):
with Session() as session:
name = cls.check_name_duplicate(collection_name, parent, 0)
collection = Collection(
name = name,
parent = parent,
type= "folder",
)
session.add(collection)
session.commit()
print('a', collection.id)
return collection
@classmethod
def check_name_duplicate(cls, collection_name, parent, n):
with Session() as session:
result = session.query(Collection).filter(Collection.name == cls.generate_name(collection_name, n), Collection.parent == parent).first()
if result is None:
return cls.generate_name(collection_name, n)
else:
new_num = n + 1
# new_name = f"{collection_name}({new_num})"
return cls.check_name_duplicate(collection_name, parent, new_num)
@classmethod
def generate_name(cls, collection_name, n):
if n==0:
return collection_name
else:
return f"{collection_name}({n})"
@classmethod
def find_collection(cls, collection_name, parent):
with Session() as session:
result = session.query(Collection).filter(Collection.name == collection_name, Collection.parent == parent).first()
return result
+24
View File
@@ -0,0 +1,24 @@
from sqlalchemy import Table, Column, String, MetaData, ForeignKey, JSON
from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB
from .base import Base
class Project(Base):
__tablename__ = "project"
id = Column(Integer, primary_key=True)
name = Column(String)
desc = Column(String)
task = Column(JSONB)
cycle = Column(JSONB)
device = Column(JSONB)
uuid = Column(String(36))
user_auth = Column(JSONB)
deleted = Column(Boolean, default = False)
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
# def __repr__(self):
# return f"User(id={self.id!r}, name={self.name!r}, fullname={self.task!r})"
+9 -1
View File
@@ -3,7 +3,7 @@ from sqlalchemy.sql import select, func
from sqlalchemy.types import Integer, BigInteger, String, Boolean, TIMESTAMP, Numeric
from sqlalchemy.dialects.postgresql import JSONB
from .base import Base
from .base import Base, Session
class MetaProjectInfo(Base):
__tablename__ = "project_metas"
@@ -17,5 +17,13 @@ class MetaProjectInfo(Base):
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
updated_at = Column(TIMESTAMP(timezone=True), onupdate=func.now())
@classmethod
def create_project_meta(cls, project):
with Session() as session:
project_meta = MetaProjectInfo(project = project['project'], cycle= project['cycle'], task=project['task'], serial_number=int(project['serial_number']))
session.add(project_meta)
session.commit()
return project_meta.id
# def __repr__(self):
# return f"User(id={self.id!r}, name={self.name!r}, fullname={self.task!r})"
+1 -1
View File
@@ -662,7 +662,7 @@ class CC2650Device(Device):
elif device_type == 'EISZeroOne':
i = 1
request_times = 0
while i <= 24:
while i < 13:
try:
# send
code = self._encode_instruction(DeviceInstruction.TYP_CIS, DeviceInstruction.CIS_CALI, i)
+128 -204
View File
@@ -1413,198 +1413,122 @@ class EISZeroOneDataDecoder(RecDataDecoder):
@staticmethod
def _decode_cali_coeff(cali_coeff: bytes) -> Optional[List[Tuple[int, int]]]:
#####################################################
# phase_coeff/phase_offset/hsrtia_a/hsrtia_b/rolloff
if cali_coeff != b'':
cis_data_len = 20
cali_table = []
hsrtia_a = []
hsrtia_b = []
rolloff = []
phase_coeff = []
phase_offset = []
phase_coeff = numpy.zeros([4, 4], dtype = int)
phase_offset = numpy.zeros([4, 4], dtype = int)
########################################
# phase_coeff
# [[gain0, g1, g2, g3] ----->最高頻
# [gain0, g1, g2, g3] ----->中頻
# [gain0, g1, g2, g3] ----->低頻
# [gain0, g1, g2, g3] ----->最低頻
# ]
#####################################################
print('cali_coeff=', cali_coeff)
if cali_coeff != b'':
cali_table = []
hsrtia_a = numpy.zeros([4, 8], dtype = int) #hsrtia_a[freq][gain]
hsrtia_b = numpy.zeros([4, 8], dtype = numpy.int64) #hsrtia_b[freq][gain]
rolloff = numpy.zeros([4, 8], dtype = int) #rolloff[freq][gain]
phase_coeff = numpy.zeros([4, 8], dtype = int) #phase_coeff[freq][gain]
phase_offset = numpy.zeros([4, 8], dtype = int) #phase_offset[freq][gain]
cis_data_len = 20
#######################################
#gain=0
#Lv[0] 160k
cis_cali_packet = 1
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][0] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][0] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][0] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 2
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][0] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][0] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][0] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][0] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 0
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 3
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][0] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][0] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][0] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][0] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=1
g = 0
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#Lv[1] 20k
cis_cali_packet = 4
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][1] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][1] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][1] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 5
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][1] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][1] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][1] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][1] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 1
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 6
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][1] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][1] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][1] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][1] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 1
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=2
#Lv[2] 5k
cis_cali_packet = 7
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][2] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][2] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][2] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 8
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][2] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][2] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][2] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][2] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 2
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 9
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][2] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][2] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][2] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][2] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 2
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=3
#Lv[3] 200R
cis_cali_packet = 10
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][3] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][3] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][3] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
hsrtia_a.append(struct.unpack('>i', cali_coeff[index+1:index+5])[0])
hsrtia_b.append(struct.unpack('>q', cali_coeff[index+5:index+13])[0])
rolloff.append(struct.unpack('>i', cali_coeff[index+13:index+17])[0])
cis_cali_packet = 11
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][3] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][3] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][3] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][3] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 3
phase_coeff[0][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 12
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][3] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][3] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][3] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][3] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
g = 3
phase_coeff[2][g] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][g] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][g] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][g] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=4
cis_cali_packet = 13
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][4] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][4] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][4] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 14
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][4] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][4] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][4] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][4] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 15
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][4] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][4] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][4] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][4] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=5
cis_cali_packet = 16
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][5] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][5] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][5] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 17
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][5] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][5] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][5] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][5] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 18
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][5] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][5] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][5] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][5] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=6
cis_cali_packet = 19
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][6] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][6] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][6] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 20
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][6] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][6] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][6] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][6] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 21
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][6] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][6] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][6] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][6] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
#gain=7
cis_cali_packet = 22
index = (cis_cali_packet - 1) * cis_data_len
hsrtia_a[0][7] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
hsrtia_b[0][7] = struct.unpack('>q', cali_coeff[index+5:index+13])[0]
rolloff[0][7] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 23
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[0][7] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[0][7] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[1][7] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[1][7] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
cis_cali_packet = 24
index = (cis_cali_packet - 1) * cis_data_len
phase_coeff[2][7] = struct.unpack('>i', cali_coeff[index+1:index+5])[0]
phase_offset[2][7] = struct.unpack('>i', cali_coeff[index+5:index+9])[0]
phase_coeff[3][7] = struct.unpack('>i', cali_coeff[index+9:index+13])[0]
phase_offset[3][7] = struct.unpack('>i', cali_coeff[index+13:index+17])[0]
print('hsrtia_a')
print(hsrtia_a)
print('hsrtia_b')
print(hsrtia_b)
print('rolloff')
print(rolloff)
print('hsrtia_a', hsrtia_a)
print('hsrtia_b', hsrtia_b)
print('rolloff', rolloff)
print('phase_coeff')
print(phase_coeff)
print('phase_offset')
@@ -1634,16 +1558,16 @@ class EISZeroOneDataDecoder(RecDataDecoder):
if len(data) < 18:
return None
ch1 = struct.unpack('>i', data[1+3:5+3])[0]
ch2 = struct.unpack('>i', data[5+3:9+3])[0]
ch3 = struct.unpack('>i', data[9+3:13+3])[0]
ch1 = struct.unpack('>i', data[1+3:5+3])[0] # unit: 1/1000 nA
ch2 = struct.unpack('>i', data[5+3:9+3])[0] # unit: mV
ch3 = struct.unpack('>i', data[9+3:13+3])[0] # unit: kOm
time_stamp: float = struct.unpack('<I', data[13+3:17+3])[0] # unit: ms
cycle_number = struct.unpack('>H', data[17+3:19+3])[0]
d19 = data[19+3]
gain = data[20+3]
finishMode = (d19 & 0x80) >> 7
ch4 = struct.unpack('<i', data[21+3:25+3])[0]
finishMode = (d19 & 0x80) >> 7
ch4 = struct.unpack('<i', data[21+3:25+3])[0] # Amp[uV]
notify_one = struct.unpack('<i', data[25+3:29+3])[0]
notify_two = struct.unpack('<i', data[29+3:33+3])[0]
notify_three = struct.unpack('<i', data[33+3:37+3])[0]
@@ -1665,59 +1589,61 @@ class EISZeroOneDataDecoder(RecDataDecoder):
return None
else:
if self.cali_coeff is not None and (self._mode == 0 or self._mode == 5):
hsrtia_a = []
hsrtia_b = []
rolloff = []
phase_coeff, phase_offset, hsrtia_a, hsrtia_b, rolloff = self.cali_coeff[0]
if (self._mode == 0 or self._mode == 5):
img = ch1 #img[ohm]
real = ch2 #real[ohm]
freq = ch3 #freq[10mHz]
img = ch1
real = ch2
freq = ch3
fre_idx = 0
voltage_amp = round(ch4 / 1000) #ch4=Amp[uV] #voltage_amp[mV]
rolloff_cali = rolloff[0][gain]
voltage_amp = round(ch4 / 1000) # Amp[mV]
rolloff_cali = rolloff[gain]
voltage_mag = math.sqrt(img ** 2 + real ** 2) * (1 + freq ** 2 / rolloff_cali ** 2 / 1e4)
current = (voltage_mag ** 2 * hsrtia_a[0][gain] + voltage_mag * hsrtia_b[0][gain]) / 1e8 #current[nA]
current = (voltage_mag ** 2 * hsrtia_a[gain] + voltage_mag * hsrtia_b[gain]) / 1e8 #[nA]
if (current != 0):
# impedance[mOhm] = voltage_amp[mV] * 1000000 / 1.414213 / current[nA] #RMS=amp*SQRT(2), SQRT(2)=1.414213
# impedance[mOhm] = voltage_amp[mv] * 1000000 / 1.414213 / current[nA] #RMS=amp*SQRT(2), SQRT(2)=1.414213
impedance = voltage_amp * 707106.78 / current
else:
impedance = 0
raw_phase = math.atan2(img , real) * 180 / math.pi
if (freq >= 1000000): #10000Hz
if (freq >= 1000000): # 10000 Hz
fre_idx = 0
elif (freq >= 10000): #100Hz
elif (freq >= 10000): # 100 Hz
fre_idx = 1
elif (freq >= 1000): #10Hz
elif (freq >= 1000): # 10 Hz
fre_idx = 2
elif (freq >= 1): #0.01Hz
elif (freq >= 1): # 0.01 Hz
fre_idx = 3
ideal_raw_phase = phase_coeff[gain][fre_idx] /1e10 * freq + phase_offset[gain][fre_idx] / 1e6
phase = raw_phase - ideal_raw_phase
phase = phase % 180 if phase % 180<=90 else phase % 180-180
imag_after_cal = impedance * math.sin(phase * math.pi / 180)
real_after_cal = impedance * math.cos(phase * math.pi / 180)
imag_after_cal = round(impedance * math.sin(phase * math.pi / 180))
real_after_cal = round(impedance * math.cos(phase * math.pi / 180))
if self._show_data:
if (self._mode == 0 or self._mode == 5):
print('|', '{:10}'.format(time_stamp),
'|', '{:5}'.format(delta),
'|', '{:5}'.format(img),
'|', '{:5}'.format(real),
'|', '{:9}'.format(freq*10), '[mHz]',
'|', '{:5}'.format(cycle_number),
'|', '{:5}'.format(round(imag_after_cal)), '[Ohm]', #Z_imag[Ohm]
'|', '{:5}'.format(round(real_after_cal)), '[Ohm]', #Z_real[Ohm]
'|', '{:5}'.format(round(impedance)), '[mOhm]',
'|', '{:5}'.format(round(phase*1000)), '[mdegree]',
'|', '{:10}'.format(round(current)), '[nA]',
'|', '{:1}'.format(gain),
'|', '{:1}'.format(finishMode),
'|', '{:5}'.format(ch1), #raw_img
'|', '{:5}'.format(ch2), #raw_real
'|', '{:8}'.format(ch3 * 10), '[mHz]', #Frequency [mHz]
'|', '{:5}'.format(cycle_number), #cycle
'|', '{:5}'.format(round(imag_after_cal)), '[Ohm]', #Z_imag [Ohm]
'|', '{:5}'.format(round(real_after_cal)), '[Ohm]', #Z_real [Ohm]
'|', '{:5}'.format(round(impedance)), '[Ohm]', #Impedance [Ohm]
'|', '{:5}'.format(round(phase*1000)), '[mdegree]', #Phase [millidegree]
'|', '{:5}'.format(round(current)), '[nA]', #Current [nA]
'|', '{:1}'.format(gain), #gain
'|', '{:1}'.format(finishMode), #finishMode
'@', str(self.device), '|', flush = True)
print('|', '{:10}'.format(time_stamp),
@@ -1725,7 +1651,7 @@ class EISZeroOneDataDecoder(RecDataDecoder):
'|', '{:5}'.format(notify_one),
'|', '{:5}'.format(notify_two),
'|', '{:5}'.format(notify_three),
'|', '{:5}'.format(voltage_amp), '[mV]',
'|', '{:5}'.format(voltage_amp), #amp[mV]
'|', flush = True)
pass
else:
@@ -1747,30 +1673,28 @@ class EISZeroOneDataDecoder(RecDataDecoder):
self._mode_stop = 0
ret = RecordingData(self.device, int(time_stamp * 1000 / 2), 0)
if self._mode == 0 or self._mode == 5: #EIS/CF Mode
ret.append_data(0, img)
ret.append_data(1, real)
ret.append_data(2, freq * 10) #[mHz]
ret.append_data(3, cycle_number)
ret.append_data(4, round(imag_after_cal)) #Z_imag [Ohm]
ret.append_data(5, round(real_after_cal)) #Z_real [Ohm]
ret.append_data(6, round(impedance)) #[mOhm]
ret.append_data(7, round(phase*1000)) #[millidegree]
ret.append_data(8, round(current)) #[nA]
ret.append_data(9, gain)
if self._mode == 0 or self._mode == 5:
ret.append_data(0, ch1) #raw_img
ret.append_data(1, ch2) #raw_real
ret.append_data(2, ch3 * 10) #Frequency [mHz]
ret.append_data(3, cycle_number) #cycle
ret.append_data(4, imag_after_cal) #Z_imag [Ohm]
ret.append_data(5, real_after_cal) #Z_real [Ohm]
ret.append_data(6, round(impedance)) #Impedance [Ohm]
ret.append_data(7, round(phase*1000)) #Phase [millidegree]
ret.append_data(8, round(current)) #Current [nA]
ret.append_data(9, gain) #gain
#debug data
ret.append_data(10, notify_one)
ret.append_data(11, notify_two)
ret.append_data(12, notify_three)
ret.append_data(13, voltage_amp) #mV
ret.append_data(13, voltage_amp) #amp[mV]
else: #CV Mode
ret.append_data(0, ch1) #Iin [nA]?
ret.append_data(1, ch2) #Vset [nV]?
ret.append_data(2, ch3) #Vout [nV]?
ret.append_data(0, ch1) #Iin [nA]
ret.append_data(1, ch2) #Vset [nV]
ret.append_data(2, ch3) #Vout [nV]
ret.append_data(3, cycle_number)
if cycle_number != self._cycle_number:
+14
View File
@@ -15,6 +15,9 @@ from .instruction import Instruction
from biopro.device.manager import DeviceManager
from biopro.text import *
from biopro.db.base import Session
from biopro.db.collection import Collection
key_list = {
'deviceList': 'device',
}
@@ -60,6 +63,14 @@ class Project(threading.Thread):
fh = logging.FileHandler(f'/home/pi/logger/project/{self.uuid}.log', mode="w")
fh.setFormatter(self._formatter)
self._logger.addHandler(fh)
default_name = 'admin'
default_parent = {"folder": [1]}
collection = Collection.find_collection(default_name, default_parent)
parent = {"folder": [collection.id]}
# create project folder
collection = Collection.create_collection(self.name, parent)
self.setup_collection(collection)
def setup_project(self, project):
for (key, value) in project.items():
@@ -79,6 +90,9 @@ class Project(threading.Thread):
complete_device = self._device_manager.get_device(mac_address)
complete_device.occupied_by_project = self._uuid
self._complete_device[device] = complete_device
def setup_collection(self, collection):
self._task_manager.create_collection(collection)
@property
def id(self) -> int:
+17 -1
View File
@@ -5,6 +5,7 @@ from xml.dom.expatbuilder import parseString
import paho.mqtt.client as mqtt
from biopro.text import *
from .task import Task
from biopro.db.collection import Collection
_RUNTIME_COMPILE = False
@@ -67,6 +68,13 @@ class TaskManager():
if cycle['range'][1] == task.uuid:
return index
def check_task_in_cycle(self, task_index):
for index, cycle in enumerate(self._cycle_list):
if self.get_index_by_uuid(cycle['range'][0]) <= task_index:
if self.get_index_by_uuid(cycle['range'][1]) >= task_index:
return True
return False
@property
def check_list(self):
return [self._running_task, *self._next_task]
@@ -162,4 +170,12 @@ class TaskManager():
def get_task(self, task_id):
return self._task_list[task_id]
def create_collection(self, parent):
for index, task in enumerate(self._task_list):
if self.check_task_in_cycle(index) == True:
if task.type == '':
collection = Collection.create_collection(task.name, {"folder": [parent.id]})
task.parent = {"folder": [collection.id]}
else:
task.parent = {"folder": [parent.id]}
+8 -8
View File
@@ -362,14 +362,14 @@ class DataServer(SocketServer, DataAPI):
self.log_verbose('device ID', device_id)
# project binding meta file
project_id = None
_project = None
if project_info != None:
_project = json.loads(project_info)
self.database_process.put_queue(['project_insert', device_id, _project])
result = self._queue_ds_dict[int(device_id)].get()
if result[0] == 'project_id':
project_id = result[1]
# project_id = None
# _project = None
# if project_info != None:
# _project = json.loads(project_info)
# self.database_process.put_queue(['project_insert', device_id, _project])
# result = self._queue_ds_dict[int(device_id)].get()
# if result[0] == 'project_id':
project_id = project_info
# while len(self._configurations) <= device_id:
# self._configurationsappend(None)
+4 -2
View File
@@ -222,7 +222,8 @@ class DataBaseProcess(Process):
try:
sql_cursor.execute(sql_str, sql_set)
except:
except BaseException as e:
print('meta create error', e)
self._psql_conn.commit()
sql_cursor.close()
self._queue_error.put(device_id)
@@ -249,7 +250,8 @@ class DataBaseProcess(Process):
try:
sql_cursor.execute(sql_str, sql_set)
except:
except BaseException as e:
print('meta update error', e)
self._psql_conn.commit()
sql_cursor.close()
self._queue_error.put(device_id)
+5 -3
View File
@@ -1102,6 +1102,7 @@ class ControlServer(SocketServer, ControlServerAPI):
client = self.data_server.client()
project = None
project_meta_id = None
if client is not None:
info = self.file_manager.use(device)
@@ -1114,10 +1115,11 @@ class ControlServer(SocketServer, ControlServerAPI):
info = self.file_manager.save(device, filename)
if device.occupied_by_project != None:
project = json.dumps(self.project_manager.get(device.occupied_by_project).info_pass_data_server())
project = self.project_manager.get(device.occupied_by_project).info_pass_data_server()
project_meta_id = MetaProjectInfo.create_project_meta(project)
with client:
client.update_device_configuration(device, info.meta_file, value, project)
client.update_device_configuration(device, info.meta_file, value, project_meta_id)
def _device_set_disable_cache(self, device: CompletedDevice, disable):
if disable: