当前位置: 首页>>代码示例>>Python>>正文


Python GsmModem.processStoredSms方法代码示例

本文整理汇总了Python中gsmmodem.modem.GsmModem.processStoredSms方法的典型用法代码示例。如果您正苦于以下问题:Python GsmModem.processStoredSms方法的具体用法?Python GsmModem.processStoredSms怎么用?Python GsmModem.processStoredSms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gsmmodem.modem.GsmModem的用法示例。


在下文中一共展示了GsmModem.processStoredSms方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GSM

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import processStoredSms [as 别名]
class GSM(object):
    def __init__(self, port, baudrate, pin=None):
        self.sms_callbacks = []
        self.port = port
        self.baudrate = baudrate
        self.pin = pin

    def run(self):
        self.modem = GsmModem(self.port, self.baudrate,
                              smsReceivedCallbackFunc=self.sms_callback)
        self.modem.smsTextMode = False
        self.modem.connect(self.pin)

    def sms_callback(self, sms):
        logger.info(sms_receive_log_template.format(sms.number,
                                                    sms.time, sms.text))
        for callback in self.sms_callbacks:
            tornado.ioloop.IOLoop.instance().add_callback(callback, sms)

    def add_sms_callback(self, callback):
        self.sms_callbacks.append(callback)

    def process_stored_sms(self, delete=False):
        self.modem.processStoredSms()
开发者ID:senghoo,项目名称:operator,代码行数:26,代码来源:gsm.py

示例2: start

# 需要导入模块: from gsmmodem.modem import GsmModem [as 别名]
# 或者: from gsmmodem.modem.GsmModem import processStoredSms [as 别名]
	def start(self):
		"""	Samotne jadro daemona: setupneme GmailAPI, setupneme GSM modem a zacneme provadet nekonecnou smycku """
		self.running = True

		# (0) SETUP VIRTUAL SERIAL PORT FOR MODEM
		if "virtualPortInitCommand" in myconfig['modem']:
			try:
				virtualSerialPortInstance = virtualSerialPort(myconfig['modem']['virtualPortInitCommand'])
				virtualSerialPortInstance.start()
			except:
				pass
		else:
			virtualSerialPortInstance = None

		# (1) SETUP GMAIL ACCESS
		logging.info('Initializing GMAIL access...')
		try:
			gmailService = gmailUtils.get_service(self.cwd)
		except RuntimeError as e:
			print(str(e))
			logging.critical(str(e))
			if (virtualSerialPortInstance is not None):
				virtualSerialPortInstance.stop()
			#sys.exit(1)
			self.stop()
		
		######################################################################################################################################################
		# (2) SETUP GSM MODEM + bind a "smsReceived" callback + poll gmail inbox
		logging.info('Initializing GSM modem on {0} port @ {1} speed...'.format(myconfig['modem']['port'], myconfig['modem']['baudrate']))
		modem = GsmModem(myconfig['modem']['port'], myconfig['modem']['baudrate'], smsReceivedCallbackFunc=self.incomingSmsHandler)
		modem.smsTextMode = False

		while self.running:
			# start of gsm init loop
			try:
				modem.connect(myconfig['modem']['pin'])
			except serial.SerialException:
				logging.error('Error: Cannot connect to modem on serial port %s @ %s. Trying again in %d sec...' % (myconfig['modem']['port'], myconfig['modem']['baudrate'], myconfig['modem']['errorRetryWaitTime']))
				time.sleep(myconfig['modem']['errorRetryWaitTime'])
			except TimeoutException:
				logging.error('Error: Serial device %s @ %s timeout. Trying again in %d sec...' % (myconfig['modem']['port'], myconfig['modem']['baudrate'], myconfig['modem']['errorRetryWaitTime']))
				time.sleep(myconfig['modem']['errorRetryWaitTime'])
			except PinRequiredError:
				# Fatal error
				logging.critical('Error: SIM card PIN required. Please provide PIN in the config file.')
				self.stop()
				return 1
			except IncorrectPinError:
				# Fatal error
				logging.critical('Error: Incorrect SIM card PIN entered!')
				self.stop()
				return 1
			else:
				logging.info('Modem connected.')
				try:
					logging.info('Checking for network coverage...')
					modem.waitForNetworkCoverage(8) # of seconds
				except TimeoutException:
					logging.warning('We can now start gmail inbox polling infinite loop.')
					print('Network signal strength is not sufficient, please adjust modem position/antenna and try again.')
					modem.close()
				else:
					logging.info('GSM modem is ready.')  
					logging.info('We are now handling all incoming SMS messages.') 

					try:
						if (myconfig['incomingSmsHandlerSetup']['processStoredSms'] == "all"):
							modem.processStoredSms(unreadOnly=False)
						elif (myconfig['incomingSmsHandlerSetup']['processStoredSms'] == "unread"):
							modem.processStoredSms(unreadOnly=True)
					except Exception as e:
						logging.critical("Nastal problem pri zpracovani drivejsich neprectenych SMS:")
						raise
						sys.exit(0)
					else:
						logging.info('We can now start gmail inbox polling infinite loop.')

						try:
							while self.running:
								# start of main gmail loop
								logging.debug('Checking incoming emails...') 
								newMessagesCount = self.incomingGmailHandler(gmailService, modem)
								time.sleep(myconfig['general']['gmailQueueWaitingPeriod'] if newMessagesCount > 0 else myconfig['general']['gmailPollingInterval'])
								# end of main gmail loop
						except KeyboardInterrupt:
							#sys.exit(0)
							self.stop()
							return 0
						except Exception as e:
							print("Nastala vyjimka v hlavni smycce daemona, viz log.")
							logging.exception("Nastal problem v hlavni smycce:")
							raise
						finally:
							print("Bye gmail loop.")
					finally:
						print("Bye stored sms handling try-cache.")
				finally:
					print("Bye.")
					modem.close()
					if (virtualSerialPortInstance is not None):
#.........这里部分代码省略.........
开发者ID:babca,项目名称:plutaniumSmsServer,代码行数:103,代码来源:server.py


注:本文中的gsmmodem.modem.GsmModem.processStoredSms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。