Files
controller-wisetopdataserver/python/biopro/devlib/__pycache__/library.cpython-37.opt-2.pyc
T

199 lines
39 KiB
Plaintext
Raw Normal View History

2021-12-20 14:52:55 +08:00
B
2021-12-22 14:29:56 +08:00
²ÃÂa²ã@sddlZddlZddlZddlTddlTddlTddlTGdddeƒZ GdddƒZ
2021-12-20 14:52:55 +08:00
Gdd „d eƒZ Gd
d d e ƒZ
Gd d
d
eejdZGdddeƒZGdddeƒZGdddeƒZGdddeƒZGdddeƒZGddde ƒZGdddeƒZdS)é)Ú*c@sPeZdZdZdZdZeedœddZe edœdd „ƒZ
2021-12-22 14:29:56 +08:00
e edœd
2021-12-20 14:52:55 +08:00
d ƒZ e edœd d
ƒZ e e
dœddƒZe edœddƒZe edœddƒZe edœddƒZeedœddZddZddZddZeeeefedœd d!„ƒZeeeefddœd"d#„ƒZeee dd$œd%d&„ƒZ!ed,e"eeefe#ee$gd(fe"dd)œd*d+„ƒZ%d(S)-Ú
DeviceLibrary)z .devlib.jsonz.devlibsBPDevLib)Ú_fileÚ_nameÚ_versionÚ _match_ruleÚ _constantÚ_paraÚ_inst)ÚnameÚversioncCs8d|_||_||_tgƒ|_tj|_tƒ|_ t
ƒ|_ dS)N) rrrZ
ListMatchRulerÚ
ConstantScopeZEMPTYr ÚParameterTabler
ÚInstructionTabler )Úselfr r
©rú:/home/pi/wisetopdataserver/python/biopro/devlib/library.pyÚ__init__>s
zDeviceLibrary.__init__)ÚreturncCs|jS)N)r)rrrrr NszDeviceLibrary.namecCs|jS)N)r)rrrrr
UszDeviceLibrary.versioncCs|jS)N)r)rrrrÚ file_path\szDeviceLibrary.file_pathcCs|jS)N)r )rrrrÚconstant`szDeviceLibrary.constantcCs|jS)N)r)rrrrÚ
match_rulehszDeviceLibrary.match_rulecCs|jS)N)r
)rrrrÚparameter_tableoszDeviceLibrary.parameter_tablecCs|jS)N)r )rrrrÚinstruction_tablevszDeviceLibrary.instruction_table)ÚdevicercCs|j |¡dk S)N)rÚis_device_match)rrrrrr}szDeviceLibrary.is_device_matchcCs6|jtjt|jƒ|j ¡|j ¡|j  ¡|j
 ¡dœS)N)r Z
specificationr
rrÚ
parametersÚ instruction) rÚAbstractLibraryLoaderZ
SPECIFICATIONÚstrrrÚas_jsonr Úlocalsr
r )rrrrr!szDeviceLibrary.as_jsoncCst|ƒS)N)r )rrrrÚ__repr__szDeviceLibrary.__repr__cCsd|jt|jƒfS)NzDeviceLibrary:%s-%s)rr r)rrrrÚ__str__ŽszDeviceLibrary.__str__)Úfilercs.t|tƒr|n|jttfdd|jƒƒS)Ncs
ˆ |¡S)N)Úendswith)Úit)r rrÚ<lambda>˜óz1DeviceLibrary.is_filename_match.<locals>.<lambda>)Ú
isinstancer r ÚanyÚmapÚFILE_EXT)Úclsr%r)r rÚis_filename_matchs
zDeviceLibrary.is_filename_matchc Cst|tƒrt|ƒ}t|tƒs,tdt|ƒƒ|j |jd¡rf| ¡}| |t  
|¡¡}WdQRXn|j |jd¡rê| d¡`}|  d¡}||j kr¨t
dt|ƒƒtj|d$}| |t  |  ¡ dd ¡¡¡}WdQRXWdQRXnt
d
t|jƒƒ|S) Nz
not a path : rrÚrbézunknown file : )ÚfileobjÚutf8Ú
surrogatepasszunknown file ext : )r*r ÚPathÚ TypeErrorr r&r-ÚopenÚparseÚ_jsonÚloadÚreadÚ FILE_HEADERÚ RuntimeErrorÚgzipZGzipFileÚloadsÚdecode)r.r%ÚretÚheaderÚgrrrr:šs 


