[Tinyos-contrib-commits] CVS: tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD Makefile, 1.1, 1.2 downloadSessions.pl, 1.1, 1.2 nodeInfo.c, 1.1, 1.2 readSD.c, 1.1, 1.2

Konrad Lorincz konradlorincz at users.sourceforge.net
Thu Dec 20 18:24:43 PST 2007


Update of /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv20801/src/gui/sessions/readSD

Modified Files:
	Makefile downloadSessions.pl nodeInfo.c readSD.c 
Log Message:
Updated readSD to handle various sampling rates

Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile	12 Dec 2007 20:44:08 -0000	1.1
--- Makefile	21 Dec 2007 02:24:41 -0000	1.2
***************
*** 1,11 ****
  FILE=readSD
  
  all:
! 	gcc -Wall $(FILE).c -o $(FILE)
  
  run:
! 	./$(FILE)
  
  clean:
! 	rm $(FILE)
! 
--- 1,11 ----
  FILE=readSD
+ EXE_FILE=$(FILE).exe
  
  all:
! 	gcc -Wall $(FILE).c -o $(EXE_FILE)
  
  run:
! 	./$(EXE_FILE)
  
  clean:
! 	rm $(EXE_FILE)

Index: downloadSessions.pl
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD/downloadSessions.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** downloadSessions.pl	12 Dec 2007 20:44:08 -0000	1.1
--- downloadSessions.pl	21 Dec 2007 02:24:41 -0000	1.2
***************
*** 4,9 ****
  use File::Basename;
  
! my $SD_DEVICE_PATH = "/dev/sda";
! #my $SD_DEVICE_PATH = "/dev/sdd";
  
  my $node = @ARGV[0];
--- 4,9 ----
  use File::Basename;
  
! #my $SD_DEVICE_PATH = "/dev/sda"; # Spaulding device
! my $SD_DEVICE_PATH = "/dev/sdd";   # Konrad's device
  
  my $node = @ARGV[0];
***************
*** 24,27 ****
  foreach my $currDir (@subDirs) {
      #print "Processing $currDir ...\n";
!     system("./readSD $currDir sessionInfo.txt $node $SD_DEVICE_PATH");
  }
--- 24,27 ----
  foreach my $currDir (@subDirs) {
      #print "Processing $currDir ...\n";
!     system("./readSD.exe $currDir sessionInfo.txt $node $SD_DEVICE_PATH");
  }

Index: nodeInfo.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD/nodeInfo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** nodeInfo.c	12 Dec 2007 20:44:08 -0000	1.1
--- nodeInfo.c	21 Dec 2007 02:24:41 -0000	1.2
***************
*** 8,12 ****
   * Returns 1 if the headblockID for nodeId was found, 0 otherwise; 
   */
! int getNodeInfo(char *fileName, uint16_t nodeID, uint32_t *headBlockID, uint32_t *nbrBlocks)
  {
      char word[50];
--- 8,12 ----
   * Returns 1 if the headblockID for nodeId was found, 0 otherwise; 
   */
! int getNodeInfo(char *fileName, uint16_t nodeID, uint32_t *startBlockID, uint32_t *nbrBlocks)
  {
      char word[50];
***************
*** 27,41 ****
          else if (atNodes == 1) {
              int node;
!             int block;
              const char delimeters[] = "<,>";
-             //printf("nodeInfo= %s\n", word);
              node  = strtoul(strtok(word, delimeters), NULL, 0);
!             block = strtoul(strtok(NULL, delimeters), NULL, 0);
!             //printf("  nodeID= %u\n", node);
!             //printf("  blockID= %u\n", block);
              if (node == nodeID) {
!                 *headBlockID = block;
!                 
!                 returnVal = 1;
              }
          }
--- 27,41 ----
          else if (atNodes == 1) {
              int node;
!             int startBlock;
!             int endBlock;
              const char delimeters[] = "<,>";
              node  = strtoul(strtok(word, delimeters), NULL, 0);
!             startBlock = strtoul(strtok(NULL, delimeters), NULL, 0);
!             endBlock = strtoul(strtok(NULL, delimeters), NULL, 0);
!             //printf("<nodeID= %u, startBlockID= %u, endBlockID= %u\n", node, startBlock, endBlock);
              if (node == nodeID) {
!                 *startBlockID = startBlock;
!                 *nbrBlocks = endBlock - startBlock;
!                 returnVal = 1;                
              }
          }
***************
*** 43,48 ****
              atNbrBlocks = 1;
          }
!         else if (strcmp(word, "<nodeID,headBlockID>=") == 0) {
!             atNodes = 1;
          }
          
--- 43,48 ----
              atNbrBlocks = 1;
          }
!         else if (strcmp(word, "<nodeID,startBlockID,endBlockID>=") == 0) {
!             atNodes = 1;            
          }
          

