Flummoxed by checksum BXOR operation

First time trying to talk to a BSS Audio device. For the record, I despise cryptic API's like this that require checksums. Seriously... WHY?!?

Anyway, here's my current code:
define_function char bsschecksum (char this_string[]) {
    stack_var char this_sum[1]
    stack_var char this_char[1]
    this_sum = "$00"
    call 'debug' ("'Checksum Start: ',this_string,' CHK:',this_sum")

    while ( length_string(this_string) > 0 )
    {
 this_char = left_string(this_string,1)

 call 'debug' ("'Checksum Current Char: ',this_char")

 remove_string(this_string,this_char,1)

 call 'debug' ("'Remaining String to Checksum: ',this_string")

 call 'debug' ("'The checksum process: ',this_sum,' BXOR ',this_char")

 this_sum =  this_sum BXOR this_char

 call 'debug' ("'Checksum PRocess Result: ',this_sum")

    }
    return this_sum;
}

The rest of the function seems to operate OK, but the BXOR function doesn't seem to work.

Here's what I'm getting:
Line     17 (14:43:05):: String To [33013:1:1]-[Checksum Start: $88X$A1$03$00$01$0E$01$00$00$00$00 CHK:$00]
Line     19 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $88]
Line     21 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: X$A1$03$00$01$0E$01$00$00$00$00]
Line     23 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $88]
Line     25 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     27 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: X]
Line     29 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $A1$03$00$01$0E$01$00$00$00$00]
Line     31 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR X]
Line     33 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     35 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $A1]
Line     37 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $03$00$01$0E$01$00$00$00$00]
Line     39 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $A1]
Line     41 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     43 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $03]
Line     45 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $00$01$0E$01$00$00$00$00]
Line     47 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $03]
Line     49 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     51 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $00]
Line     53 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $01$0E$01$00$00$00$00]
Line     55 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $00]
Line     57 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     59 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $01]
Line     61 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $0E$01$00$00$00$00]
Line     63 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $01]
Line     65 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     67 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $0E]
Line     69 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $01$00$00$00$00]
Line     71 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $0E]
Line     73 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     75 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $01]
Line     77 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $00$00$00$00]
Line     79 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $01]
Line     81 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     83 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $00]
Line     85 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $00$00$00]
Line     87 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $00]
Line     89 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     91 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $00]
Line     93 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $00$00]
Line     95 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $00]
Line     97 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line     99 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $00]
Line    101 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: $00]
Line    103 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $00]
Line    105 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]
Line    107 (14:43:05):: String To [33013:1:1]-[Checksum Current Char: $00]
Line    109 (14:43:05):: String To [33013:1:1]-[Remaining String to Checksum: ]
Line    111 (14:43:05):: String To [33013:1:1]-[The checksum process: $00 BXOR $00]
Line    113 (14:43:05):: String To [33013:1:1]-[Checksum PRocess Result: $00]


Like I said, it looks like the rest of the function is stepping through the characters correctly, but... I don't understand why I'm always just getting $00 as a result no matter what the BXOR operation is. Can someone please tell me what I'm doing wrong to get invalid results with a BXOR?

