line number extraction now works properly fixing command extraction

This commit is contained in:
specCon18 2025-03-26 15:17:05 -04:00
parent fd8a954100
commit eb29d1560a
2 changed files with 143269 additions and 14 deletions

52
main.go
View file

@ -34,25 +34,49 @@ func readFileLBL(file_path string) {
} }
} }
func removeLineNumber(input string) string { func extractCommand(line string) (string, string) {
// Define the regex pattern for the prefix 'N' followed by one or more digits and an optional space re := regexp.MustCompile(`^(.*?)\s?\*(.*)`)
re := regexp.MustCompile(`^N\d+\s?`)
// Replace the matched prefix with an empty string // Find matches
return re.ReplaceAllString(input, "") matchChecksum := re.FindStringSubmatch(line)
if len(matchChecksum) > 0 {
// Return the two segments as separate values
return matchChecksum[1], matchChecksum[2]
} else {
return "", "" // Return empty strings if no match
}
}
//TODO: P:0 convert to extractLineNumber returning like extractCommand does
func extractLineNumber(line string) (string, string) {
// Match line that starts with "N" followed by digits and an optional space
re := regexp.MustCompile(`^N(\d+)\s?(.*)`)
// Find matches
match := re.FindStringSubmatch(line)
if len(match) > 0 {
// Return the number and the remaining line as separate values
return match[1], match[2]
} else {
return "", "" // Return empty strings if no match
}
} }
func parseGcodeLine(line string){ func parseGcodeLine(line string){
//TODO: P:0 convert string to struct //TODO: P:0 convert string to struct
if strings.HasPrefix(line,"N"){ if strings.HasPrefix(line,"N"){
fmt.Println("--------------------") n,l := extractLineNumber(line)
fmt.Println("Line has line number") fmt.Println(n)
fmt.Println("--------------------") parseGcodeLine(l)
//l := removeLineNumber(line) //TODO: P:1 Write lookup table for G/M codes to get which params are required
//parseGcodeLine(l) } else if strings.HasPrefix(line, "G") || strings.HasPrefix(line,"M") {
} else if strings.HasPrefix(line, "G") { c,l := extractCommand(line)
fmt.Println("is a gcode") fmt.Println(c)
} else if strings.HasPrefix(line,"M"){ parseGcodeLine(l)
fmt.Println("is a mcode") } else if strings.HasPrefix(line,"*"){
fmt.Println("is a checksum")
} else if strings.HasPrefix(line,";"){ } else if strings.HasPrefix(line,";"){
fmt.Println("is a comment") fmt.Println("is a comment")
} }

143231
out Normal file

File diff suppressed because it is too large Load diff