http://www.boost.org/doc/libs/1_47_0/libs/bind/bind.html
Use boost:bind
October 25, 2011build a symbol database for vim
August 12, 2011#!/bin/sh
# find src files
find . ! -path ./exclude_dir_1\* -a \
! -path ./exclude_dir_2\* -a \
-regex “.*\.\(c\|h\|hpp\|cc\|cpp\|s\)” > cscope.files
# number is exact match, or else use search by default
ctags -L cscope.files –language=c:.c.h,c++:.cpp.hpp.cc,Asm:.s –excmd=number
cscope -bqk
serial monitoring under linux
August 27, 2010On windows, you can use the HHD’s serial monitor professional tools, on Linux,
what can you do to peek the serial port? Below is a quick start guide for using moni,
1. download moni
http://www.rolf-schroedter.de/moni/#download
2. download tclkit
http://www.equi4.com/starkit/started.html
3. type the following to run moni
gzip -d tclkit-*.gz
mv tclkit-* tclkit
chmod +x tclkit
./tclkit sdx.kit
A Device Monitoring System
July 14, 2010My current project is a device monitoring system. The system has following features
- Reliable device communication through specified interfaces
- Web interface for system administration and device status monitoring (including remote)
- SQL Database to archive device status data, plot trending etc.
- Support SNMP interface to network management systems (NMS).
Notes for system implementation details.
1. For rapid development, Python was chosen.
2. Pyserial is the main package used for serial communication over RS485 serial interface. To use it,
import serial, time
s = serial.Serial(port=’/dev/ttyUSB0′, timeout=1) # open first usb serial port
s.write(“command to send”)
time.sleep(0.2)
response = s.readline()
Since system may have multiple buses, serial driver will run as separate processes. On linux platform (python2.5 or later), To start a process in python, use
pid = Popen(‘path/prog_name’, arg1,arg2,..).pid
To kill a process, use
import os
os.kill(pid,9)
3. Web Server. To install a simple web server, just use thttpd. Be sure to comment out the chroot in your server configuration file. Server backend is using python cgi. To turn on cgi debugging, use,
import cgi, cgitb; cgitb.enable()
Another way is to use “import pdb;pdb.set_trace()”
To enable logging, use
import logging
logging.basicConfig(filename=’my.log’, level=logging.debug)
when you need log something, use
logging.debug(“message or vars to log”)
To get values from forms, use
form=cgi.FieldStorage()
form.getvalue(‘key’) or form.getlist(‘key’)
4. Database backend use Sqlite3 since it is included in python packages.
To create a database, you can use Python DB API 2.0
import sqlite3
c = sqlite3.connect(“test.db”,isolation_level=None) # None means immediate commit to DB for any operation
c.text_factory=str # let DB convert unicode to ascii for you
c.execute(“”"create table if not exists bus (bus_id INTEGER PRIMARY KEY, port TEXT, polling INTEGER, timeout INTEGER, state TEXT, pid INTEGER default 0)”"”) # create a bus table and use bus id as primary key.
For sql query, you can embedded variable in two ways, use ? or use named labels, see following,
bus = c.execute(“select * from bus where bus_id==?”, (bus_id,)).fetchone()
c.execute(“update bus set pid=:pid where bus_id==:busid “,{‘busid’:bus[0],’pid’:pid})
5. Use template and tables to simplify web page
from string import Template
tpl = Template(open(“site.html”).read())
print “Content-type: text/html\r\n\r\n”
print tpl.substitute(dict(current=buses,confirm=confirm))
6. Use PySNMP for SNMP agent (to be continued..)
Setup the thttpd server
May 12, 2010On embedded system, use apache2 web server could be a luxury. I have used web2py web framework and it did run but crashed my flash drive. So I decided to keep it simple. thttpd has a very small footprint and said to be secure. To install it in a debian system, just type
aptitude install thttpd
It will install as all the other packages. The next step is to configure the server, on my debian lenny, it is /etc/thttpd/thttpd.conf
I want to run python cgi programs, so the cgipattern /cgi-bin/* seems fit my needs.
The default cgi script directory is /var/www/cgi-bin and default html docs are under /var/www
You need make sure the cgi scripts have 755 permission and chown to www-data.
cgi program need print two empty lines , so the simplest cgi will be
#!/usr/bin/python
print “Content-type: text/plain\n\n”
And this works in apache, however it doesn’t work on thttpd. After struggled several hours in reading the manual, options and digging through the mail list archives, check the thttpd server log and syslog for errors. I still have no clue.
Somehow, before I give up, I find a chroot option in configuration file. I change it to nochroot, because if I do the chroot, python couldn’t run for I haven’t duplicated the /usr/python into /cgi-bin directory. That’s it! Now it runs. I have to admit : thttpd is too secure…
How to netboot debian from ubuntu based system
April 15, 20101. setup tftp server.
- You need a server with tsize support.
sudo aptitude install tftp-hpa tftpd-hpa
- set tftp directory
sudo mkdir /tftpboot
sudo chown nobody.nogroup /tftpboot
sudo chmod 777 /tftpboot
- configure tftp
sudo gedit /etc/default/tftpd-hpa
#Defaults for tftpd-hpa
RUN_DAEMON=”yes”
OPTIONS=”-l -s /tftpboot”
- start tftp
sudo /etc/init.d/tftpd-hpa start
-verify
netstat -a |grep tftp
touch /tftpboot/testfile
tftp localhost -c get testfile
2. setup a DHCP server and enable PXE booting
sudo aptitude install dhcp3-server
sudo gedit /etc/dhcp3/dhcpd.conf
- content looks like
default-lease-time 600;
max-lease-time 7200;
allow booting;
allow bootp;
# The next paragraph needs to be modified to fit your case
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.101 192.168.1.253; # depends on your router
option broadcast-address 192.168.1.255;
# the gateway address which can be different
# (access to the internet for instance)
option routers 192.168.1.1;
# indicate the dns you want to use
option domain-name-servers 192.168.1.1;
}
group {
# next-server 192.168.1.3;
host tftpclient {
# tftp client hardware address
hardware ethernet <MAC_ADDR_SEPARATE_BY_:>;
filename “pxelinux.0″;
}
}
3. move tftp images into tftp folder
goto
http://www.debian.org/releases/stable/i386/ch04s02.html.en#where-files
and get the netboot.tar.gz tarball and extract it into /tftpboot
reference
http://www.debian.org/releases/stable/i386/ch04s05.html.en
http://blog.tuxcoder.com/2008/06/configure-tftp-server-in-ubuntu.html
A useful tool — devmem2
March 25, 2010Devmem2 is a simple utility to read/write to any memory mapped locations. It is not available in debian etch but I find the source code (free GNU license) , compiled and run it perfectly on my gesbc debian eth environment.
Build:
$ gcc devmem2.c -o devmem2
To use devmem2 to toggle RTS register of the Serial Port 4 to high (RS485 mode).
./devmem2 0xfffd0004 w 0xc00008c1