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

Expose more OPC internals #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

JoakimSoderberg
Copy link

Hello,

Nice implementation of OPC. However I quickly realised that I can't use it as is, since it is tailored quite specifically to one use case.

I wanted to write an OPC proxy, and that means I need raw access to the Message struct and so on. But as the current design is these are not exposed.

I did some changes to the library that allows me to just use some parts, and implement the connection/listening and so exactly as I want to.

This is my first attempt at a Golang project so I can't say I'm an expert. I'm totally open to modifying this PR if you want that, since I'm aware these break backwards compatability.

Some notable changes:

  1. Made ReadOpc a standalone function. It did not use any of the state in the Server struct anyway. And this makes it possible to reuse in other code without being forced to use Server.
func ReadOpc(conn net.Conn) (*Message, error)
  1. I made all fields in the Message struct exported. When I'm writing my proxy the Device concept does not really work, I just want to get the raw messages and send them on, and be able to check the channel and such for each message.

  2. Renamed constants and changed comments to follow the "go standard" better. Examples:

SET_PIXEL_COLORS -> SetPixelColorsCmd

(Coming from C I kind of prefer your way as a matter of taste, but keeping to a language standard if there is such a clear one trumps that my personal taste any day).

Comments in Go should be of the form:

Something performs various actions
func Something()

Rather than:

This performs various actions
func Something()

This is from go vet suggestions.


Anyway, what I ended up using of this is the changes to the exposed fields in Message as well as making ReadOpc a function that can be used standalone. So if you want me to modify the PR to only include those changes I can do that.

Instead of using all parts of the library to run the OPC server there are scenarios where
people only wants to use parts of the library.

For example I'm writing an OPC proxy, I can't assume before starting the server how many
channels there will be, so I need to be able to have my own dispatcher.

Also I fixed the comment style for functions to match the go style.

Made ReadOPC a standalone function and exported it so that can be used standalone.
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.

1 participant