Campbell Scientific CSAT3B CSAT3B Three-Dimensional Sonic Anemometer - Page 59

unsigned short signature unsigned char* buf, int swath, unsigned short seed

Page 59 highlights

CSAT3B Three-Dimensional Sonic Anemometer NOTE The final data field in each record is the signature, a four character hexadecimal value that is a function of the specific sequence and number of bytes in the output array. The PC may calculate its own signature using each transmitted byte until reaching the signature data field. The computed signature and the transmitted signature are compared. If they match, the data were received correctly. This is very similar to a Cyclic-Redundancy-Check (CRC). Signature checking is done automatically by a datalogger when using SMD or CPI communications and does not require extra programming by the user. In most situations, a PC computes the signature by reading in the ASCII data and extracting the last four ASCII characters, casting them as Long data type. The signature is then calculated on the data sent from the CSAT3B, starting with ux and ending with the counter. All the characters after the counter are not part of the signature. Once the signature is computed using the algorithm below, it is compared to the transmitted signature. If signatures do not match, the data should be disregarded. The following block of code is an example implementation of Campbell Scientific's signature algorithm in the programming language C. To generate the signature of an output array of bytes, the "seed" needs to be initialized to 0xaaaa and a pointer passed to the first byte of the output array. The number of bytes in the output array should be entered in as the "swath". The returned value is the computed signature. // signature(), signature algorithm. // Standard signature is initialized with a seed of 0xaaaa. // Returns signature. unsigned short signature( unsigned char* buf, int swath, unsigned short seed ) { unsigned char msb, lsb; unsigned char b; int i; msb = seed >> 8; lsb = seed; for( i = 0; i < swath; i++ ) { b = (lsb

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

CSAT3B Three-Dimensional Sonic Anemometer
The final data field in each record is the signature, a four character
hexadecimal value that is a function of the specific sequence and number of
bytes in the output array.
The PC may calculate its own signature using each
transmitted byte until reaching the signature data field. The computed
signature and the transmitted signature are compared.
If they match, the data
were received correctly.
This is very similar to a Cyclic-Redundancy-Check
(CRC).
Signature checking is done automatically by a datalogger when
using SMD or CPI communications and does not require extra
programming by the user.
In most situations, a PC computes the signature by reading in the ASCII data
and extracting the last four ASCII characters, casting them as Long data type.
The signature is then calculated on the data sent from the CSAT3B, starting
with u
x
and ending with the counter.
All the characters after the counter are
not part of the signature.
Once the signature is computed using the algorithm
below, it is compared to the transmitted signature.
If signatures do not match,
the data should be disregarded.
The following block of code is an example implementation of Campbell
Scientific’s signature algorithm in the programming language C.
To generate
the signature of an output array of bytes, the “seed” needs to be initialized to
0xaaaa and a pointer passed to the first byte of the output array.
The number
of bytes in the output array should be entered in as the “swath”.
The returned
value is the computed signature.
// signature(), signature algorithm.
// Standard signature is initialized with a seed of 0xaaaa.
// Returns signature.
unsigned short signature( unsigned char* buf, int swath, unsigned short seed ) {
unsigned char msb, lsb;
unsigned char b;
int i;
msb = seed >> 8;
lsb = seed;
for( i = 0; i < swath; i++ ) {
b = (lsb << 1) + msb + *buf++;
if( lsb & 0x80 ) b++;
msb = lsb;
lsb = b;
}
return (unsigned short)((msb << 8) + lsb);
}
FIGURE 8-2 shows an example of unprompted output (RS-485 or USB) to a
PC.
A timestamp for the incoming data record may be assigned by the PC,
where the interval between records is 1/unprompted output rate.
The data in
each unprompted output record will be delayed according to the filter selected
(see TABLE 8-2).
Even after accounting for the sample delay, there may be a
synchronicity error between the PC and the CSAT3B since they each have
their own clocks.
TABLE 8-3 below shows the possible synchronicity errors
for each output rate.
NOTE
49