Chapter 10: K Line on C2C and Deferred Scan IDs (v0.4.1 update) - zymbia-carpm/garagepro_sdk GitHub Wiki

This update (SDK version 36, 0.4.1) is fully backward compatible. Existing code continues to work unchanged; the new listener described below is optional.

K-Line modules on the C2C serial device

Modules that communicate over K-Line are now reachable through the wired C2C device. Previously only CAN modules were scanned on this connection and K-Line modules were skipped — this supersedes the note in Chapter 9.

No integration changes. Connect exactly as described in Chapter 8:

GProDeviceConnection connection = GProDeviceConnection.forUart("/dev/ttyS1", 115200);

GProScanProcess scan = new GProScanProcess(context, connection, scanListener);
scan.initScan(makeName, registrationNumber, jobCardId);

Vehicles that have no K-Line bus are detected once and skipped, so scans on CAN-only cars do not get slower.

Getting the scan ID when the network was down

A scan does not need the network once it is running — modules are read and fault codes decoded on the device. The scan ID, however, is assigned by the server. A scan that finishes while the phone is offline therefore has no ID yet: onScanCompleted(...) reports scanBackendId == 0, and the SDK queues the upload for when connectivity returns.

That ID is now delivered through the new GProScanSyncListener.

1. Register the listener

Register once, as early as possible — ideally in Application.onCreate(). The upload often completes while your app is in the background or its process has been stopped, so results are held and delivered the next time a listener registers.

MasterScanProcess.setScanSyncListener(getApplicationContext(), new GProScanSyncListener() {
    @Override
    public void onScanSynced(int localScanId, int scanBackendId) {
        // the deferred scan reached the server; scanBackendId is the real ID
    }

    @Override
    public void onClearSynced(int localClearId, int clearBackendId) {
        // same, for a deferred clear-codes operation
    }
});

onClearSynced is optional — implement only onScanSynced if you do not need clear results.

Pass null to unregister. Registration lasts for the life of the process, so do not pass a listener that holds an Activity you expect to be released.

2. Keep the local scan ID as your correlation key

When onScanCompleted(...) gives you scanBackendId == 0, read the local scan ID and store it alongside whatever your app keeps for that scan. It is the key the deferred result arrives under.

@Override
public void onScanCompleted(String makeName, String registrationNumber, String jobCardId,
                            String message, int scanBackendId) {
    if (scanBackendId == 0) {
        int localScanId = mGProScanProcess.getLocalScanId();   // correlation key
        // persist localScanId; the backend ID arrives later via onScanSynced(localScanId, ...)
    }
}

GProScanProcess.getLocalClearId() and GProLiveScanProcess.getLocalScanId() do the same for clear-codes and live scans. Local IDs are unique per device and are unrelated to backend IDs.

What is guaranteed

  • Each result is delivered at most once, on the main thread.
  • Results survive the app being stopped, and are delivered on the next registration.
  • resyncData() also reports through this listener when it is the call that completes the upload.

Summary

Situation onScanCompleted Then
Network available scanBackendId = real ID nothing further
Network unavailable scanBackendId = 0 onScanSynced(localScanId, scanBackendId) once the upload completes

More reliable background uploads

Uploads deferred because of connectivity are now retried until the server accepts them, and an upload interrupted by the app being stopped is no longer lost. Data always stays on the device until the server has confirmed it.

Note: the network is still required to start a scan

Registering the vehicle and checking the command set both need the server. If either is unreachable, the scan fails with onScanFailed(...) before any module is read. Only the end of a scan tolerates being offline.

Upgrade

implementation ('com.github.zymbia-carpm:garagepro_sdk:v0.4.1') {
    transitive = true
}

Fully backward compatible.