0 Replies
      Latest reply on Aug 29, 2019 7:42 AM by karthickaitech
      karthickaitech Level 1 Level 1 (0 points)

        We send the chunk data based on the MTU, we are re-sending the missed packets by saving it in the array and adding header to each packet.

        While re-sending there are still some more missed packets.

        Code snippet for ref:

         

        -(void)SendingBytes{
          while (self.dataToSend.length > self.sendDataIndex) {
            NSInteger amountToSend = self.dataToSend.length - self.sendDataIndex;
           
            if (amountToSend > NOTIFY_MTU) {
              amountToSend = NOTIFY_MTU;
            }
        
            NSData *chunk = [NSData dataWithBytes:self.dataToSend.bytes+self.sendDataIndex length:amountToSend];
            //adding to the header with chunk
            NSString *strData = [NSString stringWithFormat:@"%dHello %@",CountValue,chunk];
            NSData *ChunkHeaderAddded = [strData dataUsingEncoding:NSUTF8StringEncoding];
            NSLog(@"%@",ChunkHeaderAddded);
            CountValue = CountValue + 1;
            Boolean boolValue = (self.ConnectingPeripheral.canSendWriteWithoutResponse);
            if (!boolValue) {
              [EmptyReceiveImagedata insertObject:ChunkHeaderAddded atIndex:0];
        //      return;
            }
            [self.ConnectingPeripheral writeValue:ChunkHeaderAddded forCharacteristic:self.characterstics type:CBCharacteristicWriteWithoutResponse];
            self.sendDataIndex += amountToSend;
          }
          if (self.completionFlag == false) {
            self.sendDataIndex = 0;
            NSLog(@"CountOf ---> %lu",(unsigned long)EmptyReceiveImagedata.count);
            while (EmptyReceiveImagedata.count > self.sendDataIndex) {
              NSLog(@"sendData ---> %ld",(long)self.sendDataIndex);
        //      Boolean boolValue = (self.ConnectingPeripheral.canSendWriteWithoutResponse);
        //      if (!boolValue) {
        //        return;
        //      }
              [self.ConnectingPeripheral writeValue:[EmptyReceiveImagedata objectAtIndex:self.sendDataIndex] forCharacteristic:self.characterstics type:CBCharacteristicWriteWithoutResponse];
              self.sendDataIndex = self.sendDataIndex + 1;
            }
            float count = (10 * self.sendDataIndex)/ self.dataToSend.length;
            completion = count / 10;
            [_BleDelegate progressBarCallback: completion];
            NSData *Eom = [@"Completed" dataUsingEncoding:NSUTF8StringEncoding];
            [self.ConnectingPeripheral writeValue:Eom forCharacteristic:self.characterstics type:CBCharacteristicWriteWithoutResponse];
            [_BleDelegate connnectingStatus:false];
            [_BleDelegate didCompleteStatus];
            self.completionFlag = true;
            [self.ConnectingPeripheral setNotifyValue:YES forCharacteristic:self.characterstics];
            NSLog(@"SentAll the packets");
            [self Notification:@"Sent all the packets"];
            completion = 0.0;
          }

        How to resend the packets which are not sent when transferring data from central to peripherals using WriteWithoutResponse ?