コード例 #1
0
boolean MP3Player::mp3PlayCallback()
{
   if(filesize==0 &&PLAY==true)
   { 
     return false;
   }
   
   else if(filesize>0 &&PLAY==true)
   {
	if(k>=BUF_SIZE)
    {     //if buffer emptied refill buffer
        //word res=
		myFile.read(AudioBuf, BUF_SIZE);
              //reset counter
        k=0; 
    }
 
    if(STA013_DATREQ())       // if STA013 request data
    {
        
        STA013_CSH();   //enable STA013
        SPI.transfer(AudioBuf[k]); //send data  
        STA013_CSL();   //disable STA013      
        k++;
        filesize--;        //counting down
    }
	
	return true;
	
   }
   else
	 return false;
   
}
コード例 #2
0
void readSettings() {
	int n,cc;
	char ch, buff[24];
	char  buff2[80];
	unsigned int ndx=0;
	int read=0;
    if (!settingsFile.open(&root, settingsFileName, O_READ)) {
        console.printf("DBG: Creating New Settings File\r\n"); console.flush();
        writeSettings();
        return;
	}
    console.printf("DBG: Opened Settings File: %s\r\n",settingsFileName);
	settingsFile.seekSet(0);
	while ((read=settingsFile.read(buff, sizeof(buff))) > 0) {
        //console.printf("DBG: READ %d\r\n",read); console.flush();
        for (cc=0; cc < read ; cc++) {
            
            ch=buff[cc];
            //console.putChar(ch); console.flush();
            buff2[ndx]=ch;
            if (ndx<MAX_INPUT_LINE) {ndx++;}
            if (ch=='\n'){//console.putChar('\r');
                if(ndx) {
                    ndx--; // eat the newline.
                }
                buff2[ndx]='\0';
                //console.puts(buff2);
                if ((ndx>4) && buff2[3]=='!') {//fix this when the files are better
                    buff2[3]='\0';
                    n=lookupIndex(buff2);
                    switch (n) {
                        case _NPW_:
                            networkSetPassword(buff2+4);
                            break;
                        case _NJN_:
                            Watchdog_Reset();
                            networkJoin(buff2 +4);
                            break;
                        case _PKY_:
                            strncpy(pachubeKey, buff2+4, MAX_PATCHUBE_KEY_LENGHT-1);
                            break;
                        case _PFD_:
                            strncpy(pachubeFeed, buff2+4, MAX_PATCHUBE_FEED_LENGHT-1);
                            break;
                        default:
                            break;
                    }
                    
                }
            
                ndx=0; 

            }
        }
    }
    
    console.printf("DBG: Finished with Settings File: %s\r\n",settingsFileName);
    
	settingsFile.close();
}
コード例 #3
0
int WiFiCmdRobot::WiFiSendPicture (int16_t n)
{
  int ret=SUCCESS;
  int16_t nbytes; 
  uint8_t buf[PAYLOAD_SIZE];
  char filename[12+1];
 
  Serial.print("n: ");
  Serial.println(n);
  
  // Open the file
  sprintf(filename, "PICT%02d.jpg", n);
  if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR;  

  Serial.print("Open file: ");
  Serial.println(filename);

  // read from the file until there's nothing else in it:
  while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
       for (unsigned int idx = 0; idx<nbytes;idx++)
       {
           tcpClient.print(buf[idx]);
       }
 
  }// while
  
  //Close file
  if (!FilePicture.close()) return FILE_CLOSE_ERROR;  
  
  return SUCCESS;
}
コード例 #4
0
ファイル: display.cpp プロジェクト: KoljaWindeler/speedoino
// grafix has to be stored at /gfx/
int speedo_disp::sd2ssd(char filename[10],int frame){
	send_command(0x15);
	send_command(0x00);
	send_command(0x7F);
	send_command(0x75);
	send_command(0x00);
	send_command(0x3F);

	SdFile root;
	SdFile file;
	SdFile subdir;
	root.openRoot(&pSD->volume);

	if(!subdir.open(&root, "gfx", O_READ))    {  return 1; };
	if(!file.open(&subdir, filename, O_READ)) {  return 2; };
	unsigned long frame_seeker=(unsigned long)frame*64*64;
	if(!file.seekSet(frame_seeker))			  {  return 3; }; // ein bild ist 64*64 Byte groß, da wir 64 lines zu je 64*2*4 Bit Breite haben

	uint8_t buf[65];
	//int n;
	//while ((n = file.read(buf, sizeof(byte)*64)) > 0) {
	for (int zeile=0;	(file.read(buf, sizeof(byte)*64)>0)	&& zeile<64;	zeile++ ) {
		for(int j=0;j<64;j++){
			send_char(buf[j]);
		};
	};
	file.close();
	subdir.close();
	root.close();
	return 0;
};
コード例 #5
0
void AtMegaWebServer::send_file(SdFile& file) {
  size_t size;
  while ((size = file.read(buffer, sizeof(buffer))) > 0) {
    if (!client_.connected()) {
      break;
    }
    client_.write((uint8_t*)buffer, size);
  }
}
コード例 #6
0
ファイル: TinyWebServer.cpp プロジェクト: d0ughb0y/Chauvet16
void TinyWebServer::send_file(SdFile& file) {
  char _buf[512];
  size_t size;
  while ((size = file.read(_buf, sizeof(_buf))) > 0) {
    if (!client_.connected()) {
      break;
    }
    write((uint8_t*)_buf, size);
  }
}
コード例 #7
0
void loop() { 
  uint32_t t;
  double r;

  Serial.println("Type any character to start");
  while (!Serial.available()) SPARK_WLAN_Loop();
  while (Serial.available()) Serial.read();

  // open or create file - truncate existing file.
  if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
    error("open failed");
  }
  // fill buf with known data
  for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
    buf[i] = 'A' + (i % 26);
  }
  buf[BUF_SIZE-2] = '\r';
  buf[BUF_SIZE-1] = '\n';
  Serial.print("File size ");
  Serial.print(FILE_SIZE_MB);
  Serial.println(" MB");
  uint32_t n = FILE_SIZE/sizeof(buf);
  Serial.println("Starting write test.  Please wait up to a minute");
  // do write test
  t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
      error("write failed");
    }
  }
  t = millis() - t;
  file.sync();
  r = (double)file.fileSize()/t;
  Serial.print("Write ");
  Serial.print(r);
  Serial.println(" kB/sec");
  Serial.println();
  Serial.println("Starting read test.  Please wait up to a minute");
  // do read test
  file.rewind();
  t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
      error("read failed");
    }
  }
  t = millis() - t;
  r = (double)file.fileSize()/t;
  Serial.print("Read ");
  Serial.print(r);
  Serial.println(" kB/sec");
  Serial.println("Done");
  file.close();
}
コード例 #8
0
void HAL::importEEPROM() {
    if (eepromFile.isOpen())
			eepromFile.close();
		if (!eepromFile.open("eeprom.bin", O_RDWR | O_CREAT | O_SYNC) ||
			eepromFile.read(virtualEeprom, EEPROM_BYTES) != EEPROM_BYTES)
		{
			Com::printFLN(Com::tOpenFailedFile, "eeprom.bin");
		} else {
      Com::printFLN("EEPROM read from sd card.");
    }
    EEPROM::readDataFromEEPROM(true);
}
コード例 #9
0
ファイル: main.cpp プロジェクト: cohabo/my_src
void setup(void) {
  Serial.begin(BPS_115200);
  Serial.println();
  PgmPrintln("Type any character to start");
  while (!Serial.available());
  
  //PgmPrint("FreeRam: ");
  //Serial.println(FreeRam());
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!card.init(SPI_HALF_SPEED)) error("card.init failed");

  // initialize a FAT volume
  if (!volume.init(&card)) error("volume.init failed");

  // open the root directory
  if (!root.openRoot(&volume)) error("openRoot failed");
  
  strcpy_P(buf, PSTR("APPEND.TXT"));
  // open for read
  if (!from.open(&root, buf, O_READ)) {
    PgmPrint("Can't open "); 
    Serial.println(buf);
    PgmPrintln("Run the append example to create the file.");
    error("from.open failed");
  }
  strcpy_P(buf, PSTR("ACOPY.TXT"));
  // create if needed, truncate to zero length, open for write
  if (!copy.open(&root, buf, O_CREAT | O_TRUNC | O_WRITE)) {
    error("copy.open failed");
  }
  // count for printing periods
  uint16_t p = 0;
  int16_t n;  
  while ((n = from.read(buf, sizeof(buf))) > 0) {
    if (copy.write(buf, n) != n) error("write failed");
    // print progress periods
    if (!(p++ % 25)) Serial.print('.');
    if (!(p % 500)) Serial.println();
  }
  Serial.println();
  if (n != 0) error ("read");
  // force write of directory entry and last data
  if (!copy.close()) error("copy.close failed");
  PgmPrintln("Copy done.");
}
コード例 #10
0
ファイル: web.cpp プロジェクト: egisz/sprinklers_pi
static void ServeFile(FILE * stream_file, const char * fname, SdFile & theFile, EthernetClient & client)
{
	freeMemory();
	const char * ext;
	for (ext=fname + strlen(fname); ext>fname; ext--)
		if (*ext == '.')
		{
			ext++;
			break;
		}
	if (ext > fname)
	{
		if (strcmp(ext, "jpg") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/jpeg");
		else if (strcmp(ext, "gif") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/gif");
		else if (strcmp(ext, "css") == 0)
			ServeHeader(stream_file, 200, "OK", true, "text/css");
		else if (strcmp(ext, "js") == 0)
			ServeHeader(stream_file, 200, "OK", true, "application/javascript");
		else if (strcmp(ext, "ico") == 0)
			ServeHeader(stream_file, 200, "OK", true, "image/x-icon");
		else
			ServeHeader(stream_file, 200, "OK", true);
	}
	else
		ServeHeader(stream_file, 200, "OK", true);


#ifdef ARDUINO
	flush_sendbuf(client);
#else
	fflush(stream_file);
#endif
	while (theFile.available())
	{
		int bytes = theFile.read(sendbuf, 512);
		if (bytes <= 0)
			break;
		client.write((uint8_t*) sendbuf, bytes);
	}
}
コード例 #11
0
ファイル: SdFatRead.c プロジェクト: aerospace6666/AeroQuad
void setup(void) {
    Serial.begin(9600);
    Serial.println();
    Serial.println("type any character to start");
    while (!Serial.available());
    Serial.println();

    // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
    // breadboards.  use SPI_FULL_SPEED for better performance.
    if (!card.init(SPI_HALF_SPEED)) error("card.init failed");

    // initialize a FAT volume
    if (!volume.init(&card)) error("volume.init failed");

    // open the root directory
    if (!root.openRoot(&volume)) error("openRoot failed");

    // open a file
    if (file.open(&root, "PRINT00.TXT", O_READ)) {
        Serial.println("Opened PRINT00.TXT");
    }
    else if (file.open(&root, "WRITE00.TXT", O_READ)) {
        Serial.println("Opened WRITE00.TXT");
    }
    else {
        error("file.open failed");
    }
    Serial.println();

    // copy file to serial port
    int16_t n;
    uint8_t buf[7];// nothing special about 7, just a lucky number.
    while ((n = file.read(buf, sizeof(buf))) > 0) {
        for (uint8_t i = 0; i < n; i++) Serial.print(buf[i]);
    }
    /* easier way
    int16_t c;
    while ((c = file.read()) > 0) Serial.print((char)c);
    */
    Serial.println("\nDone");
}
コード例 #12
0
idigi_callback_status_t iDigiFileSystem::app_process_file_read(idigi_file_request_t * const request_data,
                                                     idigi_file_data_response_t * const response_data)
{
    idigi_callback_status_t status = idigi_callback_continue;
    SdFile *file = (SdFile *) request_data->handle;

    int const result = file->read(response_data->data_ptr, response_data->size_in_bytes);

    if (result < 0)
    {
        APP_DEBUG("read %p req %d, returned err %d\n", (void *) file, response_data->size_in_bytes, result);
        response_data->error->error_status = idigi_file_unspec_error;
        goto done;
    }

    APP_DEBUG("read %p req %d, returned %d\n", (void *) file, response_data->size_in_bytes, result);
    response_data->size_in_bytes = result;

done:
    return status;
}
コード例 #13
0
boolean MP3Player::Setup_STA013(void)
{ 
  byte buf[2];
  
  if (!myFile.open("sta013.cfg", O_READ)) 
  {
    #if DEBUG
	sd.errorHalt("cfg file error");
	#endif 
	return false;
  }
  
  #if DEBUG
  Serial.println("setting STA013 from cfgfile");  
  #endif 
  
  
  while (myFile.available()) 
  {
    buf[0]=byte (myFile.read());
    buf[1]=byte (myFile.read()); 
    I2C_Write(buf[0], buf[1]);
    // Serial.write(buf[0]);
    // Serial.write(buf[1]);
  }  
  
  while(!myFile.close())
  {
	  #if DEBUG
	  Serial.println("close cfg file..");
	  #endif
  }
  
    
  #if DEBUG
  Serial.println("Setup STA013 Register Done..");     
  #endif 
  
  return true;
}
コード例 #14
0
ファイル: sdfi.cpp プロジェクト: ro0lz/_CANcrusher_ARM
boolean SD_ReadFile(const char *filename)
{
    uint32_t t_arrival = millis();
    boolean retVal = false;
    sdf.chdir();
    if (!file.open(filename, O_READ)) {
        sdf.errorHalt("opening FILE for read failed");
    }
    else
    {
        uint32_t len = file.fileSize();
        uint8_t index = 0;
        for(uint32_t i=0; i< len; i++)
        {
            int intData = file.read();
            char byteData;
            int base = 10u;
            //itoa(intData,&byteData,base);	// Convert to ASCII
            buffer[index] = (uint8_t)intData;//byteData;
            if(index < 63u) {
                index++;
            }
            else {
                usb_rawhid_send(buffer, 100u);
                index = 0;
            }

        }
        file.close();
        uint32_t t_exit = millis() - t_arrival;
        buffer[62] = (uint8_t)((t_exit & 0x000000FF)>>8);
        buffer[63] = (uint8_t)t_exit;
        usb_rawhid_send(buffer,100u);

    }
}
コード例 #15
0
ファイル: UTFT_SdRaw.cpp プロジェクト: RitterRBC/Arduino
int UTFT_SdRaw::pan(int dispx, int dispy, int sx, int sy, unsigned long offsetx, unsigned long offsety, unsigned long sizex, unsigned long sizey, char *filename, bool iswap)
{
	char buffer[2*sx];
	int cx, cy, cp;
	word temp, result;
	unsigned long temp1,temp2;
	temp1=sizex*2;
	temp2=offsetx*2;
	if (dataFile.open(filename))
	{
		cbi(_UTFT->P_CS, _UTFT->B_CS);
		cx=0;
		cy=0;
		result=sx;
		if (_UTFT->orient==PORTRAIT)
		{
			_UTFT->setXY(dispx, dispy, dispx+sx-1, dispy+sy-1);
		}
		for(int n=0;n<sy;n++)
		{
			dataFile.seekSet(((n+offsety)*temp1)+temp2);
			result=dataFile.read(&buffer,2*sx);
			if (_UTFT->orient==PORTRAIT)
			{
				for (int i=0; i<result; i+=2)
				{
					if(iswap==1)
					{
						_UTFT->LCD_Write_DATA(buffer[i+1],buffer[i]);
					}
					else
					{
					_UTFT->LCD_Write_DATA(buffer[i],buffer[i+1]);
					}						
				}
			}
			else
			{
				cp=0;
				while (cp<result)
				{
					if (((result-cp)/2)<(sx-cx))
					{
						_UTFT->setXY(dispx+cx, dispy+cy, dispx+cx+((result-cp)/2)-1, dispy+cy);
						for (int i=(result-cp)-2; i>=0; i-=2)
						{
							if(iswap==1)
							{
								_UTFT->LCD_Write_DATA(buffer[cp+i+1],buffer[cp+i]);
							}
							else
							{
								_UTFT->LCD_Write_DATA(buffer[cp+i],buffer[cp+i+1]);
							}						
						}
						cx+=((result-cp)/2);
						cp=result;
					}
					else
					{
						_UTFT->setXY(dispx+cx, dispy+cy, dispx+sx-1, dispy+cy);
						for (int i=sx-cx-1; i>=0; i--)
						{
							if(iswap==1)
							{
								_UTFT->LCD_Write_DATA(buffer[cp+(i*2)+1],buffer[cp+(i*2)]);
							}
							else
							{
								_UTFT->LCD_Write_DATA(buffer[cp+(i*2)],buffer[cp+(i*2)+1]);
							}
						}
						cp+=(sx-cx)*2;
						cx=0;
						cy++;
					}
				}
			}              
		}
		dataFile.close();
		_UTFT->setXY(0,0,_UTFT->getDisplayXSize()-1,_UTFT->getDisplayYSize()-1);
		sbi(_UTFT->P_CS, _UTFT->B_CS);
		return 0;
	}
	else
	{
		return 99;
	}
}
コード例 #16
0
ファイル: untitled.c プロジェクト: Akrobate/sketchbook
void loop()
{
  if(count >=500)
  {  
    led2 = !led2;
    digitalWrite(redLEDpin, led2);
    count = 0;
  }
  count +=1;

  char clientline[BUFSIZ];
  char *filename;
  int image = 0;
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;

    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ) 
            index = BUFSIZ -1;

          continue;
        }

        clientline[index] = 0;
        filename = 0;

        Serial.println(clientline);
       
        if (strstr(clientline, "GET /?") != 0) 
        {  
			if (!filename) filename = clientline + 5; 
			{
			Serial.println(filename);
			
                     
			int a=atoi(&filename[1]);
			Serial.println(a);
			
		int pin_num=0;
		int on_off=0;
		
			switch (a)
			{
				case 10
				pin_num=1;
				on_off=LOW;
				break;
				case 11
				pin_num=1;
				on_off=HIGH;
				break;
				
				case 20
				pin_num=2;
				on_off=LOW;
				break;
				case 21
				pin_num=2;
				on_off=HIGH;
				break;
				
				case 30
				pin_num=3;
				on_off=LOW;
				break;
				case 31
				pin_num=3;
				on_off=HIGH;
				break;
				
				case 40
				pin_num=4;
				on_off=LOW;
				break;
				case 41
				pin_num=4;
				on_off=HIGH;
				break;
				
				case 50
				pin_num=5;
				on_off=LOW;
				break;
				case 51
				pin_num=5;
				on_off=HIGH;
				break;
				
				case 60
				pin_num=6;
				on_off=LOW;
				break;
				case 61
				pin_num=6;
				on_off=HIGH;
				break;
				
				case 70
				pin_num=7;
				on_off=LOW;
				break;
				case 71
				pin_num=7;
				on_off=HIGH;
				break;
				
				case 80
				pin_num=8;
				on_off=LOW;
				break;
				case 81
				pin_num=8;
				on_off=HIGH;
				break;
				
			}
		
		if(pin_num!=0)
		{
			Serial.print("Pin:");
			Serial.print(pin_num);
			Serial.print(" State:");
			Serial.print(on_off);
			digitalWrite(pin_num, on_off);
		}
		
		
		
			
			
			}

        } 
        if (strstr(clientline, "GET / ") != 0) {
          filename = rootFileName;

        } 
        if (strstr(clientline, "GET /") != 0) {
          if (!filename) filename = clientline + 5; 

          (strstr(clientline, " HTTP"))[0] = 0;

          Serial.println(filename);

          if (! file.open(&root, filename, O_READ)) {
            client.println("HTTP/1.1 4041 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>Error 4041</h2>");
            client.println("<s2>The file does not exist.<s2>");
            client.println("");
            break;
          }

          Serial.println("Opened!");
          //File types
          client.println("HTTP/1.1 200 OK");
          if (strstr(filename, ".htm") != 0)
            client.println("Content-Type: text/html");
          else if (strstr(filename, ".css") != 0)
            client.println("Content-Type: text/css");
          else if (strstr(filename, ".png") != 0)
            client.println("Content-Type: image/png");
          else if (strstr(filename, ".jpg") != 0)
            client.println("Content-Type: image/jpeg");
          else if (strstr(filename, ".gif") != 0)
            client.println("Content-Type: image/gif");
          else if (strstr(filename, ".3gp") != 0)
            client.println("Content-Type: video/mpeg");
          else if (strstr(filename, ".pdf") != 0)
            client.println("Content-Type: application/pdf");
          else if (strstr(filename, ".js") != 0)
            client.println("Content-Type: application/x-javascript");
          else if (strstr(filename, ".xml") != 0)
            client.println("Content-Type: application/xml");
          else
            client.println("Content-Type: text");
          client.println();

          int16_t c;
          while ((c = file.read()) >= 0) {
            //Serial.print((char)c); //Prints all HTML code to serial (For debuging)
            client.print((char)c); //Prints all HTML code for web page
          }

          //Hit counter math
          if(units >= 2)
          {
            hits ++;
            units = 0;
          }
          units +=1;
          //End hit counter math


          client.print("<html><body>"); //HTML code starts here
          client.print("<P align=\"center\">"); 
          client.print("Hits since reset: <b>");   
          client.print(hits); //Print hits to client
          client.print("</b><br>");

          photocellReading = analogRead(photocellPin); 
          client.print("Light reading: "); 
          client.print(photocellReading); //Prints light reading to client

          // A few threshholds
          if (photocellReading < 10) {
            client.print(" - Dark");
          } 
          else if (photocellReading < 200) {
            client.print(" - Dim");
          } 
          else if (photocellReading < 500) {
            client.print(" - Light");
          } 
          else if (photocellReading < 800) {
            client.print(" - Bright");
          } 
          else {
            client.print(" - Very bright");
          }

          client.print("</p></body></html>"); //HTML code ends here
          //End hit counter and light value

          file.close();

        } 
        else {
          client.println("HTTP/1.1 4042 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>Error 4042</h2>");
          client.println("");
        }
        break;
      }
    }
    digitalWrite(greenLEDandBEEP, HIGH);
    delay(1);
    digitalWrite(greenLEDandBEEP, LOW);
    client.stop();
  }
