Thursday, November 24, 2011

Get signal quality from GPRS modem

A quite sophisticated bash script for getting signal quality (AT+CSQ) from GPRS modem:



#!/bin/bash


function get_response
{
        local ECHO
        # cat will read the response, then die on timeout
        cat <&5 >$TMP &
        echo "$1" >&5
        # wait for cat to die
        wait $!


        exec 6<$TMP
        read ECHO <&6
        if [ "$ECHO" != "$1" ]
        then
                exec 6<&-
                return 1
        fi


        read ECHO <&6
        read RESPONSE <&6
        exec 6<&-
        return 0
}


TMP="/tmp/response"


# Clear out old response
: > $TMP


# Set modem with timeout of 5/10 a second
stty -F /dev/ttyACM0 -echo igncr -icanon onlcr ixon min 0 time 5


# Open modem on FD 5
exec 5<>/dev/ttyACM0


get_response "AT" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"


echo


get_response "AT+CSQ" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"


exec 5<&-

Tuesday, November 15, 2011

GCC 4: error: lvalue required as increment operand

If you are compiling C code with GCC 4.x version you might receive the error:

error: lvalue required as increment operand
But the code compiled flawlessly with older versions of GCC.

The problem lies in GCC 4 which is a little more picky about the code. So we need to fix the code. Here is an example of the problematic code:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest)++ = ReadFrame8900();
}
And the fix for it:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest) = ReadFrame8900();
    Dest = (void *)Dest + 1;
}

Sunday, November 13, 2011

Preferred video/audio codecs in Windows

Ever tried to open a AVCHD (h264) video stream in VirtualDub? Well, it is not that simple - VirtualDub is designed for Video For Windows (VFW) interface, but AVCHD decoders work as DirectShow filters. It is like expecting an iPhone application to work on the Android phone.

The solution for the problem (opening AVCHD in VirtualDub) is to use DirectShow plugin for VirtualDub that allows you to open the video. You can get the plugin here: http://forums.virtualdub.org/index.php?act=ST&f=7&t=15093&st=0

Of course you also need an AVCHD (h264) decoder that is VirtualDub compatible (supports RGB decoded output) where Microsoft DTV-DVD Video Decoder isn't. But there are many options, FFmepeg is one of them, feel free to choose one yourself.

So you have DirectShow plugin and some RGB-compatible decoder installed but the video is still not displayed in VirtualDub. You see a green area where the actual video picture should be previewed and VirtualDub might be complaining about decoder's RGB compatibility. The problem is in the priority list of decoders that still picks MS DTV-DVD decoder. You can change this with some registry editing but there is something better - a utility for changing decoder priorities: http://www.codecguide.com/windows7_preferred_filter_tweaker.htm
The usage is straight forward so happy video editing once it works.