コード例 #1
0
ファイル: GsmPhone.cs プロジェクト: gbmakaveli/GSMComm
		/// <summary>
		/// AT+CNMI. Selects the procedure for indicating new messages received from the network.
		/// </summary>
		/// <param name="settings">A <see cref="T:GsmComm.GsmCommunication.MessageIndicationSettings" /> structure containing the
		/// detailed settings.</param>
		/// <remarks>The function switches to the PDU mode before setting the notifications. This
		/// causes all short messages, that are directly routed, to be presented in PDU mode. If the mode
		/// is changed (such as a switch to the text mode), all indications (containing a message) following the
		/// change are sent in the new mode.
		/// </remarks>
		public void SetMessageIndications(MessageIndicationSettings settings)
		{
			lock (this)
			{
				this.VerifyValidConnection();
				this.ActivatePduMode();
				this.LogIt(LogLevel.Info, "Setting message notifications...");
				object[] mode = new object[5];
				mode[0] = settings.Mode;
				mode[1] = settings.DeliverStyle;
				mode[2] = settings.CellBroadcastStyle;
				mode[3] = settings.StatusReportStyle;
				mode[4] = settings.BufferSetting;
				string str = string.Format("AT+CNMI={0},{1},{2},{3},{4}", mode);
				this.ExecAndReceiveMultiple(str);
			}
		}
コード例 #2
0
ファイル: GsmPhone.cs プロジェクト: gbmakaveli/GSMComm
		/// <summary>
		/// AT+CNMI. Gets the current message notification settings.
		/// </summary>
		/// <returns>A <see cref="T:GsmComm.GsmCommunication.MessageIndicationSettings" /> structure containing the detailed settings.</returns>
		public MessageIndicationSettings GetMessageIndications()
		{
			MessageIndicationSettings messageIndicationSetting;
			lock (this)
			{
				this.VerifyValidConnection();
				this.LogIt(LogLevel.Info, "Getting current message indications...");
				string str = this.ExecAndReceiveMultiple("AT+CNMI?");
				Regex regex = new Regex("\\+CNMI: (\\d+),(\\d+),(\\d+),(\\d+),(\\d+)");
				Match match = regex.Match(str);
				if (!match.Success)
				{
					this.HandleCommError(str);
					throw new CommException("Unexpected response.", str);
				}
				else
				{
					MessageIndicationSettings messageIndicationSetting1 = new MessageIndicationSettings();
					messageIndicationSetting1.Mode = int.Parse(match.Groups[1].Value);
					messageIndicationSetting1.DeliverStyle = int.Parse(match.Groups[2].Value);
					messageIndicationSetting1.CellBroadcastStyle = int.Parse(match.Groups[3].Value);
					messageIndicationSetting1.StatusReportStyle = int.Parse(match.Groups[4].Value);
					messageIndicationSetting1.BufferSetting = int.Parse(match.Groups[5].Value);
					object[] mode = new object[5];
					mode[0] = messageIndicationSetting1.Mode;
					mode[1] = messageIndicationSetting1.DeliverStyle;
					mode[2] = messageIndicationSetting1.CellBroadcastStyle;
					mode[3] = messageIndicationSetting1.StatusReportStyle;
					mode[4] = messageIndicationSetting1.BufferSetting;
					this.LogIt(LogLevel.Info, string.Format("mode={0:g}, mt={1:g}, bm={2:g}, ds={3:g}, bfr={4:g}", mode));
					messageIndicationSetting = messageIndicationSetting1;
				}
			}
			return messageIndicationSetting;
		}
