Documentation ¶
Overview ¶
Package pixelpusher provides protocol constructs for the PixelPusher.
This package complements the common protocol package, which offers top-level device protocol constructs.
In addition to offering basic protocol definitions, this package supplies facilities to construct and manipulate protocol data.
Index ¶
- Constants
- Variables
- func WriteCommand(cmd Command, w io.Writer, writeMagic bool) error
- type ColourOrder
- type Command
- type CommandID
- type Device
- func (d *Device) Clone() *Device
- func (d *Device) FixedSize() int
- func (d *Device) PacketReader() *PacketReader
- func (d *Device) PacketStream() *PacketStream
- func (d *Device) String() string
- func (d *Device) UpdatePeriodDuration() time.Duration
- func (d *Device) Write(w io.Writer, swVersion uint16) error
- type DeviceHeader
- type DeviceHeaderExt101
- type DeviceHeaderExt109
- type DeviceHeaderExt117
- type GlobalBrightnessSetCommand
- type LEDConfigureCommand
- type Packet
- type PacketReader
- type PacketStream
- func (ps *PacketStream) Flush(ds network.DatagramSender) error
- func (ps *PacketStream) Send(ds network.DatagramSender, pkt *Packet) error
- func (ps *PacketStream) SendCommand(ds network.DatagramSender, cmd Command) error
- func (ps *PacketStream) SendOrEnqueueStripState(ds network.DatagramSender, ss *StripState) error
- type ResetCommand
- type Security
- type StripBrightnessSetCommand
- type StripFlags
- type StripNumber
- type StripState
- type StripType
- type WiFiConfigureCommand
Constants ¶
const ( CommandReset CommandID = 0x01 CommandGlobalBrightnessSet = 0x02 CommandWifiConfigure = 0x03 CommandLEDConfigure = 0x04 CommandStripBrightnessSet = 0x05 )
const uint8_t pp_command_magic[16] =
* * #define COMMAND_RESET 0x01 * #define COMMAND_GLOBALBRIGHTNESS_SET 0x02 * #define COMMAND_WIFI_CONFIGURE 0x03 * #define COMMAND_LED_CONFIGURE 0x04 * #define COMMAND_STRIPBRIGHTNESS_SET 0x05
const ( // ColourOrderRGB is the colour order for RGB. ColourOrderRGB ColourOrder = 0 // ColourOrderRBG is the colour order for RBG. ColourOrderRBG = 1 // ColourOrderGBR is the colour order for GBR. ColourOrderGBR = 2 // ColourOrderGRB is the colour order for GRB. ColourOrderGRB = 3 // ColourOrderBGR is the colour order for BGR. ColourOrderBGR = 4 // ColourOrderBRG is the colour order for BRG. ColourOrderBRG = 5 )
const ( // ListenPort is the port that PixelPusher devices tend to advertise for their // pixel data. // // It's probably not useful in practice, since all modern devices will specify // their port, but it's kept here for record. ListenPort uint16 = 5078 // DefaultPort is the default PixelPusher device data port value to use when // the PixelPusher does not include a discovery header specifying this value. DefaultPort uint16 = 9798 // MinAcceptableSoftwareRevision is the software revision prior to which a // warning to update software should be issued. // // This isn't prohibitive, and this packet supports earlier versions, but // other libraries use this as a signal so we're putting it here in case you // also want to. MinAcceptableSoftwareRevision uint16 = 121 // LatestSoftwareRevision is the latest known software revision that this // package supports. LatestSoftwareRevision uint16 = 122 )
const ( // PFlagProtected is the PFLAG_PROTECTED device flag. PFlagProtected = (1 << iota) // PFlagFixedSize is the PFLAG_FIXDEDSIZE device flag. // // It indicates that sent packets must be a fixed size (Photon). // This ends up being: // // 4 + ((1 + 3 * PixelsPerStrip) * min(StripsAttached, MaxStripsPerPacket)); PFlagFixedSize // PFlagGlobalBrightness is the PFLAG_GLOBALBRIGHTNESS device flag. PFlagGlobalBrightness // PFlagStripBrightness is the PFLAG_STRIPBRIGHTNESS device flag. PFlagStripBrightness // PFlagMonochromeNotPacked is the PFLAG_MONOCHROME_NOT_PACKED device flag. PFlagMonochromeNotPacked )
PixelPusher device flags (software version > 108).
const ( // SecurityNone is the NONE security enumeration. SecurityNone Security = 0 // SecurityWEP is the WEP security enumeration. SecurityWEP = 1 // SecurityWPA is the WPA security enumeration. SecurityWPA = 2 // SecurityWPA2 is the WPA2 security enumeration. SecurityWPA2 = 3 )
enum Security { NONE = 0, WEP = 1, WPA = 2, WPA2 = 3 };
const ( // StripLPD8806 is the LPD8806 strip type. StripLPD8806 StripType = 0 // StripWS2801 is the WS2801 strip type. StripWS2801 = 1 // StripWS2811 is the WS2811 strip type. StripWS2811 = 2 // StripAPA102 is the APA102 strip type. StripAPA102 = 3 )
Variables ¶
var CommandMagic = []byte{
0x40, 0x09, 0x2d, 0xa6, 0x15, 0xa5, 0xdd, 0xe5,
0x6a, 0x9d, 0x4d, 0x5a, 0xcf, 0x09, 0xaf, 0x50,
}
CommandMagic is a magic number that precedes PixelPusher commands.
Functions ¶
func WriteCommand ¶
WriteCommand writes a Command to w.
If writeMagic is true, the CommandMagic header will be written at the beginning.
The user should use a buffered writer to support the various incremental writes that will need to be executed.
Types ¶
type ColourOrder ¶
type ColourOrder uint64
ColourOrder sets the pixel color order.
typedef enum ColourOrder { RGB=0, RBG=1, GBR=2, GRB=3, BGR=4, BRG=5} ColourOrder;
type Command ¶
type Command interface { // ID is the command ID for this command. ID() CommandID // WriteContentTo writes a command to w. // // WriteContentTo does not write the CommandMagic or the command byte. WriteContentTo(w io.Writer) error // LoadContentFrom reads a command's content from r. // // LoadContentFrom does not load the CommandMagic or the command byte. LoadContentFrom(r io.Reader) error }
Command is a general interface for the command.
func ReadCommand ¶
ReadCommand reads a Command data from r.
If consumeMagic is true, ReadCommand will expect r to begin with the CommandMagic header, and will error if it doesn't.
The user should use a buffered reader to support the various incremental reads that will need to be executed.
type Device ¶
type Device struct { DeviceHeader // The following headers *may* be present in the discovery packet, depending // on the software version. // // For DXXX, the header may be present if the SoftwareRevision device header // is >= XXX. // // If the headers are missing, these will be valid and contain default values. DeviceHeaderExt101 DeviceHeaderExt109 DeviceHeaderExt117 Extra []byte }
Device is a device header extension for the DeviceType.
/**
- uint8_t strips_attached;
- uint8_t max_strips_per_packet;
- uint16_t pixels_per_strip; // uint16_t used to make alignment work
- uint32_t update_period; // in microseconds
- uint32_t power_total; // in PWM units
- uint32_t delta_sequence; // difference between received and expected
- sequence numbers
- int32_t controller_ordinal; // configured order number for controller
- int32_t group_ordinal; // configured group number for this controller
- int16_t artnet_universe;
- int16_t artnet_channel;
- int16_t my_port; */
func ReadDevice ¶
ReadDevice reads a Device from r.
ReadDevice will select what to read based on the presence of data in the header and the software version.
func (*Device) FixedSize ¶
FixedSize returns the fixed-size packet value if one is set, or <=0 if this device does not require a fixed size (PFLAG_FIXEDSIZE).
func (*Device) PacketReader ¶
func (d *Device) PacketReader() *PacketReader
PacketReader returns a PacketReader configured for this Device.
func (*Device) PacketStream ¶
func (d *Device) PacketStream() *PacketStream
PacketStream returns a PacketStream configured for this Device.
func (*Device) UpdatePeriodDuration ¶
UpdatePeriodDuration returns d's update period, experessed in microseconds, as a time.Duration.
type DeviceHeader ¶
type DeviceHeader struct { StripsAttached uint8 MaxStripsPerPacket uint8 PixelsPerStrip uint16 `struc:",little"` UpdatePeriod uint32 `struc:",little"` PowerTotal uint32 `struc:",little"` DeltaSequence uint32 `struc:",little"` ControllerOrdinal int32 `struc:",little"` GroupOrdinal int32 `struc:",little"` ArtNetUniverse int16 `struc:",little"` ArtNetChannel int16 `struc:",little"` }
DeviceHeader is the standard PixelPusher device header.
type DeviceHeaderExt101 ¶
type DeviceHeaderExt101 struct { // MyPort is optionally present if the software version is > 100; otherwise, // it defaults to DefaultPort. MyPort uint16 `struc:",little"` // Inferred from Java code offsets. Pad2_3 []byte `struc:"[2]pad"` }
DeviceHeaderExt101 is an optional extension of the Device header that can exist if the software revision is >= 101.
type DeviceHeaderExt109 ¶
type DeviceHeaderExt109 struct { // Flags for each strip. This must have len(StripsAttached). // // On the wire, a *minimum* of 8 entries must be present. The actual number // available will be min(8, StripsAttached). StripFlags []StripFlags }
DeviceHeaderExt109 is an optional extension of the Device header that can exist if the software revision is >= 109.
DeviceHeaderExt109 requires DeviceHeaderExt101 to be present.
type DeviceHeaderExt117 ¶
type DeviceHeaderExt117 struct { // Inferred from Java code offsets. Pad0_1 []byte `struc:"[2]pad"` // If software version is > 116, this may be followed by more PixelPusher // properties. PusherFlags uint32 `struc:",little"` Segments uint32 `struc:",little"` PowerDomain uint32 `struc:",little"` }
DeviceHeaderExt117 is an optional extension of the Device header that can exist if the software revision is >= 117.
DeviceHeaderExt117 requires DeviceHeaderExt101 to be present.
type GlobalBrightnessSetCommand ¶
type GlobalBrightnessSetCommand struct {
Parameter uint16 `struc:",little"`
}
GlobalBrightnessSetCommand is a GLOBALBRIGHTNESS_SET command.
func (*GlobalBrightnessSetCommand) ID ¶
func (*GlobalBrightnessSetCommand) ID() CommandID
ID implements Command.
func (*GlobalBrightnessSetCommand) LoadContentFrom ¶
func (cmd *GlobalBrightnessSetCommand) LoadContentFrom(r io.Reader) error
LoadContentFrom implements Command.
Note that RESET command has no contents so this will do nothing and succeed.
func (*GlobalBrightnessSetCommand) WriteContentTo ¶
func (cmd *GlobalBrightnessSetCommand) WriteContentTo(w io.Writer) error
WriteContentTo implements Command.
type LEDConfigureCommand ¶
type LEDConfigureCommand struct { NumStrips uint32 `struc:",little"` StripLength uint32 `struc:",little"` StripType uint64 `struc:",little"` ColourOrder ColourOrder `struc:",little"` Group uint16 `struc:",little"` Controller uint16 `struc:",little"` ArtNetUniverse uint16 `struc:",little"` ArtNetChannel uint16 `struc:",little"` }
LEDConfigureCommand is a COMMAND_LED_CONFIGURE command.
func (*LEDConfigureCommand) LoadContentFrom ¶
func (cmd *LEDConfigureCommand) LoadContentFrom(r io.Reader) error
LoadContentFrom implements Command.
Note that RESET command has no contents so this will do nothing and succeed.
func (*LEDConfigureCommand) WriteContentTo ¶
func (cmd *LEDConfigureCommand) WriteContentTo(w io.Writer) error
WriteContentTo implements Command.
type Packet ¶
type Packet struct { // ID is this packet's ID. ID uint32 // Command is the command for this packet. // // A Packet may provide exactly one Command or StripStates value. Command Command // StripStates is the series of strip states represented by this packet. // // A Packet may provide exactly one Command or StripStates value. StripStates []*StripState }
Packet is a single PixelPusher packet data block.
type PacketReader ¶
type PacketReader struct { // PixelsPerStrip is the number of pixels belonging to a given strip. PixelsPerStrip int // StripFlags contains information about individual PixelPusher strips. // // Strip information is needed when decoding packets, since each strip's // encoding depends on its configuration. StripFlags []StripFlags }
PacketReader reads packet structure from a stream.
func (*PacketReader) ReadPacket ¶
func (pr *PacketReader) ReadPacket(r *byteslicereader.R, pkt *Packet) error
ReadPacket reads a Packet, pkt, from a source of data.
If the packet could not be read, ReadPacket returns an error.
The returned packet will reference data slices returned by r, and should not outlive the underlying buffer.
type PacketStream ¶
type PacketStream struct { // MaxStripsPerPacket is the maximum number of strip states that can be sent // in a single packet. This can be obtained from the device's DeviceHeader. MaxStripsPerPacket uint8 // PixelsPerStrip is the number of pixels per strip. // // If this is >0, and a pixel packet is submitted with a different number of // pixels, it will be corrected to conform t this limit. PixelsPerStrip uint16 // FixedSize, if >0, means that this packet must have the specified fixed // size, regardless of its contents. // // If the packet that is written exceeds this size, FixedSize will be ignored; // otherwise, the packet will be padded to write FixedSize total bytes. // // This value should be set based on the device's PusherFlags. FixedSize int // NextID is the next ID to assign to a packet. NextID uint32 // contains filtered or unexported fields }
PacketStream is the overall state of a packet stream.
A PacketStream is generally not created by a user, but rather obtained from a discovery Device instance's PacketStream method.
func (*PacketStream) Flush ¶
func (ps *PacketStream) Flush(ds network.DatagramSender) error
Flush flushes any pending strip states.
func (*PacketStream) Send ¶
func (ps *PacketStream) Send(ds network.DatagramSender, pkt *Packet) error
Send sends the contents of the specified Packet.
The Packet's ID field is ignored in favor of the PacketStream generating its own ID.
Send is a proxy for SendCommand or SendOrEnqueueStripState based on the contents of the packet.
func (*PacketStream) SendCommand ¶
func (ps *PacketStream) SendCommand(ds network.DatagramSender, cmd Command) error
SendCommand sends a Command packet to the PacketStream's connection.
func (*PacketStream) SendOrEnqueueStripState ¶
func (ps *PacketStream) SendOrEnqueueStripState(ds network.DatagramSender, ss *StripState) error
SendOrEnqueueStripState enqueues a StripState to be sent.
Enqueueing a StripState may cause a previously-enqueued StripState to be sent in order to make room for the new StripState. At most one send operation will occur per call, and that error value will be returned.
type ResetCommand ¶
type ResetCommand struct{}
ResetCommand issues a RESET command.
func (*ResetCommand) LoadContentFrom ¶
func (cmd *ResetCommand) LoadContentFrom(io.Reader) error
LoadContentFrom implements Command.
Note that RESET command has no contents so this will do nothing and succeed.
func (*ResetCommand) WriteContentTo ¶
func (cmd *ResetCommand) WriteContentTo(w io.Writer) error
WriteContentTo implements Command.
type Security ¶
type Security uint8
Security is a byte value that represents the WiFi security on a PixelPusher device.
type StripBrightnessSetCommand ¶
StripBrightnessSetCommand is a STRIPBRIGHTNESS_SET command.
func (*StripBrightnessSetCommand) ID ¶
func (*StripBrightnessSetCommand) ID() CommandID
ID implements Command.
func (*StripBrightnessSetCommand) LoadContentFrom ¶
func (cmd *StripBrightnessSetCommand) LoadContentFrom(r io.Reader) error
LoadContentFrom implements Command.
Note that RESET command has no contents so this will do nothing and succeed.
func (*StripBrightnessSetCommand) WriteContentTo ¶
func (cmd *StripBrightnessSetCommand) WriteContentTo(w io.Writer) error
WriteContentTo implements Command.
type StripFlags ¶
type StripFlags uint8
StripFlags represents information about a PixelPusher Strip.
TODO: Add other pieces of information from flags.
const ( // SFlagRGBOW is the SFLAG_RGBOW strip flag. SFlagRGBOW StripFlags = (1 << iota) // SFlagWidePixels is the SFLAG_WIDEPIXELS strip flag. SFlagWidePixels // SFlagLogarithmic is the SFLAG_LOGARITHMIC strip flag. SFlagLogarithmic // SFlagMotion is the SFLAG_MOTION strip flag. SFlagMotion // SFlagNotIdempotent is the SFLAG_NOTIDEMPOTENT strip flag. SFlagNotIdempotent // SFlagBrightness is the SFLAG_BRIGHTNESS strip flag. SFlagBrightness // SFlagMonochrome is the SFLAG_MONOCHROME strip flag. SFlagMonochrome )
PixelPusher strip flags.
func (StripFlags) IsRGBOW ¶
func (sf StripFlags) IsRGBOW() bool
IsRGBOW is true if the SFLAG_RGBOW strip flag is enabled.
If true, the packet stream uses RGBOW encoding. If false, the stream uses RGB encoding.
func (*StripFlags) PixelBufferLayout ¶
func (sf *StripFlags) PixelBufferLayout() pixel.BufferLayout
PixelBufferLayout returns the pixel buffer layout to use for this strip.
func (*StripFlags) SetRGBOW ¶
func (sf *StripFlags) SetRGBOW(v bool)
SetRGBOW sets the value of the SFLAG_RGBOW strip flag.
func (StripFlags) String ¶
func (sf StripFlags) String() string
String writes a string version of these flags.
Output looks like: 0x03(RGBOW|WIDEPIXELS)
type StripNumber ¶
type StripNumber uint8
StripNumber is the number assigned to an individual Strip.
type StripState ¶
type StripState struct { // StripNumber is the strip number that this state represents. StripNumber StripNumber // Pixels is the set of pixels that belongs to this strip. Pixels pixel.Buffer }
StripState is the pixel state of a single strip.
type WiFiConfigureCommand ¶
WiFiConfigureCommand is a WIFI_CONFIGURE command.
func (*WiFiConfigureCommand) ID ¶
func (*WiFiConfigureCommand) ID() CommandID
ID implements Command.
func (*WiFiConfigureCommand) LoadContentFrom ¶
func (cmd *WiFiConfigureCommand) LoadContentFrom(r io.Reader) error
LoadContentFrom implements Command.
Note that RESET command has no contents so this will do nothing and succeed.
func (*WiFiConfigureCommand) WriteContentTo ¶
func (cmd *WiFiConfigureCommand) WriteContentTo(w io.Writer) error
WriteContentTo implements Command.