/// <summary> /// Delete all sim contacts list /// </summary> public static void DeleteAllSimContactsList() { string emptyRecord = new string('F', SimADNRecordLen * 2); string expRecord = "9000"; string retCmd = ""; for (int rid = 1; rid <= GlobalObjUI.SimADNRecordCount; rid++) { // if record isn't empty if (!SimADNRecordEmptyID.Contains(rid)) { // Set record id SimADNPosition = rid; simCommand = "A0DC" + rid.ToString("X2") + "04" + SimADNRecordLen.ToString("X2") + emptyRecord; simExpResponse = expRecord; simResponse = ""; simRespOk = false; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI.Sim::DeleteAllSimContactsList: WRITE ADN REC " + rid.ToString("d3") + " " + simCommand + " < " + simResponse); if (retCmd != "") { // error detected SimADNError = retCmd; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } if (!simRespOk) { // wrong response SimADNError = "WRONG RESPONSE: [" + simExpResponse + "] - [" + simResponse + "]"; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } // send notify to gui MonosimEvent(new object(), new EventArgs()); } } SimADNStatus = 2; // send notify to gui MonosimEvent(new object(), new EventArgs()); }
/// <summary> /// Read sim contacts list. /// </summary> public static void ReadSimContactsList() { string emptyRecord = new string('F', SimADNRecordLen * 2) + "9000"; string expRecord = new string('?', SimADNRecordLen * 2) + "9000"; string retCmd = ""; SimADNRecordNoEmpty = 0; ADNrecords = new List <string>(); SimADNRecordEmptyID = new List <int>(); SimContacts = new Contacts(); // loop for each ADN records for (int l = 1; l <= SimADNRecordCount; l++) { // Set record id SimADNPosition = l; // Prepare sim command simCommand = "A0B2" + l.ToString("X2") + "04" + SimADNRecordLen.ToString("X2"); simExpResponse = expRecord; simResponse = ""; simRespOk = false; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI.Sim::ReadSimContactsList: READ ADN REC " + l.ToString("d3") + " " + simResponse); if (retCmd != "") { // error detected SimADNError = retCmd; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } if (!simRespOk) { // wrong response SimADNError = "WRONG RESPONSE: [" + simExpResponse + "] - [" + simResponse + "]"; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } // check for not empty records if (simResponse != emptyRecord) { // increment counter of not empty records SimADNRecordNoEmpty++; // update records list ADNrecords.Add(simResponse.Substring(0, simResponse.Length - 4)); } else { // Add to Empty record list SimADNRecordEmptyID.Add(l); } // send notify to gui MonosimEvent(new object(), new EventArgs()); } SimADNStatus = 2; // send notify to gui MonosimEvent(new object(), new EventArgs()); }
/// <summary> /// Select ADN file on sim and extract main info /// </summary> private static string ReadADN() { // Select 7F10 (DF TELECOM) simCommand = "A0A40000027F10"; simExpResponse = "9F??"; string retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI::ReadADN: SELECT DF TELECOM " + simResponse); if (retCmd != "") { return(retCmd); } if (!simRespOk) { return("WRONG RESPONSE [" + simExpResponse + "] " + "[" + simResponse + "]"); } // Select 6F3A (ADN) simCommand = "A0A40000026F3A"; simExpResponse = "9F??"; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI::ReadADN: SELECT ADN " + simResponse); if (retCmd != "") { return(retCmd); } if (!simRespOk) { return("WRONG RESPONSE [" + simExpResponse + "] " + "[" + simResponse + "]"); } // Get Response 6F3A (ADN) simCommand = "A0C00000" + simResponse.Substring(2, 2); simExpResponse = new string('?', Convert.ToInt32(simResponse.Substring(2, 2), 16) * 2) + "9000"; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI::ReadADN: GET RESPONSE " + simResponse); if (retCmd != "") { return(retCmd); } if (!simRespOk) { return("WRONG RESPONSE [" + simExpResponse + "] " + "[" + simResponse + "]"); } // Update ADN values SimADNRecordLen = Convert.ToInt32(simResponse.Substring(28, 2), 16); SimADNFileLen = Convert.ToInt32(simResponse.Substring(4, 4), 16); SimADNRecordCount = GlobalObjUI.SimADNFileLen / GlobalObjUI.SimADNRecordLen; SimADNMaxAlphaChars = GlobalObjUI.SimADNRecordLen - 14; log.Debug("GlobalObjUI::ReadADN: File len ...... : " + SimADNFileLen.ToString()); log.Debug("GlobalObjUI::ReadADN: Record len .... : " + SimADNRecordLen.ToString()); log.Debug("GlobalObjUI::ReadADN: Record count .. : " + SimADNRecordCount.ToString()); log.Debug("GlobalObjUI::ReadADN: Max Alpha chars : " + SimADNMaxAlphaChars.ToString()); return(""); }
public static void WriteSimContactsList(Contacts contacts, bool isAppend) { string emptyRecord = new string('F', SimADNRecordLen * 2); string expRecord = "9000"; string retCmd = ""; string retRecord = ""; int adnRec = 0; // loop for each ADN records for (int cid = 0; cid < contacts.SimContacts.Count; cid++) { if (!isAppend) { // first record adnRec = cid + 1; } else { // first empty record adnRec = SimADNRecordEmptyID[cid]; } // Set record id SimADNPosition = adnRec; // Prepare sim command simCommand = "A0DC" + adnRec.ToString("X2") + "04" + SimADNRecordLen.ToString("X2"); retStr = PrepareRecord(contacts.SimContacts[cid], out retRecord); if (retStr != "") { // error detected SimADNError = retStr; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } simCommand += retRecord; simExpResponse = expRecord; simResponse = ""; simRespOk = false; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI.Sim::WriteSimContactsList: WRITE ADN REC " + adnRec.ToString("d3") + " " + simCommand + " < " + simResponse); if (retCmd != "") { // error detected SimADNError = retCmd; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } if (!simRespOk) { // wrong response SimADNError = "WRONG RESPONSE: [" + simExpResponse + "] - [" + simResponse + "]"; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } // send notify to gui MonosimEvent(new object(), new EventArgs()); } if (!isAppend) { // delete old other records for (int rid = adnRec + 1; rid <= GlobalObjUI.SimADNRecordCount; rid++) { if (!SimADNRecordEmptyID.Contains(rid)) { // Set record id SimADNPosition = rid; simCommand = "A0DC" + rid.ToString("X2") + "04" + SimADNRecordLen.ToString("X2") + emptyRecord; simExpResponse = expRecord; simResponse = ""; simRespOk = false; retCmd = SendReceiveAdv(simCommand, ref simResponse, simExpResponse, ref simRespOk); log.Debug("GlobalObjUI.Sim::WriteSimContactsList: WRITE ADN REC " + rid.ToString("d3") + " " + simCommand + " < " + simResponse); if (retCmd != "") { // error detected SimADNError = retCmd; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } if (!simRespOk) { // wrong response SimADNError = "WRONG RESPONSE: [" + simExpResponse + "] - [" + simResponse + "]"; SimADNStatus = 3; // send notify to gui MonosimEvent(new object(), new EventArgs()); return; } // send notify to gui MonosimEvent(new object(), new EventArgs()); } } } SimADNStatus = 2; // send notify to gui MonosimEvent(new object(), new EventArgs()); }