コード例 #3
0
ファイル: GsmCommMain.cs プロジェクト: gbmakaveli/GSMComm
		/// <summary>
		/// Enables direct routing of new received short messages to the application.
		/// </summary>
		/// <remarks>
		/// <para>When a new message is received that is either a standard SMS message or a status report,
		/// the <see cref="E:GsmComm.GsmCommunication.GsmCommMain.MessageReceived" /> event is fired. The <see cref="T:GsmComm.GsmCommunication.IMessageIndicationObject" />
		/// in this event must be cast to a <see cref="T:GsmComm.GsmCommunication.ShortMessage" /> object which can then be decoded using
		/// <see cref="M:GsmComm.GsmCommunication.GsmCommMain.DecodeReceivedMessage(GsmComm.GsmCommunication.ShortMessage)" />.</para>
		/// <para><b>CAUTION:</b> Because the messages are forwared directly, they are <b>not</b> saved in the phone.
		/// If for some reason the message must be saved it must explicitly be done afterwards. Either by using
		/// the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessage(GsmComm.GsmCommunication.ShortMessage,System.String,System.Int32)" /> or <see cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessageWithoutStatus(GsmComm.GsmCommunication.ShortMessage,System.String)" /> functions
		/// to write the message back to the phone or by storing the message somewhere else for later use.</para>
		/// <para>It may be necessary to acknlowledge new routed messages to the phone, either because this
		/// is desired for reliable message transfer or because it is preconfigured in the phone. Use 
		/// <see cref="M:GsmComm.GsmCommunication.GsmCommMain.IsAcknowledgeRequired" /> to find out if acknowledgements must be done. To do the actual
		/// acknowledge, use <see cref="M:GsmComm.GsmCommunication.GsmCommMain.AcknowledgeNewMessage" />.</para>
		/// <para>The supported routing settings vary between different phone models. Therefore the phone is
		/// queried first and then the supported settings of the phone are compared to the settings needed for
		/// the routing functionality to work. If a specific setting is not supported and there is no
		/// alternative setting possible, an exception will be raised.</para>
		/// <para>To disable message routing, use the <see cref="M:GsmComm.GsmCommunication.GsmCommMain.DisableMessageRouting" /> function.</para>
		/// <para>EnableMessageRouting can't be used with <see cref="M:GsmComm.GsmCommunication.GsmCommMain.EnableMessageNotifications" /> at the same time.
		/// Disable one functionality before using the other.</para>
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.DisableMessageRouting" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.EnableMessageNotifications" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.DecodeReceivedMessage(GsmComm.GsmCommunication.ShortMessage)" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessage(GsmComm.GsmCommunication.ShortMessage,System.String,System.Int32)" />
		/// <seealso cref="M:GsmComm.GsmCommunication.GsmCommMain.WriteRawMessageWithoutStatus(GsmComm.GsmCommunication.ShortMessage,System.String)" />
		/// </remarks>
		public void EnableMessageRouting()
		{
			MessageIndicationSupport supportedIndications = this.theDevice.GetSupportedIndications();
			MessageIndicationMode messageIndicationMode = MessageIndicationMode.BufferAndFlush;
			if (!supportedIndications.SupportsMode(messageIndicationMode))
			{
				if (supportedIndications.SupportsMode(MessageIndicationMode.SkipWhenReserved))
				{
					messageIndicationMode = MessageIndicationMode.SkipWhenReserved;
				}
				else
				{
					if (supportedIndications.SupportsMode(MessageIndicationMode.ForwardAlways))
					{
						messageIndicationMode = MessageIndicationMode.ForwardAlways;
					}
					else
					{
						throw new CommException("The phone does not support any of the required message indication modes.");
					}
				}
			}
			SmsDeliverIndicationStyle smsDeliverIndicationStyle = SmsDeliverIndicationStyle.RouteMessage;
			if (supportedIndications.SupportsDeliverStyle(smsDeliverIndicationStyle))
			{
				CbmIndicationStyle cbmIndicationStyle = CbmIndicationStyle.Disabled;
				SmsStatusReportIndicationStyle smsStatusReportIndicationStyle = SmsStatusReportIndicationStyle.RouteMessage;
				if (!supportedIndications.SupportsStatusReportStyle(smsStatusReportIndicationStyle))
				{
					this.LogIt(LogLevel.Warning, "Attention: The phone does not support routing of new status reports. As a fallback it will be disabled.");
					smsStatusReportIndicationStyle = SmsStatusReportIndicationStyle.Disabled;
				}
				IndicationBufferSetting indicationBufferSetting = IndicationBufferSetting.Flush;
				if (!supportedIndications.SupportsBufferSetting(indicationBufferSetting))
				{
					if (supportedIndications.SupportsBufferSetting(IndicationBufferSetting.Clear))
					{
						indicationBufferSetting = IndicationBufferSetting.Clear;
					}
					else
					{
						throw new CommException("The phone does not support any of the required buffer settings.");
					}
				}
				MessageIndicationSettings messageIndicationSetting = new MessageIndicationSettings(messageIndicationMode, smsDeliverIndicationStyle, cbmIndicationStyle, smsStatusReportIndicationStyle, indicationBufferSetting);
				this.theDevice.SetMessageIndications(messageIndicationSetting);
				return;
			}
			else
			{
				throw new CommException("The phone does not support routing of standard SMS (SMS-DELIVER) messages.");
			}
		}