Friday, February 22, 2013

CC2420 CRC verification

This online calculator could do the same CRC calculation as in tinyos:

http://depa.usst.edu.cn/chenjq/www2/SDesign/JavaScript/CRCcalculation.htm


The improved CRC function can be found in tinyos:


/**
 * The following implementation computes the same polynomial.  It should be
 * (much) faster on any processor architecture, as it does not involve
 * loops. Unfortunately, I can not yet give a reference to a derivation.
 *
 * @author Andreas Koepke (porting to tinyos)
 * @author Paul Curtis (pointed out this implementation on the MSP430 yahoo mailing list)
 */



  uint16_t crc_Byte(uint16_t crc, uint8_t b) {
    crc = (uint8_t)(crc >> 8) | (crc << 8);
    crc ^= b;
    crc ^= (uint8_t)(crc & 0xff) >> 4;
    crc ^= crc << 12;
    crc ^= (crc & 0xff) << 5;
  return crc;
}


  uint16_t crc_packet(uint8_t *data, int len) {
    uint16_t crc = 0;

    while (len-- > 0)
      crc = crcByte(crc, *data++);

    return crc;
  }

Wednesday, January 9, 2013

How to clear IEEE154_FCF_ACK_REQ to remove the ACK requirement

../cc2420/csma/CC2420CsmaP.nc :

Change line143:     header->fcf &= ( (1 << IEEE154_FCF_ACK_REQ) |

to     header->fcf &= ( (0 << IEEE154_FCF_ACK_REQ) |

Change line 151:    metadata->ack = FALSE;
to      metadata->ack = TRUE;

Sunday, January 6, 2013

CC2420 Layer Diagram


[plain] view plaincopy
  1. +--------------------------------------------------+  
  2. |               Application Layer                  |  
  3. |                                                  |  
  4. +-----------------------+--------------------------+  
  5.    
  6.  +----------------------+-------------------------+  
  7.  |             Active Message Layer               |  
  8.  +----------------------+-------------------------+  
  9.    
  10.  +----------------------+-------------------------+  
  11.  |              Unique Send Layer                 |  
  12.  +----------------------+-------------------------+  
  13.                     
  14.  +----------------------+-------------------------+  
  15.  |         Optional Packet Link Layer             |  
  16.  +----------------------+-------------------------+  
  17.                           
  18.  +----------------------+-------------------------+  
  19.  |  Optional Low Power Listening Implementations  |  
  20.  +----------------------+-------------------------+  
  21.                           
  22.  +----------------------+-------------------------+  
  23.  |        Unique Receive Filtering Layer          |  
  24.  +----------------------+-------------------------+  
  25.                           
  26.  +----------------------+-------------------------+  
  27.  |      Optional 6LowPAN TinyOS Network Layer     |  
  28.  +----------------------+-------------------------+  
  29.                           
  30.  +----------------------+-------------------------+  
  31.  |     Carrier Sense Multiple Access (CSMA)       |  
  32.  +----------------------+-------------------------+  
  33.                           
  34.                                      
  35. +----------+----------+   +----------+----------+  
  36. |      ReceiveP       |   |      TransmitP      |  
  37. +----------+----------+   +----------+----------+  
  38.                                       
  39.                           
  40. +-----------------------+-------------------------+  
  41. |    SPI bus, GPIO, Interrupts, Timer Capture     |  
  42. +-------------------------------------------------+  


Thursday, December 6, 2012

Remove cc2420 software CRC check

1*. Modify CC2420TinyosNetworkP.nc in /opt/tinyos/tos/chips/CC2420/lowpan

line 160 -163:

//if(!(call CC2420PacketBody.getMetadata(msg))->crc) {
// return msg;
//}

2. Modify CC2420ReceiveP.nc in /opt/tinyos/tos/chips/CC2420/receive

line 644 -652:

// We may have received an ack that should be processed by Transmit
// buf[rxFrameLength] >> 7 checks the CRC
if (rx_buf ) {
uint8_t type = ( header->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7;
signal CC2420Receive.receive( type, m_p_rx_buf );
post receiveDone_task();
return;
}

3. 2. Modify CC2420ReceiveP.nc in /opt/tinyos/tos/chips/CC2420/receive

line 381:

if( (header.fcf & (1 << IEEE154_FCF_SECURITY_ENABLED)) && (crc << 7) ){

to

if( header.fcf & (1 << IEEE154_FCF_SECURITY_ENABLED) ){

Friday, August 17, 2012

Fix ImportError: No module named dateutil.rrule error in MAC 10.8 with Python 2.7.3


When I try to execute python code with import matplotlib, I received following errors:


Traceback (most recent call last):
  File "plotPRREachNode.py", line 6, in
    import matplotlib.pyplot as pl
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/pyplot.py", line 26, in
    from matplotlib.figure import Figure, figaspect
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/figure.py", line 19, in
    from axes import Axes, SubplotBase, subplot_class_factory
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes.py", line 19, in
    import matplotlib.dates as mdates
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/dates.py", line 122, in
    from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
ImportError: No module named dateutil.rrule


The method to solve this error is go to http://labix.org/python-dateutil/#head-2f49784d6b27bae60cde1cff6a535663cf87497b and download the python-dateutil-1.5.tar.gz 

Then untar the file and type in command line:
python setup.py install



That's it, wish this could help.


Tuesday, August 14, 2012

EASY Install matplotlib on mac ox 10.8



  1. Get Xcode 4.3.2, it's required for some of the later steps.
  2. Download the latest version of python for OSX from python.org
  3. Grab the Scipy superpack.
  4. Uninstall any previous versions of numpy/matplotlib/scipy that you currently have. That includes doing cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moving any numpy/matplotlib/scipy directories or eggs into a temp directory.
  5. cd ~/Downloads(or wherever you downloaded the superpack script to) and run sh install_superpack.sh. Answer no to the question are you installing from a repository cloned to this machine or you'll be confused about why the script keeps failing.
That should be it! You should now be able to boot up the python console and import numpy, scipy, matplotlib.
share|improve this answer




source:  http://fonnesbeck.github.com/ScipySuperpack/


Alternately, if you have curl installed, you can get the script via:
$ curl -o install_superpack.sh 
https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
To install, open a terminal in the directory that the script is located and call:
$ sh install_superpack.sh
You will be prompted for your administrator password. If you have already installed the current gFortran, you can bypass that package during the install process. Similarly, the installation requires Git, so you will be prompted to install it if you are installing remotely.

Sunday, April 29, 2012

How to resync MySQL Replication after updated master database

After update the table structure in master database, the slave stopping replication. After update the mysqldump with -d  for the new database to slave machine, it report duplicate entry error.

You can using following commands to fix it: (source: http://forums.mysql.com/read.php?26,24736,24884#msg-24884)

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; 
mysql> START SLAVE; 

Use the value 1 for any SQL statement that does not use AUTO_INCREMENT or LAST_INSERT_ID(), otherwise you will need to use the value 2. Statements that use AUTO_INCREMENT or LAST_INSERT_ID() take up 2 events in the binary log.

Friday, February 24, 2012

Setup connection to MySQL in VS 2010

Author: 
Source: http://arunasujith.blogspot.com/2012/02/mysql-c-connection-example-in-visual_10.html


Creating a MySQL database connection using C++ is  really easy. But for a beginner it can be really hard to find the correct procedure cause it will gave really troubles. At the first time when I'm doing it it took me quite some time to make it work. So I'm going to explain how to make a connection to the MySQL database using C++ code. We use the library called boost to make the connection. 

Step 1 (Download the boost library)
First step is to download the boost library. You can download it from here from the official download page Or you can download the one I've compressed and uploaded which is smaller in size from here.

Step 2 (Create the project using Visual Studio 2008)
First go  to File --> New --> Project and you'll get a screen like this. 

mysql c++ connection example

Select Visual C++ --> Win 32 --> Win 32 Console Application  and give a name to the project and press OK. 
Then set Application Type to Console Application and remember to tick the empty project. and click finish.

Then Right Click the project and add new Item a cpp source file called Connect.cpp.

// Standard includes
#include 
#include 
#include 
using namespace std;

// Connector Includes

#include "cppconnection/driver.h"
#include "cppconnection/exception.h"
#include "cppconnection/resultset.h"
#include "cppconnection/statement.h"


// Link to the Connector/C++ library
#pragma comment(lib, "mysqlcppconn.lib")

// Connection details
string server   = "localhost";
string username = "root";
string password = "123"; //

int main(){
    sql::Driver     *driver; // MySQL Driver Object
    sql::Connection *connection; // MySQL connection Object
    sql::Statement  *statement;   // Statement which holds SQL commands
    sql::ResultSet  *resultSet;    // ResultSet to hold the results
    //Here is the connection
    try{
        driver = get_driver_instance();
        connection = driver->connect(server, username, password);
        statement = connection->createStatement();
        statement->execute("USE performance_schema");
        resultSet = statement->executeQuery("show tables");
        while (resultSet->next()){
            // Iterating the result set
            cout << resultSet->getString(1) << endl;               
        }
    }
    catch (sql::Exception e){
        cout << "Error message: " << e.what() << endl;
        system("pause");
        exit(1);
    }

    //Clear resources
    delete res;
    delete statement;
    delete connection;

    system("pause");
    return 0;
}

Copy the boost folder into the project folder. In this example the folder is Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.

Then download this header and dll files and extract them into the same folder Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.

Then the final step is right cilck on the Project and go to 
Properties --> Configuration Properties --> C/C++ --> General . 
On the right hand side set the "Additional Include Directories" value to ".\" value. (with out the quotes)

That's it build your project and run the project. And one more final thing when you run the project set the  "Solution Configuration" to Release mode. In the Debug Mode I had some error which I still don't no why.

So that's it now I think you got a clear idea about creating a connection for MySQL using C++ in Visual Studio 2008. See you around with another exciting post... :)

Tuesday, January 31, 2012

get ForwardingTable size in tinyos


entry = call ForwardingTable.getTable(&n);
while(entry[cur_entry].valid)
cur_entry++;
    printf("\t\tthe length of ForwardingTable is %i\n", cur_entry);