From: Jeff Waite on
I'm a newbie to TCL. When I add the command "package require cksum",
I get the error "can't find package cksum." Is there a file I should
add to the server? If so, do you know where I can download it?

I'm trying to get a network operations software package called Priisms
to display alarm messages on an LED marquee. The command to change
the text on the sign is a series of hex numbers with a 16-bit checksum
at the end.

Bryan Oakley wrote:
> You might need to add "package require cksum" to your code as well. It's
> unfortunate that you need to do "package require cksum" but the commands
> actually live in the crc namespace.
>
> Out of curiosity, what's the point of this exercise? Is it homework?

From: Uwe Klein on
Jeff Waite wrote:
> I'm a newbie to TCL. When I add the command "package require cksum",
> I get the error "can't find package cksum." Is there a file I should

you need the "crc16" package which is a part of tcllib
( there is also a crc32 and some other crc types )
as in :

package require crc16

assumed the chars to chksumm are in the variable "data"

the command to generate crc16 is

set chksum [ ::crc::crc16 $data ]

see my previous post

uwe
From: Jeff Waite on
I tried that but I get the error "can't find package crc16"

What is the procedure for adding the crc16 library to TCL?

Uwe Klein wrote:
> you need the "crc16" package which is a part of tcllib
> ( there is also a crc32 and some other crc types )
> as in :
>
> package require crc16
>
> assumed the chars to chksumm are in the variable "data"
>
> the command to generate crc16 is
>
> set chksum [ ::crc::crc16 $data ]
>
> see my previous post
>
> uwe

From: Jeff Waite on
Just FYI, I figured out how to add the package with some help from a
colleague. The command was:

source "d:/priisms/crc16.tcl"

Uwe Klein wrote:
> you need the "crc16" package which is a part of tcllib
> ( there is also a crc32 and some other crc types )
> as in :
>
> package require crc16
>
> assumed the chars to chksumm are in the variable "data"
>
> the command to generate crc16 is
>
> set chksum [ ::crc::crc16 $data ]
>
> see my previous post
>
> uwe

From: Jeff Waite on
I'm still having a problem with creating a 16-bit checksum. I've
tried using cksum, sum, and crc but they all produce values that are
significantly different than what I need. I suppose they may be
computing the checksum differently. Below is an example of how I need
to compute the checksum.

I suspect that I'm going to have to build my own algorithm. Does
anyone know which TCL commands I can use to do the following:

1. Sum a series of hex numbers
2. Perform a bit flip (binary complement)

FYI, I'm trying to create a checksum for a series of hex numbers. For
example:

Input:

\x00\x4d\x41\x49\x4e\x00\x00\x00\x00\x26\x00\x04\x05\x0f\x09\x01\x06\xef\xf2\x01\xf2\xf3\x01\xf3\x54\x65\x73\x74\x69\x6e\x67\x20\x31\x32\x33\xef

1. Sum up all the numbers

Sum = 0AB1

2. Convert to binary

0000 1010 1011 0001

3. Take the complement (bit flip)

1111 0101 0100 1110

4. Convert back to hex

F54E

5. Show low byte first and then high byte

4EF5

Checksum = 4EF5

Jeff Waite wrote:
> What is the best way to compute a 16-bit checksum in TCL? I've tried
> using the cksum() and crc::sum commands but I just receive the error
> "invalid command name."
>
> Here's my code:
>
> set data
> \x00\x4d\x41\x49\x4e\x00\x00\x00\x00\x26\x00\x04\x05\x0f\x09\x01\x06\xef\xf2\x01\xf2\xf3\x01\xf3\x54\x65\x73\x74\x69\x6e\x67\x20\x31\x32\x33\xef
> LogToScreen "Checksum: cksum"
> set cks [cksum($data)]
> LogToScreen $cks
> LogToScreen "Checksum: crc::sum"
> set crcsum [crc::sum -format 0x%X $data]
> LogToScreen $crcsum
>
> FYI, I'm trying to create a checksum for a series of hex numbers. For
> example:
>
> Input:
> \x00\x4d\x41\x49\x4e\x00\x00\x00\x00\x26\x00\x04\x05\x0f\x09\x01\x06\xef\xf2\x01\xf2\xf3\x01\xf3\x54\x65\x73\x74\x69\x6e\x67\x20\x31\x32\x33\xef
>
> 1. Sum up all the numbers
>
> Sum = 0AB1
>
> 2. Convert to binary
>
> 0000 1010 1011 0001
>
> 3. Take the complement
>
> 1111 0101 0100 1110
>
> 4. Convert back to hex
>
> F54E
>
> 5. Show low byte first and then high byte
>
> 4EF5
>
> Checksum = 4EF5