2021-12-22 14:29:56 +08:00
 
2021-12-20 14:52:55 +08:00

4zDeviceLibrary.load)ÚpathÚjsonrcCsHt ||¡}t|j|jƒ}t|ƒ|_|j|_|j |_
|j |_ |j
|_|S)N)rr8rr r
r rrrrr Ú parameterr
rr )r.rErFÚloaderrBrrrr8»s 
zDeviceLibrary.parseFN)rEÚon_errorrc
gtdœfdd }x¦|D]ž}t|tƒr8t|ƒ}nt|tƒsRtdt|ƒƒ| ¡r |r¤x^tjt|ƒddD],\}}}t|ƒ}x|D]} ||| ƒqŠWqrWq x| ¡D] } || ƒq®Wq WˆS)N)Ú_fc
sd| ¡r`ˆ |¡r`yˆ |¡}Wn4tk
rT}zˆdk rDˆ||ƒWdd}~XYn Xˆ |¡dS)N)Úis_filer/r:Ú
BaseExceptionÚappend)rJÚlibÚe)r.rIrBrrÚ_loadÐsz)DeviceLibrary.load_library.<locals>._loadz
not a path : T)Ú followlinks)r5r*r r6ÚexistsÚosÚwalkÚiterdir)
r.rEÚ recursiverIrPÚdZdsÚfsrAr)r.rIrBrÚ load_libraryÉs 




zDeviceLibrary.load_library)FN)&Ú__name__Ú
__module__Ú __qualname__r-r<Ú __slots__r ÚDeviceLibraryVersionrÚpropertyr r
rrrZ MatchRulerrrrrÚDeviceResponseInfoÚboolrr!r#r$Ú classmethodÚUnionr5r/r:Ú JSON_OBJECTr8ÚListÚCallablerLrZrrrrr s@.  
rc@eZdZdeedœddZeeedœddƒZee efdœd d
Z
ee ee gdfdœd d ƒZ
e
je ee gdfd
œdd ƒZ
eedœddƒZejed
œddƒZddZeedœddZde ee efeedœddZeeedœddZdS)ÚDeviceLibraryRepositoryNF)rEcCsDg|_|s|j tdƒ¡|dk r.|j |¡d|_d|_d|_dS)Nz%/home/pi/wisetopdataserver/python/resF)Ú
_library_pathrMr5ÚextendÚ
_recursiveÚ _on_errorÚ_cache)rrEÚno_system_defaultrrrrós z DeviceLibraryRepository.__init__)rcCs
t|jƒS)N)Úlistri)rrrrÚ library_pathsz$DeviceLibraryRepository.library_pathcCs(t|tƒrt|ƒ}|j |¡d|_dS)N)r*r r5rirMrm)rrErrrÚadd_library_paths
 z(DeviceLibraryRepository.add_library_pathcCs|jS)N)rl)rrrrrI sz DeviceLibraryRepository.on_error)ÚvaluecCs
||_dS)N)rl)rrrrrrrIscCs|jS)N)rk)rrrrrVsz!DeviceLibraryRepository.recursivecCs
||_dS)N)rk)rrrrrrrVscCs
d|_dS)N)rm)rrrrÚ
invalid_cachesz%DeviceLibraryRepository.invalid_cachecCs(|jdkr"tj|j|j|jd|_|jS)N)rVrI)rmrrZrirkrl)rrrrÚget_library_alls

 z'DeviceLibraryRepository.get_library_all)Ú library_nameÚlibrary_versionrcCsJt|tƒrt |¡}x0| ¡D]$}|j|kr|dks>|j|kr|SqWdS)N)r*r r_Úvalue_ofrtr r
)rrurvrNrrrÚ get_library's