Index: readSD.c
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/harvard/spaulding/src/gui/sessions/readSD/readSD.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** readSD.c	12 Dec 2007 20:44:08 -0000	1.1
--- readSD.c	21 Dec 2007 02:24:41 -0000	1.2
***************
*** 11,18 ****
  #define FLASH_BLOCK_SIZE 512ul
  #define DATASTORE_BLOCK_SIZE 256ul
! #define BLOCK_DATA_SIZE (256-sizeof(uint32_t))
  
  #define GLOBALTIME_RATE_HZ 32768
! #define SAMPLING_RATE_HZ 100
  
  typedef struct FlashInfo
--- 11,18 ----
  #define FLASH_BLOCK_SIZE 512ul
  #define DATASTORE_BLOCK_SIZE 256ul
! #define BLOCK_DATA_SIZE (DATASTORE_BLOCK_SIZE-sizeof(uint32_t))
  
  #define GLOBALTIME_RATE_HZ 32768
! 
  
  typedef struct FlashInfo
***************
*** 25,33 ****
  typedef struct Block {
      uint32_t sqnNbr;
!     uint8_t data[256-sizeof(uint32_t)];
  } Block;
  
  
! #define SAMPLE_CHUNK_NUM_SAMPLES ((BLOCK_DATA_SIZE - 2*sizeof(uint32_t) - 2*sizeof(uint16_t) - sizeof(channelID_t)*MCS_MAX_NBR_CHANNELS_SAMPLED) / sizeof(sample_t))
  
  
--- 25,33 ----
  typedef struct Block {
      uint32_t sqnNbr;
!     uint8_t data[BLOCK_DATA_SIZE];
  } Block;
  
  
! #define SAMPLE_CHUNK_NUM_SAMPLES ((BLOCK_DATA_SIZE - 2*sizeof(uint32_t) - 3*sizeof(uint16_t) - sizeof(channelID_t)*MCS_MAX_NBR_CHANNELS_SAMPLED) / sizeof(sample_t))
  
  
***************
*** 35,38 ****
--- 35,39 ----
      uint32_t    localTime;
      uint32_t    globalTime;
+     uint16_t    samplingRate;
      uint16_t    timeSynched;         // true or false 
      uint16_t    nbrMultiChanSamples; // Number of samples
***************
*** 52,60 ****
  }
  
! void getBlock(Block *blockPtr, uint32_t blockID, uint32_t nbrBlocks, FILE *filePtr)
  {
! //    uint32_t blocksStartOffset = FLASH_BLOCK_SIZE;
!     uint32_t blocksStartOffset = 0;
!     uint32_t offset = blocksStartOffset + (blockID-nbrBlocks)*FLASH_BLOCK_SIZE;
  
      fseek(filePtr, offset, SEEK_SET);
--- 53,60 ----
  }
  
! void getBlock(Block *blockPtr, uint32_t blockID, FILE *filePtr)
  {
!     uint32_t blocksStartOffset = FLASH_BLOCK_SIZE;
!     uint32_t offset = blocksStartOffset + (blockID-1)*FLASH_BLOCK_SIZE;
  
      fseek(filePtr, offset, SEEK_SET);
***************
*** 62,65 ****
--- 62,75 ----
  }
  
