Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
531 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import typing # NOQA: F401 | ||
|
||
from nixnet import _cconsts | ||
from nixnet import _errors | ||
from nixnet.database import _dbc_attributes # NOQA: F401 | ||
|
||
|
||
class DatabaseObject(object): | ||
"""Database object base.""" | ||
|
||
def __init__( | ||
self, | ||
**kwargs # type: int | ||
): | ||
# type: (...) -> None | ||
if not kwargs or '_handle' not in kwargs: | ||
_errors.raise_xnet_error(_cconsts.NX_ERR_INVALID_PROPERTY_VALUE) | ||
|
||
self._handle = kwargs['_handle'] | ||
self._dbc_attributes = None # type: typing.Optional[_dbc_attributes.DbcAttributeCollection] | ||
|
||
def __eq__(self, other): | ||
if isinstance(other, self.__class__): | ||
return self._handle == typing.cast(DatabaseObject, other)._handle | ||
else: | ||
return NotImplemented | ||
|
||
def __ne__(self, other): | ||
result = self.__eq__(other) | ||
if result is NotImplemented: | ||
return result | ||
else: | ||
return not result | ||
|
||
def __hash__(self): | ||
return hash(self._handle) | ||
|
||
def __repr__(self): | ||
return '{}(handle={})'.format(type(self).__name__, self._handle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import typing # NOQA: F401 | ||
|
||
from nixnet import _cconsts | ||
from nixnet import _errors | ||
from nixnet import _funcs | ||
from nixnet import constants | ||
from nixnet.database import _database_object # NOQA: F401 | ||
|
||
|
||
def find_object( | ||
parent_handle, # type: int | ||
object_class, # type: typing.Type[_database_object.DatabaseObject] | ||
object_name, # type: typing.Text | ||
): | ||
# type: (...) -> _database_object.DatabaseObject | ||
from nixnet.database._cluster import Cluster | ||
from nixnet.database._ecu import Ecu | ||
from nixnet.database._frame import Frame | ||
from nixnet.database._lin_sched import LinSched | ||
from nixnet.database._lin_sched_entry import LinSchedEntry | ||
from nixnet.database._pdu import Pdu | ||
from nixnet.database._signal import Signal | ||
from nixnet.database._subframe import SubFrame | ||
|
||
class_enum = constants.ObjectClass.CLUSTER # arbitrary default value | ||
|
||
if object_class is Cluster: | ||
class_enum = constants.ObjectClass.CLUSTER | ||
elif object_class is Ecu: | ||
class_enum = constants.ObjectClass.ECU | ||
elif object_class is Frame: | ||
class_enum = constants.ObjectClass.FRAME | ||
elif object_class is LinSched: | ||
class_enum = constants.ObjectClass.LIN_SCHED | ||
elif object_class is LinSchedEntry: | ||
class_enum = constants.ObjectClass.LIN_SCHED_ENTRY | ||
elif object_class is Pdu: | ||
class_enum = constants.ObjectClass.PDU | ||
elif object_class is Signal: | ||
class_enum = constants.ObjectClass.SIGNAL | ||
elif object_class is SubFrame: | ||
class_enum = constants.ObjectClass.SUBFRAME | ||
else: | ||
_errors.raise_xnet_error(_cconsts.NX_ERR_INVALID_PROPERTY_VALUE) | ||
|
||
found_handle = _funcs.nxdb_find_object(parent_handle, class_enum, object_name) | ||
if found_handle == 0: | ||
_errors.raise_xnet_error(_cconsts.NX_ERR_DATABASE_OBJECT_NOT_FOUND) | ||
|
||
return object_class(_handle=found_handle) |
Oops, something went wrong.