corrected all bugs
This commit is contained in:
@@ -106,9 +106,12 @@ func (c *Client) pollLoop() {
|
||||
ticker := time.NewTicker(2 * time.Second) // Increased from 500ms to 2s
|
||||
defer ticker.Stop()
|
||||
|
||||
pollCount := 0
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
pollCount++
|
||||
|
||||
// Try to connect if not connected
|
||||
c.connMu.Lock()
|
||||
@@ -161,6 +164,10 @@ func (c *Client) pollLoop() {
|
||||
status.ProgressTotal = progress[0]
|
||||
status.ProgressCurrent = progress[1]
|
||||
}
|
||||
} else {
|
||||
// Motors stopped - reset progress
|
||||
status.ProgressTotal = 0
|
||||
status.ProgressCurrent = 0
|
||||
}
|
||||
|
||||
c.statusMu.Lock()
|
||||
@@ -388,69 +395,6 @@ func (c *Client) queryStatus() (*Status, error) {
|
||||
return status, nil
|
||||
}
|
||||
|
||||
// queryElementLengths queries element lengths (command 9)
|
||||
func (c *Client) queryElementLengths() ([]int, error) {
|
||||
reply, err := c.sendCommand(CMD_READ_BANDS, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Debug: log raw bytes
|
||||
log.Printf("Ultrabeam element lengths raw reply (%d bytes): %v", len(reply), reply)
|
||||
|
||||
// Try to extract 6 words - the protocol says 6 words (12 bytes)
|
||||
// But we're receiving 14 bytes, so there might be padding
|
||||
|
||||
if len(reply) < 12 {
|
||||
return nil, fmt.Errorf("element lengths reply too short: %d bytes", len(reply))
|
||||
}
|
||||
|
||||
lengths := make([]int, 6)
|
||||
|
||||
// Try different interpretations
|
||||
log.Printf("=== Attempting different parsings ===")
|
||||
|
||||
// Method 1: Standard little-endian from byte 0
|
||||
log.Printf("Method 1 (little-endian from 0):")
|
||||
for i := 0; i < 6 && i*2+1 < len(reply); i++ {
|
||||
lo := int(reply[i*2])
|
||||
hi := int(reply[i*2+1])
|
||||
val := lo | (hi << 8)
|
||||
log.Printf(" Element %d: bytes[%d,%d] = [%d,%d] => %d mm", i, i*2, i*2+1, lo, hi, val)
|
||||
}
|
||||
|
||||
// Method 2: Big-endian from byte 0
|
||||
log.Printf("Method 2 (big-endian from 0):")
|
||||
for i := 0; i < 6 && i*2+1 < len(reply); i++ {
|
||||
hi := int(reply[i*2])
|
||||
lo := int(reply[i*2+1])
|
||||
val := lo | (hi << 8)
|
||||
log.Printf(" Element %d: bytes[%d,%d] = [%d,%d] => %d mm", i, i*2, i*2+1, hi, lo, val)
|
||||
}
|
||||
|
||||
// Method 3: Skip first 2 bytes, then little-endian
|
||||
log.Printf("Method 3 (skip 2 bytes, little-endian):")
|
||||
for i := 0; i < 6 && i*2+3 < len(reply); i++ {
|
||||
lo := int(reply[i*2+2])
|
||||
hi := int(reply[i*2+3])
|
||||
val := lo | (hi << 8)
|
||||
log.Printf(" Element %d: bytes[%d,%d] = [%d,%d] => %d mm", i, i*2+2, i*2+3, lo, hi, val)
|
||||
}
|
||||
|
||||
// For now, use method 1 (original)
|
||||
for i := 0; i < 6; i++ {
|
||||
if i*2+1 >= len(reply) {
|
||||
break
|
||||
}
|
||||
lo := int(reply[i*2])
|
||||
hi := int(reply[i*2+1])
|
||||
lengths[i] = lo | (hi << 8)
|
||||
}
|
||||
|
||||
log.Printf("Final lengths: %v", lengths)
|
||||
return lengths, nil
|
||||
}
|
||||
|
||||
// queryProgress queries motor progress (command 10)
|
||||
func (c *Client) queryProgress() ([]int, error) {
|
||||
reply, err := c.sendCommand(CMD_PROGRESS, nil)
|
||||
|
||||
Reference in New Issue
Block a user