Skip to content

Commit

Permalink
Merge pull request #371 from svenauhagen/devel
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgarga committed Jul 28, 2017
2 parents 986bb19 + 1f6933d commit 2e89533
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 30 deletions.
3 changes: 1 addition & 2 deletions net/pfSense-pkg-cellular/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# $FreeBSD$

PORTNAME= pfSense-pkg-cellular
PORTVERSION= 1.1.4
PORTREVISION= 1
PORTVERSION= 1.1.5
CATEGORIES= net
MASTER_SITES= # empty
DISTFILES= # empty
Expand Down
85 changes: 60 additions & 25 deletions net/pfSense-pkg-cellular/files/usr/local/sbin/cellular.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
"""
CLI for lte cards in pfsense systems.
2016 by Fabian Schweinfurth [email protected] (Voleatech GmbH Pfullingen, Germany)
2016 - 2017 by Voleatech GmbH ([email protected])
"""

import sys
import os
import time

import argparse
import ConfigParser
Expand All @@ -38,7 +39,9 @@
huawei = (lambda a: a.startswith("Huawei"))

class CellularInterface:
"""Cellular Serial interface for LTE cards by Voleatech."""
"""
Cellular Serial interface for LTE cards by Voleatech.
"""

DEBUG = False

Expand Down Expand Up @@ -93,7 +96,9 @@ def set_timeout(self, t):
self.timeout = t

def set_config(self, args):
"""write config to .cellular.conf"""
"""
write config to .cellular.conf
"""
tmp = ConfigParser.ConfigParser()

if (os.path.isfile(self.conf)):
Expand All @@ -113,9 +118,11 @@ def set_config(self, args):
print("OK", file=sys.stdout)

def init_hardware(self):
"""write hardware information to .cellular.conf.
"""
write hardware information to .cellular.conf.
sets self.module and self.manufacturer"""
sets self.module and self.manufacturer
"""

tmp = ConfigParser.ConfigParser()

Expand Down Expand Up @@ -160,7 +167,9 @@ def init_hardware(self):
tmp.write(f)

def init_config(self, config_file):
"""initialize config file if not present or from old version."""
"""
initialize config file if not present or from old version.
"""

#make sure confdir exists
if (not os.path.isdir(self.confdir)):
Expand Down Expand Up @@ -208,7 +217,8 @@ def at_cmd(self, cmd, args, short = False):
cmd - AT command without <AT> at the beginning
to_stdout - should answer be printed to stdout? (default True)
return (return code, answer)."""
return (return code, answer).
"""

import re

Expand All @@ -222,8 +232,17 @@ def at_cmd(self, cmd, args, short = False):
return ("-1", "-1")

# send AT command
ret = self.ser.write("AT{}\r".format(cmd))
answ = self.ser.read(1024)
# We will try 3 times since the modem is sometimes busy
for x in range(0, 2):

ret = self.ser.write("AT{}\r".format(cmd))
answ = self.ser.read(1024)

# better save than sorry
if "OK" in answ:
break

time.sleep(0.2)

# better save than sorry
if ("ERROR" in answ) or (not "OK" in answ):
Expand All @@ -244,7 +263,9 @@ def at_cmd(self, cmd, args, short = False):
return (ret, answ)

def custom_command(self, args):
"""send a custom command to the module"""
"""
send a custom command to the module
"""
cmd = args.cmd

if ("AT" in args.cmd and args.cmd.index("AT") == 0):
Expand All @@ -253,9 +274,11 @@ def custom_command(self, args):
return self.at_cmd(cmd, args)

def signal_strength(self, args):
"""receive signal strength converted to 1-4
"""
receive signal strength converted to 1-4
returns ERROR on Error"""
returns ERROR on Error
"""

args.silent = True
widget = self.widget(args)
Expand All @@ -269,9 +292,11 @@ def signal_strength(self, args):
return widget

def _parse_signal_strength(self, strength):
"""parse and convert signal strength to 1-4"""
"""
parse and convert signal strength to 1-4
"""

steps = [0, 1, 9, 14, 19, 30]
steps = [0, 1, 9, 14, 19, 31]

rssi = int(strength.split(",")[0])

Expand All @@ -284,7 +309,9 @@ def _parse_signal_strength(self, strength):
return str(ret -1)

def _at_information(self, args):
"""receive module information"""
"""
receive module information
"""

return self.at_cmd("I", args)

Expand All @@ -294,7 +321,8 @@ def _at_infoex(self, args):
return self.at_cmd("^SYSINFOEX", args, short = True)

def infoex(self, args):
"""system information
"""
system information
^SYSINFOEX: 2,3,0,1,,6,"LTE",101,"LTE"
^SYSINFOEX: <srv_status>,<srv_domain>,<roam_status>,<sim_state>,<lock_state>,<sysmode>,<sysmode_name>,<submode>,<submode_name>
"""
Expand All @@ -316,7 +344,9 @@ def _get_submode_name(self, infoex):
return infoex.split(",")[6].strip('"')

def get_model(self, args, silent=False):
"""get model of module."""
"""
get model of module.
"""
import re
# TODO: +GMM
info = self._at_information(args)
Expand All @@ -334,7 +364,9 @@ def get_model(self, args, silent=False):
return info

def get_manufacturer(self, args, silent=False):
"""get manufacturere of module."""
"""
get manufacturere of module.
"""
import re
# TODO: +GMI
info = self._at_information(args)
Expand All @@ -357,7 +389,9 @@ def information(self, args):
return ret

def get_carrier(self, args):
"""get carrier and convert to string."""
"""
get carrier and convert to string.
"""

args.silent = True
widget = self.widget(args)
Expand All @@ -371,13 +405,15 @@ def get_carrier(self, args):
return widget

def _parse_carrier(self, ret):

# HUAWAI ONLY
if (huawei(self.manufacturer)):
return ret.split(",")[2].strip('"')
'''
Parse carrier string
'''
return ret.split(",")[2].strip('"')

def widget(self, args):
"""get widget information (signal strength, carrier, mode)"""
"""
get widget information (signal strength, carrier, mode)
"""
import re

cmds = (("+CSQ", self._parse_signal_strength),
Expand All @@ -398,7 +434,6 @@ def widget(self, args):
if (not args.silent):
print(",".join(out), file=sys.stdout)


return (out, ret[1])


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function widgetcallback_modem(transport) {
}
}

setTimeout("widget()", 5000);
setTimeout("widget()", 30000);
}

function getinfoex_modem() {
Expand Down Expand Up @@ -178,7 +178,7 @@ function infoexcallback_modem(transport) {
$("#modem-mode").html("");
}

setTimeout("getinfoex_modem()", 5000);
setTimeout("getinfoex_modem()", 30000);
}

function getstatus_modem() {
Expand Down Expand Up @@ -223,7 +223,7 @@ function statuscallback_modem(transport) {
} else {
$("#modem #ipaddr").html("");
}
setTimeout('getstatus_modem()', 5000);
setTimeout('getstatus_modem()', 30000);
}

function set_signal(str) {
Expand Down

0 comments on commit 2e89533

Please sign in to comment.