Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request JSON and JSON5 string output explicitly from PVA tools #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhangt58
Copy link

  • Eliminated the json5 opt test on EPICS base version
  • Explicitly pass -M json for regular JSON string request
  • Using -M json5 for JSON5 string request

The original intention is to make the JSON string output from PVA tools easily handled by Python without installing third-party libraries for JSON5. However, the -M json returns the JSON5 format by default (EPICS base > 7.0.6.1).

- see e5961df of pvAccessCPP repo
- eliminated the json5 opt test on EPICS base version:
  - explicitly pass -M json for regular JSON string
  - while -M json5 for JSON5 string
@zhangt58
Copy link
Author

See also epics-base/pvAccessCPP#201

@zhangt58
Copy link
Author

Here are the use cases:

$ pvget -M json tong:calc1 | cut -d' ' -f2- | python3 -m json.tool

{
    "value": 6.0,
    "alarm": {
        "severity": 1,
        "status": 1,
        "message": "HIGH"
    },
    "timeStamp": {
        "secondsPastEpoch": 1740756899,
        "nanoseconds": 84770332,
        "userTag": 0
    },
    "display": {
        "limitLow": 0.0,
        "limitHigh": 10.0,
        "description": "Counter No. 1",
        "units": "Counts",
        "precision": 0,
        "form": {
            "index": 0,
            "choices": [
                "Default",
                "String",
                "Binary",
                "Decimal",
                "Hex",
                "Exponential",
                "Engineering"
            ]
        }
    },
    "control": {
        "limitLow": 0.0,
        "limitHigh": 10.0,
        "minStep": 0.0
    },
    "valueAlarm": {
        "active": false,
        "lowAlarmLimit": 2.0,
        "lowWarningLimit": 4.0,
        "highWarningLimit": 6.0,
        "highAlarmLimit": 8.0,
        "lowAlarmSeverity": 0,
        "lowWarningSeverity": 0,
        "highWarningSeverity": 0,
        "highAlarmSeverity": 0,
        "hysteresis": 0
    }
}

To deal with JSON5 format, I have to install e.g.: pip install json5:

$ pvget -M json5 tong:calc1 | cut -d' ' -f2- | python3 -m json5.tool
{
    value: 0.0,
    alarm: {
        severity: 2,
        status: 1,
        message: "LOLO",
    },
    timeStamp: {
        secondsPastEpoch: 1740756983,
        nanoseconds: 84797876,
        userTag: 0,
    },
    display: {
        limitLow: 0.0,
        limitHigh: 10.0,
        description: "Counter No. 1",
        units: "Counts",
        precision: 0,
        form: {
            index: 0,
            choices: [
                "Default",
                "String",
                "Binary",
                "Decimal",
                "Hex",
                "Exponential",
                "Engineering",
            ],
        },
    },
    control: {
        limitLow: 0.0,
        limitHigh: 10.0,
        minStep: 0.0,
    },
    valueAlarm: {
        active: false,
        lowAlarmLimit: 2.0,
        lowWarningLimit: 4.0,
        highWarningLimit: 6.0,
        highAlarmLimit: 8.0,
        lowAlarmSeverity: 0,
        lowWarningSeverity: 0,
        highWarningSeverity: 0,
        highAlarmSeverity: 0,
        hysteresis: 0,
    },
}

@zhangt58
Copy link
Author

Presumably, the JSON parser is backward compatible, for instance, json5.tool can deal with regular JSON and JSON5, but the built-in one cannot. I'm not sure about the cases for other programming languages, and also not clear about the reasons behind the -M json defaults to json5 introduced since EPICS base 7.0.6.1.

@anjohnson
Copy link
Member

The pvDataCPP and pvAccessCPP modules can still be built as stand-alone support modules against earlier versions of EPICS Base back to 3.15 and maybe even earlier, which is why the conditional is present in src/factory/printer.cpp. Removing the conditional would break that backwards compatibility. We have some CI builds on Appveyor which should demonstrate that as we do build pvAccessCPP against Base 3.15 (but Appveyor builds aren't reliable and frequently fail anyway).

@AppVeyorBot
Copy link

Build pvDataCPP 1.0.52 failed (commit 8a9f665b77 by @zhangt58)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants