Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue Aug 21 02:18:27 2012 +0000
Revision:
13:7a1fb885a8e4
Parent:
12:d472f9811262
Child:
15:f2569d8e4176
Put resetting of event/power number counters to directly after making of file. Move startup config to inside OpenCommWin (and force it on startup). This should ensure that even numbers always correspond to sequence numbers.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 2:e67f7c158087 1 #include "SnCommWin.h"
uci1 2:e67f7c158087 2
uci1 6:6f002d202f59 3 #include "SnHeaderFrame.h"
uci1 2:e67f7c158087 4 #include "SnConfigFrame.h"
uci1 8:95a325df1f6b 5 #include "SnEventFrame.h"
uci1 8:95a325df1f6b 6 #include "SnPowerFrame.h"
uci1 8:95a325df1f6b 7 #include "SnStatusFrame.h"
uci1 2:e67f7c158087 8 #include "SnSDUtils.h"
uci1 2:e67f7c158087 9
uci1 12:d472f9811262 10 bool SnCommWin::IsTimedOut(const uint32_t timeout_clock) const {
uci1 12:d472f9811262 11 if ( timeout_clock > 0 ) {
uci1 12:d472f9811262 12 if (time(0)>timeout_clock) {
uci1 12:d472f9811262 13 return true;
uci1 12:d472f9811262 14 }
uci1 12:d472f9811262 15 }
uci1 12:d472f9811262 16 return false;
uci1 12:d472f9811262 17 }
uci1 12:d472f9811262 18
uci1 2:e67f7c158087 19 SnCommWin::ECommWinResult SnCommWin::SendData(SnConfigFrame& conf,
uci1 2:e67f7c158087 20 SnEventFrame& evt,
uci1 8:95a325df1f6b 21 SnPowerFrame& pow,
uci1 2:e67f7c158087 22 char* const genBuf,
uci1 3:24c5f0f50bf1 23 const uint32_t bsize,
uci1 12:d472f9811262 24 const uint32_t timeout,
uci1 12:d472f9811262 25 const uint32_t handshakeTimeout) {
uci1 12:d472f9811262 26 #ifdef DEBUG
uci1 3:24c5f0f50bf1 27 printf("SnCommWin::SendData\r\n");
uci1 12:d472f9811262 28 #endif
uci1 2:e67f7c158087 29 ECommWinResult res = kUndefFail;
uci1 2:e67f7c158087 30 if (conf.IsSendingAllFiles()) {
uci1 12:d472f9811262 31 #ifdef DEBUG
uci1 3:24c5f0f50bf1 32 printf("sending all files\r\n");
uci1 12:d472f9811262 33 #endif
uci1 12:d472f9811262 34 res = SnSDUtils::SendAllFiles(this, timeout,
uci1 12:d472f9811262 35 genBuf, bsize, conf, evt, pow,
uci1 12:d472f9811262 36 handshakeTimeout);
uci1 2:e67f7c158087 37 } else {
uci1 2:e67f7c158087 38 if (conf.GetCommSendData()==0) {
uci1 12:d472f9811262 39 #ifdef DEBUG
uci1 3:24c5f0f50bf1 40 printf("no data to send\r\n");
uci1 12:d472f9811262 41 #endif
uci1 2:e67f7c158087 42 res = kOkNoMsg;
uci1 2:e67f7c158087 43 } else {
uci1 2:e67f7c158087 44 const uint32_t nev = (conf.GetCommSendData()>0) ?
uci1 3:24c5f0f50bf1 45 conf.GetCommSendData() // send N events
uci1 3:24c5f0f50bf1 46 : 0u; // send all events in last file
uci1 12:d472f9811262 47 #ifdef DEBUG
uci1 12:d472f9811262 48 printf("calling SendData. f=%x, nev=%u\r\n",SnSDUtils::GetCurFile(), nev);
uci1 12:d472f9811262 49 #endif
uci1 2:e67f7c158087 50 res = SendData(SnSDUtils::GetCurFile(), SnSDUtils::GetCurFileName(),
uci1 12:d472f9811262 51 conf, evt, pow, genBuf, bsize, nev, timeout, handshakeTimeout);
uci1 12:d472f9811262 52 #ifdef DEBUG
uci1 3:24c5f0f50bf1 53 printf("after send data cur file, res=%d\r\n",(int)res);
uci1 12:d472f9811262 54 #endif
uci1 2:e67f7c158087 55 }
uci1 2:e67f7c158087 56 }
uci1 2:e67f7c158087 57 return res;
uci1 2:e67f7c158087 58 }
uci1 2:e67f7c158087 59
uci1 2:e67f7c158087 60 SnCommWin::ECommWinResult SnCommWin::SendData(FILE* inf, const char* infn,
uci1 2:e67f7c158087 61 const SnConfigFrame& curConf,
uci1 2:e67f7c158087 62 SnEventFrame& evt,
uci1 8:95a325df1f6b 63 SnPowerFrame& pow,
uci1 2:e67f7c158087 64 char* const genBuf,
uci1 6:6f002d202f59 65 const uint32_t bsize,
uci1 2:e67f7c158087 66 const uint32_t nevts,
uci1 6:6f002d202f59 67 const uint32_t timeout_clock,
uci1 12:d472f9811262 68 const uint32_t handshakeTimeout) {
uci1 2:e67f7c158087 69 // nevts==0 ==> send all events
uci1 2:e67f7c158087 70
uci1 12:d472f9811262 71 #ifdef DEBUG
uci1 12:d472f9811262 72 printf("SnCommWin::SendData file (%p), fn=%s\r\n",inf,infn);
uci1 12:d472f9811262 73 #endif
uci1 2:e67f7c158087 74 ECommWinResult res = kUndefFail;
uci1 12:d472f9811262 75 bool didDel = false;
uci1 2:e67f7c158087 76 if (inf!=0) {
uci1 12:d472f9811262 77 #ifdef DEBUG
uci1 12:d472f9811262 78 printf("sending file name %s\r\n",infn);
uci1 12:d472f9811262 79 #endif
uci1 6:6f002d202f59 80 // send the file name
uci1 6:6f002d202f59 81 res = SendFilename(infn, genBuf, timeout_clock);
uci1 3:24c5f0f50bf1 82 if (res>kAllFails) {
uci1 6:6f002d202f59 83 if (genBuf!=0) {
uci1 12:d472f9811262 84 #ifdef DEBUG
uci1 12:d472f9811262 85 printf("calling send file contents\r\n");
uci1 12:d472f9811262 86 #endif
uci1 6:6f002d202f59 87 // send the contents
uci1 8:95a325df1f6b 88 res = SendFileContents(inf, curConf, evt, pow, genBuf,
uci1 12:d472f9811262 89 nevts, timeout_clock);
uci1 12:d472f9811262 90 #ifdef DEBUG
uci1 12:d472f9811262 91 printf("res=%d (fails=%d)\r\n",(int)res,(int)kAllFails);
uci1 12:d472f9811262 92 #endif
uci1 12:d472f9811262 93 if (res>kAllFails) {
uci1 12:d472f9811262 94 #ifdef DEBUG
uci1 12:d472f9811262 95 printf("calling wait handshake\r\n");
uci1 12:d472f9811262 96 #endif
uci1 6:6f002d202f59 97 // wait for handshake
uci1 6:6f002d202f59 98 uint8_t hndshk=0;
uci1 12:d472f9811262 99 res = WaitHandshake(handshakeTimeout, genBuf, bsize, hndshk);
uci1 6:6f002d202f59 100 if ( (res==SnCommWin::kOkWithMsg) // got handshake
uci1 6:6f002d202f59 101 && (nevts==0) // sent whole file
uci1 6:6f002d202f59 102 && curConf.IsDeletingFiles() // want to delete
uci1 12:d472f9811262 103 && (inf!=SnSDUtils::GetCurFile()) // not current file
uci1 6:6f002d202f59 104 && (hndshk==SnHeaderFrame::kHnShOkComplCode)) { // whole file received
uci1 6:6f002d202f59 105 // delete it
uci1 6:6f002d202f59 106 SnSDUtilsWhisperer::DeleteFile(inf, infn);
uci1 12:d472f9811262 107 didDel=true;
uci1 6:6f002d202f59 108 }
uci1 3:24c5f0f50bf1 109 }
uci1 2:e67f7c158087 110 }
uci1 2:e67f7c158087 111 }
uci1 12:d472f9811262 112 } else {
uci1 12:d472f9811262 113 #ifdef DEBUG
uci1 12:d472f9811262 114 printf("inf=0!\r\n");
uci1 12:d472f9811262 115 #endif
uci1 12:d472f9811262 116 }
uci1 12:d472f9811262 117 if ( (inf!=SnSDUtils::GetCurFile()) && (didDel==false) ) {
uci1 12:d472f9811262 118 SnSDUtils::CloseOutputFile(inf);
uci1 2:e67f7c158087 119 }
uci1 2:e67f7c158087 120 return res;
uci1 2:e67f7c158087 121 }
uci1 8:95a325df1f6b 122
uci1 8:95a325df1f6b 123 SnCommWin::ECommWinResult SnCommWin::WaitHandshake(const uint32_t timeout,
uci1 8:95a325df1f6b 124 char* const buf,
uci1 8:95a325df1f6b 125 const uint32_t bsize,
uci1 8:95a325df1f6b 126 uint8_t& hndShkCode) {
uci1 12:d472f9811262 127 // ensure we don't wait forever
uci1 12:d472f9811262 128 const uint32_t to = (timeout>0) ? timeout : kListenTimeout;
uci1 12:d472f9811262 129 #ifdef DEBUG
uci1 12:d472f9811262 130 printf("WaitHandshake, to=%u\r\n",to);
uci1 12:d472f9811262 131 #endif
uci1 8:95a325df1f6b 132
uci1 12:d472f9811262 133 const int mlen = ReceiveAll(buf, SnHeaderFrame::SizeOf(), to);
uci1 8:95a325df1f6b 134 if (mlen>0 && static_cast<uint32_t>(mlen) == SnHeaderFrame::SizeOf()) {
uci1 8:95a325df1f6b 135 uint32_t msgLen=0;
uci1 8:95a325df1f6b 136 const char* b = buf;
uci1 8:95a325df1f6b 137 SnHeaderFrame::ReadFrom(b, hndShkCode, msgLen);
uci1 12:d472f9811262 138 #ifdef DEBUG
uci1 12:d472f9811262 139 printf("got handshake code=%02x, len=%u\r\n",hndShkCode,msgLen);
uci1 12:d472f9811262 140 #endif
uci1 8:95a325df1f6b 141 if ((hndShkCode & SnHeaderFrame::kHndShkBits)!=0) {
uci1 8:95a325df1f6b 142 return SnCommWin::kOkWithMsg;
uci1 8:95a325df1f6b 143 } else {
uci1 8:95a325df1f6b 144 // TODO: somehow handle unexpected message?
uci1 8:95a325df1f6b 145 return SnCommWin::kUnexpectedRec;
uci1 8:95a325df1f6b 146 }
uci1 8:95a325df1f6b 147 }
uci1 8:95a325df1f6b 148 return SnCommWin::kOkNoMsg;
uci1 8:95a325df1f6b 149 }
uci1 8:95a325df1f6b 150
uci1 8:95a325df1f6b 151 SnCommWin::ECommWinResult SnCommWin::GetConfig(SnConfigFrame& conf,
uci1 8:95a325df1f6b 152 const uint32_t timeOut,
uci1 8:95a325df1f6b 153 char* const confBuf,
uci1 8:95a325df1f6b 154 const uint32_t bsize) {
uci1 8:95a325df1f6b 155 // confBuf assumed to alread be of allocated size
uci1 8:95a325df1f6b 156
uci1 12:d472f9811262 157 #ifdef DEBUG
uci1 8:95a325df1f6b 158 printf("GetConfig, to=%u\r\n",timeOut);
uci1 12:d472f9811262 159 #endif
uci1 8:95a325df1f6b 160
uci1 8:95a325df1f6b 161 SnCommWin::ECommWinResult res = SnCommWin::kUndefFail;
uci1 8:95a325df1f6b 162 if (bsize<SnHeaderFrame::kMaxSizeOf || bsize<SnConfigFrame::kMaxSizeOf) {
uci1 8:95a325df1f6b 163 res = SnCommWin::kUndefFail;
uci1 8:95a325df1f6b 164 } else {
uci1 8:95a325df1f6b 165 // get header
uci1 8:95a325df1f6b 166 const int hlen = ReceiveAll(confBuf, SnHeaderFrame::SizeOf(), timeOut);
uci1 8:95a325df1f6b 167 if (hlen>0 && static_cast<uint32_t>(hlen)==SnHeaderFrame::SizeOf()) {
uci1 8:95a325df1f6b 168 uint8_t mcode=0; uint32_t mlen=0;
uci1 8:95a325df1f6b 169 const char* b = confBuf;
uci1 8:95a325df1f6b 170 SnHeaderFrame::ReadFrom(b, mcode, mlen);
uci1 12:d472f9811262 171 #ifdef DEBUG
uci1 8:95a325df1f6b 172 printf("mcode=%02x, mlen=%u\r\n", mcode, mlen);
uci1 12:d472f9811262 173 #endif
uci1 12:d472f9811262 174 if (mcode==SnHeaderFrame::kNoConfigCode) {
uci1 12:d472f9811262 175 // no config to get
uci1 12:d472f9811262 176 res = SnCommWin::kOkWithMsg;
uci1 12:d472f9811262 177 } else if (mcode!=SnHeaderFrame::kConfigCode) {
uci1 8:95a325df1f6b 178 res = SnCommWin::kUnexpectedRec;
uci1 8:95a325df1f6b 179 } else {
uci1 8:95a325df1f6b 180 // get config
uci1 8:95a325df1f6b 181 const int clen = ReceiveAll(confBuf, mlen, timeOut);
uci1 8:95a325df1f6b 182 if (clen>0 && static_cast<uint32_t>(clen)==mlen) {
uci1 8:95a325df1f6b 183 b = confBuf;
uci1 8:95a325df1f6b 184 conf.ReadFrom(b);
uci1 12:d472f9811262 185 res = SnCommWin::kOkWthMsgNoConf;
uci1 8:95a325df1f6b 186 } else {
uci1 8:95a325df1f6b 187 res = SnCommWin::kUnexpectedRec;
uci1 8:95a325df1f6b 188 }
uci1 8:95a325df1f6b 189 }
uci1 8:95a325df1f6b 190 } else {
uci1 8:95a325df1f6b 191 res = SnCommWin::kUnexpectedRec;
uci1 8:95a325df1f6b 192 }
uci1 8:95a325df1f6b 193 }
uci1 8:95a325df1f6b 194 return res;
uci1 8:95a325df1f6b 195 }
uci1 8:95a325df1f6b 196
uci1 8:95a325df1f6b 197 SnCommWin::ECommWinResult SnCommWin::SendStatus(const SnConfigFrame& conf,
uci1 8:95a325df1f6b 198 const SnEventFrame& evt,
uci1 8:95a325df1f6b 199 const SnPowerFrame& pow,
uci1 10:3c93db1cfb12 200 const uint16_t seq,
uci1 10:3c93db1cfb12 201 const float thmrate,
uci1 10:3c93db1cfb12 202 const float evtrate,
uci1 8:95a325df1f6b 203 char* const genBuf,
uci1 8:95a325df1f6b 204 const uint32_t timeout_clock) {
uci1 8:95a325df1f6b 205 // TODO: check if connected?
uci1 12:d472f9811262 206 #ifdef DEBUG
uci1 12:d472f9811262 207 printf("########### Send Status\r\n");
uci1 12:d472f9811262 208 #endif
uci1 8:95a325df1f6b 209 const uint32_t ssize = SnStatusFrame::SizeOf(SnStatusFrame::kIOVers, conf);
uci1 8:95a325df1f6b 210 char* b = genBuf;
uci1 8:95a325df1f6b 211 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kStatusCode, ssize);
uci1 10:3c93db1cfb12 212 SnStatusFrame::WriteTo(b, GetCommType(), conf, evt, genBuf, seq, thmrate, evtrate);
uci1 10:3c93db1cfb12 213 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kPowerCode,
uci1 10:3c93db1cfb12 214 pow.SizeOf(SnPowerFrame::kIOvers));
uci1 10:3c93db1cfb12 215 pow.WriteTo(b);
uci1 10:3c93db1cfb12 216 int msiz = b-genBuf;
uci1 10:3c93db1cfb12 217 int mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 8:95a325df1f6b 218 #ifdef DEBUG
uci1 8:95a325df1f6b 219 printf("status frame:\r\n");
uci1 8:95a325df1f6b 220 for (uint32_t i=0; i<msize; i++) {
uci1 8:95a325df1f6b 221 printf("%02X ",genBuf[i]);
uci1 8:95a325df1f6b 222 }
uci1 8:95a325df1f6b 223 printf("\r\n");
uci1 8:95a325df1f6b 224 #endif
uci1 8:95a325df1f6b 225 if (mlen==msiz) {
uci1 12:d472f9811262 226 #ifdef DEBUG
uci1 10:3c93db1cfb12 227 printf("status+power sent\r\n");
uci1 12:d472f9811262 228 #endif
uci1 8:95a325df1f6b 229 b = genBuf;
uci1 10:3c93db1cfb12 230 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kEventCode,
uci1 10:3c93db1cfb12 231 evt.SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 232 conf.GetWvLoseLSB(), conf.GetWvLoseMSB()));
uci1 10:3c93db1cfb12 233 evt.WriteTo(b, conf.GetWvLoseLSB(), conf.GetWvLoseMSB(),
uci1 10:3c93db1cfb12 234 conf.GetWvBaseline());
uci1 10:3c93db1cfb12 235 return SnCommWin::kOkMsgSent;
uci1 8:95a325df1f6b 236 }
uci1 8:95a325df1f6b 237 return SnCommWin::kFailPartSent;
uci1 8:95a325df1f6b 238 }
uci1 8:95a325df1f6b 239
uci1 12:d472f9811262 240 SnCommWin::ECommWinResult SnCommWin::SendFilename(const char* inf,
uci1 8:95a325df1f6b 241 char* const genBuf,
uci1 8:95a325df1f6b 242 const uint32_t timeout_clock) {
uci1 12:d472f9811262 243 #ifdef DEBUG
uci1 12:d472f9811262 244 printf("SnCommWin::SendFilename %s\r\n",inf);
uci1 12:d472f9811262 245 #endif
uci1 12:d472f9811262 246 // remove the directory
uci1 12:d472f9811262 247 const char* fn = strrchr(inf, '/');
uci1 12:d472f9811262 248 if (fn==0) {
uci1 12:d472f9811262 249 // no directory
uci1 12:d472f9811262 250 fn = inf;
uci1 12:d472f9811262 251 } else if (fn!=inf) {
uci1 12:d472f9811262 252 ++fn; // move past the '/' if it was found
uci1 12:d472f9811262 253 }
uci1 12:d472f9811262 254 #ifdef DEBUG
uci1 12:d472f9811262 255 printf("send %s\r\n",fn);
uci1 12:d472f9811262 256 #endif
uci1 8:95a325df1f6b 257 const size_t flen = strlen(fn);
uci1 8:95a325df1f6b 258 char* b = genBuf;
uci1 8:95a325df1f6b 259 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFilenameCode, flen);
uci1 12:d472f9811262 260 b = SnBitUtils::WriteTo(b, fn, flen);
uci1 12:d472f9811262 261 const int msiz = b-genBuf;
uci1 8:95a325df1f6b 262 const int mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 263 #ifdef DEBUG
uci1 12:d472f9811262 264 printf("time = %u, timeout = %u\r\n",time(0), timeout_clock);
uci1 12:d472f9811262 265 #endif
uci1 8:95a325df1f6b 266 return (msiz==mlen) ? SnCommWin::kOkMsgSent : SnCommWin::kFailPartSent;
uci1 8:95a325df1f6b 267 }
uci1 8:95a325df1f6b 268
uci1 12:d472f9811262 269 int SnCommWin::SendFileBlock(FILE* inf,
uci1 12:d472f9811262 270 const uint8_t blockHeaderCode,
uci1 12:d472f9811262 271 const uint32_t blockSize,
uci1 12:d472f9811262 272 char* const genBuf,
uci1 12:d472f9811262 273 const uint32_t timeout) {
uci1 12:d472f9811262 274 // sends the block from the file. does not check if the file has sufficient bytes
uci1 12:d472f9811262 275 // this should be done before calling this function
uci1 12:d472f9811262 276 // (where the number of bytes in the file can be cached)
uci1 12:d472f9811262 277 char* b = genBuf;
uci1 12:d472f9811262 278 SnHeaderFrame::WriteTo(b, blockHeaderCode, blockSize);
uci1 12:d472f9811262 279 SnBitUtils::ReadFrom(inf, b, blockSize);
uci1 12:d472f9811262 280 #ifdef DEBUG
uci1 12:d472f9811262 281 printf("Sending block hc %02x, len=%u\r\n",blockHeaderCode,blockSize+SnHeaderFrame::SizeOf());
uci1 12:d472f9811262 282 #endif
uci1 12:d472f9811262 283 return SendAll(genBuf, blockSize+SnHeaderFrame::SizeOf(), timeout);
uci1 12:d472f9811262 284 }
uci1 12:d472f9811262 285
uci1 12:d472f9811262 286 SnCommWin::ECommWinResult SnCommWin::SendFileContents(FILE* inf,
uci1 12:d472f9811262 287 const SnConfigFrame& curConf,
uci1 12:d472f9811262 288 SnEventFrame& evt,
uci1 12:d472f9811262 289 SnPowerFrame& pow,
uci1 12:d472f9811262 290 char* const genBuf,
uci1 12:d472f9811262 291 uint32_t nevts,
uci1 12:d472f9811262 292 const uint32_t timeout_clock) {
uci1 12:d472f9811262 293 // firstEvt==0 ==> start at beginning
uci1 12:d472f9811262 294 // nevts==0 ==> all events
uci1 12:d472f9811262 295
uci1 12:d472f9811262 296 #ifdef DEBUG
uci1 12:d472f9811262 297 printf("SendFileContents (byte streaming)\r\n");
uci1 12:d472f9811262 298 #endif
uci1 12:d472f9811262 299
uci1 12:d472f9811262 300 // store position in file so we can go back to it afterwards
uci1 12:d472f9811262 301 // this is probably not necessary, because if this file is open
uci1 12:d472f9811262 302 // in write-only mode, we're screwed..
uci1 12:d472f9811262 303 const int fpos = ftell(inf);
uci1 12:d472f9811262 304 if (fpos>0) {
uci1 12:d472f9811262 305 fseek(inf, 0, SEEK_SET);
uci1 12:d472f9811262 306 }
uci1 12:d472f9811262 307 // how many bytes?
uci1 12:d472f9811262 308 fseek(inf, 0, SEEK_END); // go to end
uci1 12:d472f9811262 309 const int fend = ftell(inf);
uci1 12:d472f9811262 310 fseek(inf, 0, SEEK_SET); // go to start
uci1 12:d472f9811262 311 #ifdef DEBUG
uci1 12:d472f9811262 312 printf("fend=%d\r\n",fend);
uci1 12:d472f9811262 313 printf("fpos=%d\r\n",fpos);
uci1 12:d472f9811262 314 #endif
uci1 12:d472f9811262 315
uci1 12:d472f9811262 316 // variables used when sending data
uci1 12:d472f9811262 317 char* b = genBuf;
uci1 12:d472f9811262 318 int msiz, mlen;
uci1 12:d472f9811262 319
uci1 12:d472f9811262 320 // first is the file header, which has no SnHeaderFrame
uci1 12:d472f9811262 321 msiz = SnSDUtils::SizeOfFileHeader(SnSDUtils::kIOvers);
uci1 12:d472f9811262 322 bool ok = (ftell(inf)+msiz)<=fend;
uci1 12:d472f9811262 323 if (ok) {
uci1 12:d472f9811262 324 mlen = SendFileBlock(inf, SnHeaderFrame::kFileHeadrCode,
uci1 12:d472f9811262 325 msiz, genBuf, timeout_clock);
uci1 12:d472f9811262 326 ok &= (msiz+SnHeaderFrame::SizeOf())==mlen;
uci1 12:d472f9811262 327
uci1 12:d472f9811262 328 #ifdef DEBUG
uci1 12:d472f9811262 329 printf("sent file header. ok=%d\r\n",(int)ok);
uci1 12:d472f9811262 330 #endif
uci1 12:d472f9811262 331
uci1 12:d472f9811262 332 // the header info for each block
uci1 12:d472f9811262 333 uint8_t hcode;
uci1 12:d472f9811262 334 uint32_t hlen;
uci1 12:d472f9811262 335
uci1 12:d472f9811262 336 // count number of events / power readings sent
uci1 12:d472f9811262 337 uint32_t evtsSent=0, powsSent=0;
uci1 12:d472f9811262 338
uci1 12:d472f9811262 339 // now just loop through file and send each block
uci1 12:d472f9811262 340 while ( ok
uci1 12:d472f9811262 341 && (feof(inf)==0)
uci1 12:d472f9811262 342 && (ferror(inf)==0)
uci1 12:d472f9811262 343 && ((ftell(inf)+SnHeaderFrame::SizeOf())<=fend) ) {
uci1 12:d472f9811262 344 // read the header for the block
uci1 12:d472f9811262 345 SnSDUtils::ReadBlockHeader(inf, hcode, hlen);
uci1 12:d472f9811262 346 #ifdef DEBUG
uci1 12:d472f9811262 347 printf("new block: hc=%02x, hl=%u, ftell=%d, fend=%d\r\n",
uci1 12:d472f9811262 348 hcode, hlen, ftell(inf), fend);
uci1 12:d472f9811262 349 #endif
uci1 12:d472f9811262 350 ok &= (ftell(inf)+hlen)<=fend;
uci1 12:d472f9811262 351 if (ok) {
uci1 12:d472f9811262 352 // send the block
uci1 12:d472f9811262 353 // TODO: repack events?
uci1 12:d472f9811262 354 msiz = hlen + SnHeaderFrame::SizeOf();
uci1 12:d472f9811262 355 mlen = SendFileBlock(inf, hcode, hlen, genBuf, timeout_clock);
uci1 12:d472f9811262 356 ok &= msiz==mlen;
uci1 12:d472f9811262 357 if (ok) {
uci1 12:d472f9811262 358 if (hcode==SnHeaderFrame::kEventCode) {
uci1 12:d472f9811262 359 ++evtsSent;
uci1 12:d472f9811262 360 if (nevts>0) {
uci1 12:d472f9811262 361 if (evtsSent>=nevts) {
uci1 12:d472f9811262 362 #ifdef DEBUG
uci1 12:d472f9811262 363 printf("send %u events. stop\r\n",evtsSent);
uci1 12:d472f9811262 364 #endif
uci1 12:d472f9811262 365 break;
uci1 12:d472f9811262 366 }
uci1 12:d472f9811262 367 }
uci1 12:d472f9811262 368 } else if (hcode==SnHeaderFrame::kPowerCode) {
uci1 12:d472f9811262 369 ++powsSent;
uci1 12:d472f9811262 370 }
uci1 12:d472f9811262 371 } else {
uci1 12:d472f9811262 372 #ifdef DEBUG
uci1 12:d472f9811262 373 printf("not ok when sending hcode=%02x\r\n",hcode);
uci1 12:d472f9811262 374 #endif
uci1 12:d472f9811262 375 }
uci1 12:d472f9811262 376 }
uci1 12:d472f9811262 377 }
uci1 12:d472f9811262 378
uci1 12:d472f9811262 379 #ifdef DEBUG
uci1 12:d472f9811262 380 printf("loop done. ok=%d\r\n",(int)ok);
uci1 12:d472f9811262 381 #endif
uci1 12:d472f9811262 382
uci1 12:d472f9811262 383 // send number of events sent
uci1 12:d472f9811262 384 #ifdef DEBUG
uci1 12:d472f9811262 385 printf("sending evtsSent (%u)\r\n",evtsSent);
uci1 12:d472f9811262 386 #endif
uci1 12:d472f9811262 387 b = genBuf;
uci1 12:d472f9811262 388 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileNevtsCode, sizeof(uint32_t));
uci1 12:d472f9811262 389 b = SnBitUtils::WriteTo(b, evtsSent);
uci1 12:d472f9811262 390 msiz = b - genBuf;
uci1 12:d472f9811262 391 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 392 ok &= msiz==mlen;
uci1 12:d472f9811262 393
uci1 12:d472f9811262 394 // send number of power readings sent
uci1 12:d472f9811262 395 #ifdef DEBUG
uci1 12:d472f9811262 396 printf("sending powsSent (%u)\r\n",powsSent);
uci1 12:d472f9811262 397 #endif
uci1 12:d472f9811262 398 b = genBuf;
uci1 12:d472f9811262 399 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileNpwrsCode, sizeof(uint32_t));
uci1 12:d472f9811262 400 b = SnBitUtils::WriteTo(b, powsSent);
uci1 12:d472f9811262 401 msiz = b - genBuf;
uci1 12:d472f9811262 402 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 403 ok &= msiz==mlen;
uci1 12:d472f9811262 404
uci1 12:d472f9811262 405 }
uci1 12:d472f9811262 406
uci1 12:d472f9811262 407
uci1 12:d472f9811262 408 // put file position back
uci1 12:d472f9811262 409 fseek(inf, fpos, SEEK_SET);
uci1 12:d472f9811262 410
uci1 12:d472f9811262 411 #ifdef DEBUG
uci1 12:d472f9811262 412 printf("end contents: ok=%d\r\n",(int)ok);
uci1 12:d472f9811262 413 #endif
uci1 12:d472f9811262 414
uci1 12:d472f9811262 415 return ok ? SnCommWin::kOkMsgSent : SnCommWin::kFailPartSent;
uci1 12:d472f9811262 416 }
uci1 12:d472f9811262 417
uci1 12:d472f9811262 418 /*
uci1 8:95a325df1f6b 419 SnCommWin::ECommWinResult SnCommWin::SendFileContents(FILE* inf,
uci1 8:95a325df1f6b 420 const SnConfigFrame& curConf,
uci1 8:95a325df1f6b 421 SnEventFrame& evt,
uci1 8:95a325df1f6b 422 SnPowerFrame& pow,
uci1 8:95a325df1f6b 423 char* const genBuf,
uci1 8:95a325df1f6b 424 uint32_t nevts,
uci1 8:95a325df1f6b 425 const uint32_t timeout_clock,
uci1 8:95a325df1f6b 426 const uint32_t firstEvt) {
uci1 12:d472f9811262 427 printf("comm win send file contents\r\n");
uci1 8:95a325df1f6b 428 // firstEvt==0 ==> start at beginning
uci1 8:95a325df1f6b 429 // nevts==0 ==> all events
uci1 8:95a325df1f6b 430
uci1 8:95a325df1f6b 431 const int fpos = ftell(inf);
uci1 8:95a325df1f6b 432 if (fpos>0) {
uci1 8:95a325df1f6b 433 fseek(inf, 0, SEEK_SET);
uci1 8:95a325df1f6b 434 }
uci1 12:d472f9811262 435 // how many bytes?
uci1 12:d472f9811262 436 fseek(inf, 0, SEEK_END); // go to end
uci1 12:d472f9811262 437 const int fend = ftell(inf);
uci1 12:d472f9811262 438 fseek(inf, 0, SEEK_SET); // go to start
uci1 12:d472f9811262 439 printf("fend=%d\r\n",fend);
uci1 8:95a325df1f6b 440 printf("fpos=%d\r\n",fpos);
uci1 8:95a325df1f6b 441 // get file header
uci1 8:95a325df1f6b 442 uint64_t macadr;
uci1 8:95a325df1f6b 443 uint32_t run;
uci1 8:95a325df1f6b 444 uint16_t seq;
uci1 12:d472f9811262 445 bool ok = (ftell(inf)+SnSDUtils::SizeOfFileHeader(SnSDUtils::kIOvers))<=fend;
uci1 12:d472f9811262 446 if (ok) {
uci1 12:d472f9811262 447 SnSDUtils::ReadFileHeader(inf, macadr, run, seq, &pow);
uci1 12:d472f9811262 448 printf("read file header: run %u, seq %hu\r\n",run,seq);
uci1 12:d472f9811262 449 }
uci1 12:d472f9811262 450
uci1 12:d472f9811262 451 printf(">>> file hdr read ftell(inf)=%d\r\n",ftell(inf));
uci1 8:95a325df1f6b 452
uci1 8:95a325df1f6b 453 // check block
uci1 8:95a325df1f6b 454 uint8_t hcode;
uci1 8:95a325df1f6b 455 uint32_t hlen;
uci1 12:d472f9811262 456 ok &= (ftell(inf)+SnHeaderFrame::SizeOf())<=fend;
uci1 12:d472f9811262 457 if (ok) {
uci1 12:d472f9811262 458 SnSDUtils::ReadBlockHeader(inf, hcode, hlen);
uci1 12:d472f9811262 459 printf("read block hd %02x, len %u\r\n",hcode,hlen);
uci1 12:d472f9811262 460 if (hcode==SnHeaderFrame::kPowerCode) {
uci1 12:d472f9811262 461 ok &= (ftell(inf)+SnPowerFrame::SizeOf(SnPowerFrame::kIOvers))<=fend;
uci1 12:d472f9811262 462 if (ok) {
uci1 12:d472f9811262 463 pow.ReadFrom(inf);
uci1 12:d472f9811262 464 printf("read power: v1=%g, v2=%g\r\n",pow.GetAveV1(), pow.GetAveV2());
uci1 12:d472f9811262 465 // now read the next header
uci1 12:d472f9811262 466 ok &= (ftell(inf)+SnHeaderFrame::SizeOf())<=fend;
uci1 12:d472f9811262 467 if (ok) {
uci1 12:d472f9811262 468 SnSDUtils::ReadBlockHeader(inf, hcode, hlen);
uci1 12:d472f9811262 469 printf("read new header: hc %02x, hlen=%u\r\n",hcode,hlen);
uci1 12:d472f9811262 470 }
uci1 12:d472f9811262 471 }
uci1 12:d472f9811262 472 }
uci1 8:95a325df1f6b 473 }
uci1 8:95a325df1f6b 474
uci1 12:d472f9811262 475 printf(">>> power tried ftell(inf)=%d\r\n",ftell(inf));
uci1 12:d472f9811262 476
uci1 12:d472f9811262 477 printf("hcode=%02x\r\n",hcode);
uci1 12:d472f9811262 478 printf("ok=%d\r\n",(int)ok);
uci1 12:d472f9811262 479 printf("feof=%d\r\n",feof(inf));
uci1 12:d472f9811262 480 printf("ferror=%d\r\n",ferror(inf));
uci1 12:d472f9811262 481 printf("%d+%u <= %d ? %d\r\n",ftell(inf),hlen,fend,
uci1 12:d472f9811262 482 (int)((ftell(inf)+hlen)<=fend));
uci1 12:d472f9811262 483
uci1 8:95a325df1f6b 484 // TODO: check memory for temporary config/event frames?
uci1 8:95a325df1f6b 485 // get config
uci1 8:95a325df1f6b 486 while ((hcode!=SnHeaderFrame::kConfigCode)
uci1 12:d472f9811262 487 && ok
uci1 8:95a325df1f6b 488 && (feof(inf)==0)
uci1 12:d472f9811262 489 && (ferror(inf)==0)
uci1 12:d472f9811262 490 && ((ftell(inf)+hlen) <= fend) ) {
uci1 12:d472f9811262 491 printf("skip: ftell=%d, hlen=%u\r\n",ftell(inf),hlen);
uci1 8:95a325df1f6b 492 fseek(inf, hlen, SEEK_CUR); // skip this block
uci1 12:d472f9811262 493 ok = (ftell(inf)+SnHeaderFrame::SizeOf())<=fend;
uci1 12:d472f9811262 494 if (ok) {
uci1 12:d472f9811262 495 SnSDUtils::ReadBlockHeader(inf, hcode, hlen);
uci1 12:d472f9811262 496 printf("hcs >>> ftell(inf)=%d, hcode=%02x, hlen=%u\r\n",ftell(inf),hcode,hlen);
uci1 12:d472f9811262 497 printf("feof=%d, ferror=%d\r\n",feof(inf),ferror(inf));
uci1 12:d472f9811262 498 }
uci1 8:95a325df1f6b 499 }
uci1 8:95a325df1f6b 500
uci1 12:d472f9811262 501 printf("checking ftell\r\n");
uci1 12:d472f9811262 502 bool gotConf = false;
uci1 12:d472f9811262 503 ok = (ftell(inf)+hlen) <= fend;
uci1 12:d472f9811262 504 printf("making temp config\r\n");
uci1 12:d472f9811262 505 SnConfigFrame conf; // TODO: SOMETIMES STALLS HERE!
uci1 12:d472f9811262 506 printf("trying to read\r\n");
uci1 12:d472f9811262 507 if (ok && (hcode==SnHeaderFrame::kConfigCode)) {
uci1 12:d472f9811262 508 printf("reading config from ftell=%d, hcode=%02x, hlen=%u, ok=%d\r\n",
uci1 12:d472f9811262 509 ftell(inf), hcode, hlen, (int)ok);
uci1 12:d472f9811262 510 conf.ReadFrom(inf);
uci1 12:d472f9811262 511 gotConf = (ftell(inf) <= fend) && (feof(inf)==0) && (ferror(inf)==0);
uci1 12:d472f9811262 512 }
uci1 12:d472f9811262 513 printf(">>> conf. ftell(inf)=%d, gotconf=%d\r\n",ftell(inf),(int)gotConf);
uci1 8:95a325df1f6b 514
uci1 8:95a325df1f6b 515 char* b = genBuf;
uci1 12:d472f9811262 516 int msiz, mlen;
uci1 12:d472f9811262 517 if (ok && gotConf) {
uci1 12:d472f9811262 518 // get event size
uci1 12:d472f9811262 519 uint8_t sLoseLSB=0, sLoseMSB=0;
uci1 12:d472f9811262 520 uint16_t sWvBase=0;
uci1 12:d472f9811262 521 curConf.GetPackParsFor(GetCommType(), sLoseLSB, sLoseMSB, sWvBase);
uci1 12:d472f9811262 522
uci1 12:d472f9811262 523 // size of event in file
uci1 12:d472f9811262 524 const uint32_t esize = SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 12:d472f9811262 525 conf.GetWvLoseLSB(),
uci1 12:d472f9811262 526 conf.GetWvLoseMSB());
uci1 12:d472f9811262 527
uci1 12:d472f9811262 528 printf("esize=%u\r\n",esize);
uci1 12:d472f9811262 529
uci1 12:d472f9811262 530 // number of events / power readings we will send
uci1 12:d472f9811262 531 uint32_t evtsSent=0, powsSent=0;
uci1 8:95a325df1f6b 532 b = genBuf;
uci1 12:d472f9811262 533 // send the file header
uci1 12:d472f9811262 534 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileHeadrCode,
uci1 12:d472f9811262 535 SnSDUtils::SizeOfFileHeader(SnSDUtils::kIOvers));
uci1 12:d472f9811262 536 SnSDUtils::WriteFileHeader(b, macadr, run, seq);
uci1 8:95a325df1f6b 537 msiz = b-genBuf;
uci1 8:95a325df1f6b 538 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 8:95a325df1f6b 539 if (mlen==msiz) {
uci1 12:d472f9811262 540 // send power header
uci1 8:95a325df1f6b 541 b = genBuf;
uci1 12:d472f9811262 542 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kPowerCode,
uci1 12:d472f9811262 543 pow.SizeOf(SnPowerFrame::kIOvers));
uci1 12:d472f9811262 544 pow.WriteTo(b);
uci1 8:95a325df1f6b 545 msiz = b-genBuf;
uci1 8:95a325df1f6b 546 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 547 ++powsSent;
uci1 8:95a325df1f6b 548 if (mlen==msiz) {
uci1 12:d472f9811262 549 // send the config
uci1 12:d472f9811262 550 b = genBuf;
uci1 12:d472f9811262 551 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kConfigCode,
uci1 12:d472f9811262 552 conf.SizeOf(SnConfigFrame::kIOVers));
uci1 12:d472f9811262 553 conf.WriteTo(b);
uci1 12:d472f9811262 554 msiz = b-genBuf;
uci1 12:d472f9811262 555 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 556 if (mlen==msiz) {
uci1 12:d472f9811262 557 ok = true;
uci1 12:d472f9811262 558 }
uci1 8:95a325df1f6b 559 }
uci1 8:95a325df1f6b 560 }
uci1 12:d472f9811262 561
uci1 12:d472f9811262 562 printf("ok=%d, nevts=%u\r\n",(int)ok,nevts);
uci1 8:95a325df1f6b 563
uci1 12:d472f9811262 564 if (ok) {
uci1 12:d472f9811262 565 // size of event sent over afar
uci1 12:d472f9811262 566 const uint32_t ssize = SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 12:d472f9811262 567 sLoseLSB, sLoseMSB);
uci1 12:d472f9811262 568
uci1 12:d472f9811262 569 // loop over blocks. send event & power frames
uci1 12:d472f9811262 570 // until EOF or nevets have been sent
uci1 12:d472f9811262 571 uint8_t hc; uint32_t hl;
uci1 12:d472f9811262 572 while (ok && (feof(inf)==0)
uci1 12:d472f9811262 573 && (ferror(inf)==0)
uci1 12:d472f9811262 574 && (ftell(inf)<fend) ) { // feof doesn't seem to work
uci1 12:d472f9811262 575 printf(">>> ftell(inf)=%d\r\n",ftell(inf));
uci1 12:d472f9811262 576 if ((ftell(inf)+SnHeaderFrame::SizeOf())<=fend) {
uci1 12:d472f9811262 577 SnSDUtils::ReadBlockHeader(inf, hc, hl);
uci1 12:d472f9811262 578 if (hc==SnHeaderFrame::kEventCode) {
uci1 12:d472f9811262 579 if ((ftell(inf)+ssize)<=fend) {
uci1 12:d472f9811262 580 evt.ReadFrom(inf, genBuf,
uci1 12:d472f9811262 581 conf.GetWvLoseLSB(), conf.GetWvLoseMSB(),
uci1 12:d472f9811262 582 conf.GetWvBaseline());
uci1 12:d472f9811262 583 if (evt.GetEvtNum()>=firstEvt) {
uci1 12:d472f9811262 584 ++evtsSent;
uci1 12:d472f9811262 585 printf("sending evt %u\r\n",evtsSent);
uci1 12:d472f9811262 586 // must be after evt.Read, since that uses the buffer
uci1 12:d472f9811262 587 b = genBuf;
uci1 12:d472f9811262 588 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kEventCode, ssize);
uci1 12:d472f9811262 589 evt.WriteTo(b, sLoseLSB, sLoseMSB, sWvBase); // will repack if necessary
uci1 12:d472f9811262 590 msiz = b-genBuf; //SnHeaderFrame::SizeOf()+ssize;
uci1 12:d472f9811262 591 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 592 ok &= mlen==msiz;
uci1 12:d472f9811262 593 }
uci1 12:d472f9811262 594 } else {
uci1 12:d472f9811262 595 printf("event header, but not enough bytes in file\r\n");
uci1 12:d472f9811262 596 ok = false;
uci1 12:d472f9811262 597 }
uci1 12:d472f9811262 598 } else if (hc==SnHeaderFrame::kPowerCode) {
uci1 12:d472f9811262 599 if ((ftell(inf)+SnPowerFrame::SizeOf(SnPowerFrame::kIOvers))<=fend) {
uci1 12:d472f9811262 600 ++powsSent;
uci1 12:d472f9811262 601 pow.ReadFrom(inf);
uci1 12:d472f9811262 602 printf("sending power frame %u, v1=%g, v2=%g, t=%u\r\n",
uci1 12:d472f9811262 603 powsSent, pow.GetAveV1(), pow.GetAveV2(), pow.GetTime());
uci1 12:d472f9811262 604 b = genBuf;
uci1 12:d472f9811262 605 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kPowerCode,
uci1 12:d472f9811262 606 SnPowerFrame::SizeOf(SnPowerFrame::kIOvers));
uci1 12:d472f9811262 607 pow.WriteTo(b);
uci1 12:d472f9811262 608 msiz = b-genBuf;
uci1 12:d472f9811262 609 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 610 ok &= mlen==msiz;
uci1 12:d472f9811262 611 } else {
uci1 12:d472f9811262 612 printf("power header, but not enough bytes in file\r\n");
uci1 12:d472f9811262 613 ok = false;
uci1 12:d472f9811262 614 }
uci1 12:d472f9811262 615 } else {
uci1 12:d472f9811262 616 printf("unhandled block. hc=%hhu, hl=%u\r\n",
uci1 12:d472f9811262 617 hc, hl);
uci1 12:d472f9811262 618 if ((ftell(inf)+hl)<=fend) {
uci1 12:d472f9811262 619 fseek(inf, hl, SEEK_CUR); // skip this block
uci1 12:d472f9811262 620 } else {
uci1 12:d472f9811262 621 printf("not enough bytes in file to skip block\r\n");
uci1 12:d472f9811262 622 ok = false;
uci1 12:d472f9811262 623 }
uci1 8:95a325df1f6b 624 }
uci1 8:95a325df1f6b 625 } else {
uci1 12:d472f9811262 626 printf("not enough bytes in file to read header\r\n");
uci1 12:d472f9811262 627 printf("feof=%d\r\n",feof(inf));
uci1 12:d472f9811262 628 printf("ftell(inf)=%d, hdr size=%u, fend=%u\r\n",
uci1 12:d472f9811262 629 (ftell(inf)), SnHeaderFrame::SizeOf(), fend);
uci1 8:95a325df1f6b 630 ok = false;
uci1 8:95a325df1f6b 631 }
uci1 8:95a325df1f6b 632 }
uci1 12:d472f9811262 633 // send number of events sent
uci1 12:d472f9811262 634 b = genBuf;
uci1 12:d472f9811262 635 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileNevtsCode, sizeof(uint32_t));
uci1 12:d472f9811262 636 b = SnBitUtils::WriteTo(b, evtsSent);
uci1 12:d472f9811262 637 msiz = b - genBuf;
uci1 12:d472f9811262 638 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 639 ok &= msiz==mlen;
uci1 12:d472f9811262 640 // send number of power readings sent
uci1 12:d472f9811262 641 b = genBuf;
uci1 12:d472f9811262 642 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileNpwrsCode, sizeof(uint32_t));
uci1 12:d472f9811262 643 b = SnBitUtils::WriteTo(b, powsSent);
uci1 12:d472f9811262 644 msiz = b - genBuf;
uci1 12:d472f9811262 645 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 12:d472f9811262 646 ok &= msiz==mlen;
uci1 8:95a325df1f6b 647 }
uci1 12:d472f9811262 648 } else {
uci1 12:d472f9811262 649 printf("failed to get config from file\r\n");
uci1 12:d472f9811262 650 // send corrupted file handshake
uci1 8:95a325df1f6b 651 b = genBuf;
uci1 12:d472f9811262 652 SnHeaderFrame::WriteTo(b, SnHeaderFrame::kFileReadFailCode, 0u);
uci1 12:d472f9811262 653 msiz = b-genBuf;
uci1 8:95a325df1f6b 654 mlen = SendAll(genBuf, msiz, timeout_clock);
uci1 8:95a325df1f6b 655 ok &= msiz==mlen;
uci1 8:95a325df1f6b 656 }
uci1 12:d472f9811262 657
uci1 8:95a325df1f6b 658 // put file position back
uci1 8:95a325df1f6b 659 fseek(inf, fpos, SEEK_SET);
uci1 8:95a325df1f6b 660
uci1 8:95a325df1f6b 661 return ok ? SnCommWin::kOkMsgSent : SnCommWin::kFailPartSent;
uci1 8:95a325df1f6b 662 }
uci1 12:d472f9811262 663 */