i have an array of Uint8Array and it’s contain something like this , it has 40 element and the elements are like this
let incomePacket = new Uint8Array(40);
incomePacket[0] = 'G';
incomePacket[1] = 0x92;
incomePacket[2] = '0';
incomePacket[3] = '1';
incomePacket[4] = '2';
incomePacket[5] = '3';
incomePacket[6] = '4';
incomePacket[7] = '5';
incomePacket[8] = '6';
incomePacket[9] = '7';
incomePacket[10] = '8';
incomePacket[11] = '9';
incomePacket[12] = 'a';
incomePacket[13] = 'b';
incomePacket[14] = 'c';
incomePacket[15] = 'd';
incomePacket[16] = 'e';
incomePacket[17] = 'f';
incomePacket[18] = 'G';
incomePacket[19] = 'H';
//NEXT PACKET
incomePacket[20] = 'G';
incomePacket[21] = 6;
incomePacket[22] = 'q';
incomePacket[23] = 'w';
incomePacket[24] = 'e';
incomePacket[25] = 'r';
incomePacket[26] = 't';
incomePacket[27] = 'y';
incomePacket[28] = 0;
incomePacket[29] = 0;
incomePacket[30] = 0;
incomePacket[31] = 0;
incomePacket[32] = 0;
incomePacket[33] = 0;
incomePacket[34] = 0;
incomePacket[35] = 0;
incomePacket[36] = 0;
incomePacket[37] = 0;
incomePacket[38] = 0;
incomePacket[39] = 0;
and that packet come from embeded device from BLE plugin , now i want to parse it like this ;
constructor(public zone: NgZone, public navCtrl: NavController, public navParams: NavParams, public ble: BLE, platform: Platform) {
this.tab1 = WeeklySchedulePage;
this.tab2 = DateSchedulePage;
this.d = navParams.get("device")["id"];
// this.data = navParams.get("device").id;
this.device = navParams.get("device");
//this.connected = JSON.stringify(this.device);
platform.ready().then(() => {
ble.connect(navParams.get("device")["id"]).subscribe((p) => {
this.deviceId = navParams.get("device")["id"];
// this.d = "Success";
zone.run(() => {
this.status = "Connected"
// this.status = p.characteristics.length.toString()
})
this.total = [];
this.isGetContinue = false;
// this.data = JSON.stringify(p);
let lastChar = p.characteristics[4];
let serviceId = lastChar.service;
let chUUID = lastChar.characteristic;
this.serviceWriteID = serviceId;
this.serviceWriteUUID = chUUID;
let lastChar2 = p.characteristics[3];
let serviceId2 = lastChar2.service;
let chUUID2 = lastChar2.characteristic;
this.serviceNotificationId = serviceId2;
this.serviceNotificationUUID = chUUID2;
let lastCharRead = p.characteristics[0];
let serviceIdRead = lastChar.service;
let chUUIDRead = lastChar.characteristic;
this.ble.startNotification(this.navParams.get("device")["id"], this.serviceNotificationId, this.serviceNotificationUUID).subscribe(m => {
this.zone.run(()=>{
const BLE_RXD = new Uint8Array(m);
// this.data = String.fromCharCode.apply(null, BLE_RXD);
this.data += '\n' + String.fromCharCode.apply(null, new Uint8Array(m));
if (BLE_RXD[0] === 'G'.charCodeAt(0)) {
this.output = "IN G PORT";
if ((BLE_RXD[1] & 0x80) === 0x80)// we have a continus packet
{
this.d = "IN X80"
for (var i = 2; i < (BLE_RXD[1] & 0x7F) + 2; i++) {
this.all_rxd[this.packet_cnt] = BLE_RXD[i];
this.packet_cnt++;
}
}
else {
this.cdata = "IN ELSE"
for (var z = 2; z < (BLE_RXD[1] + 2); z++) {
this.all_rxd[this.packet_cnt] = BLE_RXD[z];
this.packet_cnt++;
}
this.packet_cnt = 0;
//print the whole recive packet
// console.log(this.all_rxd.toString());
// this.zone.run(() => {
// this.connected = "FINAL";
// })
}
}
})
})
but it never come to last else statement , when i manualy debug this code in non ionic enviroment with evertyhing work weel but in ionic it’s never come to last else