The data I saw in the print is correct, but the values sent out through the send level are problemat
I am sending a send level to the central control host through Duet, but there is a problem. Could you please take a look at where the problem is!
thank you very much!
Line 29 2024-11-04 (14:37:20):: fbValue:-70
Line 30 2024-11-04 (14:37:20):: fnSendLevelFeedback:-70
public static void fnSendLevelFeedback(int number,int value,Module onBehalfOf)
{
System.out.println("fnSendLevelFeedback:"+value);
fnSendLevelFeedback(number,value,1,onBehalfOf);
}
public static void fnSendLevelFeedback(int number,int value, int port,Module onBehalfOf)
{// TODO Change the TSE for your own needs
AdvancedEvent advEv = new AdvancedEvent(new Boolean(false),ChinaDspAdvancedEvent.MISC);
Level level = new Level(Level.L_SINTEGER,value);
System.out.println("level:"+level.shortValue());
//level.setVal(level);
Event ev = new Event();
ev.type = Event.E_LEVEL;
ev.idx = number;
ev.dataType = Event.D_LEVEL;
ev.dataValue = level;
ModuleComponentEvent e = new ModuleComponentEvent(onBehalfOf, advEv, ev, port);
onBehalfOf.processAdvancedEvent(e);
}
Line 18 2024-11-04 (14:43:14):: Level Value From [41001:1:1] - Level 8 Value= 186
sbRxMsg.append(paramArrayOfbyte,0,paramInt);
if(sbRxMsg.length()==12) {
int SliderId;
int fbValue;
SliderId= (sbRxMsg.byteAt(8)+1);
System.out.println("SliderId:"+SliderId);
fbValue= (Bits.getShort(new byte[] {sbRxMsg.byteAt(11),sbRxMsg.byteAt(10)},0)/100);
System.out.println("fbValue:"+fbValue);
TalkToNX.fnSendLevelFeedback(SliderId,fbValue,this);
0
Comments
I'm not into Duet and Java programming, but maybe this is a range issue, in conjunction with snapi.
Maybe the "real" value -70 get scaled to the standard level range 0..255. What is the range of the "real" value?
0 to -72
I think it's an interpretation mismatch. 186 is the decimal of the 2's signed complement of -70.
Binary: 10111010
Decimal: 186
2's signed complement is a typical way to represent a signed value as an unsigned.
The MSB (bit 7) represents the sign. MSB=1 represents "signed", MSB=0 represents "unsigned"
Calculation is pretty simple: add the negative value to the base, to get it's 2's complement
256 +(-72) = 184
or simpler: use the signed value without the sign
256 - 72 = 184
256 - 70 = 186
256 - 36 = 220
256 - 1 = 255
If the signed value will be 0 or in positive range, it is taken like it is, but could not be higher than 127.
Maybe not explained best, but...
https://www.rapidtables.com/convert/number/binary-to-decimal.html?x=10111010
https://en.wikipedia.org/wiki/Two's_complement
So for passing it out to the Duet device as a signed value, it maybe "somehow has to be marked as signed for the level". But at that point I'm out
I understand what you mean, but I'm not sure if ev.dataValue=level; How to convert this position