コード例 #17
0
ファイル: main.cpp プロジェクト: cohabo/my_src
/*
 * create enough files to force a cluster to be allocated to dir.
 */
void dirAllocTest(SdFile &dir) {
  char buf[13], name[13];
  SdFile file;
  uint16_t n; 
  uint32_t size = dir.fileSize();
 
  // create files and write name to file
  for (n = 0; ; n++){
    // make file name
    sprintf(name, "%u.TXT", n);
   
    // open start time
    uint32_t t0 = millis();
    if (!file.open(&dir, name, O_WRITE | O_CREAT | O_EXCL)) {
      error("open for write failed");
    }
   
    // open end time and write start time
    uint32_t t1 = millis();
    // write file name to file
    file.print(name);
    if (!file.close()) error("close write");
   
    // write end time
    uint32_t t2 = millis();
    PgmPrint("WR ");
    Serial.print(n);
    Serial.print(' ');
   
    // print time to create file
    Serial.print(t1 - t0);
    Serial.print(' ');
   
    // print time to write file
    Serial.println(t2 - t1);
   
    // directory size will change when a cluster is added
    if (dir.fileSize() != size) break;
  }

  // read files and check content
  for (uint16_t i = 0; i <= n; i++) {
    sprintf(name, "%u.TXT", i);
   
    // open start time
    uint32_t t0 = millis();
    if (!file.open(&dir, name, O_READ)) {
      error("open for read failed");
    }
    
    // open end time and read start time
    uint32_t t1 = millis();
    int16_t nr = file.read(buf, 13);
    if (nr < 5) error("file.read failed");
    
    // read end time
    uint32_t t2 = millis();
    
    // check file content
    if (strlen(name) != (uint16_t)nr || strncmp(name, buf, nr)) {
      error("content compare failed");
    }
    if (!file.close()) error("close read failed");
    
    PgmPrint("RD ");
    Serial.print(i);
    Serial.print(' ');
    
    // print open time
    Serial.print(t1 - t0);
    Serial.print(' ');
    
    // print read time
    Serial.println(t2 - t1);
  }
}
コード例 #18
0
ファイル: handset.cpp プロジェクト: veonik/transpond
void loop() {
    unsigned long tick = millis();
    long diff = tick - lastTick;
    avgTickDelay = expAvg(avgTickDelay, diff);
    lastTick = tick;
    if (printTicks > printTicksI) {
        Serial.print("tick delay: ");
        Serial.print(diff);
        Serial.println("ms");
    }

    // Radio tick.
    radio->tick();

    // Send helo.
    diff = tick - lastSent;
    if ((lastAck < lastSent && diff > MAX_SEND_WAIT)
        || diff > MIN_SEND_WAIT
    ) {
        avgSendDelay = expAvg(avgSendDelay, diff);
        lastSent = tick;
        if (printTicks > printTicksI) {
            printTicksI++;
            Serial.print("send delay: ");
            Serial.print(diff);
            Serial.println("ms");
        }

        if (sendInfx) {
            Message msg("he");
            radio->send(&msg);
        } else {
            Message msg("lo");
            radio->send(&msg);
        }
        sendInfx = !sendInfx;
    }

    // Update metrics.
    tick = millis();
    if (tick - lastUpdate > UPDATE_WAIT) {
        memcpy(&mLast, &m, sizeof(metrics));
        lastUpdate = tick;
        lastVcc = readVcc();

        sinceLastAck = (int) ((lastUpdate - lastAck) / 1000L);
        if (sinceLastAck < 0) {
#ifdef DEBUG
            Serial.println("sinceLastAck less than 0");
            Serial.print("round((");
            Serial.print(lastUpdate);
            Serial.print(" - ");
            Serial.print(lastAck);
            Serial.print(") / 1000.0) = ");
            Serial.println(sinceLastAck);
#endif

            sinceLastAck = 0;
        }

        if (lastAck + TIMEOUT_WAIT < lastSent) {
            lastRoundtrip = NO_READING_INT;
            lastRssi = NO_READING_INT;
        }

        writeLog();
    }

    // Pipeline tick.
    pipe->tick();

    // Serial commands.
    if (Serial.available()) {
        String cmd = Serial.readStringUntil('\n');
        if (cmd[0] == 'D') {
            dataFile.close();
            if (!dataFile.open(root, logFilename, O_READ)) {
                Serial.println();
                Serial.println("Could not open file for reading");
                return;
            }
            uint32_t offset;
            long cmdOffset = cmd.substring(1).toInt();
            if (cmdOffset < 0) {
                offset = dataFile.fileSize() + cmdOffset;
            } else {
                offset = cmdOffset;
            }
            dataFile.seekSet(offset);
            char buf[128];
            int16_t read;
            bool firstRead = true;
            do {
                read = dataFile.read(buf, 127);
                buf[read] = 0;
                if (firstRead && read > 0) {
                    firstRead = false;
                    char *firstNewline = strchr(buf, '\n');
                    Serial.print(++firstNewline);
                } else {
                    Serial.print(buf);
                }
            } while (read > 0);
            Serial.println();
            dataFile.close();

        } else if (cmd[0] == 'L') {
            printCardInfo();

        } else if (cmd[0] == 'I') {
            Serial.print(F("Average tick delay: "));
            Serial.print(avgTickDelay);
            Serial.println(F("ms"));
            Serial.print(F("Average send delay: "));
            Serial.print(avgSendDelay);
            Serial.println(F("ms"));
            Serial.print(F("RAM free: "));
            Serial.print(freeRam());
            Serial.println(F(" bytes"));
            printTicks = (int) cmd.substring(1).toInt();
            printTicksI = 0;
        } else if (cmd[0] == 'G') {
            Serial.print(F("Location: "));
            Serial.print(m.latitude, 6);
            Serial.print(F(","));
            Serial.println(m.longitude, 6);
        } else if (cmd[0] == 'U') {
            Message msg("up");
            radio->send(&msg);
        } else if (cmd[0] == 'F') {
            if (m.logging != MODULE_ENABLED) {
                Serial.println(F("Requesting to enable logging"));
            } else {
                Serial.println(F("Requesting to disable logging"));
            }
            Message msg("tl");
            radio->send(&msg);
        } else if (cmd[0] == 'T') {
            Serial.print(F("Remote data logging is "));
            Serial.println(m.logging == MODULE_ENABLED ? "enabled" : "disabled");
        }
    }
}
コード例 #19
0
void setup() {

    int logNo;
	char configLineBuffer[LINE_BUFFER_MAX];
    spi.begin(SPI_281_250KHZ, MSBFIRST, 0);
	
	pinMode(GRN_LED,OUTPUT);
	pinMode(ORN_LED,OUTPUT);
	pinMode(RED_LED,OUTPUT);
	digitalWrite(GRN_LED,HIGH);
	digitalWrite(ORN_LED,LOW);
	digitalWrite(RED_LED,LOW);

    iwdg_init(IWDG_PRE_256, WATCHDOG_TIMEOUT);
    Watchdog_Reset();

	
    if (!card.init(&spi)) { 
    //if (!card.init()) { 
        console.printf("FTL: card.init failed");
    }
    delay(100);
    
    // initialize a FAT volume
    if (!volume.init(&card)) {
        console.printf("FTL: volume.init failed");
    }
    
    // open the root directory
    if (!root.openRoot(&volume)) 
        ;//SerialUSB.println("FTL: openRoot failed");
    
    for (logNo=0; (!logOpened) && logNo<512; logNo++) {
        Watchdog_Reset();
       //int snprintf(char *str, size_t size, const char *format, ...);
        snprintf(logFileName,15,"LOG%03d.TXT",logNo);
        if (file.open(&root, logFileName, O_READ)) {
            //SerialUSB.print("DBG: Exists  :"); SerialUSB.println(logFileName);
            file.close();
        } else if (file.open(&root, logFileName, O_CREAT|O_READ|O_WRITE)) {
            //SerialUSB.print("DBG: New File:"); SerialUSB.println(logFileName); 
            logOpened=true;
            file.sync();
            file.close();
            file.open(&root,logFileName,O_WRITE|O_READ);
			while (file.read(configLineBuffer,LINE_BUFFER_MAX)) {
				
			}
            file.sync();
        }    
    }
    //if (!logOpened) SerialUSB.println("FTL: openRoot failed");

	digitalWrite(GRN_LED,LOW);
	digitalWrite(RED_LED,HIGH);
    readSettings();
	console.printf("LSV:" BOM_VERSION "\r\n");
    console.printf("NST: %s\r\n",networkStatus()?"CONNECTED":"NOT CONNECTED");
	digitalWrite(ORN_LED,HIGH);
	digitalWrite(RED_LED,networkStatus()?HIGH:LOW);
	
}
コード例 #20
0
void writeGPSLog(uint32_t gpstime, int32_t latitude, int32_t longitude, int32_t altitude) {
#else
void writeGPSLog(int32_t latitude, int32_t longitude, int32_t altitude) {
#endif
if (f.SDCARD == 0) return;
  if (gps_data.open(GPS_LOG_FILENAME, O_WRITE | O_CREAT | O_APPEND)) {
#ifdef UBLOX  
    gps_data.print(gpstime); gps_data.write(',');
#endif
    gps_data.print(latitude); gps_data.write(',');
    gps_data.print(longitude); gps_data.write(',');
    gps_data.print(altitude); gps_data.println();
    gps_data.close();
  } else { 
    return;
  }
}

void writePLogToSD() {
  if (f.SDCARD == 0) return;
  plog.checksum = calculate_sum((uint8_t*)&plog, sizeof(plog));
  if (permanent.open(PERMANENT_LOG_FILENAME, O_WRITE | O_CREAT | O_TRUNC)) {
    permanent.print(F("arm=")); permanent.println(plog.arm);
    permanent.print(F("disarm=")); permanent.println(plog.disarm);
    permanent.print(F("start=")); permanent.println(plog.start);
    permanent.print(F("armed_time=")); permanent.println(plog.armed_time);
    permanent.print(F("lifetime=")); permanent.println(plog.lifetime, DEC);
    permanent.print(F("failsafe=")); permanent.println(plog.failsafe);
    permanent.print(F("i2c=")); permanent.println(plog.i2c);
    permanent.print(F("running=")); permanent.println(plog.running, DEC);
    permanent.print(F("checksum=")); permanent.println(plog.checksum, DEC);
    permanent.print(F("debug=")); permanent.print(debug[0]);
    permanent.print(F(",")); permanent.print(debug[1]);
    permanent.print(F(",")); permanent.print(debug[2]);
    permanent.print(F(",")); permanent.println(debug[3]);
    permanent.println();
    permanent.close();
  } else { 
    return;
  }
}

void fillPlogStruct(char* key, char* value) {
  if (strcmp(key, "arm") == 0) sscanf(value, "%u", &plog.arm);
  if (strcmp(key, "disarm") == 0) sscanf(value, "%u", &plog.disarm);
  if (strcmp(key, "start") == 0) sscanf(value, "%u", &plog.start);
  if (strcmp(key, "armed_time") == 0) sscanf(value, "%lu", &plog.armed_time);
  if (strcmp(key, "lifetime") == 0) sscanf(value, "%lu", &plog.lifetime);
  if (strcmp(key, "failsafe") == 0) sscanf(value, "%u", &plog.failsafe);
  if (strcmp(key, "i2c") == 0) sscanf(value, "%u", &plog.i2c);
  if (strcmp(key, "running") == 0) sscanf(value, "%hhu", &plog.running);
  if (strcmp(key, "checksum") == 0) sscanf(value, "%hhu", &plog.checksum);
}

void readPLogFromSD() {
  if (f.SDCARD == 0) return;
  SdFile myfile;
  char key[12];
  char value[32];
  char* tabPtr = key;
  int c;
  uint8_t i = 0;
   
  if (myfile.open(PERMANENT_LOG_FILENAME, O_READ)) {
    while (myfile.available()) {
      c = myfile.read();
      switch ((char)c) {
        case ' ':
          break;
        case '=':
          *tabPtr = '\0';
          tabPtr = value;
          break;  
        case '\n':
          *tabPtr = '\0';
          tabPtr = key;
          i = 0;
          fillPlogStruct(key, value);
          memset(key, '\0', sizeof(key));
          memset(value, '\0', sizeof(value));
          break;
        default:
          i++;
          if (i <= 12) {
            *tabPtr = (char)c;
            tabPtr++;
          }
          break;
        }
    }
  } else return;
  if (calculate_sum((uint8_t*)&plog, sizeof(plog)) != plog.checksum) {
#if defined(BUZZER)
    alarmArray[7] = 3;
    blinkLED(9, 100, 3);
#endif
    // force load defaults
    plog.arm = plog.disarm = plog.start = plog.failsafe = plog.i2c = 11;
    plog.running = 1;
    plog.lifetime = plog.armed_time = 3;
    writePLogToSD();
  }
}
コード例 #21
0
ファイル: UTFT_SdRaw.cpp プロジェクト: RitterRBC/Arduino
int UTFT_SdRaw::load(int x, int y, int sx, int sy, char *filename, int bufmult, bool iswap)
{
	char buf[(2*bufmult)*sx];
	int cx, cy, cp;
	word result;
	if (dataFile.open(filename))
	{
		cbi(_UTFT->P_CS, _UTFT->B_CS);
		cx=0;
		cy=0;
		result=bufmult*sx;
		if (_UTFT->orient==PORTRAIT)
		{
			_UTFT->setXY(x, y, x+sx-1, y+sy-1);
		}
		for(int n=0;n<sy;n+=bufmult)
		{
			result=dataFile.read(&buf,(2*bufmult)*sx);
			if (_UTFT->orient==PORTRAIT)
			{
				for (int i=0; i<result; i+=2) 
				{
					if(iswap==1)
					{
						_UTFT->LCD_Write_DATA(buf[i+1],buf[i]);
					}
					else
					{
						_UTFT->LCD_Write_DATA(buf[i],buf[i+1]);
					}
				}
			}
			else
			{
				cp=0;
				while (cp<result)
				{
					if (((result-cp)/2)<(sx-cx))
					{
						_UTFT->setXY(x+cx, y+cy, x+cx+((result-cp)/2)-1, y+cy);
						for (int i=(result-cp)-2; i>=0; i-=2)
						{
							if(iswap==1)
							{
								_UTFT->LCD_Write_DATA(buf[cp+i+1],buf[cp+i]);
							}
							else
							{
								_UTFT->LCD_Write_DATA(buf[cp+i],buf[cp+i+1]);
							}
						}
						cx+=((result-cp)/2);
						cp=result;
					}			
					else
					{
						_UTFT->setXY(x+cx, y+cy, x+sx-1, y+cy);
						for (int i=sx-cx-1; i>=0; i--)
						{
							if(iswap)
							{							
							_UTFT->LCD_Write_DATA(buf[cp+(i*2)+1],buf[cp+(i*2)]);
							}
							else
							{
							_UTFT->LCD_Write_DATA(buf[cp+(i*2)],buf[cp+(i*2)+1]);
							}
						}
						cp+=(sx-cx)*2;
						cx=0;
						cy++;
					}
				}
			}              
		}
		dataFile.close();
		_UTFT->setXY(0,0,_UTFT->getDisplayXSize()-1,_UTFT->getDisplayYSize()-1);
		sbi(_UTFT->P_CS, _UTFT->B_CS);
		return 0;
	}
	else
	{
		return 99;
	}
}
コード例 #22
0
ファイル: robot.cpp プロジェクト: RobotEdh/RobotChipKit
int robot_Send_Picture (uint8_t n)
{    
 uint16_t param[MAX_PARAMS];
 uint8_t paramlen = 0;
 uint8_t msg[MSG_SIZE_MAX];
 uint8_t msg_len = 0;
 uint8_t tag [MAX_TAGS];
 uint16_t value [MAX_TAGS];
 uint8_t nbtags;
 
 char filename[12+1];
 uint16_t nbytes = 0;
 uint8_t buf[PAYLOAD_SIZE];
 
 int ret = SUCCESS;
 
 Serial.println("Start robot_Send_Picture");
 
 // Open picture file
 sprintf(filename, "PICT%d.jpg", n);  
 if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR; 
 Serial.println("open ok "); 
 
 //Send the Picture message 
 param[0] = (uint16_t)n;
 param[1] = (uint16_t)FilePicture.fileSize();
 paramlen = 2;

 ret = IOTSerial.IOTSsend(1, PICTURE, param, paramlen); 
            
 //Read the message replied to be sure that the client is ready to receive the picture
 ret = IOTSerial.IOTSread(1, msg, &msg_len);
 Serial.print("Call IOTSread 1, ret: "); Serial.print(ret); Serial.print(", msg_len: "); Serial.println((int)msg_len);

 if (ret != SUCCESS) {
     Serial.println("error IOTSread");  
     ret = IOTSerial.IOTSflush(1);
     return 0;
 }
 
 //Decode the message
 IOTSerial.IOTSgetTags(msg, tag, value, &nbtags); // parse the response  
 Serial.print("Call IOTSgetTags, nbtags: "); Serial.println((int)nbtags);
    
 if (nbtags < 1)          return -1; 
    
 Serial.print("tag[0]: ");Serial.println((int)tag[0],HEX); 
 if (tag[0]!= TAG_CMDID)   return -2;
 Serial.print("tag[1]: "); Serial.println((int)tag[1]);  
 if (tag[1]!= TAG_RESP)   return -3;
 Serial.print("value[1]: "); Serial.println((int)value[1]);        
 if (value[1] == RESP_KO) return -4;
 if (value[1] != RESP_OK) return -5;

  // read from the file until there's nothing else in it:
 while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
       for (uint16_t i = 0;i<nbytes;i++)
       {
         ret = IOTSerial.IOTSRawsend(1, buf [i]); 
       }
 
 }// while 
  
 //Close file
 if (!FilePicture.close()) return FILE_CLOSE_ERROR; 
 
    
 Serial.println("End OK robot_IOT"); 
 return SUCCESS;                     
}			 
コード例 #23
0
ファイル: main.cpp プロジェクト: cohabo/my_src
void setup() {
  Serial.begin(BPS_115200);
  PgmPrintln("Type any character to start");
  while (!Serial.available());
  
 // PgmPrint("Free RAM: ");
 /// Serial.println(FreeRam());  
 
  // initialize the SD card at SPI_FULL_SPEED for best performance.
  // try SPI_HALF_SPEED if bus errors occur.
  if (!card.init(SPI_FULL_SPEED)) error("card.init failed");
  
  // initialize a FAT volume
  if (!volume.init(&card)) error("volume.init failed!");

  PgmPrint("Type is FAT");
  Serial.println(volume.fatType(), DEC);
  
  if (!root.openRoot(&volume)) error("openRoot failed");
  
  // open or create file - truncate existing file.
  if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) {
    error("open failed");
  }
  
  // fill buf with known data
  for (uint16_t i = 0; i < (BUF_SIZE-2); i++) {
    buf[i] = 'A' + (i % 26);
  }
  buf[BUF_SIZE-2] = '\r';
  buf[BUF_SIZE-1] = '\n';
  
  PgmPrint("File size ");
  Serial.print(FILE_SIZE_MB);
  PgmPrintln(" MB");
  PgmPrintln("Starting write test.  Please wait up to a minute");
  
  // do write test
  uint32_t n = FILE_SIZE/sizeof(buf);
  uint32_t t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
      error("write failed");
    }
  }
  t = millis() - t;
  file.sync();
  double r = (double)file.fileSize()/t;
  PgmPrint("Write ");
  Serial.print(r);
  PgmPrintln(" KB/sec");
  Serial.println();
  PgmPrintln("Starting read test.  Please wait up to a minute");
  
  // do read test
  file.rewind();
  t = millis();
  for (uint32_t i = 0; i < n; i++) {
    if (file.read(buf, sizeof(buf)) != sizeof(buf)) {
      error("read failed");
    }
  }
  t = millis() - t;
  r = (double)file.fileSize()/t;
  PgmPrint("Read ");
  Serial.print(r);
  PgmPrintln(" KB/sec");
  PgmPrintln("Done");
}
コード例 #24
0
ファイル: main.cpp プロジェクト: cohabo/my_src
void setup() 
{
  Serial.begin(BPS_115200);
  Serial.println("> type any char to start");
  while (!Serial.available());
  Serial.println();

  if (!card.init(SPI_HALF_SPEED)) 
    Serial.println("> card.init failed");
  else
    Serial.println("> card.init passed");
//  spi.end();
  
  SD_SPI.begin(SPI_HIGH_CLOCK, MSBFIRST, 0);
  
  delay(100);
  
  // initialize a FAT volume
  if (!volume.init(&card,1)) 
    Serial.println("> volume.init failed");
  else
    Serial.println("> volume.init passed");
    
  // open the root directory
  if (!root.openRoot(&volume)) 
    Serial.println("> openRoot failed");
  else
    Serial.println("> openRoot passed");

  // open a file
  if (file.open(&root, "Read.txt", O_READ)) 
  {
    Serial.println("> Opened Read.txt");
    Serial.println("> Reading ...");
    Serial.println();
    for(int i=0; i<15; i++)
      Serial.print((char)file.read());
    Serial.println("");
  }
  else
  {
    Serial.println("file.open failed");
  }
  Serial.println();  
  Serial.println("> Reading remained data...");
  Serial.println();  
  int16_t n;
  uint8_t buf[7];// nothing special about 7, just a lucky number.
  while ((n = file.read(buf, sizeof(buf))) > 0) 
  {
    for (uint8_t i = 0; i < n; i++) 
      Serial.print((char)buf[i]);
  }
  /* easier way
  int16_t c;
  while ((c = file.read()) > 0) Serial.print((char)c);
  */
  file.close();
  Serial.println("\n> Done");
  SD_SPI.end();
  
}