Skip to main content

Extracts GPS positions from J1939 PGN 65267 CAN logs

Project description

j1939parser

codecov PyPI version Python versions License: MIT

Extract GPS position and vehicle speed from SAE J1939 CAN logs or live CAN interfaces


📚 Table of Contents


Overview

j1939parser is a Python library for decoding vehicle position (latitude and longitude) from J1939 CAN bus data, specifically PGN 65267 (0xFEF3) Vehicle Position, as well as support for live reading from CAN hardware or parsing log files.

It supports two modes of operation:

  • Case A: Tail and parse a CAN log file (e.g., output from candump can0 > output.log)
  • Case B: Read directly from a live CAN interface like can0 on a Raspberry Pi with MCP2515 CAN module

Features

  • Extract latitude and longitude from J1939 PGN 65267 frames
  • Support real-time streaming from live CAN interface or log files
  • Auto-detects source type (file or CAN interface)
  • Graceful fallback if python-can library is missing
  • Includes platform check with warning for non-Raspberry Pi environments
  • Lightweight and easy to integrate into existing Python projects

Installation

# Basic install (file parsing only)
pip install j1939parser

# For live CAN interface support (requires python-can)
pip install 'j1939parser[can]'

Usage

Parsing from a CAN Log file (output.log)

from j1939parser import stream_vehicle_positions

source = "output.log"  # Path to your CAN log file

for lat, lon in stream_vehicle_positions(source):
    print(f"Live GPS → Latitude: {lat:.7f}, Longitude: {lon:.7f}")

This will tail the log file and print new positions as they appear.

Reading from live CAN interface (e.g., Raspberry Pi can0)

from j1939parser import stream_vehicle_positions

source = "can0"  # Your CAN interface name

for lat, lon in stream_vehicle_positions(source):
    print(f"Live GPS → Latitude: {lat:.7f}, Longitude: {lon:.7f}")

Hardware Setup

Raspberry Pi with Linux-based OS

Waveshare MCP2515 CAN module (SPI-based)

CAN interface enabled and configured (e.g., can0)

Bitrate typically set to 250000:

sudo ip link set can0 up type can bitrate 250000

Use candump to log CAN traffic:

candump can0 > output.log

How Input LOg Lines Should Look

Typical CAN log lines compatible with the parser have this format:

(1737413716.432751)  can1  18FEF34A   [8]  0E 23 6A 93 1E DE 81 34

18FEF34A contains the PGN (18FEF3 = PGN 65267 + source)

Data bytes follow in hex, exactly 8 bytes for PGN 65267 vehicle position

Development & Contribution

Contributions are welcome! Please open issues or pull requests.


Testing

You can run the unit tests using pytest as follows:

# Run all tests in the tests/ directory
python -m pytest tests/

# Or run a specific test file
python -m pytest tests/test_position.py

Note:
Make sure to install your package in editable mode first:

pip install -e '.[can]'

This ensures your package is available for the tests to import.



Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

j1939parser-0.1.4.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

j1939parser-0.1.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file j1939parser-0.1.4.tar.gz.

File metadata

  • Download URL: j1939parser-0.1.4.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for j1939parser-0.1.4.tar.gz
Algorithm Hash digest
SHA256 aa78536866bed88f3f951b7522a069977344569d9a405e207ef5b0bbae4993db
MD5 e931cd23379204c62f0077fc86c50050
BLAKE2b-256 a8221be56babb5804b444e9d47c77e3b64f1c8a0ce4ebfa5078927e2db27ff41

See more details on using hashes here.

File details

Details for the file j1939parser-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: j1939parser-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for j1939parser-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2079b9983fff0c39876544b1f247e858c7628ff21745452dd437dce961475bfd
MD5 43c73c07310b44d1b63bb05b0355c8c5
BLAKE2b-256 9a8089008c283d17a0ac0c35e4b609287496acc6961871ecadf33d8a33c0add8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page