Dynalite Checksum Formula
John Paul
Junior Member
I have a Dynalite device for which the commands require a checksum and i wanted to write a function call which will do the checksum calculation for me. I know there are modules available but i wanted to add a simple include file instead. Here is the function i have written, which is incomplete.
DEFINE_FUNCTION INTEGER CKS(INTEGER P1,INTEGER P2,INTEGER P3,INTEGER P4,INTEGER P5,INTEGER P6,INTEGER P7)
{
LOCAL_VAR INTEGER nCheckSum
nCheckSum = !(P1+P2+P3+P4+P5+P6+P7) +1
RETURN nCheckSum
}
Here is the formula for the checksum.
1) In Windows, Start / Programs / Accessories / Calculator
2) In Calculator, under View, Select Scientific
3) In Calculator, select Hex
4) Add the first 7 Hex bytes, then press = (ie: 1C + 01 + 20 + 00 + 00 + 00 + FF total = 13C)
5) Press the <Not> button (in our example, the total = FFFFFEC3)
6) Add 1 to the total (in our example, the total = FFFFFEC4)
7) The checksum is the two least significant characters (in our example, checksum = C4)
DEFINE_FUNCTION INTEGER CKS(INTEGER P1,INTEGER P2,INTEGER P3,INTEGER P4,INTEGER P5,INTEGER P6,INTEGER P7)
{
LOCAL_VAR INTEGER nCheckSum
nCheckSum = !(P1+P2+P3+P4+P5+P6+P7) +1
RETURN nCheckSum
}
Here is the formula for the checksum.
1) In Windows, Start / Programs / Accessories / Calculator
2) In Calculator, under View, Select Scientific
3) In Calculator, select Hex
4) Add the first 7 Hex bytes, then press = (ie: 1C + 01 + 20 + 00 + 00 + 00 + FF total = 13C)
5) Press the <Not> button (in our example, the total = FFFFFEC3)
6) Add 1 to the total (in our example, the total = FFFFFEC4)
7) The checksum is the two least significant characters (in our example, checksum = C4)
Comments
-
I have a Dynalite device for which the commands require a checksum and i wanted to write a function call which will do the checksum calculation for me. I know there are modules available but i wanted to add a simple include file instead. Here is the function i have written, which is incomplete.
DEFINE_FUNCTION INTEGER CKS(INTEGER P1,INTEGER P2,INTEGER P3,INTEGER P4,INTEGER P5,INTEGER P6,INTEGER P7)
{
LOCAL_VAR INTEGER nCheckSum
nCheckSum = !(P1+P2+P3+P4+P5+P6+P7) +1
RETURN nCheckSum
}
Here is the formula for the checksum.
1) In Windows, Start / Programs / Accessories / Calculator
2) In Calculator, under View, Select Scientific
3) In Calculator, select Hex
4) Add the first 7 Hex bytes, then press = (ie: 1C + 01 + 20 + 00 + 00 + 00 + FF total = 13C)
5) Press the <Not> button (in our example, the total = FFFFFEC3)
6) Add 1 to the total (in our example, the total = FFFFFEC4)
7) The checksum is the two least significant characters (in our example, checksum = C4)
John, try the below code:
DEFINE_VARIABLE
volatile CONTROL_MESSAGE[8]
DEFINE_CALL 'CheckSum Calculator' (CHAR BYTE_1,CHAR BYTE_2,CHAR BYTE_3,CHAR BYTE_4,CHAR,BYTE_5,CHAR BYTE_6,CHAR BYTE_7)
LOCAL_VAR
CHAR COUNT
CHAR TOTAL
CHAR CHECKSUM
{
CONTROL_MESSAGE[1] = BYTE_1
CONTROL_MESSAGE[2] = BYTE_2
CONTROL_MESSAGE[3] = BYTE_3
CONTROL_MESSAGE[4] = BYTE_4
CONTROL_MESSAGE[5] = BYTE_5
CONTROL_MESSAGE[6] = BYTE_6
CONTROL_MESSAGE[7] = BYTE_7
COUNT = 1
TOTAL = 0
WHILE (COUNT <8)
{
TOTAL = TOTAL+CONTROL_MESSAGE[COUNT]
COUNT = COUNT+1
}
CHECKSUM = (TOTAL * $FF) BAND $FF
CONTROL_MESSAGE[8] = CHECKSUM
SET_LENGTH_STRING(CONTROL_MESSAGE,8)
}
George -
The 'NOT' function in Netlinx is BNOT,
! Is a comparison. BNOT is a calculation. -
I needed this calculation a couple of weeks ago so here's the function I came up with and a snippet of code that uses it.
DEFINE_FUNCTION CHAR fn2CompChkSum(INTEGER iStartByte,INTEGER iEndByte,CHAR iStr[]) { STACK_VAR INTEGER i; STACK_VAR CHAR cChkSum; if(!iStartByte) iStartByte = 1; if(!iEndByte) iEndByte = LENGTH_STRING(iStr); for(i = iStartByte ; i <= iEndByte ; i++) { cChkSum = cChkSum + iStr[i]; } cChkSum = ((BNOT cChkSum)+1);// & $FF);// & FF not needed since return is a single char //fnDev_DeBug("'2CompChkSum-[ ',cChkSum,' ] :DEBUG<',ITOA(__LINE__),'>'"); RETURN cChkSum; } DEFINE_FUNCTION CHAR fnTV_ProcessQ() { STACK_VAR INTEGER nFBS; nFBS = find_string(cTV_TxQueue,"TV_QUEUE_DELIM",1); if(nFBS) { STACK_VAR CHAR cQcmd[6]; cQcmd = "SAM_CMD_PREFIX,GET_BUFFER_STRING(cTV_TxQueue,nFBS-1)"; REMOVE_STRING(cTV_TxQueue,"TV_QUEUE_DELIM",1); cTV_LastCmd = "cQcmd,fn2CompChkSum(0,0,cQcmd)"; SEND_STRING dvTV,cTV_LastCmd;
The function allows you to pass it the start byte and end byte of the string to calculate or pass the function 0,0, and it will start at 1 and use the length of the string passed as the byte count. -
You really should just use the AMX module as it is really good and quick to implement.
-
Thanks a lot for all the inputs.
-
where can i get the checksum module?You really should just use the AMX module as it is really good and quick to implement. -
I think champ was referring to the Dynalite module not a checksum module since there is no checksum module that I am aware of. If you need a checksum function you might try posting your devices checksum requirements and maybe someone will help. This is now a ghost town of a forum so good luck with that.where can i get the checksum module?
Leave a Comment
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums
