Friday, August 21, 2015

Linux useful commands and informations

1. In debian based OS apt-get install command will download the .deb package in the below folder before installation.

    /var/cache/apt/archives/

2. To format disk in commandline

      sudo cfdisk /dev/sdb

   One another option is

     sudo mkfs.ext4 /dev/sdb1

3. Find User ID (uid) of the current user in Linux system.

      id -u [USER_NAME]

      eg:  id -u root  (which will be 0).

4. Change ownership of a folder for specific user.

      chown -R [UID_OF_USER] [PATH_TO _FOLDER]

      eg: chown -R 1000 /opt/tinyos-2.x/

5. Find a file or directory in specific place.

      find [PATH_TO_SEARCH] -name [FILE_NAME]

      eg: find /opt -name tinyos.sh

6. Install grub due to some error in grub.

      grub-install --root-directory=/dev/sda

7. Write OS image (*.img) into USB/ microSD in linux (Ubuntu).
     Create bootable USB/ microSD from image file (.img)

      sudo dd if=./BBB*.img of=/dev/sdX

      sdX, here X denote where the device is mounted.

8. SSh connection failure due to the error "Host key verification failed."

     ssh-keygen -R



9. Find baud rate of a serial device through commanline

    sudo stty -F /dev/ttyUSB0    //replace ttyUSB0

Monday, June 1, 2015

PostgreSQL Useful commands


PostgreSQL Useful commands

  • To copy a table to create new one
    • CREATE TABLE table_name_2 ( like table_name_2 including all)
  • Insert columns from one table to another
    • insert into table_name (phone_no,subscriber_name,address,pincode,place,district) select phone_no,subscriber_name,address,pincode,place,district from tabele_2;
  • Insert column of one table from another table, where second table colum length is less than 95
    • insert into table_back 
    • (
    •   phone_no,subscriber_name,address,pincode,place,district
    • ) select phone_no,subscriber_name,address,pincode,place,district from table_2 where length (subscriber_name) > 95;
  • Delete complete content from table
    • DELETE FROM table_name;
  • Delete a column from table
    • DELETE FROM table_name WHERE phone_no = 7382613796;
  • Change table name
    • ALTER TABLE table_name RENAME TO TABLE_NAME_2;
  • Change column datatype
    • ALTER TABLE table_name ALTER COLUMN phone_no TYPE bigint USING (phone_no::bigint); 
      • phone_no is the column name.
  • Delete row when length of a column not equal to 10
    • delete FROM table_name WHERE length(phone_no)!=10;
  • Update column by its first n characters, if the character length is to be reduced
    • update test_1 set subscriber_name = left(subscriber_name,10);
  • To create new table from old table, sorted by systemtime
    • create table new_racktemp as select * from racktemp order by systemtime;
  • Alter/ Update existing table by inserting new column, setting it with primary key and insert the column with serial numbers starting from 1.
    • alter table new_racktemp add column slno bigserial primary key;
  • For creating sequence number and updating column with that (not tested)
    • CREATE SEQUENCE seq;
    • ALTER SEQUENCE seq RESTART WITH 1;
    • UPDATE racktemp SET slno=nextval('seq');
  • Dump and restore for command line
    • Go to "cmd"
    • Change directory to the Postgres Bin folder      
    • cd // cd C:\Program Files\PostgreSQL\9.3\bin
    • Use pg_dump to backup
      • pg_dump.exe -U postgres -t "table_name" "Data_base_name" > "Path&Name_Backup"
      • //pg_dump.exe -U postgres -t consotable hpc > C:\Users\CFD\Desktop\consot.backup
  • Use psql to restore to another database
    • psql.exe -U postgres "DB_name" < "Path for backup file"
    • //psql.exe -U postgres testdb < C:\Users\CFD\Desktop\consot.backup
  • Get values of the last updated row inreference to serial number
    • SELECT * from table_name order by slno desc limit 1

Monday, December 22, 2014

PCB Design with CADSTAR






Tuesday, November 18, 2014

PostgresQL Database connection with MATLAB

Configuration Steps

Steps:

1. Download and copy JDBC driver for Postgres version from this link
http://jdbc.postgresql.org/download.html

2. Follow this link to edit JDBC driver path to Matlab java class path.
http://in.mathworks.com/help/database/ug/postgresql-jdbc-windows.html

3. Follow above link to complete the connection.


Matlab Data Retrieval from PostgresQL 

1. Connect to database

DataBase =  database('hpc','postgres','postgres','Vendor','PostgreSQL')

2. Conver num to string for comparison

startdate= num2str('2014-11-02');
endddate=num2str('2014-11-08');

3. SQL query and execute the query

sqlquery = ['select temp1, temp2, temp3, temp4, temp5, temp6, temp7, temp8 from racktemp where nodeid = 7 and systemtime BETWEEN (''',startdate,''') and (''',endddate,''')'];
curs = exec(DataBase,sqlquery);

4. Fetch the data and store in an array

curs = fetch(curs);
Data = curs.Data;
Data(15,2)

5. Close connection

close(DataBase);

6. Use integer variable inside Postgres query in Matlab

are = 10
sqlquery = ['select loadavg1min from punecpuload where sno =' num2str(are)]

7. Use string variable inside Postgres query in Matlab

nodeL = num2str('r4-c1-n1');
sqlquery = ['select count(*) FROM consotabletemp where node_id =(''',nodeL,''')'];

Wednesday, July 4, 2012

Select the Channel for transmission in TinyOS, NesC

Here i have described how to change the channel for Zigbee transmission in TinyOS. Programs i have done are for TelosB mote and so the methods are applicable to the Zigbee CC2420 only. I believe for other motes the methods are more or less the same.

By default in TinyOS the channel used for CC2420 transmission is 26th channel, and it is defined in CC2420.h file. Here i have described about three methods for selecting the channel.

(1) Change the channel by Makefile

  Add this line in Makefile and enjoy.
CFLAGS += -DCC2420_DEF_CHANNEL=25
Where 25 is the required channel.

(2) Change the channel dynamically in NesC programming

  Use the command CC2420Config.setChannel() in interface "CC2420Config", which is provided by the component "CC2420ControlC". Sample program is given below.

Configuration
configuration ChannelAppC {
}

implementation {
  components ChannelC;
  components MainC;
  components LedsC;
  components new TimerMilliC() as Timer;
  components CC2420ControlC;  //Component for Channel selection

  ChannelC.Boot -> MainC;
  ChannelC.Led  -> LedsC.Leds;
  ChannelC.Timer -> Timer;

  components ActiveMessageC;
  components new AMSenderC(6);

  ChannelC.SplitControl -> ActiveMessageC;
  ChannelC.Packet    -> AMSenderC;
  ChannelC.AMPacket  -> AMSenderC;
  ChannelC.AMSend    -> AMSenderC;

  ChannelC.CC2420Config -> CC2420ControlC; //Wiring for Channel selection
}

Module
#include "printf.h"

module ChannelC {
  uses interface Boot;
  uses interface Leds as Led;
  uses interface Timer;

  uses interface SplitControl;
  uses interface Packet;
  uses interface AMPacket;
  uses interface AMSend; 
  uses interface CC2420Config;
}

implementation {

  enum {
    AM_SIZE = 6,
  };

  typedef nx_struct MessageDef {
    nx_uint16_t counter;
  } MessageDef;

  uint16_t counter = 0;
  bool busy = FALSE;
  message_t pkt;
  uint8_t len;
  uint8_t channel;
  
  event void Boot.booted() {
    call SplitControl.start();
  }

  event void SplitControl.startDone(error_t err) {
    call CC2420Config.setChannel(25);
    call CC2420Config.sync();
    call Timer.startPeriodic(500);
  }

  event void Timer.fired() {
    MessageDef* ptrpkt = (MessageDef*)(call Packet.getPayload(&pkt, len));
    counter++;
    call Led.led0Toggle();
    ptrpkt -> counter = counter;
    if (!busy) {
      if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(MessageDef)) == SUCCESS) busy = TRUE;
    }
  }

  event void AMSend.sendDone(message_t* msg, error_t error) {
    if (&pkt == msg) {
      busy = FALSE;
      call Led.led1Toggle();
      channel = call CC2420Config.getChannel();
      printf("Channel : %d\n", channel);
      printf("Counter = %d\n\n",counter);
      printfflush();
    }
  }
  
  event void SplitControl.stopDone(error_t err) {
  }
  event void CC2420Config.syncDone( error_t error ) {
  }
}

(3) Change the channel in the TinyOS source

By default CC2420 is using 26th channel for transmission and it is defined in CC2420.h header file in /opt/tinyos-2.x/tos/chips/cc2420/. So by editing that header file and recompiling the program will change the channel. Edit the below given line
#ifndef CC2420_DEF_CHANNEL
#define CC2420_DEF_CHANNEL 25
#endif
 Where 25 is the required channel.

Sunday, July 1, 2012

GIO Input and Output of TelosB

This program can be used as a reference for the usage of General Input Output pin(GIO) of TelosB. Here i a have used the GIO output of TelosB to connect a buzzer and trigger it in every 2 seconds, making it on and off.

General input/output pin details of TelosB is given below.

GIO No.
TeloB Pin out
MSP430 processor Pin out
Note
GIO-0
10 (10 pin connector)
20
Have to short R16 in TelosB
GIO-1
7 (10 pin connector)
21
Have to short R14 in TelosB
GIO-2
3 (6 pin connector)
23

GIO-3
4 (6 pin connector)
26


In my program i have used GIO3 and hence i have connected the positive of buzzer to 4th pin of 6 pin expansion connector and negative to Gnd of TelosB.


This is the configuration for the application.
configuration BuzzerAppC {
}

implementation{
   components BuzzerC, MainC;
   components HplMsp430GeneralIOC;
   components BusyWaitMicroC;
   components new TimerMilliC() as Timer;
   components LedsC;

   BuzzerC.Boot -> MainC.Boot;
   //BuzzerC.indication2 -> HplMsp430GeneralIOC.Port23; For input
   BuzzerC.indication3 -> HplMsp430GeneralIOC.Port26; 
   BuzzerC.Timer -> Timer;
   BuzzerC.delay -> BusyWaitMicroC;
   BuzzerC.Leds -> LedsC;
}

This is the module for the application.
module BuzzerC{
   uses interface Boot;
   uses interface HplMsp430GeneralIO as indication3;
   uses interface BusyWait as delay;
   uses interface Timer as Timer;
   uses interface Leds;
}

implementation{
  uint16_t value;
  uint16_t i;
  event void Boot.booted() {
    call Timer.startPeriodic(2000);
  }
  event void Timer.fired() {
    call Leds.led0Toggle();
    call indication3.makeOutput();
    call indication3.set();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
    call indication3.clr();
    for (i=0;i<100;i++) {
      call delay.wait(10000);
    }
  }  
}

Monday, June 11, 2012

Calculate execution time of code in TinyOS

Here i have used the interface "LocalTime" and component "LocalTimeMilliC" for calculating the execution time.

This is the Configuration for calculating the execution time. Here i have given a sample code and it is not complete in sense of a complete application.
configuration TMP102AppC {
}
implementation {
  components LocalTimeMilliC, TMP102C as App;
  App.LocalTime -> LocalTimeMilliC; 

 ---Other Configurations---
}

This is the module for the application.
#include "printf.h"

module TMP102C {
   uses interface LocalTime <tmilli>;
     ---Other Interfaces---
}

implementation {
uint32_t start_time;
uint32_t stop_time;

 ---Other Code---

start_time = call LocalTime.get();  // Put this line where you want to start count.
   
---Other Code---

 stop_time = call LocalTime.get();  // Put this line where you want to stop count.
 printf("Execution Time = %d\n",(stop_time-start_time));  //Print the execution time.
    
}