public virtual async Task <YSms> fetchPdu(int slot)
        {
            byte[]        binPdu;
            List <string> arrPdu = new List <string>();
            string        hexPdu;
            YSms          sms;

            binPdu = await this._download("sms.json?pos=" + Convert.ToString(slot) + "&len=1");

            arrPdu = this.imm_json_get_array(binPdu);
            hexPdu = this.imm_decode_json_string(arrPdu[0]);
            sms    = new YSms(this);
            await sms.set_slot(slot);

            await sms.parsePdu(YAPIContext.imm_hexStrToBin(hexPdu));

            return(sms);
        }
        public virtual async Task <int> checkNewMessages()
        {
            string bitmapStr;

            byte[]        prevBitmap;
            byte[]        newBitmap;
            int           slot;
            int           nslots;
            int           pduIdx;
            int           idx;
            int           bitVal;
            int           prevBit;
            int           i;
            int           nsig;
            int           cnt;
            string        sig;
            List <YSms>   newArr     = new List <YSms>();
            List <YSms>   newMsg     = new List <YSms>();
            List <YSms>   newAgg     = new List <YSms>();
            List <string> signatures = new List <string>();
            YSms          sms;

            bitmapStr = await this.get_slotsBitmap();

            if (bitmapStr == _prevBitmapStr)
            {
                return(YAPI.SUCCESS);
            }
            prevBitmap     = YAPIContext.imm_hexStrToBin(_prevBitmapStr);
            newBitmap      = YAPIContext.imm_hexStrToBin(bitmapStr);
            _prevBitmapStr = bitmapStr;
            nslots         = 8 * (newBitmap).Length;
            newArr.Clear();
            newMsg.Clear();
            signatures.Clear();
            nsig = 0;
            // copy known messages
            pduIdx = 0;
            while (pduIdx < _pdus.Count)
            {
                sms  = _pdus[pduIdx];
                slot = await sms.get_slot();

                idx = ((slot) >> (3));
                if (idx < (newBitmap).Length)
                {
                    bitVal = ((1) << ((((slot) & (7)))));
                    if ((((newBitmap[idx]) & (bitVal))) != 0)
                    {
                        newArr.Add(sms);
                        if (await sms.get_concatCount() == 0)
                        {
                            newMsg.Add(sms);
                        }
                        else
                        {
                            sig = await sms.get_concatSignature();

                            i = 0;
                            while ((i < nsig) && ((sig).Length > 0))
                            {
                                if (signatures[i] == sig)
                                {
                                    sig = "";
                                }
                                i = i + 1;
                            }
                            if ((sig).Length > 0)
                            {
                                signatures.Add(sig);
                                nsig = nsig + 1;
                            }
                        }
                    }
                }
                pduIdx = pduIdx + 1;
            }
            // receive new messages
            slot = 0;
            while (slot < nslots)
            {
                idx     = ((slot) >> (3));
                bitVal  = ((1) << ((((slot) & (7)))));
                prevBit = 0;
                if (idx < (prevBitmap).Length)
                {
                    prevBit = ((prevBitmap[idx]) & (bitVal));
                }
                if ((((newBitmap[idx]) & (bitVal))) != 0)
                {
                    if (prevBit == 0)
                    {
                        sms = await this.fetchPdu(slot);

                        newArr.Add(sms);
                        if (await sms.get_concatCount() == 0)
                        {
                            newMsg.Add(sms);
                        }
                        else
                        {
                            sig = await sms.get_concatSignature();

                            i = 0;
                            while ((i < nsig) && ((sig).Length > 0))
                            {
                                if (signatures[i] == sig)
                                {
                                    sig = "";
                                }
                                i = i + 1;
                            }
                            if ((sig).Length > 0)
                            {
                                signatures.Add(sig);
                                nsig = nsig + 1;
                            }
                        }
                    }
                }
                slot = slot + 1;
            }
            _pdus = newArr;
            // append complete concatenated messages
            i = 0;
            while (i < nsig)
            {
                sig    = signatures[i];
                cnt    = 0;
                pduIdx = 0;
                while (pduIdx < _pdus.Count)
                {
                    sms = _pdus[pduIdx];
                    if (await sms.get_concatCount() > 0)
                    {
                        if (await sms.get_concatSignature() == sig)
                        {
                            if (cnt == 0)
                            {
                                cnt = await sms.get_concatCount();

                                newAgg.Clear();
                            }
                            newAgg.Add(sms);
                        }
                    }
                    pduIdx = pduIdx + 1;
                }
                if ((cnt > 0) && (newAgg.Count == cnt))
                {
                    sms = new YSms(this);
                    await sms.set_parts(newAgg);

                    newMsg.Add(sms);
                }
                i = i + 1;
            }
            _messages = newMsg;
            return(YAPI.SUCCESS);
        }