Mittwoch, 8. August 2012

[Atmel Studio] [TBLAVR] Strange AVR-Studio 6.0 behaviour

I just experienced heavy troubles when using TBL-Library for AVR in Atmel Studio 6.0

I had a quite simple project set up which was last compiled in Atmel Studio 6.0 beta and includes tbl-Library (-ltbl).

As there came up another bug after a minor -completely unrelated - update with an older Toolchain (WINAVR2007525) from anouther Compnay using the library, I started debugging the library.

Previously compileable projects weren't any more. They showed some very strange error messages, such as

 'DevComSlave_t' has no member named 'SendFrame'  

Editor-Resolvment worked fine, so I took a look into DevComSlave.h (via rightclick on #include<tbl/DevComSlave.h> / Go to implementation and i saw the following:

 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~ DevComSlave-Object ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            
      typedef struct devComSlaveStruct  
      {  
           unsigned char                    Address;                    // Slave Address  
           volatile unsigned char          MCAddress;                    // Multicast Address  
           unsigned short                    ID;                              // Device-ID, configurable by User, could be used to identify device types etc.  
           volatile unsigned char*          Data;                         // Pointer to valid Data            
           volatile unsigned char          DataUpperBound;               // Length-1 (highest index) of acceptable Data Packages. Set 0 if Data of any length up to 256 Bytes should be accepted  
           volatile unsigned char          NewReceived;               // 0 ... no Data available, != 0: New Received (see "New Received Bitmapping" below)  
           // RW-Output (if enabled)  
           volatile uint8_t*               RWPort;                         // Port, where RW-Wire is connected (e.g. for Buscoupler,...)  
           uint8_t                              RW_bp;                         // Bit Position, where RW-Wire is connected (Pn0...Pn7), e.g. PC3  
           unsigned char                    RWPolarity;                    // 0... when writing, RW-Wire is logic 0, 1 when reading    
                                                                            // 1... when writing, RW-Wire is logic 1, 0 when reading  
           DevComSlaveCommandHandler_t CommandHandler;                 
           // A callback-function, that handles all Commands that are NOT handled internally. Feedback Execution State (either DCS_CMDHANDLER_SUCCESS or DCS_CMDHANDLER_ERROR).  
           // parameters:  
           //          pCmd               Pointer to Command (pCmd[0]) and its parameters (pCmd[1]...pCmd[pUpperBound])  
           //          pLastCtrlByte     Controlbyte of the Frame the command was received in  
           //          pUpperBound          UpperBound of pCmd  
           //          pAllowsResponse     Indicates whether the command allows responding (Cmd received via Unicast) or not (Cmd received via Broad-/Multicast)  
           //  
           // return:  
           //          DCS_CMDHANDLER_SUCCESS          if Execution of Command was successful  
           //          DCS_CMDHANDLER_ERROR          if Execution of Command was unsuccessful or command is unknown  
           DevComSlaveFrameTransmitter_t SendFrame;  
      }   
      DevComSlave_t;  

Well, that is rather strange. For some reason I thought, why not try to open AVR-Studio 6.0 as Administrator and I did so.

Guess what? Compiled smoothly.

To be honest, I have not the slightest idea, why it didn't compile otherwise and even more important, why avr-gcc showed that strange - completely unrelated - error messages.

Any suggestions?

Samstag, 4. August 2012

[Android] Create Eclipse Project for OpenCV in Native Code

Going to come later..

Eclipse IDE for Native OpenCV development on Android

As my new internship requires me to do Android-development, I'm trying to build myself a clean Eclipse-IDE and easy-to-follow Step-by-Step instructions on how to do that, so I can fall back to this clean environment whenenver I messed up my working one. Therefore I extract all components into one Root-Directory and create a script to set needed Environment-Variables whenever changing or deploying it to a new machine.

Please note I used Eclipse Indigo, although Juno is already available, because Juno has some serious problems when combined with Android NDK, they're currently working on that.

  1. Get yourself Java JDK  from http://www.oracle.com/technetwork/java/javase/downloads/index.html. I fetched Java SE 7. Of course you have to install JDK after the download succeeded.
  2. Create a root-folder (I called it androidEclipse) and download the following items to this location:
    1. Get Eclipse for Java Develpers EE from http://www.eclipse.org/downloads/. I downloaded Indigo for Windows 64bit. Extract it somewhere on your system, but make sure you have no spaces in the absolute path to avoid possible complications with NDK and OpenCV later on.
    2. Get Native Development Kit for Android http://developer.android.com/tools/sdk/ndk/index.html (android-ndk-r8b-windows.zip in my case)
    3. Get OpenCV4Android in latest version from http://opencv.org/downloads.html (2.4.2 here) 
  3. Extract all archives and place it together in a Folder, e.g. androidEclipse
  4. Install CDT (C and C++ Development)
    1. Go to Help => Install new Software
    2. Enter the p2 repository url which could be found at http://www.eclipse.org/cdt/downloads.php. In my case it was http://download.eclipse.org/tools/cdt/releases/indigo. Select CDT Main and Optional features and install it after agreeing the terms and conditions.
      Note: Probably it doesn't work because of conflicting dependencies. In this case (when installing Indigo, never experienced that in Juno) install CDT Main Features,TCF and Uncategorized, restart Eclipse and then install CDT Optional features.
      Install new Software: CDT

    3. Restart Ecplise
    4. Test if you can create a new C or C++ project and compile a Hello-World project.
  5. Install ADT (Android Development Tools) Plugin to eclipse.
    Refer to http://developer.android.com/tools/sdk/eclipse-adt.html and install similar to CDT via Repository URL https://dl-ssl.google.com/android/eclipse/. Please keep in mind, if this repository is extraordinary slow or not working, just drop the s in https - this is also recommended from developer.android.com.
    You need to install Developer Tools and NDK Plugins, but I'm not quite sure the second one is necessary.
  6. Now we have to adjust the Environment of our IDE. We have to create two environment-variables:
    NDKROOT ... Path to root of ndk-Folder (e.g. D:\AV\androidEclipse\android-ndk-r8b)
    OPENCVROOT ... Path to root of android-openCV-Folder (e.g. D:\AV\androidEclipse\OpenCV-2.4.2-android-sdk)

    You have to restart Eclipse (best your whole System, Windows is often a bit unpredictable in these manners) in order to get it to know the new environment variables. Windows console knows them immediately, but some other applications (such as eclipse) don't.
  7. Depending on which Android platform you're developing on, you have to install further API Support. To do so, go to SDK-Manager and select the desired packages. I additionally installed API 10 SDK Platform Android 2.3.3 and the Google APIs for API 10.
  8. Good, you're done and your IDE is (or should be) ready. Please refer the next post on how to create a Project that features JNI and OpenCV - and the combination of those two.

    Click here for the next post