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

pvxinfo also shows the null value for StoreType::Compound data types like any or union #46

Closed
wanglin86769 opened this issue Jun 8, 2023 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@wanglin86769
Copy link

Describe the bug
The pvxinfo CLI tool also shows the null value for StoreType::Compound data types like any or union.

To Reproduce
Steps to reproduce the behavior:

  1. Start a PVXS server and provide NTNDArray data as follows,
int server() {
    server::SharedPV pv(server::SharedPV::buildMailbox());
    auto def = nt::NTNDArray{}.build();
    auto initial = def.create();
    pv.open(initial);
    server::Server::fromEnv()        // Configure a server using $EPICS_PVAS_* or $EPICS_PVA_*
            .addPV("my:pv:name", pv) // add (and name) one local PV
            .run();                  // run until SIGINT
    return 0;
}
  1. Use pvxinfo to print info for "my:pv:name",
my:pv:name from 10.1.236.131:5075
struct "epics:nt/NTNDArray:1.0" {
    union value        null
    struct "codec_t" {
        string name
        any parameters            null
    } codec
    int64_t compressedSize
    int64_t uncompressedSize
    int32_t uniqueId
    struct "time_t" {
        int64_t secondsPastEpoch
        int32_t nanoseconds
        int32_t userTag
    } dataTimeStamp
    struct "alarm_t" {
        int32_t severity
        int32_t status
        string message
    } alarm
    struct "time_t" {
        int64_t secondsPastEpoch
        int32_t nanoseconds
        int32_t userTag
    } timeStamp
    struct[] dimension
    struct[] attribute
}

Expected behavior
pvxinfo prints info without value.

Information (please complete the following):

  • PVXS Version: 1.2.0
  • EPICS Base Version: 7.0.7

From the source code, it looks like null values are always printed no matter what fmt._showValue is,
https://github.com/mdavidsaver/pvxs/blob/master/src/datafmt.cpp

@mdavidsaver
Copy link
Member

Thank you for reporting this.

I also think it is a bug that the element types of dimension and attribute are not printed.

@mdavidsaver mdavidsaver added the bug Something isn't working label Jun 14, 2023
@mdavidsaver
Copy link
Member

I think this issue should be addressed by 2a83e49.

$ ./bin/linux-x86_64/pvxinfo my:pv:name
my:pv:name from [fe80::7816:e3ff:fe25:5208]%5:5075
struct "epics:nt/NTNDArray:1.0" {
    union {
        bool[] booleanValue
        int8_t[] byteValue
        int16_t[] shortValue
        int32_t[] intValue
        int64_t[] longValue
        uint8_t[] ubyteValue
        uint16_t[] ushortValue
        uint32_t[] uintValue
        uint64_t[] ulongValue
        float floatValue
        double doubleValue
    } value
    struct "codec_t" {
        string name
        any parameters
    } codec
    int64_t compressedSize
    int64_t uncompressedSize
    int32_t uniqueId
    struct "time_t" {
        int64_t secondsPastEpoch
        int32_t nanoseconds
        int32_t userTag
    } dataTimeStamp
    struct "alarm_t" {
        int32_t severity
        int32_t status
        string message
    } alarm
    struct "time_t" {
        int64_t secondsPastEpoch
        int32_t nanoseconds
        int32_t userTag
    } timeStamp
    struct[] {
        int32_t size
        int32_t offset
        int32_t fullSize
        int32_t binning
        bool reverse
    } dimension
    struct[] {
        string name
        any value
        string[] tags
        string descriptor
        struct "alarm_t" {
            int32_t severity
            int32_t status
            string message
        } alarm
        struct "time_t" {
            int64_t secondsPastEpoch
            int32_t nanoseconds
            int32_t userTag
        } timeStamp
        int32_t sourceType
        string source
    } attribute
}

When shown with values, all null/zero in this case.

$ ./bin/linux-x86_64/pvxget -F tree my:pv:name
my:pv:name
    struct "epics:nt/NTNDArray:1.0" {
        union value null
        struct "codec_t" {
            string name = ""
            any parameters null
        } codec
        int64_t compressedSize = 0
        int64_t uncompressedSize = 0
        int32_t uniqueId = 0
        struct "time_t" {
            int64_t secondsPastEpoch = 0
            int32_t nanoseconds = 0
            int32_t userTag = 0
        } dataTimeStamp
        struct "alarm_t" {
            int32_t severity = 0
            int32_t status = 0
            string message = ""
        } alarm
        struct "time_t" {
            int64_t secondsPastEpoch = 0
            int32_t nanoseconds = 0
            int32_t userTag = 0
        } timeStamp
        struct[] dimension = {0}[]
        struct[] attribute = {0}[]
    }

@wanglin86769
Copy link
Author

After building the latest master branch of PVXS on Debian 10, pvxinfo and pvxget printed the expected result for the empty NTNDArray data. Thank you for fixing this.

@mdavidsaver
Copy link
Member

fyi. I had a look at https://github.com/wanglin86769/node-epics-pva/blob/master/wrapper/wrapper.cpp I would be interested in seeing a JSON output format (eg. Value::Fmt::JSON) added alongside the tree and delta formats.

@wanglin86769
Copy link
Author

Thanks for your interest in JSON format. If there is something that I can contribute, I will be glad to do it.

@wanglin86769
Copy link
Author

I think the key point is to output pvxs::Value in valid JSON format, since JSON syntax is strict. For example, some problems I encountered were,

  1. If some possible pvAccess data types are not taken into account, unexpected output with invalid JSON format may be generated.
  2. Trailing comma is not allowed in an object or array in JSON.
  3. The numbers NaN and Infinity are not support in JSON, they are considered null.

@mdavidsaver
Copy link
Member

  1. If some possible pvAccess data types are not taken into account, unexpected output with invalid JSON format may be generated.

A "reversible" mapping would be best. That is, one which could be parsed to recover the original with no loss of information. I understand that this would likely be difficult as among other aspects, JSON has no direct analog to the PVD structure ID names (eg. enum_t). Nor the struct vs union distinction. Some of this project would need to be establishing a convention. eg. special otherwise invalid field name like "+id":"enum_t" Or "+type":"struct".

3. The numbers NaN and Infinity are not support in JSON, they are considered null.

If not initially, at some point an option for JSON5 format would be helpful. fyi. epics-base has included a JSON5 aware parser since 7.0.5, which I would like in future to start using with PVXS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants