Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue May 03 02:01:35 2016 +0000
Revision:
116:8099b754fbb4
Parent:
114:554fa3a956b4
Child:
119:b3d7699d0eb0
One program for all stns via UID/MAC lookup table or generation. Status sends number trg/evt and livetime, not rates. Add 512 sample evt and RFFT-LUTs. Add L1Scaledown trg bit. Allow skip SST reset at start. Fix dt at end of seq. End of comm signal.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 21:ce51bb0ba4a5 1 #include "SnEventFrame.h"
uci1 21:ce51bb0ba4a5 2
uci1 21:ce51bb0ba4a5 3 #include "SnCRCUtils.h"
uci1 21:ce51bb0ba4a5 4
uci1 21:ce51bb0ba4a5 5 //#define DEBUG
uci1 21:ce51bb0ba4a5 6
uci1 56:0bba0ef15697 7 #if CHIPBOARD==ATWD4CH
uci1 21:ce51bb0ba4a5 8 const uint8_t SnEventFrame::kIOVers = 1; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 114:554fa3a956b4 9 #elif CHIPBOARD==SST4CH
uci1 56:0bba0ef15697 10 const uint8_t SnEventFrame::kIOVers = 2; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 114:554fa3a956b4 11 #elif CHIPBOARD==SST4CH_1GHz
uci1 114:554fa3a956b4 12 const uint8_t SnEventFrame::kIOVers = 3; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 116:8099b754fbb4 13 #elif CHIPBOARD==SST4CH512
uci1 116:8099b754fbb4 14 const uint8_t SnEventFrame::kIOVers = 4; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 116:8099b754fbb4 15 #elif CHIPBOARD==SST4CH512_1GHz
uci1 116:8099b754fbb4 16 const uint8_t SnEventFrame::kIOVers = 5; // MUST BE INCREASED if any member var changes (==> also if kNchans, etc. change!)
uci1 114:554fa3a956b4 17 #else
uci1 114:554fa3a956b4 18 #error CHIPBOARD value not accounted for in event frame i/o version.
uci1 56:0bba0ef15697 19 #endif
uci1 21:ce51bb0ba4a5 20
uci1 21:ce51bb0ba4a5 21 const char* SnEventFrame::ReadFrom(const char* const buf,
uci1 21:ce51bb0ba4a5 22 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 23 const uint16_t wvBaseline) {
uci1 21:ce51bb0ba4a5 24 // no check on the length of buf is done here
uci1 21:ce51bb0ba4a5 25 // that should be been done already
uci1 21:ce51bb0ba4a5 26 //
uci1 21:ce51bb0ba4a5 27 // must match ::WriteToBuf
uci1 21:ce51bb0ba4a5 28
uci1 21:ce51bb0ba4a5 29 // NOTE: on the mbed, this is reduntant (char is unsigned)
uci1 21:ce51bb0ba4a5 30 // but this way, the block can be copied to other computers
uci1 21:ce51bb0ba4a5 31 // and still work.
uci1 21:ce51bb0ba4a5 32 union Usub {
uci1 21:ce51bb0ba4a5 33 const char* s;
uci1 21:ce51bb0ba4a5 34 const uint8_t* u;
uci1 21:ce51bb0ba4a5 35 } b;
uci1 21:ce51bb0ba4a5 36 b.s = buf;
uci1 56:0bba0ef15697 37
uci1 21:ce51bb0ba4a5 38 uint8_t Rv=0;
uci1 21:ce51bb0ba4a5 39 b.s = SnBitUtils::ReadFrom(b.s, Rv); // i/o version
uci1 21:ce51bb0ba4a5 40 if (Rv>0) {
uci1 56:0bba0ef15697 41
uci1 56:0bba0ef15697 42 const uint16_t nsamps = GetTotSamplesForIOVers(Rv);
uci1 56:0bba0ef15697 43
uci1 21:ce51bb0ba4a5 44 b.s = SnBitUtils::ReadFrom(b.s, fMbedTime);
uci1 21:ce51bb0ba4a5 45 b.s = SnBitUtils::ReadFrom(b.s, fEvtNum);
uci1 21:ce51bb0ba4a5 46 b.s = SnBitUtils::ReadFrom(b.s, fDTms);
uci1 21:ce51bb0ba4a5 47 b.s = SnBitUtils::ReadFrom(b.s, fTrgNum);
uci1 21:ce51bb0ba4a5 48 b.s = SnBitUtils::ReadFrom(b.s, fTrgBits);
uci1 56:0bba0ef15697 49 b.u = UnpackWavef(b.u, fData, loseLSB, loseMSB, wvBaseline, nsamps);
uci1 21:ce51bb0ba4a5 50 b.s = SnBitUtils::ReadFrom(b.s, fCRC);
uci1 56:0bba0ef15697 51
uci1 56:0bba0ef15697 52 #if CHIPBOARD!=ATWD4CH
uci1 116:8099b754fbb4 53 const uint16_t nstopBytes = GetStopBytesForIOVersBufferSafe(Rv);
uci1 56:0bba0ef15697 54 if (Rv>1) {
uci1 56:0bba0ef15697 55 b.s = SnBitUtils::ReadFrom(b.s, fStop, nstopBytes);
uci1 56:0bba0ef15697 56 }
uci1 56:0bba0ef15697 57 #endif
uci1 21:ce51bb0ba4a5 58 }
uci1 21:ce51bb0ba4a5 59
uci1 21:ce51bb0ba4a5 60 return b.s;
uci1 21:ce51bb0ba4a5 61 }
uci1 21:ce51bb0ba4a5 62
uci1 21:ce51bb0ba4a5 63 char* SnEventFrame::WriteTo(char* const buf,
uci1 21:ce51bb0ba4a5 64 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 65 const uint16_t wvBaseline) const {
uci1 21:ce51bb0ba4a5 66 // no check on the length of the buf is done here
uci1 21:ce51bb0ba4a5 67 // that should be done already
uci1 21:ce51bb0ba4a5 68 //
uci1 21:ce51bb0ba4a5 69 // must match ReadFromBuf
uci1 21:ce51bb0ba4a5 70
uci1 21:ce51bb0ba4a5 71 // NOTE: on the mbed, this is reduntant (char is unsigned)
uci1 21:ce51bb0ba4a5 72 // but this way, the block can be copied to other computers
uci1 21:ce51bb0ba4a5 73 // and still work.
uci1 21:ce51bb0ba4a5 74 union {
uci1 21:ce51bb0ba4a5 75 char* s;
uci1 21:ce51bb0ba4a5 76 uint8_t* u;
uci1 21:ce51bb0ba4a5 77 } b;
uci1 21:ce51bb0ba4a5 78 b.s = buf;
uci1 21:ce51bb0ba4a5 79
uci1 21:ce51bb0ba4a5 80 b.s = SnBitUtils::WriteTo(b.s, kIOVers); // i/o version
uci1 21:ce51bb0ba4a5 81
uci1 56:0bba0ef15697 82 const uint16_t nsamps = GetTotSamplesForIOVers(kIOVers);
uci1 56:0bba0ef15697 83
uci1 21:ce51bb0ba4a5 84 b.s = SnBitUtils::WriteTo(b.s, fMbedTime);
uci1 21:ce51bb0ba4a5 85 b.s = SnBitUtils::WriteTo(b.s, fEvtNum);
uci1 21:ce51bb0ba4a5 86 b.s = SnBitUtils::WriteTo(b.s, fDTms);
uci1 21:ce51bb0ba4a5 87 b.s = SnBitUtils::WriteTo(b.s, fTrgNum);
uci1 21:ce51bb0ba4a5 88 b.s = SnBitUtils::WriteTo(b.s, fTrgBits);
uci1 56:0bba0ef15697 89 b.u = PackWavef(b.u, fData, loseLSB, loseMSB, wvBaseline, nsamps);
uci1 21:ce51bb0ba4a5 90 b.s = SnBitUtils::WriteTo(b.s, fCRC);
uci1 21:ce51bb0ba4a5 91
uci1 56:0bba0ef15697 92 #if CHIPBOARD!=ATWD4CH
uci1 116:8099b754fbb4 93 const uint16_t nstopBytes = GetStopBytesForIOVersBufferSafe(kIOVers);
uci1 56:0bba0ef15697 94 if (kIOVers>1) {
uci1 56:0bba0ef15697 95 // we test kIOVers rather than the CHIPBOARD #define in order
uci1 56:0bba0ef15697 96 // to ensure that the i/o version is the ONLY variable that determines
uci1 56:0bba0ef15697 97 // what the event looks like in a file or communication.
uci1 56:0bba0ef15697 98 // this is the only way to ensure readability going forward.
uci1 116:8099b754fbb4 99 #ifdef DEBUG
uci1 116:8099b754fbb4 100 printf("kNstopBytes=%hu, nstopBytes=%hu, kIOVers=%hhu\r\n",
uci1 116:8099b754fbb4 101 kNstopBytes, nstopBytes, kIOVers);
uci1 116:8099b754fbb4 102 char* x = b.s;
uci1 116:8099b754fbb4 103 #endif
uci1 56:0bba0ef15697 104 b.s = SnBitUtils::WriteTo(b.s, fStop, nstopBytes);
uci1 116:8099b754fbb4 105 #ifdef DEBUG
uci1 116:8099b754fbb4 106 printf("wrote %d stop bytes\r\n", b.s - x);
uci1 116:8099b754fbb4 107 #endif
uci1 56:0bba0ef15697 108 }
uci1 56:0bba0ef15697 109 #endif
uci1 56:0bba0ef15697 110
uci1 21:ce51bb0ba4a5 111 #ifdef DEBUG
uci1 21:ce51bb0ba4a5 112 printf("SnEventFrame::WriteTo:\r\n");
uci1 21:ce51bb0ba4a5 113 for (uint32_t i=0; i<b.s-buf; i++) {
uci1 21:ce51bb0ba4a5 114 printf("%02X ",buf[i]);
uci1 21:ce51bb0ba4a5 115 }
uci1 21:ce51bb0ba4a5 116 printf("\r\n");
uci1 21:ce51bb0ba4a5 117 #endif
uci1 21:ce51bb0ba4a5 118
uci1 21:ce51bb0ba4a5 119 return b.s;
uci1 21:ce51bb0ba4a5 120 }
uci1 21:ce51bb0ba4a5 121
uci1 21:ce51bb0ba4a5 122 void SnEventFrame::CalcCRC() {
uci1 21:ce51bb0ba4a5 123 // CRC made using union on a little endian (mbed) processor
uci1 42:ac162d15e578 124 fCRC = SnCRCUtils::GetCRC32for(fData, kTotSamps);
uci1 56:0bba0ef15697 125 #if CHIPBOARD!=ATWD4CH
uci1 56:0bba0ef15697 126 fCRC = SnCRCUtils::GetUpdatedCRC32for(fCRC, fStop, kNstopBytes);
uci1 56:0bba0ef15697 127 #endif
uci1 42:ac162d15e578 128 #ifdef DEBUG
uci1 42:ac162d15e578 129 printf("SnEventFrame::CalcCRC crc=%u\r\n",fCRC);
uci1 42:ac162d15e578 130 #endif
uci1 21:ce51bb0ba4a5 131 }
uci1 21:ce51bb0ba4a5 132
uci1 21:ce51bb0ba4a5 133 bool SnEventFrame::ReadFromFileToBuf(FILE* f,
uci1 21:ce51bb0ba4a5 134 char* const evtBuf,
uci1 21:ce51bb0ba4a5 135 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 136 const uint8_t loseMSB) {
uci1 21:ce51bb0ba4a5 137 // file position expected to be at this event frame already
uci1 21:ce51bb0ba4a5 138 bool ret = false;
uci1 21:ce51bb0ba4a5 139 if (f!=0) {
uci1 25:57b2627fe756 140 if (fread(evtBuf, SizeOf(kIOVers, loseLSB, loseMSB), 1u, f)!=0) {
uci1 21:ce51bb0ba4a5 141 ret = true;
uci1 21:ce51bb0ba4a5 142 }
uci1 21:ce51bb0ba4a5 143 }
uci1 21:ce51bb0ba4a5 144 return ret;
uci1 21:ce51bb0ba4a5 145 }
uci1 21:ce51bb0ba4a5 146
uci1 21:ce51bb0ba4a5 147 bool SnEventFrame::ReadFrom(FILE* f,
uci1 21:ce51bb0ba4a5 148 char* const evtBuf,
uci1 21:ce51bb0ba4a5 149 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 150 const uint16_t wvBaseline) {
uci1 21:ce51bb0ba4a5 151 // file position expected to be at this event frame already
uci1 21:ce51bb0ba4a5 152 const bool ret = ReadFromFileToBuf(f, evtBuf, loseLSB, loseMSB);
uci1 21:ce51bb0ba4a5 153 if (ret) {
uci1 21:ce51bb0ba4a5 154 ReadFrom(evtBuf, loseLSB, loseMSB, wvBaseline);
uci1 21:ce51bb0ba4a5 155 }
uci1 21:ce51bb0ba4a5 156 return ret;
uci1 21:ce51bb0ba4a5 157 }
uci1 21:ce51bb0ba4a5 158
uci1 21:ce51bb0ba4a5 159 bool SnEventFrame::WriteTo(FILE* f, char* const evtBuf,
uci1 21:ce51bb0ba4a5 160 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 161 const uint16_t wvBaseline) const {
uci1 21:ce51bb0ba4a5 162 // file pointer should be in correct location
uci1 21:ce51bb0ba4a5 163
uci1 21:ce51bb0ba4a5 164 WriteTo(evtBuf, loseLSB, loseMSB, wvBaseline);
uci1 21:ce51bb0ba4a5 165 return WriteToFileFromBuf(f, evtBuf, loseLSB, loseMSB);
uci1 21:ce51bb0ba4a5 166 }
uci1 21:ce51bb0ba4a5 167
uci1 21:ce51bb0ba4a5 168 bool SnEventFrame::WriteToFileFromBuf(FILE* f, char* const evtBuf,
uci1 21:ce51bb0ba4a5 169 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 21:ce51bb0ba4a5 170 // file pointer should be in correct location
uci1 21:ce51bb0ba4a5 171
uci1 21:ce51bb0ba4a5 172 bool ret = false;
uci1 21:ce51bb0ba4a5 173 if (f!=0) {
uci1 21:ce51bb0ba4a5 174 fwrite(evtBuf, SizeOf(kIOVers, loseLSB, loseMSB), 1u, f);
uci1 21:ce51bb0ba4a5 175 ret = (ferror(f)==false);
uci1 21:ce51bb0ba4a5 176 }
uci1 21:ce51bb0ba4a5 177 return ret;
uci1 21:ce51bb0ba4a5 178
uci1 21:ce51bb0ba4a5 179 }
uci1 21:ce51bb0ba4a5 180
uci1 21:ce51bb0ba4a5 181
uci1 21:ce51bb0ba4a5 182 uint8_t* SnEventFrame::PackWavef(uint8_t* const buf, const uint16_t* const data,
uci1 21:ce51bb0ba4a5 183 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 56:0bba0ef15697 184 const uint16_t wvBaseline,
uci1 56:0bba0ef15697 185 const uint16_t nsamps) {
uci1 21:ce51bb0ba4a5 186 // Compress the data. This is potentially LOSSY; it depends
uci1 21:ce51bb0ba4a5 187 // on the dynamic range and on the options.
uci1 21:ce51bb0ba4a5 188 // See SnConfigFrame::fWvLoseLSB and SnConfigFrame::fWvLoseMSB.
uci1 21:ce51bb0ba4a5 189 // If the number of least signficant bits to lose is not 0, the
uci1 21:ce51bb0ba4a5 190 // compression will be lossy (decreased resolution -- this is ok
uci1 21:ce51bb0ba4a5 191 // if the noise of the signal is much greater than the resolution).
uci1 21:ce51bb0ba4a5 192 // Losing the most significant bits will only be lossy if the
uci1 21:ce51bb0ba4a5 193 // signal-SnConfigFrame::fWvBaseline cannot fit in the reduced
uci1 21:ce51bb0ba4a5 194 // dynamic range (each MSB bit reducing the DR by a factor of 2).
uci1 21:ce51bb0ba4a5 195 //
uci1 21:ce51bb0ba4a5 196 // Note that the mbed uses little endian. Behavior should be the
uci1 21:ce51bb0ba4a5 197 // same on big endian, but this has not been tested.
uci1 21:ce51bb0ba4a5 198 //
uci1 21:ce51bb0ba4a5 199 // Use an unsigned buffer to prevent bits being changed during
uci1 21:ce51bb0ba4a5 200 // an implicit unsigned -> signed cast.
uci1 21:ce51bb0ba4a5 201 //
uci1 21:ce51bb0ba4a5 202 // buf = the byte array into which the data should be packed
uci1 21:ce51bb0ba4a5 203 // data = the data to pack
uci1 21:ce51bb0ba4a5 204 // loseLSB = number of least significant bits to throw away
uci1 21:ce51bb0ba4a5 205 // loseMSB = number of most significant bits to throw away
uci1 21:ce51bb0ba4a5 206 // wvBaseline = baseline to subtract to from ADC before packing
uci1 21:ce51bb0ba4a5 207
uci1 21:ce51bb0ba4a5 208 const uint32_t blen = SizeOfPackedWavef(loseLSB, loseMSB);
uci1 21:ce51bb0ba4a5 209 const uint8_t packSmpBits = BITS_IN_SHORT-loseLSB-loseMSB;
uci1 21:ce51bb0ba4a5 210
uci1 21:ce51bb0ba4a5 211 // make sure this buffer space is all 0's to start
uci1 21:ce51bb0ba4a5 212 memset(buf, 0, blen*sizeof(uint8_t));
uci1 21:ce51bb0ba4a5 213
uci1 21:ce51bb0ba4a5 214 const uint16_t clipHi = uint16_t(
uci1 21:ce51bb0ba4a5 215 uint16_t(uint16_t(0xFFFFu >> loseLSB) << (loseLSB+loseMSB))
uci1 21:ce51bb0ba4a5 216 >> loseMSB);
uci1 21:ce51bb0ba4a5 217
uci1 21:ce51bb0ba4a5 218 uint8_t* b = buf;
uci1 21:ce51bb0ba4a5 219 const uint16_t* dev = data;
uci1 21:ce51bb0ba4a5 220 uint16_t dum;
uci1 21:ce51bb0ba4a5 221 int8_t sbit=0;
uci1 56:0bba0ef15697 222 for (uint16_t i=0; i<nsamps; ++i, ++dev) {
uci1 21:ce51bb0ba4a5 223 // dump the bits we don't want
uci1 21:ce51bb0ba4a5 224 dum = (*dev) - wvBaseline;
uci1 21:ce51bb0ba4a5 225 if (dum<clipHi) {
uci1 21:ce51bb0ba4a5 226 dum >>= loseLSB;
uci1 21:ce51bb0ba4a5 227 dum <<= (loseLSB+loseMSB);
uci1 21:ce51bb0ba4a5 228 } else {
uci1 21:ce51bb0ba4a5 229 dum = clipHi << loseMSB;
uci1 21:ce51bb0ba4a5 230 }
uci1 21:ce51bb0ba4a5 231 if (sbit<=0) {
uci1 21:ce51bb0ba4a5 232 // lose MSB's put in previous short (or none if sbit==0)
uci1 21:ce51bb0ba4a5 233 dum <<= -sbit;
uci1 21:ce51bb0ba4a5 234 *b |= dum >> 8u; // "first" byte of the short
uci1 21:ce51bb0ba4a5 235 dum <<= 8u;
uci1 21:ce51bb0ba4a5 236 *(b+1) |= dum >> 8u; // "second"
uci1 21:ce51bb0ba4a5 237 // move to next number (dev++ in the for loop)
uci1 21:ce51bb0ba4a5 238 // move starting bit up
uci1 21:ce51bb0ba4a5 239 // but stay in this byte of the buf (do not increment b)
uci1 21:ce51bb0ba4a5 240 // since kPackSmpBits <= kBitsInShort, sbit can't
uci1 21:ce51bb0ba4a5 241 // move past the end of the current two bytes
uci1 21:ce51bb0ba4a5 242 sbit += packSmpBits;
uci1 21:ce51bb0ba4a5 243 } else {
uci1 21:ce51bb0ba4a5 244 // first few bits towards the end of this short
uci1 21:ce51bb0ba4a5 245 dum >>= sbit;
uci1 21:ce51bb0ba4a5 246 *b |= dum >> 8u; // "first" byte of the short
uci1 21:ce51bb0ba4a5 247 dum <<= 8u;
uci1 21:ce51bb0ba4a5 248 *(b+1) |= dum >> 8u; // "second"
uci1 21:ce51bb0ba4a5 249 if ( (sbit+packSmpBits) >= BITS_IN_SHORT ) {
uci1 21:ce51bb0ba4a5 250 b+=2; // move to next short in the buf
uci1 21:ce51bb0ba4a5 251 i--; dev--; // but stay on this number
uci1 21:ce51bb0ba4a5 252 // move starting bit back into the short we just filled
uci1 21:ce51bb0ba4a5 253 sbit -= BITS_IN_SHORT;
uci1 21:ce51bb0ba4a5 254 } else {
uci1 21:ce51bb0ba4a5 255 // stay in this buffer and move to the next number
uci1 21:ce51bb0ba4a5 256 // move starting bit up
uci1 21:ce51bb0ba4a5 257 sbit += packSmpBits;
uci1 21:ce51bb0ba4a5 258 }
uci1 21:ce51bb0ba4a5 259 }
uci1 21:ce51bb0ba4a5 260 }
uci1 21:ce51bb0ba4a5 261
uci1 21:ce51bb0ba4a5 262 return buf+blen;
uci1 21:ce51bb0ba4a5 263 }
uci1 21:ce51bb0ba4a5 264
uci1 21:ce51bb0ba4a5 265 const uint8_t* SnEventFrame::UnpackWavef(const uint8_t* const buf,
uci1 21:ce51bb0ba4a5 266 uint16_t* const data,
uci1 21:ce51bb0ba4a5 267 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 268 const uint8_t loseMSB,
uci1 56:0bba0ef15697 269 const uint16_t wvBaseline,
uci1 56:0bba0ef15697 270 const uint16_t nsamps) {
uci1 21:ce51bb0ba4a5 271 if (loseLSB==0 && loseMSB==0 && wvBaseline==0) {
uci1 56:0bba0ef15697 272 memcpy(data, buf, nsamps*sizeof(uint16_t));
uci1 21:ce51bb0ba4a5 273 } else {
uci1 21:ce51bb0ba4a5 274
uci1 21:ce51bb0ba4a5 275 const uint8_t packSmpBits = BITS_IN_SHORT-loseLSB-loseMSB;
uci1 21:ce51bb0ba4a5 276
uci1 21:ce51bb0ba4a5 277 // make sure data is all 0's to start
uci1 56:0bba0ef15697 278 memset(data, 0, nsamps*sizeof(uint16_t));
uci1 21:ce51bb0ba4a5 279
uci1 21:ce51bb0ba4a5 280 const uint8_t* b = buf;
uci1 21:ce51bb0ba4a5 281 uint16_t* dev = data;
uci1 21:ce51bb0ba4a5 282 uint16_t dum;
uci1 21:ce51bb0ba4a5 283 int8_t sbit=0;
uci1 56:0bba0ef15697 284 for (uint16_t i=0; i<nsamps; ++i, ++dev) {
uci1 21:ce51bb0ba4a5 285 dum = (*b) << 8u;
uci1 21:ce51bb0ba4a5 286 dum |= *(b+1);
uci1 21:ce51bb0ba4a5 287 if (sbit<=0) {
uci1 21:ce51bb0ba4a5 288 dum >>= (-sbit+loseLSB+loseMSB);
uci1 21:ce51bb0ba4a5 289 dum <<= loseLSB;
uci1 21:ce51bb0ba4a5 290 *dev |= dum;
uci1 21:ce51bb0ba4a5 291 // add baseline and move to next number (dev++ in the for loop)
uci1 21:ce51bb0ba4a5 292 *dev += wvBaseline;
uci1 21:ce51bb0ba4a5 293 // but stay in this short of the buf (do not increment b)
uci1 21:ce51bb0ba4a5 294 // move starting bit up
uci1 21:ce51bb0ba4a5 295 sbit += packSmpBits;
uci1 21:ce51bb0ba4a5 296 } else {
uci1 21:ce51bb0ba4a5 297 dum <<= sbit;
uci1 21:ce51bb0ba4a5 298 dum >>= loseMSB+loseLSB;
uci1 21:ce51bb0ba4a5 299 dum <<= loseLSB;
uci1 21:ce51bb0ba4a5 300 *dev = dum;
uci1 21:ce51bb0ba4a5 301 if ( (sbit+packSmpBits) >= BITS_IN_SHORT ) {
uci1 21:ce51bb0ba4a5 302 b+=2; // move to next short in the buf
uci1 21:ce51bb0ba4a5 303 i--; dev--; // but stay on this number
uci1 21:ce51bb0ba4a5 304 // move starting bit back into the short we just read from
uci1 21:ce51bb0ba4a5 305 sbit -= BITS_IN_SHORT;
uci1 21:ce51bb0ba4a5 306 } else {
uci1 21:ce51bb0ba4a5 307 // add baseline and move to next number (dev++ in the for loop)
uci1 21:ce51bb0ba4a5 308 *dev += wvBaseline;
uci1 21:ce51bb0ba4a5 309 sbit += packSmpBits;
uci1 21:ce51bb0ba4a5 310 }
uci1 21:ce51bb0ba4a5 311 }
uci1 21:ce51bb0ba4a5 312 }
uci1 21:ce51bb0ba4a5 313 }
uci1 21:ce51bb0ba4a5 314
uci1 21:ce51bb0ba4a5 315 return buf+SizeOfPackedWavef(loseLSB, loseMSB);
uci1 21:ce51bb0ba4a5 316 }
uci1 21:ce51bb0ba4a5 317