rdChecksum.h File Reference

#include <stdint.h>

Go to the source code of this file.

Functions

uint32_t rdxsum_calc (const int32_t *ptr, char version)
void rdxsum_fill (int32_t *ptr, char version)
int32_t rdxsum_test (const int32_t *ptr)

Function Documentation

uint32_t rdxsum_calc ( const int32_t *  ptr,
char  version 
)

Definition at line 27 of file rdChecksum.c.

Referenced by append_dcs_alarm_block(), append_dcs_header_block(), append_dcs_monitor_block(), dump_one_record(), rdxsum_fill(), rdxsum_test(), and send_bogus_stuff().

00028 {
00029    uint32_t  sum   = 0;
00030    const int32_t    *begin = ptr + 2;      /* contiguous data starts here */
00031    const int32_t    *end   = ptr + (*ptr); /* this is one word too far    */
00032    int32_t           v2    = version & 0x3;
00033 
00034    /* protect against null pointers */
00035    if (!ptr) return 0;
00036 
00037    /* 
00038     * By reserving 2 bits at the top we can support 4 possible
00039     * checksum algorithms, in case we wish to switch at a later
00040     * time, while still retaining the ability to know which
00041     * algorithm was used.  Until all are implemented, cascade
00042     * downward until an existing one is found.
00043     */
00044    switch (v2) {
00045    case 0x3:
00046       v2 = 0x3;     /* tag with what we used, not requested     */
00047       /* break; */  /* this version not supported: fall through */
00048    case 0x2:
00049       v2 = 0x2;     /* tag with what we used, not requested     */
00050       /* break; */  /* this version not supported: fall through */
00051    case 0x1:
00052       v2 = 0x1 ;    /* tag with what we used, not requested     */
00053       /* --- add next algorithm here, make break "active"       */
00054       /* break; */  /* this version not supported: fall through */
00055    case 0x0:
00056    default:
00057       /* the "0" and default algorithm is very simple ...       */
00058       /* simply add up everything ignoring overflows            */
00059          
00060       v2 = 0x0;     /* tag with what we used, not requested     */
00061       sum = *ptr;   /* prime the pump with the word count       */
00062       while (begin<end) sum += *begin++;
00063    }
00064    /* remove top two bits and replace them with the version */
00065    return (sum & 0x3fffffff) | ( version << 30 );
00066 }

void rdxsum_fill ( int32_t *  ptr,
char  version 
)
int32_t rdxsum_test ( const int32_t *  ptr  ) 

Definition at line 105 of file rdChecksum.c.

References rdxsum_calc().

Referenced by dump_one_record(), and RawDataBlock::TestChecksum().

00106 {
00107    uint32_t stored;
00108    int32_t version; 
00109 
00110    /* protect against null pointers */
00111    if (!ptr) return 1;
00112 
00113    stored  = *(ptr+1);
00114    version = ( 0x3 & ( stored >> 30 ) );
00115    return stored != rdxsum_calc(ptr,version);
00116 }


Generated on 22 Nov 2017 for loon by  doxygen 1.6.1