+ void printFlashInfo(char *devicePath)
+ {
+     FlashInfo flashInfo;
+     FILE *sdFilePtr = fopen(devicePath, "rb");
+     getFlashInfo(&flashInfo, sdFilePtr);
+     
+     printf("hash= %u, tail= %u, head= %u\n", flashInfo.hash, flashInfo.tail, flashInfo.head);
+     fclose(sdFilePtr);
+ }
+ 
  void printBlock(FILE *filePtr, Block *blockPtr)
  {
***************
*** 67,72 ****
      uint16_t samp = 0;
      SampleChunk *scPtr = (SampleChunk*) blockPtr->data;
!     fprintf(filePtr, "# blockID= %u:  localTime= %u, globalTime= %u, timeSynched= %u, nbrMultiChanSamples= %u, channelIDs= {",
!            blockPtr->sqnNbr, scPtr->localTime, scPtr->globalTime, scPtr->timeSynched, scPtr->nbrMultiChanSamples);
  
      for (i = 0; i < MCS_MAX_NBR_CHANNELS_SAMPLED; ++i) {
--- 77,82 ----
      uint16_t samp = 0;
      SampleChunk *scPtr = (SampleChunk*) blockPtr->data;
!     fprintf(filePtr, "# blockID= %u:  localTime= %u, globalTime= %u, samplingRate= %u, timeSynched= %u, nbrMultiChanSamples= %u, channelIDs= {",
!             blockPtr->sqnNbr, scPtr->localTime, scPtr->globalTime, scPtr->samplingRate, scPtr->timeSynched, scPtr->nbrMultiChanSamples);
  
      for (i = 0; i < MCS_MAX_NBR_CHANNELS_SAMPLED; ++i) {
***************
*** 83,87 ****
              double globalTimeSec = scPtr->globalTime / (double)GLOBALTIME_RATE_HZ;
              double sampleTimeSec = globalTimeSec + (double)(samp/MCS_MAX_NBR_CHANNELS_SAMPLED)/
!                                                    (double)SAMPLING_RATE_HZ;
              fprintf(filePtr, "\n%.4f ", sampleTimeSec);
          }
--- 93,97 ----
              double globalTimeSec = scPtr->globalTime / (double)GLOBALTIME_RATE_HZ;
              double sampleTimeSec = globalTimeSec + (double)(samp/MCS_MAX_NBR_CHANNELS_SAMPLED)/
!                                                    (double)scPtr->samplingRate;
              fprintf(filePtr, "\n%.4f ", sampleTimeSec);
          }
***************
*** 116,119 ****
--- 126,130 ----
  int main(int argc, char** argv)
  {
+ 
      char *sessionDir = argv[1];
      char *sessionInfoFile = argv[2];
***************
*** 127,133 ****
      printf("=> nodeID= %d: %s\n", nodeID, infoFilePath);
  
!     if (getNodeInfo(infoFilePath, nodeID, &startBlockID, &nbrBlocks)) {     
!         // (1) - Open the SD card 
!         //FlashInfo flashInfo;
          Block block;
          uint32_t i = 0;
--- 138,150 ----
      printf("=> nodeID= %d: %s\n", nodeID, infoFilePath);
  
!     // (1) Print the FlashInfo
!     //printFlashInfo(devicePath);
!     //return 0;
! 
! 
!     if (getNodeInfo(infoFilePath, nodeID, &startBlockID, &nbrBlocks)) {
!         //printf("   found sessionInfo for nodeID= %u, startBlockID= %u, nbrBlocks= %u\n", nodeID, startBlockID, nbrBlocks);
! 
!         // (1) - Open the SD card
          Block block;
          uint32_t i = 0;
***************
*** 138,145 ****
          outFilePtr = fopen(outFile, "w");
  
-         printf("   found sessionInfo for nodeID= %u, startBlockID= %u, nbrBlocks= %u\n", nodeID, startBlockID, nbrBlocks);
  
          for (i = startBlockID; i < (startBlockID + nbrBlocks); ++i) {
!             getBlock(&block, i, nbrBlocks, sdFilePtr);
              printBlock(outFilePtr, &block);
          }
--- 155,161 ----
          outFilePtr = fopen(outFile, "w");
  
  
          for (i = startBlockID; i < (startBlockID + nbrBlocks); ++i) {
!             getBlock(&block, i, sdFilePtr);
              printBlock(outFilePtr, &block);
          }
***************
*** 159,197 ****
  /* int main(int argc, char** argv) */
  /* { */
! /*     FlashInfo flashInfo; */
! /*     Block block; */
! /*     int i = 0; */
! /*     FILE *filePtr; */
! /*     uint32_t startBlockID = 1; */
! /*     uint32_t nbrBlocks = 0; */
! 
! /*     if (argc != 3) { */
! /*         printf("ERROR: Wrong number of arguments\n"); */
! /*         return 1; */
! /*     } */
! /*     else { */
! /*         startBlockID = atoi(argv[1]); */
! /*         nbrBlocks = atoi(argv[2]); */
! /*         if (startBlockID < 1 || nbrBlocks < 1) { */
! /*             printf("ERROR: Bad blockID or nmbrBlocks\n"); */
! /*             return 1; */
! /*         } */
! /*     } */
! 
! /*     printf("startBlockID= %u, nbr= %u\n", startBlockID, nbrBlocks); */
! /*     //filePtr = fopen("sd.img","rb"); */
! /*     //filePtr = fopen("/dev/sdd","rb"); */
! /*     filePtr = fopen("/dev/sdb","rb"); */
! 
! /*     getFlashInfo(&flashInfo, filePtr); */
! /*     printf("hash= %u, tail= %u, head= %u\n", flashInfo.hash, flashInfo.tail, flashInfo.head); */
! 
! /*     for (i = startBlockID; i < (startBlockID + nbrBlocks); ++i) { */
! /*         getBlock(&block, i, filePtr); */
! /*         printBlock(&block); */
! /*     } */
! 
! /*     printf("sizeof(uint32_t) = %d\n", sizeof(uint32_t)); */
! /*     fclose(filePtr); */
  /*     return 0; */
  /* } */
--- 175,179 ----
  /* int main(int argc, char** argv) */
  /* { */
! /*     printFlashInfo("/dev/sdd"); */
  /*     return 0; */
  /* } */



More information about the Tinyos-contrib-commits mailing list