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

Implement handling of NaN values #33

Open
andig opened this issue Jun 12, 2019 · 3 comments
Open

Implement handling of NaN values #33

andig opened this issue Jun 12, 2019 · 3 comments

Comments

@andig
Copy link
Contributor

andig commented Jun 12, 2019

SMA describes NaN values for sunspec types in https://www.sma.de/fileadmin/content/landingpages/pl/FAQ/SunSpec_Modbus-TI-en-15.pdf, chapter 3.6. I'm note sure if those are part of the SunSpec spec, however if they are it would be nice to add them to Point and return NaN instead of the literal nan bytes value.

@andig
Copy link
Contributor Author

andig commented Jun 14, 2019

I've solved this by rolling my own scaledValue function:

func scaledValue(p sunspec.Point) float64 {
	f := p.ScaledValue()

	switch p.Type() {
	case "acc16":
		fallthrough
	case "uint16":
		if p.Value() == uint16(math.MaxUint16) {
			f = math.NaN()
		}
	case "acc32":
		fallthrough
	case "uint32":
		if p.Value() == uint32(math.MaxUint32) {
			f = math.NaN()
		}
	case "acc64":
		fallthrough
	case "uint64":
		if p.Value() == uint64(math.MaxUint64) {
			f = math.NaN()
		}
	case "int16":
		if p.Value() == int16(math.MinInt16) {
			f = math.NaN()
		}
	case "int32":
		if p.Value() == int32(math.MinInt32) {
			f = math.NaN()
		}
	case "int64":
		if p.Value() == int64(math.MinInt64) {
			f = math.NaN()
		}
	}

	return f
}

Would appreciate any insight if this is SunSpec standard (and should serve a PR) or if it's SMA-specific.

@andig
Copy link
Contributor Author

andig commented Jun 14, 2019

Actually, the are standard: Information Model Overview - Version 1.8, section Data Points / Standard Data Formats.

@andig andig changed the title handling of nan values Implement handling of NaN values Jun 28, 2019
@andig
Copy link
Contributor Author

andig commented Jun 28, 2019

See sunspec/pysunspec#74 for discussion related to the python reference implementation.

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 a pull request may close this issue.

1 participant