Documentation
¶
Overview ¶
addressablegcode package implements gcode.AddressableGcoder interface to model a gcode with an address element.
Define a Gcode struct that implement gcode.AddressableGcoder interface. This struct contain a word field to store the word value and an address field to store the address value.
Like AddressableGcoder interface, this Gcode struct use generics with the restrictions defined by AddressType.
A "New" constructor method allow to instance new Gcode[T] object. This method use some internal rules combined with gcode.IsValidWord to validate the inputs before create any instance
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gcode ¶
type Gcode[T gcode.AddressType] struct { //Gcoder (via embedded gcode.Gcoder interface) gcode.Gcoder // contains filtered or unexported fields }
Gcode struct that implements GcodeAddresser interface.
Is composed of a gcode struct and includes an address field to store an address instance.
func New ¶
func New[T gcode.AddressType](word byte, address T) (*Gcode[T], error)
New return a new Gcode[T] instance or error if some inputs are invalids word is the letter that compose the gcode address is the value of the gcode
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gc, err := addressablegcode.New[float32]('X', 12.3)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%s", gc)
}
Output: X12.300
func (*Gcode[T]) Address ¶
func (g *Gcode[T]) Address() T
Address return the value of the address
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gc, err := addressablegcode.New[int32]('N', 66555)
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Println(gc.Address())
}
Output: 66555
Example (Second) ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New[int32]('N', 66555)
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
// save a reference to gcode addressable instance in a gcoder interface
var gc gcode.Gcoder = gca
if !gc.HasAddress() {
fmt.Println("Ups! gcode not contain address")
return
}
// try recovery the reference to gcode addressable instance from a gcoder interface
// using assertion
if value, ok := gc.(gcode.AddressableGcoder[int32]); ok {
add := value.Address()
fmt.Printf("the int32 address recovered is %v\n", add)
}
}
Output: the int32 address recovered is 66555
func (*Gcode[T]) Compare ¶
Compare allows checking if the current entity is equal to a Gcoder input
This method is executed when to be called from a Gcode instance or a Gcoder instance that contains a reference to a Gcode object. If the input Gcoder does not implement some addressablegcode.Gcode[T] data type then it returns false
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
addressableGcode, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
anotherAddressableGcode, err := addressablegcode.New('X', "\"Hello World!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Printf("%v\n", addressableGcode.Compare(anotherAddressableGcode))
}
Output: false
Example (Second) ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
"github.com/mauroalderete/gcode-core/gcode/unaddressablegcode"
)
func main() {
addressableGcode, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
unaddressableGcode, err := unaddressablegcode.New('X')
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Printf("%v\n", addressableGcode.Compare(unaddressableGcode))
}
Output: false
func (*Gcode[T]) HasAddress ¶
HasAddress indicate if the gcode contain or not an address.
This method is called from a GcodeAddressable instance or a GcodeAddresser instance that contains a reference to a GcodeAddressable object. Always return true.
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Printf("%v\n", gca.HasAddress())
}
Output: true
Example (Second) ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
// assign reference from gcode addressable instance to gcoder interface
var gc gcode.Gcoder = gca
fmt.Printf("%v\n", gc.HasAddress())
}
Output: true
func (*Gcode[T]) SetAddress ¶
SetAddress allow to store a new value
If the address data type is string then the new value is verified. If it doesn't satisfy the a string format then SetAddress returns an error.
func (*Gcode[T]) String ¶
String return gcode formatted
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Println(gca)
}
Output: X"Hola mundo!"
Example (Second) ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New('X', "\"Hola mundo!\"")
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
// assign reference from gcode addressable instance to gcoder interface
var gc gcode.Gcoder = gca
fmt.Println(gc)
}
Output: X"Hola mundo!"
func (*Gcode[T]) Word ¶
Word return a copy of the word struct in the gcode
Example ¶
package main
import (
"fmt"
"github.com/mauroalderete/gcode-core/gcode/addressablegcode"
)
func main() {
gca, err := addressablegcode.New[int32]('D', 0)
if err != nil {
_ = fmt.Errorf("%s", err.Error())
return
}
fmt.Println(gca.Word())
}
Output: 68