/// <summary> /// Get the shelf life paraeter from the log state information. /// Used in getting the <see cref="ShelfLife"/>. /// </summary> /// <param name="lsi">The log state information from the tag.</param> /// <returns>Extracted shelf life parameter, <see cref="ShelfLifeParam"/>.</returns> /// <exception cref="ApplicationException">Exception thrown when the log state does not contain the shelf life information.</exception> public ShelfLifeParam ExtractShelfLifeResp(LogStateInfo lsi) { if (!lsi.hasShelfLife) { throw new ApplicationException("ExtractShelfLifeReponse: no shelf life present."); } ShelfLifeParam slp = new ShelfLifeParam(); slp.actEnergy = lsi.shelfLife.actEnergy; slp.curShelfLife = lsi.shelfLife.curShelfLife; slp.initLife = lsi.shelfLife.initLife; slp.initTemp = lsi.shelfLife.initTemp; slp.maxTemp = lsi.shelfLife.maxTemp; slp.minTemp = lsi.shelfLife.minTemp; slp.negSlEn = lsi.shelfLife.negSlEn; slp.normTemp = lsi.shelfLife.normTemp; slp.slAlgEn = lsi.shelfLife.slAlgEn; slp.slSensId = lsi.shelfLife.slSensId; return(slp); }
/* Get the curent log state from the tag. */ private LogStateInfo LogStateExchange(uint password, bool secured) { BitBuffer bb; NurApi.CustomExchangeParams xch; NurApi.CustomExchangeResponse resp; int respLen, bytePtr; byte flags; LogStateInfo ls = new LogStateInfo(); /* Build the command. */ bb = BuildCommand(CMD_GET_LOGSTATE, null); /* No expected length because shelf life is unknown; handle not needed here. */ xch = BuildDefault(bb, 0, true, false); resp = hApi.CustomExchangeSingulated(password, secured, NurApi.BANK_EPC, 32, epc.Length * 8, epc, xch); respLen = resp.tagBytes.Length; if (resp.error != NurApiErrors.NUR_NO_ERROR) { if (respLen >= MIN_ERROR_RESP_LENGTH) { InterpretedException("Get log state", resp); } DoException("Get log state", resp); } /* If the response is full, then the shelf life blocks and current shelf life are present. */ ls.hasShelfLife = (respLen >= LOGSTATE_FULL_BYTE_LEN); /* Big-endian bytes for crossings. */ bytePtr = 0; ls.eLowCnt = resp.tagBytes[bytePtr++]; ls.lowCnt = resp.tagBytes[bytePtr++]; ls.uprCnt = resp.tagBytes[bytePtr++]; ls.eUprCnt = resp.tagBytes[bytePtr++]; /* TODO: convert to uint -> get by masks. It is the "System Status" field, 32 bits. */ /* Measurement address pointer. */ ls.addrPtr = (int)GetBitsBigEndian(resp.tagBytes, BytesToBits(bytePtr), 10); /* Number of memory replacements. */ ls.nrOfRepl = (int)GetBitsBigEndian(resp.tagBytes, BytesToBits(bytePtr) + 10, 6); /* Number of measurements. */ ls.nrOfMeas = (int)GetBitsBigEndian(resp.tagBytes, BytesToBits(bytePtr) + 16, 15); /* Active? */ ls.sysActive = GetBit(resp.tagBytes, BytesToBits(bytePtr) + 15) == 1; bytePtr += 4; if (ls.hasShelfLife) { uint tmpVal; /* 64 bits for Shelf life block 0 & 1 + 24 bits for current shelf life = 8 + 3 = 11 bytes. */ /* Shelf life block 0: */ ls.shelfLife.actEnergy = resp.tagBytes[bytePtr++]; ls.shelfLife.normTemp = resp.tagBytes[bytePtr++]; ls.shelfLife.minTemp = resp.tagBytes[bytePtr++]; ls.shelfLife.maxTemp = resp.tagBytes[bytePtr++]; /* Shelf life block 1: */ tmpVal = GetBigEndian32FromBytes(resp.tagBytes, bytePtr); bytePtr += 4; ls.shelfLife.slAlgEn = IsMaskBitSet(tmpVal, FLAG_SL_EN_BIT); ls.shelfLife.negSlEn = IsMaskBitSet(tmpVal, FLAG_SL_NEG_EN_BIT); ls.shelfLife.slSensId = ((tmpVal >> SL_SENSID_LSH) & SL_SENSID_MASKVAL); ls.shelfLife.initTemp = ((tmpVal >> SL_INITTEMP_LSH) & SL_INITTEMP_MASKVAL); ls.shelfLife.initLife = ((tmpVal >> SL_INITLIFE_LSH) & SL_INITLIFE_MASKVAL);; /* Big-endian 24-bit value. */ ls.shelfLife.curShelfLife = resp.tagBytes[bytePtr++]; ls.shelfLife.curShelfLife <<= 8; ls.shelfLife.curShelfLife |= resp.tagBytes[bytePtr++]; ls.shelfLife.curShelfLife <<= 8; ls.shelfLife.curShelfLife |= resp.tagBytes[bytePtr++]; } flags = resp.tagBytes[bytePtr]; ls.actLogging = IsMaskBitSet(flags, FLG_ACT_LOG_BIT); ls.full = IsMaskBitSet(flags, FLG_MEASFULL_BIT); ls.overWritten = IsMaskBitSet(flags, FLG_OVRWR_BIT); ls.adError = IsMaskBitSet(flags, FLG_ADERR_BIT); ls.battLow = IsMaskBitSet(flags, FLG_LOWBATT_BIT); ls.slLowError = IsMaskBitSet(flags, FLG_SLLOWERRR_BIT); ls.slHighError = IsMaskBitSet(flags, FLG_SLHIGHERRR_BIT); ls.expired = IsMaskBitSet(flags, FLG_SLEXP_BIT); return(ls); }