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

IFirmwareInformation #4

Open
alexsuslov opened this issue Jul 29, 2021 · 4 comments
Open

IFirmwareInformation #4

alexsuslov opened this issue Jul 29, 2021 · 4 comments
Labels
discussion enhancement New feature or request

Comments

@alexsuslov
Copy link

Hi
What do u think about

type IFirmwareInformation interface {
	FirmwareVersion()string
	ProtocolVersion()string
	MachineType()string
	ExtruderCount()int
	UUID()string
}

type FirmwareInformation struct {
	info            map[string]string
}

My parse functions

func ParseHead(line string, info map[string]string){
	pois:=[]int{}
	for _, name := range names{
		poi:=strings.Index(line, name)
		pois= append(pois, poi)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(pois)))
	e:=len(line)
	for _,s:= range pois{
		line:=line[s:e]
		v:=strings.Split(line, ":")
		info[v[0]]=v[1]
		e=s
	}
}

var names = []string{
	"FIRMWARE_NAME",
	"SOURCE_CODE_URL",
	"PROTOCOL_VERSION",
	"MACHINE_TYPE",
	"EXTRUDER_COUNT",
	"UUID",
}

func ParseHead(line string, info map[string]string){
	pois:=[]int{}
	for _, name := range names{
		poi:=strings.Index(line, name)
		pois= append(pois, poi)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(pois)))
	e:=len(line)
	for _,s:= range pois{
		line:=line[s:e]
		v:=strings.Split(line, ":")
		info[v[0]]=v[1]
		e=s
	}
}

Convert example

FIRMWARE_NAME:Marlin Ver 1.0.1 SOURCE_CODE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:Ender-3 V2 EXTRUDER_COUNT:1 UUID:cede2a2f-41a2-4748-9b12-c55c62f367ff
Cap:SERIAL_XON_XOFF:0
Cap:BINARY_FILE_TRANSFER:0
Cap:EEPROM:1
Cap:VOLUMETRIC:1
Cap:AUTOREPORT_TEMP:1
Cap:PROGRESS:0
Cap:PRINT_JOB:1
Cap:AUTOLEVEL:0
Cap:Z_PROBE:0
Cap:LEVELING_DATA:0
Cap:BUILD_PERCENT:0
Cap:SOFTWARE_POWER:0
Cap:TOGGLE_LIGHTS:0
Cap:CASE_LIGHT_BRIGHTNESS:0
Cap:EMERGENCY_PARSER:0
Cap:PROMPT_SUPPORT:0
Cap:AUTOREPORT_SD_STATUS:0
Cap:THERMAL_PROTECTION:1
Cap:MOTION_MODES:0
Cap:CHAMBER_TEMPERATURE:0
ok

to map

info = {map[string]string} 
 0 = UUID -> cede2a2f-41a2-4748-9b12-c55c62f367ff
 1 = SERIAL_XON_XOFF -> 0
 2 = AUTOREPORT_TEMP -> 1
 3 = PROGRESS -> 0
 4 = PRINT_JOB -> 1
 5 = TOGGLE_LIGHTS -> 0
 6 = THERMAL_PROTECTION -> 1
 7 = EXTRUDER_COUNT -> 1 
 8 = BINARY_FILE_TRANSFER -> 0
 9 = VOLUMETRIC -> 1
 10 = Z_PROBE -> 0
 11 = AUTOREPORT_SD_STATUS -> 0
 12 = MOTION_MODES -> 0
 13 = PROTOCOL_VERSION -> 1.0 
 14 = SOURCE_CODE_URL -> https
 15 = FIRMWARE_NAME -> Marlin Ver 1.0.1 
 16 = EEPROM -> 1
 17 = AUTOLEVEL -> 0
 18 = BUILD_PERCENT -> 0
 19 = EMERGENCY_PARSER -> 0
 20 = MACHINE_TYPE -> Ender-3 V2 
 21 = LEVELING_DATA -> 0
 22 = SOFTWARE_POWER -> 0
 23 = CASE_LIGHT_BRIGHTNESS -> 0
 24 = PROMPT_SUPPORT -> 0
 25 = CHAMBER_TEMPERATURE -> 0
@naueramant
Copy link
Owner

That looks awesome man 😄! We could also provide some methods on the map like GetUUID etc. for easier access of common fields.

I guess now would also be a good time to introduce some unit testing 😅

@naueramant naueramant added discussion enhancement New feature or request labels Aug 9, 2021
@alexsuslov
Copy link
Author

May me universal?

func ( Firmware FirmwareInformation )Get(name)(result string, ok bool){
  result, ok =  Firmware.info[name]
  return
}

@naueramant
Copy link
Owner

Maybe both? then i would be easy to access specific labels which are individuals to some printers and still easy to get stuff like GetFirmwareVersion().

What do you think @alexsuslov ?

@alexsuslov
Copy link
Author

Yes, I thought to make this method additionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants