From: lionel Date: Tue, 29 Dec 2015 09:01:17 +0000 (+0100) Subject: Patch : no more need of a custom cp210.ko kernel module ! X-Git-Url: http://gitweb.enneade.fdn.org/?a=commitdiff_plain;h=8b5c3898bd88429df5e7c66b4703a6cea4f084d5;p=pyowl.git Patch : no more need of a custom cp210.ko kernel module ! --- diff --git a/README b/README index 7504097..973b280 100644 --- a/README +++ b/README @@ -1,3 +1,17 @@ ### PyOWL # Py daemon storing OWL data on MySQL +Requires a python-serial or pyserial (depending of your Linux distribution) module version >= 2.7 to be able to set the correct baud rate when connecting the CM160. +If not, it will die during initialisation. + +If you really cannot update to it (there is no dependencies on Debian Jessie but who knows ...) then you will have to hack a bit : +- copy the cp210.c file in "driver" directory to you kernel source tree and recompile +or +- recompile only the cp210.ko module using you kernel headers and overwrite the existing one found into /lib/modules/blablabla +- rmmod cp210; modprobe cp210 +- find the following line in cm160Server.py : +self.__ser = serial.Serial(self.__serialPortName, 250000, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30) +and change "250000" to "0" like this : +self.__ser = serial.Serial(self.__serialPortName, 0, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30) + +The daemon should know being able to find, connect and retrieve data from the CM160. diff --git a/cm160Server.py b/cm160Server.py index a5f4c27..d309b84 100755 --- a/cm160Server.py +++ b/cm160Server.py @@ -377,11 +377,8 @@ class CM160: self.__ser = None try: - # TODO WHY : why must we use a custom cp210x driver ? why can't we just specify the baud rate here ? - # self.__ser = serial.Serial(self.__serialPortName, 250000, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30) - #Assume we have the custom cp210x driver loaded that maps the requested baud rate of 0 to a physical port speed of 250000 Bps required - #for the CM160 device. - self.__ser = serial.Serial(self.__serialPortName, 0, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30) +# Important here : you MUST have a python-serial (or pyserial) module version >= 2.7 (take a look at the README) + self.__ser = serial.Serial(self.__serialPortName, 250000, bytesize=8, parity='N', stopbits=1, xonxoff=False, rtscts=False, dsrdtr = False, timeout=30) sd = self.__ser.getSettingsDict() keys = sd.keys() diff --git a/driver/README b/driver/README deleted file mode 100644 index 4bafa5e..0000000 --- a/driver/README +++ /dev/null @@ -1,14 +0,0 @@ -Patched serial driver for kernel 3.16.2 - -diff : - -407,408c407,408 -< if( baud == 0) baud = 250000; /* KLUDGE for Owl Energy Monitor, Use baud rate (B0 Hang up) that is unlikely to be of any use */ -< else if (baud <= 300) baud = 300; ---- -> if (baud <= 300) -> baud = 300; - - -Warning : Makefile does not fully handle installation (just take a look at it). -You have to manually copy/remove/delete stuff yourself (mainly because I'm lazy, but also because I don't like scripts playing with things in /lib/modules). diff --git a/driver/README.serial b/driver/README.serial new file mode 100644 index 0000000..6ebfd87 --- /dev/null +++ b/driver/README.serial @@ -0,0 +1,20 @@ +REALLY READ the main README before doing anything with that stuff !!! + + +Patched serial driver for kernel 3.16.2 + +diff : + +407,408c407,408 +< if( baud == 0) baud = 250000; /* KLUDGE for Owl Energy Monitor, Use baud rate (B0 Hang up) that is unlikely to be of any use */ +< else if (baud <= 300) baud = 300; +--- +> if (baud <= 300) +> baud = 300; + + +Warning : Makefile does not fully handle installation (just take a look at it). +You have to manually copy/remove/delete stuff yourself (mainly because I'm lazy, but also because I don't like scripts playing with things in /lib/modules). + + +** The Debian package came from testing (stable == Jessie) and can be installed as simple as "dpkg -i *.deb" on Jessie. Works like a charm ** diff --git a/driver/python-serial_2.7-1_all.deb b/driver/python-serial_2.7-1_all.deb new file mode 100644 index 0000000..fee90b5 Binary files /dev/null and b/driver/python-serial_2.7-1_all.deb differ diff --git a/init/cm160 b/init/cm160 index c23f6e8..02dd7c7 100755 --- a/init/cm160 +++ b/init/cm160 @@ -13,24 +13,31 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin . /lib/lsb/init-functions -DAEMON=/usr/local/owl/cm160server.py -PIDFILE=/usr/local/owl/cm160server.pid -OPTIONS="-s 1" +DAEMON_PATH=/usr/local/owl/ +DAEMON=cm160Server.py +PIDFILE=cm160Server.pid +OPTIONS="-s 0" +cd $DAEMON_PATH test -x $DAEMON || exit 5 # RUNASUSER=ntp case $1 in start) + DATE=`date +%Y%m%d-%H:%m:%S` + if [ -f $DAEMON_PATH/cm160Server.log ] + then + mv $DAEMON_PATH/cm160Server.log $DAEMON_PATH/cm160Server.log_$DATE + fi log_daemon_msg "Starting OWL data graber daemon" "cm160server.py" - start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --startas $DAEMON -- $OPTIONS + start-stop-daemon --start --quiet --oknodo --background --pidfile $PIDFILE --chdir $DAEMON_PATH --startas $DAEMON -- $OPTIONS status=$? log_end_msg $status ;; stop) log_daemon_msg "Stopping OWL data graber daemon" "cm160server.py" - start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE + start-stop-daemon --stop --quiet --oknodo --name $DAEMON log_end_msg $? rm -f $PIDFILE ;;