Ejemplo n.º 1
0
Archivo: ds18b20.c Proyecto: Dearn/SW2
short ds18b20ReadTempNoRom(void)
{
	owStrongPullupOff();
	if(owPresence())
	{
		unsigned char tempL;
		unsigned char tempH;
		volatile unsigned char Th;
		volatile unsigned char Tl;
		volatile unsigned char res1;
		volatile unsigned char res2;
		volatile unsigned char crc;
		owWrite(ONE_WIRE_CMD_SKIP_ROM);
		owWrite(ONE_WIRE_CMD_READ_SCRATCHPAD);
		tempL = owRead();
		tempH = owRead();
		Th = owRead();
		Tl = owRead();
		res1 = owRead();
		res2 = owRead();
		COUNT_REMAIN = owRead();
		COUNT_PER = owRead();
		crc = owRead();
		owPresence();
//		COUNT_REMAIN = COUNT_REMAIN/2;
//		COUNT_PER = (COUNT_PER-COUNT_REMAIN)/COUNT_PER);
//		LCDPutunsigned char(0x30+((COUNT_PER-COUNT_REMAIN)/COUNT_PER)*10000, 40, 10, LARGE, BLACK, YELLOW);

		{short temperature = ( (unsigned short)tempH << 8) | tempL;
		return(temperature);
		}
	}
	return(0x7FFF);
}
Ejemplo n.º 2
0
static bool expbrdScan(void)
{
  uint8_t i = 0;
  bool status = false;

  if (owScan(&nBoards))
  {
    DEBUG_PRINT("Found %d memories.\n", nBoards);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }

  for (i = 0; i < nBoards; i++)
  {
    if (owRead(i, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[i]))
    {
      if (expbrdIsValid(&expbrdData[i]))
      {
        DEBUG_PRINT("Info board %i:\n", i);
        expbrdPrintData(&expbrdData[i]);
        status = true;
      }
    }
    else
    {
      DEBUG_PRINT("Reading board nr:%d [FAILED].\n", i);
    }
  }

  return status;
}
Ejemplo n.º 3
0
void memReadProcess()
{
  uint8_t memId = p.data[0];
  uint8_t readLen = p.data[5];
  uint32_t memAddr;
  uint8_t status = 0;

  memcpy(&memAddr, &p.data[1], 4);

  MEM_DEBUG("Packet is MEM READ\n");
  p.header = CRTP_HEADER(CRTP_PORT_MEM, READ_CH);
  // Dont' touch the first 5 bytes, they will be the same.

  if (memId == EEPROM_ID)
  {
    if (memAddr + readLen <= EEPROM_SIZE &&
        eepromReadBuffer(&p.data[6], memAddr, readLen))
      status = 0;
    else
      status = EIO;
  }
  else if (memId == LEDMEM_ID)
  {
    if (memAddr + readLen <= sizeof(ledringmem) &&
        memcpy(&p.data[6], &(ledringmem[memAddr]), readLen))
      status = 0;
    else
      status = EIO;
  }
  else
  {
    memId = memId - NBR_STATIC_MEM;
    if (memAddr + readLen <= OW_MAX_SIZE &&
        owRead(memId, memAddr, readLen, &p.data[6]))
      status = 0;
    else
      status = EIO;
  }

#if 0
  {
    int i;
    for (i = 0; i < readLen; i++)
      consolePrintf("%X ", p.data[i+6]);

    consolePrintf("\nStatus %i\n", status);
  }
#endif

  p.data[5] = status;
  if (status == 0)
    p.size = 6 + readLen;
  else
    p.size = 6;


  crtpSendPacket(&p);
}
Ejemplo n.º 4
0
/**
 * Read a block from a memory bank and print in hex
 *
 * bank    MemoryBank to read a block from
 * portnum port number
 * SNum    the serial number for the device
 * addr    address to start reading from
 * len     length of data to read
 *
 * @return 'true' if the dumping of the memory bank
 *          worked.
 */
