@@ -40,7 +40,7 @@ public byte[] Encode(IPacket packet)
4040 // 如果上一条指令发送的是REG.R/REG.BR, 保存上下文供回复查询结果使用
4141 if ( packet is IRegisterPacket registerPacket &&
4242 ( registerPacket . Operation == RegisterOperation . ReadRequest
43- || registerPacket . Operation == RegisterOperation . BitsReadResult ) )
43+ || registerPacket . Operation == RegisterOperation . BitsReadRequest ) )
4444 _lastRegisterRequest = registerPacket ;
4545
4646 return packet switch
@@ -96,7 +96,7 @@ public bool TryDecode(ref ReadOnlySequence<byte> buffer, out IPacket? packet)
9696 if ( _lastRegisterRequest . Operation == RegisterOperation . ReadRequest )
9797 packet = new RegisterPacket ( RegisterOperation . ReadResult , _lastRegisterRequest . Regfile , _lastRegisterRequest . Address , ( uint ) hexValue ) ;
9898 else if ( _lastRegisterRequest . Operation == RegisterOperation . BitsReadRequest )
99- packet = new RegisterPacket ( RegisterOperation . BitsReadResult , _lastRegisterRequest . Regfile , _lastRegisterRequest . Address , ( uint ) hexValue ) ;
99+ packet = new RegisterPacket ( RegisterOperation . BitsReadResult , _lastRegisterRequest . Regfile , _lastRegisterRequest . Address , _lastRegisterRequest . StartBit , _lastRegisterRequest . EndBit , ( uint ) hexValue ) ;
100100 else
101101 throw new NotImplementedException ( "unknown register request & result when decoding." ) ;
102102 _lastRegisterRequest = null ;
@@ -124,30 +124,35 @@ public static byte[] EncodeRegister(CarrotAsciiProtocolConfiguration config, IRe
124124 string wrapper_first = config . CommandWrapper == CommandWrapper . Func ? "(" : ";" ;
125125 string wrapper_mid = config . CommandWrapper == CommandWrapper . Func ? "," : ";" ;
126126 string wrapper_last = config . CommandWrapper == CommandWrapper . Func ? ");" : ";" ;
127+ string terminal = "\r \n " ;
127128 string cmd = packet . Operation switch
128129 {
129130 RegisterOperation . Write =>
130131 /* REG.W(ADDR,VAL); */
131132 $ "{ rfCmds . WriteRegCommand } { wrapper_first } " +
132133 $ "{ packet . Address : X} { wrapper_mid } " +
133- $ "{ packet . Value : X} { wrapper_last } ",
134+ $ "{ packet . Value : X} { wrapper_last } " +
135+ terminal ,
134136 RegisterOperation . ReadRequest =>
135137 /* REG.R(ADDR); */
136138 $ "{ rfCmds . ReadRegCommand } { wrapper_first } " +
137- $ "{ packet . Address : X} { wrapper_last } ",
139+ $ "{ packet . Address : X} { wrapper_last } " +
140+ terminal ,
138141 RegisterOperation . BitsWrite =>
139142 /* REG.BW(ADDR,START,END,VAL); */
140143 $ "{ rfCmds . WriteBitsCommand } { wrapper_first } " +
141144 $ "{ packet . Address : X} { wrapper_mid } " +
142145 $ "{ packet . StartBit } { wrapper_mid } " +
143146 $ "{ packet . EndBit } { wrapper_mid } " +
144- $ "{ packet . Value : X} { wrapper_last } ",
147+ $ "{ packet . Value : X} { wrapper_last } " +
148+ terminal ,
145149 RegisterOperation . BitsReadRequest =>
146150 /* REG.BR(ADDR,START,END); */
147151 $ "{ rfCmds . ReadBitsCommand } { wrapper_first } " +
148152 $ "{ packet . Address : X} { wrapper_mid } " +
149153 $ "{ packet . StartBit } { wrapper_mid } " +
150- $ "{ packet . EndBit } { wrapper_last } ",
154+ $ "{ packet . EndBit } { wrapper_last } " +
155+ terminal ,
151156 _ => throw new NotImplementedException ( ) ,
152157 } ;
153158
0 commit comments