Home AMX User Forum NetLinx Studio

Changing parsed values from Hex to Dec

Hi there,

How to I change Hex values to true decimal for feedback?

I am parsing values from my av amp and they are being displayed as '0D' for 13, '1F' for
31 etc.

I want to display these as the standard decimal values and eventually use these values
for displaying volume feeback in percentage format.

Many thanks in advance.

Mike

Comments

  • HedbergHedberg Posts: 671
    try hextoi().
  • mkleynhansmkleynhans Posts: 78
    Thanks for the tip Harold,

    I have added the following code;

    DATA_EVENT [dvOnkyo]{
    string:
    {
    stack_var char cMsg[50]
    SELECT
    {
    ACTIVE (find_string (data.text,'!1MVL',1)):
    {
    cString = data.text
    cVolume = mid_string (cString,22,2)
    cVolumeActual = HEXTOI(cVolume);
    SEND_COMMAND dvtp, "'^TXT-100,0,',(cVolumeActual)"

    }
    }
    }
    }

    but this seems to be sending things like / for 47, . for 46, - for 45 etc. etc so its converting them
    to Chr on a Hex table and not Decimal..

    Back to the drawing board, or in my case trawling forums and begging for help =)
  • John GonzalesJohn Gonzales Posts: 609
    Take a look at the FORMAT command, it should do what you need.

    -John
  • HedbergHedberg Posts: 671
    mkleynhans wrote: »
    Thanks for the tip Harold,


    cString = data.text
    cVolume = mid_string (cString,22,2)
    cVolumeActual = HEXTOI(cVolume);
    SEND_COMMAND dvtp, "'^TXT-100,0,',(cVolumeActual)"

    I think it's working properly. You're starting off with an ascii representation of a hex, something like '2F'. The HEXTOI() function is converting that to an integer value (47) and storing it as cVolume Actual. Then, you are displaying the ASCII code associated with 47 on your touchpanel. What you need to do us present the ASCII representation of the 47 and you do that with the ITOA() function:

    SEND_COMMAND dvtp, "'^TXT-100,0,', ATOI(cVolumeActual)" Edit WRONG! should be: ITOA(cVolumeActual)

    To display an integer in human readable form, use ITOA() To perform an arithmetic calculation on an integer, just do it.

    as John says, check out the format() function. It presents a lot more control over what the resulting string looks like than does ITOA()
  • jjamesjjames Posts: 2,908
    HEXTOI() is exactly what's needed to convert Integra's / Onkyo's volume level to an integer.

    Try something like this - it should help you parse the remaining responses very easily.
    data_event [dvOnkyo]
    {
    	string:
    	{
    		stack_var char cMsg[50]
    		
    		// data.text = !1MVL0C
    		while(find_string(data.text,"$0a",1))
    		{
    			// Get this response only!
    			cMsg = remove_string(data.text,"$0a",1);
    			// cMsg = !1MVL0C
    			
    			// Remove junk
    			remove_string(cMsg,'!1',1);
    			// cMsg = MVL0C
    			
    			// Shorten response by 1, which remove carriage return
    			set_length_string(cMsg,length_string(cMsg)-1);
    			// cMsg = MVL0C
    			
    			// switch() on the response and remove the first 3 letters at the same time
    			switch(remove_string(cMsg,left_string(cMsg,3),1))
    			{
    				case 'MVL':
    				{
    					// send the converted text to the panel
    					// cMsg = 0C (left only with the value)
    					send_command dvtp, "'^TXT-100,0,',itoa(hextoi(cMsg))"
    				}
    				
    				case 'PWR':
    				{
    					// only need to parse cMsg
    				}
    				
    				case 'LMD':
    				{
    					// only need to parse cMsg
    				}
    			}
    		}
    	}
    }
    
  • John GonzalesJohn Gonzales Posts: 609
    Harold's explanation is really good. I would take note of JJames' post too. He shows a much better and more versatile way to extract the data from the response string rather than relying on cVolume = mid_string (cString,22,2).

    -John
  • mkleynhansmkleynhans Posts: 78
    Guys,

    Thanks so much for the help, I would never have got the ,itoa(hextoi( bit.
    It works like a thing of beauty =))

    I will keep reading the Netlinx Reference Guide and am looking forward to
    my L2. Hopefully then wont have to keep bugging you guys for answers.

    Next step for me is to get the level_event feeding back to the volume
    bargraph!!

    Thanks again,

    Mike
  • jjamesjjames Posts: 2,908
    Mike,

    How you send the level will matter on how the level is setup on your touch panel. By default, I believe the low value is zero and the high is 255. I prefer to set it to 0-100 while keeping track of my own variable. You'll soon find out that the response from the AVR, no matter it being serial or Ethernet, will be not be snappy. In fact, I believe you get a volume status change every half second, which depending on how quickly you send a volume up command could be anywhere between 2-3 volume steps up per half second. So, instead of your bargraph reading 51-52-53-54-55 as you volume up, if you depend on the feedback it will read something along the lines of 51-53-56, etc. and it will change slowly. To me this is unacceptable, especially if you have an actual bargraph, it will look too jittery.

    *Note - this is true for Integra devices, I know Onkyos they are the same exact piece, so YMMV.

    That all being said, I would store a volume variable and then send a direct volume command to the receiver. So instead of a MVLUP command, I'd use MVL2B, MVL2C, MVL2D, etc. etc. and update the bargraph based on my volume variable. You could rely on the volume feedback level for when the receiver powers up, but I usually set it to a specific turn on volume. This way, I always know where it's at.

    Just my 2-cents.
  • bobbob Posts: 296
    Hi guys, could somebody point me to the Onkyo/Integra module? I need to control an Onkyo PR-SC5509 (Integra DHC80.3). Thank you very much.
Sign In or Register to comment.