fix: bug on steppir control
This commit is contained in:
@@ -50,10 +50,32 @@ func TestBuildSetDirectionAndCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A REAL status frame captured off an SDA controller (F4BPO's, 2026-07-15):
|
||||
// 40 41 00 4C C5 84 00 87 30 38 0D — 50.313 MHz, idle, bidirectional, interface
|
||||
// version "08". Using the actual device output (rather than hand-built bytes)
|
||||
// pins parseStatus to real hardware, and independently confirms the ÷10 wire
|
||||
// scale: 0x4CC584 × 10 = 50 313 000 Hz, a genuine 6 m frequency.
|
||||
func TestParseStatusRealFrame(t *testing.T) {
|
||||
frame := []byte{0x40, 0x41, 0x00, 0x4C, 0xC5, 0x84, 0x00, 0x87, 0x30, 0x38, 0x0D}
|
||||
st, err := parseStatus(frame)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st.Frequency != 50313 {
|
||||
t.Errorf("freq = %d kHz, want 50313 (50.313 MHz)", st.Frequency)
|
||||
}
|
||||
if st.Direction != DirBi { // 0x87 & 0xE0 = 0x80 = bidirectional
|
||||
t.Errorf("direction = %d, want %d (bidirectional)", st.Direction, DirBi)
|
||||
}
|
||||
if st.MotorsMoving != 0 {
|
||||
t.Errorf("moving = %d, want 0 (motors byte 0x00)", st.MotorsMoving)
|
||||
}
|
||||
}
|
||||
|
||||
// parseStatus decodes what the controller sends back — the inverse of buildSet's
|
||||
// frequency field, plus the direction nibble.
|
||||
// frequency field, plus the direction nibble and the motors-busy byte.
|
||||
func TestParseStatus(t *testing.T) {
|
||||
frame := []byte{0x00, 0x00, 0x00, 0x15, 0x79, 0xA8, 0x01, 0x40, '1', '2', 0x0D}
|
||||
frame := []byte{0x40, 0x41, 0x00, 0x15, 0x79, 0xA8, 0x01, 0x40, '0', '8', 0x0D}
|
||||
st, err := parseStatus(frame)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user