SMALLINT dumpBankBlock (SMALLINT bank, int portnum, uchar SNum[8],
                        int addr, int len)
{
   uchar read_buf[8000];  // make larger if the data being read is larger
   int i;

   if(!owRead(bank,portnum,SNum,addr,FALSE,&read_buf[0],len))
      return FALSE;

   for(i=0;i<len;i++)
      printf("%02X ",read_buf[i]);
   printf("\n");

   return TRUE;

}
Ejemplo n.º 5
0
static void enumerateDecks(void)
{
  uint8_t nDecks = 0;
  bool noError = true;

  owInit();

  if (owScan(&nDecks))
  {
    DECK_INFO_DBG_PRINT("Found %d deck memor%s.\n", nDecks, nDecks>1?"ies":"y");
  } else {
    DEBUG_PRINT("Error scanning for deck memories, "
                "no deck drivers will be initialised\n");
    nDecks = 0;
  }

#ifndef IGNORE_OW_DECKS
  for (int i = 0; i < nDecks; i++)
  {
    DECK_INFO_DBG_PRINT("Enumerating deck %i\n", i);
    if (owRead(i, 0, sizeof(deckInfos[0].raw), (uint8_t *)&deckInfos[i]))
    {
      if (infoDecode(&deckInfos[i]))
      {
        deckInfos[i].driver = findDriver(&deckInfos[i]);
        printDeckInfo(&deckInfos[i]);
      } else {
#ifdef DEBUG
        DEBUG_PRINT("Deck %i has corrupt OW memory. "
                    "Ignoring the deck in DEBUG mode.\n", i);
        deckInfos[i].driver = &dummyDriver;
#else
        DEBUG_PRINT("Deck %i has corrupt OW memory. "
                    "No driver will be initialized!\n", i);
        noError = false;
#endif
      }
    }
    else
    {
      DEBUG_PRINT("Reading deck nr:%d [FAILED]. "
                  "No driver will be initialized!\n", i);
      noError = false;
    }
  }
#else
  DEBUG_PRINT("Ignoring all OW decks because of compile flag.\n");
  nDecks = 0;
#endif

  // Add build-forced driver
  if (strlen(deck_force) > 0) {
    DEBUG_PRINT("DECK_FORCE=%s found\n", deck_force);
  	//split deck_force into multiple, separated by colons, if available 
    char delim[] = ":"; 

    char temp_deck_force[strlen(deck_force)]; 
    strcpy(temp_deck_force, deck_force); 
    char * token = strtok(temp_deck_force, delim); 
 
    while (token) { 
      deck_force = token; 

      const DeckDriver *driver = deckFindDriverByName(deck_force);
      if (!driver) {
        DEBUG_PRINT("WARNING: compile-time forced driver %s not found\n", deck_force);
      } else if (driver->init || driver->test) {
        if (nDecks <= DECK_MAX_COUNT)
        {
          nDecks++;
          deckInfos[nDecks - 1].driver = driver;
          DEBUG_PRINT("compile-time forced driver %s added\n", deck_force);
        } else {
          DEBUG_PRINT("WARNING: No room for compile-time forced driver\n");
        }
      }
      token = strtok(NULL, delim); 
	}
  }

  if (noError) {
    count = nDecks;
  }

  return;
}
Ejemplo n.º 6
0
bool owTest()
{
  uint8_t nOwMem = 0;
  uint8_t nOwIter = 0;
  OwSerialNum sn;

  if (owScan(&nOwMem))
  {
    DEBUG_PRINT("Found %d.\n", nOwMem);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }

  for (nOwIter = 0; nOwIter < nOwMem; nOwIter++)
  {
    if (owGetinfo(nOwIter, &sn))
    {
      DEBUG_PRINT("Serial 0x%X %X %X %X %X %X %X %X.\n",
                  sn.type, sn.id[0], sn.id[1], sn.id[2],
                  sn.id[3], sn.id[4], sn.id[5], sn.crc);
    }
    else
    {
      DEBUG_PRINT("Mem:%d Getinfo [FAILED].\n", nOwIter);
    }
  }

#ifdef OW_READ_TEST
  {
    static uint8_t testbuf[129];

    if (owRead(0, 0, OW_MAX_SIZE, testbuf))
    {
      for (nOwIter = 0; nOwIter < OW_MAX_SIZE; nOwIter++)
      {
        consolePrintf("%X ", testbuf[nOwIter]);
        testbuf[nOwIter] = nOwIter;
      }
      consolePrintf("\n");
    }
  }
#endif
#ifdef OW_WRITE_TEST
  if (owWrite(0, 0, sizeof(bqData), bqData))
  {
    DEBUG_PRINT("Write [OK].\n");
  }
  else
  {
    DEBUG_PRINT("Write [FAIL].\n");
  }
//  if (owWrite(1, 0, sizeof(dummyData2), dummyData2))
//  {
//    DEBUG_PRINT("Write [OK].\n");
//  }
//  else
//  {
//    DEBUG_PRINT("Write [FAIL].\n");
//  }
#endif

  return true;
}
Ejemplo n.º 7
0
static bool expbrdScan(void)
{
  uint8_t i = 0;
  bool status = false;
#if 1
  if (owScan(&nBoards))
  {
    DEBUG_PRINT("Found %d memories.\n", nBoards);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }


#if 0
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);

  status = owWrite(0, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[0]);

  if( status == true )
  {
	  DEBUG_PRINT("owWrite LED Ring OK\n");
  }
  else
  {
	  DEBUG_PRINT("owWrite LED Ring Fail\n");
  }
#endif



  for (i = 0; i < nBoards; i++)
  {
    if (owRead(i, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[i]))
    {
      if (expbrdIsValid(&expbrdData[i]))
      {
        DEBUG_PRINT("Info board %i:\n", i);
        expbrdPrintData(&expbrdData[i]);
        status = true;
      }
    }
    else
    {
      DEBUG_PRINT("Reading board nr:%d [FAILED].\n", i);
    }
  }
#endif
  /*
  nBoards = 1;
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);
  */

  owScan(&nBoards);

  return status;
}