Skip to content

Commit

Permalink
cleaned up messages, better byte order swapping, python uses version …
Browse files Browse the repository at this point in the history
…checking, wpiformat
  • Loading branch information
gerth2 committed Sep 23, 2024
1 parent 0f87540 commit 44e0e49
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Note that these are case sensitive!
* arm64
* x86-64
* x86
- `-PtgtIp`: Specifies where `./gradlew deploy` should try to copy the fat JAR to
- `-PtgtIP`: Specifies where `./gradlew deploy` should try to copy the fat JAR to
- `-Pprofile`: enables JVM profiling

## Out-of-Source Dependencies
Expand Down
14 changes: 7 additions & 7 deletions photon-lib/py/photonlibpy/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _decodeGeneric(self, unpackFormat, numBytes):
# Interpret the bytes as the requested type.
# Note due to NT's byte order assumptions,
# we have to flip the order of intList
value = struct.unpack(unpackFormat, bytes(reversed(intList)))[0]
value = struct.unpack(unpackFormat, bytes(intList))[0]

return value

Expand All @@ -98,47 +98,47 @@ def decode8(self) -> int:
*
* @return A decoded byte from the packet.
"""
return self._decodeGeneric(">b", 1)
return self._decodeGeneric("<b", 1)

def decode16(self) -> int:
"""
* Returns a single decoded short from the packet.
*
* @return A decoded short from the packet.
"""
return self._decodeGeneric(">h", 2)
return self._decodeGeneric("<h", 2)

def decodeInt(self) -> int:
"""
* Returns a decoded int (32 bytes) from the packet.
*
* @return A decoded int from the packet.
"""
return self._decodeGeneric(">l", 4)
return self._decodeGeneric("<l", 4)

def decodeFloat(self) -> float:
"""
* Returns a decoded float from the packet.
*
* @return A decoded float from the packet.
"""
return self._decodeGeneric(">f", 4)
return self._decodeGeneric("<f", 4)

def decodeLong(self) -> int:
"""
* Returns a decoded int64 from the packet.
*
* @return A decoded int64 from the packet.
"""
return self._decodeGeneric(">q", 8)
return self._decodeGeneric("<q", 8)

def decodeDouble(self) -> float:
"""
* Returns a decoded double from the packet.
*
* @return A decoded double from the packet.
"""
return self._decodeGeneric(">d", 8)
return self._decodeGeneric("<d", 8)

def decodeBoolean(self) -> bool:
"""
Expand Down
9 changes: 7 additions & 2 deletions photon-lib/py/photonlibpy/photonCamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ def _versionCheck(self) -> None:
)

versionString = self.versionEntry.get(defaultValue="")
if len(versionString) > 0 and versionString != PHOTONVISION_VERSION:
localUUID = PhotonPipelineResult.photonStruct.MESSAGE_VERSION
remoteUUID = self._rawBytesEntry.getTopic().getProperty("message_uuid")

if remoteUUID is None or len(remoteUUID) == 0:
wpilib.reportWarning(f"PhotonVision coprocessor at path {self._path} has not reported a message interface UUID - is your coprocessor's camera started?", True)
elif localUUID != remoteUUID:
# Verified version mismatch

bfw = """
Expand All @@ -250,6 +255,6 @@ def _versionCheck(self) -> None:

wpilib.reportWarning(bfw)

errText = f"Photon version {PHOTONLIB_VERSION} does not match coprocessor version {versionString}. Please install photonlibpy version {versionString}, or update your coprocessor to {PHOTONLIB_VERSION}."
errText = f"Photonlibpy version {PHOTONLIB_VERSION} (With message UUID {localUUID}) does not match coprocessor version {versionString} (with message UUID {remoteUUID}). Please install photonlibpy version {versionString}, or update your coprocessor to {PHOTONLIB_VERSION}."
wpilib.reportError(errText, True)
raise Exception(errText)
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ else if (!isConnected()) {
DriverStation.reportWarning(
"PhotonVision coprocessor at path "
+ path
+ " has note reported a message interface UUID - is your coprocessor's camera started?",
+ " has not reported a message interface UUID - is your coprocessor's camera started?",
true);
} else if (!local_uuid.equals(remote_uuid)) {
// Error on a verified version mismatch
Expand Down
1 change: 0 additions & 1 deletion scripts/catnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


def list_topics(inst: ntcore.NetworkTableInstance, root: str):

topics = inst.getTable(root).getTopics()
subtables = inst.getTable(root).getSubTables()

Expand Down

0 comments on commit 44e0e49

Please sign in to comment.