Home AMX User Forum AMX General Discussion

NAD delimeter Help

I am working on an NAD VISO FIVE and trying to parse the buffer and can not figure out the response termination.

I have this right now just for testing with the power commands
DEFINE_START
CREATE_BUFFER dvNADViso2, cBUFFER

DEFINE_EVENT
DATA_EVENT[dvNADViso2]
{
    ONLINE:
    {
	SEND_COMMAND dvNADViso2 , "'SET BAUD 9600,8,N,1'"
	
	CLEAR_BUFFER cBUFFER  
    }
    STRING:
    {
	cBUFFER = "cBUFFER, DATA.TEXT"
	SEND_STRING 0, "'cBuffer ', cBUFFER"
	WHILE (FIND_STRING (cBUFFER,"13",1))
	{
	    SEND_STRING 0, "'cBuffer in While', cBUFFER"
	    DISPMSG = REMOVE_STRING(cBUFFER,"13",1)
	    SEND_STRING 0, "'Response; ', DISPMSG"
	}
    }
}

I never get into the While Statement. I receive this in the diag window

Line 1 (22:31:05):: 2
Line 2 (22:31:05):: Command Sent; #1#21#21^A#2#212#13
Line 3 (22:31:10):: cBuffer #1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^@#2#211#1#205^D#2#178#1#20'^@#2#196#1#20(^B#2#193#1#20!^B#2#200#1#20#1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^
Line 4 (22:31:10):: cBuffer #1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^@#2#211#1#205^D#2#178#1#20'^@#2#196#1#20(^B#2#193#1#20!^B#2#200#1#20#1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^
Line 5 (22:31:12):: NO RESPONSE RECEIVED; #1#21#21^A#2#212#13 SENDING NEXT CMD
Line 6 (22:31:21):: 1
Line 7 (22:31:21):: Command Sent; #1#21#21^@#2#213#13
Line 8 (22:31:22):: cBuffer #1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^@#2#211#1#205^D#2#178#1#20'^@#2#196#1#20(^B#2#193#1#20!^B#2#200#1#20#1#20#20VISO FIVE#2L#1#20#21^A#2#213#1#20#23#241#2#227#1#20#24^
Line 9 (22:31:28):: NO RESPONSE RECEIVED; #1#21#21^@#2#213#13 SENDING NEXT CMD

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    I am working on an NAD VISO FIVE and trying to parse the buffer and can not figure out the response termination.
    Do you have the protocol document? The doc should explain the command and response format.
  • I do have it, it looks like the same document as the other NAD pieces as far as the protocol. There is only explaination really about the Checksum format besides pinout and baud rate
  • If I add the "13" to the buffer I get it to go through the loop, it looks like there is no terminator on the responses. Looking at the buffer I do not see a $0D or "13" unless I add it.
    Also this is screwing me up. I do power on I can filter that no problem, but power off I get the following

    Line 15 (10:25:16):: Response; $01$14$15^@$02$D6$01$14$15^@$02$D6$0D

    The ^@ is causing issues. $01 is the $14 means it is a response, $15 is Power, then it is suppose to be a value but I get ^@, which I can not decipher. This should be 94,64 decimal or 40,41 hex
  • Joe HebertJoe Hebert Posts: 2,159
    If I add the "13" to the buffer I get it to go through the loop, it looks like there is no terminator on the responses. Looking at the buffer I do not see a $0D or "13" unless I add it.
    I don?t see anything in the doc you posted that states there is supposed to be a $0D terminator. The commands and responses terminate with a checksum.
    it is suppose to be a value but I get ^@, which I can not decipher. This should be 94,64 decimal
    That?s what you are getting.

    ^ (ASCII) = 94 (decimal) = $5E (hex) and
    @ (ASCII) = 64 (decimal) = $40 (hex)

    You can look at it as ASCII, decimal, or hex. It?s all the same thing when you boil it down to 1s and 0s.
  • So the control charactor for the check sum is 2, I should be breaking on that, I really don't need the checksum.

    So I should be more like
    STRING:
        {
    	cBUFFER = "cBUFFER, DATA.TEXT"
    	SEND_STRING 0, "'cBuffer ', cBUFFER"
    	WHILE (FIND_STRING (cBUFFER,"2",1))
    	{
    	    SEND_STRING 0, "'cBuffer in While', cBUFFER"
    	    DISPMSG = REMOVE_STRING(cBUFFER,"2",1)
    
  • Ok here is the problem that I am having I receive the data and I can pull out the pieces that I need.
    I get
    #1#20#24^@#2

    1 = start of response
    20 = response command
    24 = Mute function
    ^ = "94"
    @ = "64"

    The 94 means the next item is encoded and I need to do a bitwise AND 191 with it. This is where I have the issue. I have this and it is not working.
    DISPMSG = ITOA("ATOI(cData) BAND 191")
    

    But I can do this fine, so it is how do I get the Dec value out of the CHR values,
     IF (cData = "64")
     {
    	cData = '0'
     }
    ELSE IF (cData = "65")
    {
    	cData = '1'
    }
    
  • TYPE_CAST is my friend. I am finding the forums to be much more helpful than the manual, just takes some time searching and reading through to find what I am looking for.
  • Ok I am having a problem with the getting the right volume levels I am receiving 255 for a volume level of -1, I know that the device is responding back with the data sent least significant bit first but I am not sure how to go ahead and get the correct value. Any hints. I have tried the TYPE_CAST function and I am not getting the correct values I for other responses such as video input I can decode the encoded data (TYPE_CAST and then BAND 191) but I am stuck on this which is not encoded.

    At this point DISPMSG is the data all checksums and other bits are removed, so the 94 says the next thing is encoded and needs to BAND 191.
    nData is an INTEGER
    If it is -15 I am getting 241 in the SEND_STRING
    
    IF (FIND_STRING(DISPMSG,"94",1))		//If Data is encoded
    {
    	cTRASH = REMOVE_STRING(DISPMSG, "94",1)
    	nData = TYPE_CAST(DISPMSG)
    	DISPMSG = ITOA(nData & 191)			// Decode Data
    }
    ELSE
    {
            nData = TYPE_CAST(DISPMSG)
    	DISPMSG = ITOA(nData)
    }
    SEND_STRING 0,"'Volume=',DISPMSG"
    
  • Joe HebertJoe Hebert Posts: 2,159
    nData is an INTEGER
    If it is -15 I am getting 241 in the SEND_STRING
    I?m not following the converting and TYPE_CASTing logic so I?m not much help there. If it?s working, then more power to you.

    By definition an INTEGER is unsigned so you won?t get negative numbers.
    SINTEGERs are signed.
    Negative numbers are represented by using the 2?s compliment and 241 is the 2?s compliment of -15 when using 8 bit logic.
  • So then
    DISPMSG = BNOT(nData) BAND $FF
    

    Should give me the right results.
  • Joe HebertJoe Hebert Posts: 2,159
    So then
    DISPMSG = BNOT(nData) BAND $FF
    

    Should give me the right results.
    BNOT = 1?s compliment.
    2?s compliment = 1?s compliment + 1
    Anything (8 bit) BAND $FF doesn?t do anything to Anything, it still equals Anything.
  • Thanks so it is this that I am looking for
    DISPMSG= ITOA(BNOT nData +1)
    

    Thanks for your help, I have a lot to learn and am waiting to go to training
  • Ok I really am not getting something here.
    I can get the appropriate values if the number is encoded but if it is not encoded I can not get the approriate value.
    Line 15 (17:40:47):: Device_ID=VISO FIVE
    Line 16 (17:40:47):: Power=1
    Line 17 (17:40:47):: VOLUME FULL; #213#1#20#23#241#2
    Line 18 (17:40:47):: VOLUME FULL; #241#2
    Line 19 (17:40:47):: VOLUME LENGHT 2
    Line 20 (17:40:47):: Volume Encoded Data; #241
    Line 21 (17:40:47):: Volume=-241
    Line 22 (17:40:47):: Mute=0
    Line 23 (17:40:47):: Input=0
    Line 24 (17:40:47):: Audio_Signal=1
    Line 25 (17:40:47):: Surround_Mode=1
    Line 26 (17:40:47):: Bass=2
    Line 27 (17:40:47):: Trebel=0
    Line 28 (17:40:47):: Tone_Defeat=0

    As you can see here I can get the Bass value but that was encoded and I did not have to do anything to it after the BAND 191. When it is not encoded such as a volume level of -15 as shown above I can not get that value. So here is what is happening in that section.
    IF (FIND_STRING(DISPMSG,"1,20,23",1))		//VOLUME
    {
    	SEND_STRING 0, "'VOLUME FULL; ',DISPMSG"
    	cCommand = REMOVE_STRING(DISPMSG, "1,20,23",1)	//Remove Command Info
    	SEND_STRING 0, "'VOLUME FULL; ',DISPMSG"
    	nLen = LENGTH_STRING(DISPMSG)
    	SEND_STRING 0, "'VOLUME LENGHT ',ITOA(nLen)"
    	DISPMSG = LEFT_STRING(DISPMSG, nlen - 1)
    	SEND_STRING 0,"'Volume Encoded Data; ',DISPMSG"
    	IF (FIND_STRING(DISPMSG,"94",1))		//If Data is encoded
    	{
    		    cTRASH = REMOVE_STRING(DISPMSG, "94",1)
    		    nData = ATOI(DISPMSG)
    		    DISPMSG = ITOA(nData & 191)			// Decode Data
    	}
    	ELSE
    	{
    		    nData = TYPE_CAST(DISPMSG)
    		    nData= TYPE_CAST((BNOT nData) +1)
    		    nData2 = TYPE_CAST(nData)
    		    DISPMSG = ITOA(nData2)
    	}
    	SEND_STRING 0,"'Volume=',DISPMSG"
    }
    
    I have tried with just ATOI and also the TYPE_CAST as you see there and I can not get it to work out.
  • jweatherjweather Posts: 320
    Look at the command set table to find out how to decode the volume values, or post the command set document here and I'll look at it. Many devices have lookup tables or other formulas to map volume levels between dB and RS-232 values. It may be that 241 = -15dB by whatever calculation they use.
  • It is being sent least significant bit first.

    So if I was going to set the level at -15 then I would send:

    1, 21, 23, 241, 2, 226

    which is start:
    start, command (21 is set), function (23 is volume, 241 is value, checksum flag, checksum
  • Joe HebertJoe Hebert Posts: 2,159
    I second the suggestion by jweather to look in the doc to see how volume is represented.

    If I had to shoot in the dark I would treat everything with the sign bit set (the most significant bit) as a negative value and go from there.
  • It does not say anything as for the way the responses are coming back, but when they are sent it is least significant bit first, and seeing that I am getting the same values in the data back then I am saying that they are coming back least sig bit first. That is where I am getting stuck. This is only my second system that I am programming and the first one was all text ASCII and I did not have to do any conversions. So I am trying to figure out how I go from lsb to the actual value.
  • Joe HebertJoe Hebert Posts: 2,159
    As I mentioned earlier, 241 is the 2?s compliment of -15 so the value you are getting looks correct.

    If you are getting a value back that is greater than 127 (which means the most significant bit [the sign bit] must be set) then you should treat that number as the 2?s compliment representation of a negative number. If the number is less than 128 then the sign bit must be 0 so the number is positive and can be left as is.
  • I know this would give me the two's compliment, but I am not sure how to reverse the two's compliment back to decimal.
    DISPMSG= ITOA(BNOT nData +1)
    
  • Joe HebertJoe Hebert Posts: 2,159
    There are a slew of web sites that explain 2?s compliment so give Google a try. Here is one link:

    http://academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm
Sign In or Register to comment.