Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions go/byteconverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,13 @@ func ByteSliceToFloat64Slice(slice []byte) []float64 {
return result
}

func ByteSliceToRuneSlice(slice []byte) []rune {
result := make([]rune, len(slice))
for idx, b := range slice {
result[idx] = rune(b)
}
return result
}

func RuneSliceToByteSlice(slice []rune) []byte {
result := make([]byte, len(slice))
for idx, b := range slice {
result[idx] = byte(b)
}
return result
}

func ByteSliceToString(slice []byte) string {
n := bytes.IndexByte(slice, 0)
return string(slice[:n])
}

// Todo: This would break encoding of UTF-8 chars. Evaluate []byte(str)
func StringToByteSlice(str string, maxLen uint64) ([]byte, error) {
runes := []rune(str)
bytes := make([]byte, maxLen, maxLen)
Expand Down
3 changes: 3 additions & 0 deletions go/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@

2025-10-07: 2.0.17 (9ad863d)
- Fix bool arrays in setters

2026-04-15: 2.0.18 (7685cab7)
- Fix mapping of char from rune to byte (Issue: https://github.com/Tinkerforge/generators/issues/65)
2 changes: 1 addition & 1 deletion go/example_authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
ipcon.Enumerate() // then trigger enumerate.
})

ipcon.RegisterEnumerateCallback(func(uid string, connectedUid string, position rune, hardwareVersion [3]uint8,
ipcon.RegisterEnumerateCallback(func(uid string, connectedUid string, position byte, hardwareVersion [3]uint8,
firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType ipconnection.EnumerationType) {
fmt.Printf("UID: %s\n", uid)
switch enumerationType {
Expand Down
2 changes: 1 addition & 1 deletion go/example_enumerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
defer ipcon.Disconnect()
// Don't use device before ipcon is connected.

ipcon.RegisterEnumerateCallback(func(uid string, connectedUid string, position rune, hardwareVersion [3]uint8,
ipcon.RegisterEnumerateCallback(func(uid string, connectedUid string, position byte, hardwareVersion [3]uint8,
firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType ipconnection.EnumerationType) {
fmt.Printf("UID: %s\n", uid)
switch enumerationType {
Expand Down
12 changes: 5 additions & 7 deletions go/generate_go_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_go_constants(self):
enum_values = []

for constant in constant_group.get_constants():
value = str(constant.get_value()) if not "rune" in constant_type else "'" + constant.get_value() + "'"
value = str(constant.get_value()) if not "byte" in constant_type else "'" + constant.get_value() + "'"

if constant_type == "bool":
value = value.lower()
Expand Down Expand Up @@ -187,16 +187,14 @@ def go_fill_payload(self, elements, bufferName):
def go_read_results(self, elements, bufferName, low_level_in_bits=True):
read_results = []
for elem in elements:
size = elem.get_size()

if elem.get_level() == 'low' and elem.get_role() == 'stream_chunk_data':
read_results.append("copy({name}[:], ByteSliceTo{type}Slice({buf}.Next({mult} * {chunk_size}/8)))".format(buf=bufferName, name=elem.get_go_name(), type=elem.get_go_type(ignore_cardinality=True).title(), chunk_size= elem.get_cardinality(), mult = go_common.get_go_type_size(elem.get_go_type(ignore_cardinality=True))))
continue

if "rune" in elem.get_go_type() and elem.get_cardinality() == 1:
read_results.append("{ret_name} = rune({buf}.Next(1)[0])".format(buf=bufferName, ret_name=elem.get_go_name()))
elif "rune" in elem.get_go_type():
read_results.append("copy({ret_name}[:], ByteSliceTo{type}Slice({buf}.Next({len})))".format(buf=bufferName, ret_name=elem.get_go_name(), type=elem.get_go_type(ignore_cardinality=True).title(), len=elem.get_cardinality()))
if "byte" in elem.get_go_type() and elem.get_cardinality() == 1:
read_results.append("{ret_name} = {buf}.Next(1)[0]".format(buf=bufferName, ret_name=elem.get_go_name()))
elif "byte" in elem.get_go_type():
read_results.append("copy({ret_name}[:], {buf}.Next({len}))".format(buf=bufferName, ret_name=elem.get_go_name(), type=elem.get_go_type(ignore_cardinality=True).title(), len=elem.get_cardinality()))
elif "bool" in elem.get_go_type() and elem.get_cardinality() > 1:
read_results.append("copy({ret_name}[:], ByteSliceTo{type}Slice({buf}.Next({len})))".format(buf=bufferName, ret_name=elem.get_go_name(), type=elem.get_go_type(ignore_cardinality=True).title(), len=math.ceil(elem.get_cardinality() / 8)))
elif elem.get_go_type() == "string":
Expand Down
6 changes: 3 additions & 3 deletions go/go_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def get_go_type(self, ignore_cardinality=False, ignore_constant_group=False, con
return self.get_constant_group(index=self.get_indices()[0]).get_name().camel

if self.get_type() == 'char':
element_type = 'rune'
element_type = 'byte'
elif self.get_type() == 'string':
return 'string'
elif self.get_type() == 'bool':
Expand Down Expand Up @@ -281,7 +281,7 @@ def get_go_type(self):
'uint64': 'uint64',
'float': 'float32',
'bool': 'bool',
'char': 'rune',
'char': 'byte',
'string': 'string'
}

Expand All @@ -296,7 +296,7 @@ def get_go_type(self):
'uint64': 64,
'float32':32,
'bool': 1,
'rune': 8,
'byte': 8,
'string': 'string'
}

Expand Down
6 changes: 3 additions & 3 deletions go/ipcon_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (ipcon *IPConnection) RegisterDisconnectCallback(fn func(DisconnectReason))
// For the bottommost Brick in a stack it is "0".
// With this information it is possible to reconstruct the complete network topology.
//
// * position rune - For Bricks: '0' - '8' (position in stack). For Bricklets: 'a' - 'd' (position on Brick).
// * position byte - For Bricks: '0' - '8' (position in stack). For Bricklets: 'a' - 'd' (position on Brick).
//
// * hardwareVersion [3]uint8 - Major, minor and release number for hardware version.
//
Expand All @@ -88,7 +88,7 @@ func (ipcon *IPConnection) RegisterDisconnectCallback(fn func(DisconnectReason))
// For example: master_brick.DeviceIdentifier or ambient_light_bricklet.DeviceIdentifier.
//
// * enumerationType EnumerationType - Type of enumeration.
func (ipcon *IPConnection) RegisterEnumerateCallback(fn func(uid string, connectedUID string, position rune, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType EnumerationType)) uint64 {
func (ipcon *IPConnection) RegisterEnumerateCallback(fn func(uid string, connectedUID string, position byte, hardwareVersion [3]uint8, firmwareVersion [3]uint8, deviceIdentifier uint16, enumerationType EnumerationType)) uint64 {
wrapper := func(bytes []byte) {
var header internal.PacketHeader

Expand All @@ -100,7 +100,7 @@ func (ipcon *IPConnection) RegisterEnumerateCallback(fn func(uid string, connect
bytes = bytes[8:]
uid := internal.ByteSliceToString(bytes[0:8])
connectedUID := internal.ByteSliceToString(bytes[8:16])
position := rune(bytes[16])
position := bytes[16] // Todo: Evaluate a custom datatype with .String() etc.
hardwareVersion := [3]uint8{bytes[17], bytes[18], bytes[19]}
firmwareVersion := [3]uint8{bytes[20], bytes[21], bytes[22]}
deviceIdentifier := binary.LittleEndian.Uint16(bytes[23:25])
Expand Down