z#DeviceLibraryRepository.get_library)ÚresponsercCs$x| ¡D]}| |¡r
|Sq
WdS)N)rtr)rryrNrrrÚ
match_library5s
z%DeviceLibraryRepository.match_library)NF)N)r[r\r]rfr5rr`rprdr rqrgrLrIÚsetterrbrVrsrrtr_ÚOptionalrxrarzrrrrrhòs 
rhc@s0eZdZdZedœddZeedœddƒZeedœdd „ƒZ ee
dœd
d ƒZ e
dœd d
Z e
dœddZeedœddZee
dœddZd.ee
edœddZee
dœddZeeeefdœddZeedœd d!„Zeedœd"d#„Zeeeefdd$fd%œd&d'„Zd$eeefd(œd)d*„Zd+d,„Zd-S)/ÚDeviceParameter)Ú_libraryÚ
_parameterÚ_contextÚ_flag_disable_guardingÚ_last_modified_timestamp)Úlibraryc
C||_i|_|j t|ƒ¡|_xª|j ¡D]œ}y | ¡}Wnt t
fk
rRYq*Xt |t ƒr~|j
tjkrtt|ƒ}qºt |ƒ}n<t |tƒrt|ƒ}n(t |tttfƒr¤ntd|j
t|ƒfƒ||j|j
<q*W|tj}t |tƒsòtdtt|ƒƒƒ|tj}t |tƒstdtt|ƒƒƒ|tj}t |t tfƒrjt|ƒdkrzttdd|ƒƒsztdt|ƒƒntd|jjƒtƒ|_d |_ dS)
Nz,unsupported value type for parameter %s : %szillegal sample rate type : zillegal amp gain type : rcSs
t|tƒS)N)r*Úint)Úvrrrr(r)z*DeviceParameter.__init__.<locals>.<lambda>zillegal channel contain type + zillegal channel type : F)!r~rrÚchainÚDeviceParameterScoper€rÚvaluesÚ init_paraÚPropertyDomainErrorÚActionDomainErrorr*ror Ú
ParameterInfoÚCHANNELÚsetrbr„Úfloatr=ÚtypeÚ SAMPLE_RATEr ÚAMP_GAINÚlenÚallr,Ú __class__r[Útimerr)rZ para_infoZ
para_valueÚ sample_rateÚamp_gainÚchannelrrrrcs@ 
 






 
"zDeviceParameter.__init__)rcCs|jS)N)r~)rrrr¡szDeviceParameter.librarycCs|jS)N)r€)rrrrÚcontext¥szDeviceParameter.contextcCs
t|jƒS)N)r„r)rrrrÚlast_modified_timestamp©sz'DeviceParameter.last_modified_timestampcCs t|jjƒS)N)r“r~r)rrrrÚ__len__­szDeviceParameter.__len__cCs ||jjkS)N)r~r)rÚitemrrrÚ __contains__°szDeviceParameter.__contains__)rrcCs
| |¡S)N)Ú
get_parameter)rrrrrÚ __getitem__³szDeviceParameter.__getitem__)rrrcCs| ||¡dS)N)Ú
set_parameter)rrrrrrrÚ __setitem__¶szDeviceParameter.__setitem__F)ÚparaÚraw_datarcCsJ|jj}||}|j}|tkr.| |d|j¡S|tkr:dS|j|j}|S)N) r~rÚdomainÚParameterPropertyDomainÚ get_valuer€ÚParameterActionDomainrr )rÚtableÚinfor¥rBrrr¹s zDeviceParameter.get_parameter)rrc
C|jj}||}|j}|tkr&t|ƒt|tƒr@td|dƒ|tkrLdS|t krXdS| 
|¡sztd|dt |ƒƒ|j |}||j |<|j
sèy| ||j¡Wn@tk
}z"||j |<t|dt |ƒƒ|Wdd}~XYnXtƒ|_dS)Nzcollection parameter z do not support this operationzinvalid parameter z : zillegal value : )r~rZParameterConstantDomainZConstantDomainErrorr*ÚParameterCollectionDomainr=Z
valid_parar rrÚ ensure_guardr€ÚIllegalParameterValueErrorrr)rrrÚoldrOrrrÕs,




&zDeviceParameter.set_parameter)Úoperc
Cst|tƒst |¡}|jj}||}|j}t|tƒs@td|ƒ|j|}t|t ƒr^t |ƒ}nt
|ƒ}y|  |||j ¡Wn2tk
}zt
|t|ƒƒ|Wdd}~XYnX|jsy| ||j ¡Wn>tk
r}z||j|<t
|t|ƒƒ|Wdd}~XYnXtƒ|_dS)Nznot a collection parameter )r*Ú ParameterCollectionValueOperatorr8r~rr=rroZ oper_parar€r­r rrr) rÚtargetr®rOrrrÚoper_parameterûs,


 


"
"zDeviceParameter.oper_parametercCs |jj ¡S)N)r~rÚkeys)rrrr szDeviceParameter.keyscCs|jjjddS)NT)Z show_private)r~rÚkeys_all)rrrrr´#szDeviceParameter.keys_allÚDeviceConfiguration)ÚothercCspt|tƒr| |¡}n.t|tƒr(|j}nt|tƒr4ntd|jjƒx|  ¡D]\}}||j|<qNWt
ƒ|_ dS)Nzunsupported overwrite type : ) r*Ú_overwrite_for_configurationr}rÚdictr6r•r[Úitemsrr)rÚkr…rrrÚ overwrite&s
 

zDeviceParameter.overwrite)Úconfrc
sZ|jj}ig}xv|jddD]f}||kr||}t| ¡ƒdkrzy| ||||j¡ˆ|<Wq„ttfk
rvYq„Xq|  |¡qWxÌt|ƒdkrTg}t|ƒ}|jj
fˆŽ}xp|D]h}t t fdd| ¡ƒƒr|j
}y| ||||¡ˆ|<Wnttfk
rYnXq¸|  |¡q¸Wt|ƒ|krNtdd t dd|ƒ¡ƒ|}qŠWˆS) NT)Ú list_hidercs|ˆkS)Nr)r')Útmprrr(Wr)z>DeviceParameter._overwrite_for_configuration.<locals>.<lambda>zrecursive dependency : ú cSs|jS)N)r )r'rrrr(br))r~rr“Zcast_value_dependencyÚ
cast_valuer€rrMÚchildr”r,r r=Újoin) rZdeprºZdep_nextZdep_sizeršr)r<s8
z,DeviceParameter._overwrite_for_configurationcCs(|jjt|jjƒdd|j ¡DƒdœS)NcSsi|]\}}t |¡|qSr)Ú
JsonSerializeÚto_json)Ú.0rºr…rrrú
<dictcomp>lsz+DeviceParameter.as_json.<locals>.<dictcomp>)rurvrG)r~r r r
r)rrrrr!hs
zDeviceParameter.as_jsonN)F)r[r\r]r^rrr`ÚScoperšr„rrbr ÚAnyr rdÚIterabler³r´ÚDictr»r!rrrrr}<s(%>&% ,r}cs>eZdZdZedœfdd ZeedœddZdd „Z ‡Z
S)
r‡)r)rGcstƒ t| ¡ƒ¡||_dS)N)Úsuperrror´r)rrG)r•rrrtszDeviceParameterScope.__init__)ÚkeyrcCs|jj|ddS)NF))r)rrrrÚ get_localxszDeviceParameterScope.get_localcCsdS)Nr‡r)rrrrr$|szDeviceParameterScope.__str__) r[r\r]r^r}rr r$Ú
__classcell__rr)r•rr‡qsr‡c@s†eZdZdZdZdZdZejZej Z ej
Z
eeee e
fZ dZ e
jd0eedœdd „ƒZeed
œd d Zed
œddZeedœddZee
jedœddƒƒZee
jedœddƒƒZeeedœddƒZeeedœddƒZeedœddƒZeeedœddƒZ eedœdd „ƒZ!d1ed"œd#d$„Z"e
jeed%œd&d'„ƒZ#e
jd2eeed(œd)d*„ƒZ$e
jee%eefd+œd,d-„ƒZ&d3d.d/„Z'd!S)4rµZ _LIBRARY_Z _VERSION_Z
_DEVICE_NAME_Z
_DEVICE_ADDR_rF)rcCsdS)Nr)rÚ list_privaterrrÀszDeviceConfiguration.keys)rrcCs
| |¡S)N)Úcontain_parameter)rrrrrÊsz DeviceConfiguration.__contains__)rcCs
| |¡S)N))rrrrrr ÍszDeviceConfiguration.__getitem__)rrrcCs| ||¡dS)N))rrrrrrrÐszDeviceConfiguration.__setitem__cCsdS)Nr)rrrrÓszDeviceConfiguration.librarycCsdS)Nr)rrrrrvÜsz#DeviceConfiguration.library_versioncCsdS)Nr)rrrrÚ device_nameåszDeviceConfiguration.device_namecCsdS)Nr)rrrrÚdevice_addressísz"DeviceConfiguration.device_addresscCst| tj¡ƒS)N)r„r)rrrrr—õszDeviceConfiguration.sample_ratecCst| tj¡ƒS)N)ror)rrrrr™ùszDeviceConfiguration.channelcCst| tj¡ƒS)N)r„r)rrrrr˜ýszDeviceConfiguration.amp_gainN)r cCs$y
| |¡Stk
r|SXdS)N)ÚKeyError)rr ÚdefaultrrrÚgets
zDeviceConfiguration.get)r rcCsdS)Nr)rr rrr
sz%DeviceConfiguration.contain_parameter)r rcCsdS)Nr)rr rrrsz!DeviceConfiguration.get_parameter)r rrcCsdS)Nr)rr rrrrr sz!DeviceConfiguration.set_parameterc
Cs|j|j|j|ji}|dkr|j|j|j|jtj|jtj|jtj |j
i}xH|j ||dD]6}|tj krX|j
|dd}t|tƒr†t|ƒ}|||<qXW|S)NF)))ÚLIBRARYrƒÚVERSIONrvrr—rr™rr˜ÚREQUIREDrŸr*ro)rZ list_disablerBr…rrrr!)s  

 zDeviceConfiguration.as_json)FF)N)F)FFF)(r[r\r]r×Ú DEVICE_NAMEÚ DEVICE_ADDRrŒrrrr^ÚabcÚabstractmethodrfr rbr r`rvr|ÚADDRESSrÒr„r—r™rdr!rrrrsL4   )Ú metaclassc@eZdZdZeeeefefdœddZ de
edœddZ e edœd d
ƒZ
e edœd d ƒZe eedœd
dƒZe eedœddƒZeedœddZdeeedœddZeedœddZdS)ÚSimpleDeviceConfiguration)r)rGcsRtˆtƒr$‡fddˆ ¡Dƒ|_n*x"tjD]}|ˆkr,td|ƒq,Wˆ|_dS)Ncsi|]}ˆ||qSrr))rGrrIsz6SimpleDeviceConfiguration.__init__.<locals>.<dictcomp>z"lost required configuration key : )r*rr=)rrGÚreqr)rGrrGs 
 z"SimpleDeviceConfiguration.__init__F)rcCst|j ¡ƒS)N)ror)rrrrRszSimpleDeviceConfiguration.keyscCst| |j¡ƒS)N)r )rrrrUsz!SimpleDeviceConfiguration.librarycCst| |j¡ƒS)N)r r×)rrrrrvYsz)SimpleDeviceConfiguration.library_versionc Cs.yt| |j¡ƒSttfk
r(dSXdS)N)r Ú
ValueError)rrrr]sz%SimpleDeviceConfiguration.device_namecCs*yt| |j¡ƒStk
r$dSXdS)N)ÚtuplerŸ)rrrrdsz(SimpleDeviceConfiguration.device_address)r rcCs
||jkS)N)r)rr rrrksz+SimpleDeviceConfiguration.contain_parameter)r rcCs
|j|S)N)r)rr rrrnsz'SimpleDeviceConfiguration.get_parameter)r rrcCs||j|<dS)N)r)rr rrrrrqsz'SimpleDeviceConfiguration.set_parameterN)FF)F)r[r\r]r^rdr rrfr`rvr|rbrrrrDs c@eZdZdZeedœddZeedœddƒZ eedœdd „ƒZ
ee edœd
d ƒZ ee e
dœd d
ƒZeedœddƒZeedœddZdeeedœddZeeeefdœddZdeedœddZdS)ÚDeviceParameterConfiguration)r~r)rGcCs||_||_dS)N)r~r)rrGrrrrxsz%DeviceParameterConfiguration.__init__)rcCs|jjS)N)r~r )rrrr|sz$DeviceParameterConfiguration.librarycCs t|jjƒS)N)r r~r
)rrrrrvsz,DeviceParameterConfiguration.library_versioncCsdS)Nr)rrrrsz(DeviceParameterConfiguration.device_namecCsdS)Nr)rrrrˆsz+DeviceParameterConfiguration.device_addresscCs|jjS)N)r)rrrrŒsz$DeviceParameterConfiguration.context)r rcCs||jkp||jkp||jkS)N)rr×)rr rrrsz.DeviceParameterConfiguration.contain_parameterF)r rcCs@||jkr|jjS||jkr(t|jjƒS|jj}|jj|ddS)NF)) rÖr~r r×r r
rr)rr rrrs