(NOTE: my debug call just sends to a virtual port which creates a duplicate entry, that's why my results are all odd numbered lines, I just cut out the duplicate lines)

Comments

  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
    FYI - I just wrote and released a module for control for this in the Mopedia. Doesn't answer your question. But, it might help get the gig done.
    E
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    Like I said, it looks like the rest of the function is stepping through the characters correctly, but... I don't understand why I'm always just getting $00 as a result no matter what the BXOR operation is. Can someone please tell me what I'm doing wrong to get invalid results with a BXOR?

    Clue #1

    When you compile your code, you should be getting a couple of these warnings:
    WARNING: C10571: Converting type [string] to [CHAR]  
    

    Clue #2

    When you run the code, you should be seeing these run-time errors every time thru the loop if you monitor Diagnostics:
    DoNumberExpression - Error 2  Tk=0x2012  Line=xx
    GetString - Error 1  Tk=0x0000
    CopyString (Reference) - Error 1  S=0x0000  D=0x1011
    RunCode - Address Mismatch 0x4050 0x000596 0x000598
    


    Netlinx and 1 character arrays do not always play nice.

    Try changing your function to this:
    define_function char bsschecksum (char this_string[]) {
    
        stack_var char this_sum
        stack_var char this_char
        this_sum = $00
        call 'debug' ("'Checksum Start: ',this_string,' CHK:',this_sum")
    
        while ( length_string(this_string) > 0 )
        {
          this_char = get_buffer_char(this_string)
    
          call 'debug' ("'Checksum Current Char: ',this_char")
    
          call 'debug' ("'Remaining String to Checksum: ',this_string")
    
          call 'debug' ("'The checksum process: ',this_sum,' BXOR ',this_char")
    
          this_sum =  this_sum BXOR this_char
    
          call 'debug' ("'Checksum PRocess Result: ',this_sum")
    
        }
        return this_sum;
    } 
    


    I don?t know if your checksum routine is correct and doing what it should but the BXOR is calculating correctly now:
    Line      2 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Start: $88X$A1$03$00$01$0E$01$00$00$00$00 CHK:$00]
    Line      4 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $88]
    Line      6 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: X$A1$03$00$01$0E$01$00$00$00$00]
    Line      8 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: $00 BXOR $88]
    Line     10 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: $88]
    Line     12 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: X]
    Line     14 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $A1$03$00$01$0E$01$00$00$00$00]
    Line     16 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: $88 BXOR X]
    Line     18 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: $D0]
    Line     20 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $A1]
    Line     22 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $03$00$01$0E$01$00$00$00$00]
    Line     24 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: $D0 BXOR $A1]
    Line     26 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: q]
    Line     28 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $03]
    Line     30 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $00$01$0E$01$00$00$00$00]
    Line     32 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: q BXOR $03]
    Line     34 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: r]
    Line     36 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $00]
    Line     38 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $01$0E$01$00$00$00$00]
    Line     40 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: r BXOR $00]
    Line     42 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: r]
    Line     44 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $01]
    Line     46 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $0E$01$00$00$00$00]
    Line     48 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: r BXOR $01]
    Line     50 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: s]
    Line     52 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $0E]
    Line     54 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $01$00$00$00$00]
    Line     56 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: s BXOR $0E]
    Line     58 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: }]
    Line     61 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $01]
    Line     63 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $00$00$00$00]
    Line     65 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: } BXOR $01]
    Line     67 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: |]
    Line     69 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $00]
    Line     71 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $00$00$00]
    Line     73 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: | BXOR $00]
    Line     75 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: |]
    Line     77 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $00]
    Line     79 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $00$00]
    Line     81 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: | BXOR $00]
    Line     83 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: |]
    Line     85 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $00]
    Line     87 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: $00]
    Line     89 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: | BXOR $00]
    Line     91 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: |]
    Line     93 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum Current Char: $00]
    Line     95 2017-07-10 (18:51:49):: String To [33001:1:10]-[Remaining String to Checksum: ]
    Line     97 2017-07-10 (18:51:49):: String To [33001:1:10]-[The checksum process: | BXOR $00]
    Line     99 2017-07-10 (18:51:49):: String To [33001:1:10]-[Checksum PRocess Result: |]/code]
    

    Hope this helps.
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    Thanks Joe! I do still get one "converting type [string] to [char]" warning with that code, supposedly on the while(length_string(this_string) > 0) line (but I've frequently seen the compiler indicate a line number a line or few down from the line where the real error is). I've always been a bit confused about that error, I always understood it as trying to stuff a 'more than one character' string into a single character variable. But I've seen it enough times, and the code still works OK anyway, to feel like it's often a meaningless compiler error.

    Unfortunately I'm not going to be able to test this code for a bit; the site I was working at has no internet connectivity yet, and not even any cell phone service. I've made an issue out of refusing to do any more work out there until I've got internet connectivity on site. That could be weeks.
  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
  • Joe HebertJoe Hebert Junior Member Posts: 2,154
    Thanks Joe! I do still get one "converting type [string] to [char]" warning with that code?
    Sure thing. Just for the record, the function I modified for you and posted does not generate any errors or warnings. I just double checked to be sure. Either you didn't copy the code exactly or you've got something else going on.

    Have fun.
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    ericmedley wrote: »
    Here's the link for you.
    I did download and look at this, but for the time being want to keep digging the hole I'm already in.

  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    Joe Hebert wrote: »
    Just for the record, the function I modified for you and posted does not generate any errors or warnings.

    Yep my mistake. I left the quotes around the $00 in the [this_sum = "$00"] line. Thanks!

  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
    give this a whirl
    
    define_function char[45] fn_BSS_Message_Checksum(char message[45]){
        stack_var char  MyBuff[45];
        stack_var integer sNew
        stack_var integer Checksum;
        MyBuff=message;
        Checksum=type_cast("MyBuff[1]")
        get_buffer_char(MyBuff)
        while(length_string(MyBuff)){
            sNew=type_cast("MyBuff[1]")
            Checksum=Checksum bxor sNew 
            get_buffer_char(MyBuff)
            } // while
        return "Checksum";
        } // def_fun
    
    
  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
    feddx wrote: »
    Ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha ha..... (wheezes coughs dies)


    You're not the only one who has had issues with this awful piece of gear. A couple years back Mr Medley and I shared a moment.

    The link posted through the forum's automation is poo.

    https://www.amxforums.com/forum/technical-forum/general-discussion/120583-losing-my-fricken-mind-bxor

    ha!
    Indeed,
    I (seriously) had a ban on them prior to AMX/Harman/Samsung buying them. If it showed up in a project I took a pass. It's not only the protocol that is nightmarish. (and don't even get me started on trying to troubleshoot on-site with this protocol) But, it is - in and of itself - flaky. The whole concept of 'Subscribe" to feedback from something doesn't work the way one would think. Just because you subscribe to something doesn't usually mean you'll get continuous feedback. You have to re-subscribe pretty much after every "Set" command you send. So, Subscribe really means more something like Get. (except for some things it's different - but mostly it's the same, except for certain times when it's completely different) The VoIP Dialer is also quirky. The two most strange things are the On/Off Hook feedback coming from the unit doesn't match reality quite often. Also, the Caller ID, for some reason, is considered the same kind of feedback as a volume level. when you subscribe to volume bar graph or Caller ID, you get reports of the status every 1 second, whether or not it has changed or not. To many of these status messages can bog traffic down pretty badly.

    Now, AMX sales engineers are spec-ing the thing in large systems and I have to play along. AMX does have it working somewhat well within RPM. The volume control is still really flaky. But, it's functional. However, the just released AMX Duet module for us mere programmers (June 2017) was definitely a half-baked cookie and was essentially non-functional. While it sorta worked, it had several key flaws that killed it. I've been working on a project using it and the whole mess got so bad that AMX has escalated it to software engineering. I'm supposed to have a fix today sometime, or at least early next week. If so, that will help.

    I've used the module I've written on 3 projects now and it seems pretty stable. I will say it is not what I'd call 'comprehensive' In other words, it doesn't do everything. It just does the basics of what I tend to do most. I have a true PASSTHRU and PASSBACK so I can send in raw commands when I need special things. (The AMX Duet modules PASSTHRU is stunningly bad. you should download it and look to se what I mean.)

    I had hoped AMX would address the protocol but it's pretty clear now they have no intention of doing so. Perhaps it's too much to re-tool it or whatever. It's not that the protocol is insurmountable. But, when you think that there's several competitors out there with similar (if not better) products that are very easy to program and impliment, that AMX might have bought into a white elephant. (imagine that...)

    I know my current client who's been having the problems that resulted in the AMX Escalation has sworn off the BSS altogether. They will finish out their current run of projects but have already started spec-ing Biamp. I wish I could say I felt bad about that. But, being on the receiving end of the whole BSS roll-out, I must admit I'm not.

  • MLaletasMLaletas Junior Member Posts: 224
    Ive used my module for BSS for a couple projects now and its works not too bad, granted it only accounts for some objects so any new projects that implement objects I havent dealt with yet means more testing :(

    Eric I thought last year you said they were going to do an overhaul on the protocol and make it more ascii based? Its all your fault!
  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
    MLaletas wrote: »
    Ive used my module for BSS for a couple projects now and its works not too bad, granted it only accounts for some objects so any new projects that implement objects I havent dealt with yet means more testing :(

    Eric I thought last year you said they were going to do an overhaul on the protocol and make it more ascii based? Its all your fault!

    Yeah - I haven't picked the winner of the world series in the past 5 years as well. I'm the 'Bad-Luck Schleprock" of AMX Programmers. I'm only reporting what they tell me. It was all just a pipe dream I guess.
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    Why did I not find that thread when I was searching the forums before I made this new subject post? <insert sad face here>
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    I might have hot network ports for this project next week. Before I jump back in, I's like to clarify something on the BSS protocol:

    The BSS documentation and samples provided clearly state you must do the checksum first, then escape the control characters.

    The discussion threads here indicate the escaping of control characters must happen first, before doing the checksum.

    Can one of you confirm for sure it's one way, or the other?
  • ericmedleyericmedley Senior Member - 3709 Posts Posts: 4,156
    I might have hot network ports for this project next week. Before I jump back in, I's like to clarify something on the BSS protocol:

    The BSS documentation and samples provided clearly state you must do the checksum first, then escape the control characters.

    The discussion threads here indicate the escaping of control characters must happen first, before doing the checksum.

    Can one of you confirm for sure it's one way, or the other?

    I'm doing checksum first, then replacing. Oh geez! Look at the time! It's 2017. Why the F are we doing F-ing checksums and hex?
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    Thanks for the clarification, sorry to push one of your buttons again ;-)
  • fogled@mizzou[email protected] h4x354x0r Posts: 549
    I finally got network connectivity at the site. I HAVE IT WORKING! Thanks everyone for your help; I ended up swiping feddx's fnBSSCommand function, took a few runs at the actual command codes, and now I'm up and running.
  • feddxfeddx Junior Member Posts: 140
    I finally got network connectivity at the site. I HAVE IT WORKING! Thanks everyone for your help; I ended up swiping feddx's fnBSSCommand function, took a few runs at the actual command codes, and now I'm up and running.

    Good. Every time a programmer masters communication with a BSS device, somewhere an ulcer is healed. That's the only reason I continue this.

    And it's not at all swiping if I offer it freely. I'm just glad it helped you. We all have to work to keep each other up and floating. Otherwise we are just dragging everyone down.

    I still hold on to a few trade secrets close to the vest though.

    Good luck and happy coding.
  • MLaletasMLaletas Junior Member Posts: 224
    Here's to us healing ulcers! Here here
Sign In or Register to comment.