def test_filename(self): testfile = tempfile.NamedTemporaryFile(suffix='.debug', delete=False) testfile.close() try: gammu.SetDebugFile(testfile.name) self.check_operation(testfile.name) finally: gammu.SetDebugFile(None) os.unlink(testfile.name)
def test_nothing(self): gammu.SetDebugLevel('nothing') testfile = tempfile.NamedTemporaryFile(suffix='.debug', delete=False) testfile.close() try: gammu.SetDebugFile(testfile.name) self.check_operation(None) with open(testfile.name, 'r') as handle: self.assertEqual('', handle.read()) finally: gammu.SetDebugFile(None) os.unlink(testfile.name)
def setUpGammu(): # fish out the global var global sm # setups the SMS gammu system # returns true if all good # return false if there are issues if debug is True: logging.debug('About to put gammu into debug mode logging to: ' + str(logfile)) gammu.SetDebugLevel('errorsdate') gammu.SetDebugFile(logfile) # create a state machine sm = gammu.StateMachine() # try and read the config try: sm.ReadConfig(Filename='/home/pi/.gammurc') except Exception, e: logging.error('gammu Readconfig failed' + str(e)) sm = None return # ok went bad - return false return False
def test_filename(self): testfile = tempfile.NamedTemporaryFile(suffix='.debug') try: gammu.SetDebugFile(testfile.name) self.check_operation(testfile.name) finally: testfile.close()
def check_operation(self, filename, handle=None): """ Executes gammu operation which causes debug logs. """ gammu.DecodePDU(PDU_DATA) gammu.SetDebugFile(None) if handle: handle.close() if filename is not None: with open(filename, 'r') as handle: self.assertTrue('SMS type: Status report' in handle.read())
def info(): ''' Displays configuration summary and tries to connect to phone. ''' import Wammu.WammuSettings import Wammu.Utils import gammu settings = Wammu.WammuSettings.WammuConfig() section = settings.ReadInt('/Gammu/Section') config = settings.gammu.GetConfig(section) if config['Connection'] == '' or config['Device'] == '': print(_('Wammu is not configured!')) cfg = { 'StartInfo': settings.ReadBool('/Gammu/StartInfo'), 'UseGlobalDebugFile': True, 'DebugFile': None, # Set on other place 'SyncTime': settings.ReadBool('/Gammu/SyncTime'), 'Connection': config['Connection'], 'LockDevice': settings.ReadBool('/Gammu/LockDevice'), 'DebugLevel': 'textalldate', # Set on other place 'Device': config['Device'], 'Model': config['Model'], } # Compatibility with old Gammu versions cfg = Wammu.Utils.CompatConfig(cfg) print(_('Wammu configuration:')) print('%-15s: %s' % (_('Connection'), cfg['Connection'])) print('%-15s: %s' % (_('Model'), cfg['Model'])) print('%-15s: %s' % (_('Device'), cfg['Device'])) print(_('Connecting...')) if Wammu.debug: gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textalldate') sm = gammu.StateMachine() sm.SetConfig(0, cfg) sm.Init() print(_('Getting phone information...')) Manufacturer = sm.GetManufacturer() Model = sm.GetModel() IMEI = sm.GetIMEI() Firmware = sm.GetFirmware() Code = sm.GetSecurityStatus() print(_('Phone infomation:')) print('%-15s: %s' % (_('Manufacturer'), Manufacturer)) print('%-15s: %s (%s)' % (_('Model'), Model[0], Model[1])) print('%-15s: %s' % (_('IMEI'), IMEI)) print('%-15s: %s' % (_('Firmware'), Firmware[0])) if Code is not None: print('%-15s: %s' % (_('Requested code'), Code))
def main(): # Global debug level gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textall') state_machine = gammu.StateMachine() state_machine.ReadConfig() # Use global debug stub regardless configuration c = state_machine.GetConfig(0) c['UseGlobalDebugFile'] = True state_machine.SetConfig(0, c) state_machine.Init() manufacturer = state_machine.GetManufacturer() model = state_machine.GetModel() imei = state_machine.GetIMEI() firmware = state_machine.GetFirmware() print('Phone infomation:') print(('{0:<15}: {1}'.format('Manufacturer', manufacturer))) print(('{0:<15}: {1} ({2})'.format('Model', model[0], model[1]))) print(('{0:<15}: {1}'.format('IMEI', imei))) print(('{0:<15}: {1}'.format('Firmware', firmware[0])))
async def main(): gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textall') config = dict(Device="/dev/ttyS6", Connection="at") worker = gammu.asyncworker.GammuAsyncWorker() worker.configure(config) try: await worker.init_async() await get_info(worker) await get_network_info(worker) await send_message_async(worker, '6700', 'BAL') # Just a busy waiting for event # We need to keep communication with phone to get notifications print('Press Ctrl+C to interrupt') while 1: try: signal = await worker.get_signal_quality_async() print('Signal is at {0:d}%'.format(signal['SignalPercent'])) except Exception as e: print('Exception reading signal: {0}'.format(e)) await asyncio.sleep(10); except Exception as e: print('Exception:') print(e) print("Terminate Start") await worker.terminate_async() print("Terminate Done")
#!/usr/bin/env python import gammu import sys # Global debug level gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textall') sm = gammu.StateMachine() sm.ReadConfig() # Use global debug stub regardless configuration c = sm.GetConfig(0) c['UseGlobalDebugFile'] = True sm.SetConfig(0, c) sm.Init() Manufacturer = sm.GetManufacturer() Model = sm.GetModel() IMEI = sm.GetIMEI() Firmware = sm.GetFirmware() print _('Phone infomation:') print '%-15s: %s' % (_('Manufacturer'), Manufacturer) print '%-15s: %s (%s)' % (_('Model'), Model[0], Model[1]) print '%-15s: %s' % (_('IMEI'), IMEI) print '%-15s: %s' % (_('Firmware'), Firmware[0])
def setUp(self): if 'GAMMU_DEBUG' in os.environ: gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textall')
def test_none(self): gammu.SetDebugFile(None) self.check_operation(None)
from GammuActions import * import gammu import logging import sys import threading log = logging.getLogger('gammu-manager') #esempio di uso ''' # Global debug level gammu.SetDebugFile(sys.stderr) gammu.SetDebugLevel('textall') sm = gammu.StateMachine() sm.ReadConfig() sm.setConfig() # Use global debug stub regardless configuration #c = sm.GetConfig(0) #c['UseGlobalDebugFile'] = True #sm.SetConfig(0, c) sm.Init() ''' class GammuStatus: DISCONNECTED = 0 CONNECTING = 1