Beispiel #1
0
int initNetworkDHCP(){
	int retval;
	if (NutRegisterDevice(&DEV_ETHER, 0, 0)) {
		LogMsg_P(LOG_INFO, PSTR("Registering ethernet failed."));
		retval = 1;
    }
    else if (NutDhcpIfConfig(DEV_ETHER_NAME, NULL, 0)) {
        uint8_t initial_mac[6] = MY_MAC;
 
        if (NutDhcpIfConfig(DEV_ETHER_NAME, initial_mac, 0)) {
            u_long initial_ip_addr = inet_addr(MY_IP);
            u_long initial_ip_mask = inet_addr(MY_MASK);
            NutNetIfConfig(DEV_ETHER_NAME, initial_mac, initial_ip_addr, initial_ip_mask);
			retval = 2;
        }
    }
    if (NutRegisterDiscovery(INADDR_BROADCAST, 0, DISF_INITAL_ANN)) {
        //printf("Discover Service failed");
		LogMsg_P(LOG_INFO, PSTR("Discover Service failed"));
		retval = 3;
    } else {
		LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: OK"));
		LogMsg_P(LOG_INFO, PSTR("IP = [%d],[%d],[%d],[%d]"));
        default_handler = NutRegisterDiscoveryCallback(MyHandler);
		retval = 4;
    }
	return retval;
}
Beispiel #2
0
//Haal tijd op via ntp
tm getNTPTime(){
 
    time_t ntp_time = 0;
    tm *ntp_datetime;
    uint32_t timeserver = 0;
 
    _timezone = -1 * 60 * 60; //GMT+1
 
	LogMsg_P(LOG_INFO, PSTR("Retrieving time from 78.192.65.63..."));
 
    timeserver = inet_addr("78.192.65.63");
 	int i;
    for (i = 0;i < 20; i++) {
        if (NutSNTPGetTime(&timeserver, &ntp_time) == 0) {
            break;
        } else {
            NutSleep(1000);
			LogMsg_P(LOG_INFO, PSTR("Fout bij ophalen ntp tijd, pogingen over:%d"),(20-i));
        }
    }
    ntp_datetime = localtime(&ntp_time);

	LogMsg_P(LOG_INFO, PSTR("NTP time is: %02d:%02d:%02d\n"), ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
 
    //printf("NTP time is: %02d:%02d:%02d\n", ntp_datetime->tm_hour, ntp_datetime->tm_min, ntp_datetime->tm_sec);
 	tm gmt;
	gmt.tm_hour = ntp_datetime->tm_hour;
	gmt.tm_min  = ntp_datetime->tm_min;
	gmt.tm_sec	= ntp_datetime->tm_sec;
	gmt.tm_mday = ntp_datetime->tm_mday;
	gmt.tm_mon  = ntp_datetime->tm_mon;
	gmt.tm_year = ntp_datetime->tm_year;

	return gmt;
}
Beispiel #3
0
void clientSend(TCPSOCKET *sock, char* buffer, int len){
	if (NutTcpSend(sock, buffer, len) != len) {
    LogMsg_P(LOG_INFO, PSTR("Fout bij zenden client data"));
	}
	else{
		LogMsg_P(LOG_INFO, PSTR("Geen Fout bij zenden client data?"));
	}
}
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	NutThreadSetPriority(1);
	NutTimerInit();
	sei();

	printf("\nreading EEPROM\n");
	NutSleep(1000);
	readEEPROM();
	printf("UTC: %d\n",IMCconfig.UTC);
	NutSleep(1000);

	IMCconfig.UTC++;	
	printf("na ophoging UTC: %d\n",IMCconfig.UTC);
	saveEEPROM();
	NutSleep(1000);
	readEEPROM();
	printf("na saving en reading UTC: %d\n",IMCconfig.UTC);

	printf("\nResetting EEPROM\n");
	NutSleep(1000);
	resetEEPROM();
	NutSleep(1000);
	readEEPROM();

	for (;;)
	{
		
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	initMenu();
	sei();
	NutTimerInit();
	NutThreadSetPriority(1);
	int keyvalue = KbGetKey();
	int old;
	LcdBackLight(LCD_BACKLIGHT_ON);
	if(NutRegisterDevice(&DEV_ETHER, 0x8300, 5))printf("Error: No LAN device\n");
	else printf("Lan device initialized\n");
	
	for (;;)
	{
		keyvalue = KbGetKey();
		if(old != keyvalue){
			stateMenu(keyvalue);
			old = keyvalue;
		}		
		NutSleep(100);
		WatchDogRestart();
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
Beispiel #6
0
/*!
 * \brief Find a descriptor for a piece of text.
 *
 * A LookUp Table (LUT) is searched for matching text.
 * The row in which the match was found is returned.
 * If no match was found, the descriptor of the last entry
 * is returned. As a result, the table should always contain
 * at least one entry. And that last one should be the
 * default/empty or error value, depending on your needs.
 *
 * \note    The compare used is not case sensitive.
 * \note    If byLen is 0, only the first part of pcText
 *          needs to match.
 *          E.g. "foo" in the LUT will match "foo",
 *          E.g. "foo" in the LUT will match "foobar"
 *          By passing the length of pcText (not including the
 *          \0 character), will force an exact match.
 *          E.g. "foo" in the LUT will match "foo",
 *          E.g. "foo" in the LUT will not match "foobar",
 *
 * \param   tLookupTable [in] The lookup table.
 * \param   pcText [in] The text to find the value for
 *          this does not need to be 0 terminated.
 * \param   byLen [in] See notes above.
 *
 * \return  The descriptor of the row that matched.
 *          Or the descriptor of the last row if no match.
 */
void *LutSearch(CONST tLut tLookupTable[],
                CONST char *pcText,
                unsigned char byLen)
{
    unsigned char byRow = 0;

    for (byRow = 0; byRow < (unsigned char)(-1); byRow++)
    {
        unsigned char byTagLen = 0;

        if (tLookupTable[byRow].pszTag == NULL)
        {
            break;
        }

        byTagLen = strlen_P(tLookupTable[byRow].pszTag);

        if ((byLen != 0) && (byTagLen != byLen))
        {
            continue;   /* not the same size; keep looking */
        }

        /* case-insensitive compare */
        if (strncasecmp_P(pcText, tLookupTable[byRow].pszTag, byTagLen) == 0)
        {
            break;
        }
    }

#ifdef UTIL_DEBUG
    LogMsg_P(LOG_DEBUG, PSTR("Match %d"), byRow);
#endif /* #ifdef UTIL_DEBUG */

    return (tLookupTable[byRow].pDesc);
}
THREAD(Uart0KeyEvents, arg)
{
    //LogMsg_P(LOG_INFO, PSTR("UART-Thread Start"));

    NutThreadSetPriority(200);  // low prio
    for (;;)
    {
        char *result = "";
        char rst[] = "reset\n";

        if (stream==NULL)
        {
            //LogMsg_P(LOG_INFO, PSTR("Stream is NULL!"));
            NutSleep(2000);           //Mhe
            continue;
        }

        result = fgets(result, 16, stream);
        short _reset_received = strcmp(rst, result);

        if (_reset_received == 0){
            LogMsg_P(LOG_INFO, PSTR(">>>>>> RESET COMMAND RECEIVED"));
            //RESET SIR!
            WatchDogStart(0);
        }
    }
}
Beispiel #8
0
int clientReceive(TCPSOCKET *sock, char *buffer, int len){
	int got;
	got = NutTcpReceive(sock, buffer, len);
	if (got <= 0) {
    LogMsg_P(LOG_INFO, PSTR("Fout bij ontvangen client data"));
	}
	return got;
}
THREAD(T1, arg)
{
	for (;;) {
		//NutSleep(1000);
		LogMsg_P(LOG_INFO, PSTR("T1"));
		printf("Yello");
		NutDelay(100);
	}
}
Beispiel #10
0
/*!
 * \brief Allocate memory.
 *
 * \param   unSize [in] Amount of memory to allocate.
 *
 * \return  pointer to the allocated memory.
 *          NULL if there is no memory left or you requested 0 size.
 */
void *MyMalloc(unsigned int unSize)
{
    void *pResult = NULL;

    if ((unSize != 0) &&
        ((pResult = NutHeapAlloc(unSize)) == NULL))
    {
        LogMsg_P(LOG_ERR, PSTR("No memory [%u]"), unSize);
    }
    return (pResult);
}
Beispiel #11
0
/*!
 * \brief Allocate new memory if needed.
 *
 * Checks if a memory block is large enough to hold additional data.
 * If it is not, the buffer is reallocated so it can hold the additional data.
 *
 * \param   ppcBuf [in,out] Address of a pointer to a memory block.
 * \param   punBufSize [in,out] The currently allocated size, [out] the new blocksize
 * \param   unBufInUse [in] Currently in use.
 * \param   unSizeNeeded [in] Size of the data to add.
 *
 * \return  0 when the buffer is large enough to add the data.
 *          -1 if no new memory could be allocated.
 */
int BufferMakeRoom(char **ppcBuf, unsigned int *punBufSize, unsigned int unBufInUse, unsigned int unSizeNeeded)
{
#ifdef UTIL_DEBUG
    LogMsg_P(LOG_DEBUG, PSTR("Have %u,Need %u"), (*punBufSize - unBufInUse), unSizeNeeded);
#endif /* #ifdef UTIL_DEBUG */

    if (unSizeNeeded > (*punBufSize - unBufInUse))
    {
        unsigned int unBlockSize = 256;
        char *pNewBuf = NULL;

        if (unBlockSize < unSizeNeeded)
        {
            unBlockSize = unSizeNeeded;
        }

        pNewBuf = MyMalloc(*punBufSize + unBlockSize);
        if (pNewBuf == NULL)
        {
            return (-1);
        }
        else
        {
            *punBufSize += unBlockSize;

#ifdef UTIL_DEBUG
            LogMsg_P(LOG_DEBUG, PSTR("MemBlock is %u now"), *punBufSize);
#endif /* #ifdef UTIL_DEBUG */

            if (*ppcBuf != NULL)
            {
                memcpy(pNewBuf, *ppcBuf, unBufInUse);
            }
            MyFree(*ppcBuf);
            *ppcBuf = pNewBuf;
        }
    }
    return (0);
}
Beispiel #12
0
int x1205ReadByte(unsigned char addr)
{
	int retval = 1;
	u_char writeBuffer[2];
	u_char readBuffer[2];
	
	writeBuffer[0] = 0;
	writeBuffer[1] = addr;  // SC register in x1205 RTC, datasheet page 10
	
	// TwMasterTransact schrijft eerst en leest daarna. Dit is wat we willen.
	// Schrijf eerst werk register we willen lezen, daarna lees het register
	
	if( TwMasterTransact(I2C_SLA_RTC, writeBuffer, 2, readBuffer, 2, NUT_WAIT_INFINITE) != 2 )
	{
		retval = -1;
		LogMsg_P(LOG_INFO, PSTR("error x1205readByte()"));
	}
	else
	{
		LogMsg_P(LOG_INFO, PSTR("x1205 says: [%02x][%02x]"), readBuffer[0], readBuffer[1] );
	}
	return retval;
}
Beispiel #13
0
/* ******************************************************************* */
void x1205Init(void)
/*
 * Initialiseer TWI, gebruik NUT/OS functionaliteit. 
 * see: http://www.ethernut.de/api/ of http://www.ethernut.de/nutwiki/I2C
 *
 */
{
	TwInit(0);   
	// 0 betekent dat wij master zijn, alle andere devices op de bus
	// zijn slaves.
	
	// Optioneel:
	//TwIOCtr(TWI_SETSPEED, &....);
	
	 LogMsg_P(LOG_INFO, PSTR("x1205Init()"));
}
Beispiel #14
0
static int GetCSD (DRIVE *pDrive)
{
    int   i;
    int  nError = MMC_ERROR;
    BYTE bData[16];
    WORD wREAD_BL_LEN;
    WORD wC_SIZE;
    WORD wC_SIZE_MULT;
    WORD wDummy;
    DWORD dTotalSectors = 0;

    MMCCommand(MMC_READ_CSD, 0, 0);
    if (MMCDataToken() != 0xfe)
    {
        LogMsg_P(LOG_ERR, PSTR("error during CSD read"));
    }
    else
    {
        for (i=0; i<16; i++)
        {
            bData[i] = SPIgetByte();
        }

        SPIputByte(0xff);    /* checksum -> don't care about it for now */
        SPIputByte(0xff);    /* checksum -> don't care about it for now */

        SPIdeselect();

        /*
         * Get the READ_BL_LEN
         */
        wREAD_BL_LEN = (1 << (bData[5] & 0x0F));

        /*
         * Get the C_SIZE
         */
        wC_SIZE  = (bData[6] & 0x03);
        wC_SIZE  = wC_SIZE << 10;

        wDummy   = bData[7];
        wDummy   = wDummy << 2;
        wC_SIZE |= wDummy;

        wDummy   = (bData[8] & 0xC0);
        wDummy   = wDummy >> 6;
        wC_SIZE |= wDummy;

        /*
         * Get the wC_SIZE_MULT
         */
        wC_SIZE_MULT  = (bData[9] & 0x03);
        wC_SIZE_MULT |= wC_SIZE_MULT << 1;
        wDummy        = (bData[10] & 0x80);
        wDummy        = wDummy >> 7;
        wC_SIZE_MULT |= wDummy;
        wC_SIZE_MULT  = (1 << (wC_SIZE_MULT+2));

        dTotalSectors  = wC_SIZE+1;
        dTotalSectors *= wC_SIZE_MULT;

        pDrive->dTotalSectors = dTotalSectors;
        pDrive->wSectorSize   = wREAD_BL_LEN;

        nError = MMC_OK;
    }

    return(nError);
} /* GetCSD */
Beispiel #15
0
	int main(void) {
		//audioInit();
		//setVolume(254);
		WatchDogDisable();		//disable watchdog
		NutDelay(100);			//wait for it to disable
		SysInitIO();			//initialise input and output
		SPIinit();				//initialise SPI-registers (speed, mode)
		LedInit();				//initialise led
		initLCD();				//initialise lcd
		Uart0DriverInit();		//initialise Universal asynchronous receiver/transmitter  
		Uart0DriverStart();		//start Uart
		printf("\n\n\n\nHardware initialization done\n\n");
		LogInit();				//initialise ability to log
		CardInit();				//initialise cardreader
		printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n");

		if (NutSegBufInit(8192) == 0) {
			puts("NutSegBufInit: Fatal error");
		}
		
		/*
		* Initialize the MP3 decoder hardware.
		*/
		if (VsPlayerInit() || VsPlayerReset(0)) {
			puts("VsPlayer: Fatal error");
		}
		
		if(X12Init() == -1){
			printf("error initializing RTC");	//initialise X12RTC 
		}				
		tm gmt;
		if (X12RtcGetClock(&gmt) == 0) {
			LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
		}

		if (At45dbInit() == AT45DB041B) {
			// ......
		}

		RcInit();					//Initialise the Remote Control module
		KbInit();					//Initialise keyboard
		initMenu();					//Initialise menu
		NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512);	//create thread to handle button presses
		printf("\nInitialization done.\n");
		initAlarms();
		SysControlMainBeat(ON); 	//enable 4.4 msecs heartbeat interrupt
		printf("Heartbeat on.\n");
		NutThreadSetPriority(1);	//Increase our priority so we can feed the watchdog.
		sei();						//enable global interrupts
		NutThreadCreate("Bg", TimeSyncThread, NULL, 512);
		NutThreadCreate("Bq", RefreshSceenThread, NULL, 512);
		NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512);
		printf("\nEntering main loop.\n");
		LcdBackLight(LCD_BACKLIGHT_ON);
		for(;;){
			NutSleep(100);
			WatchDogRestart();			//restart watchdog
		}
		
		return(0);
	}
Beispiel #16
0
int main(void)
{
	
    WatchDogDisable();

    NutDelay(100);

    SysInitIO();
	
	SPIinit();
    
	LedInit();
	
	LcdLowLevelInit();
	LcdBackLight(1);
	PrintStr("Starting System");
    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    CardInit();

	char custom[48] = ALL;
	
	LoadCustomChars(custom, 6);
	
    X12Init();
    if (X12RtcGetClock(&gmt) == 0)
    {
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
    }

    if (At45dbInit()==AT45DB041B)
    {
        // ......
    }


    RcInit();
    
	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	
	ClearLcdScreen();

	//Nieuwe threads aanmaken
    NutThreadCreate("t01", Thread1, NULL, 512);
	NutThreadCreate("time", TimeUpdater, NULL, 512);
	
	//Start netwerk
	int i = initNetworkDHCP();
	LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i);

	//Haal Internet tijd op
	pgmt = getNTPTime();
	X12RtcSetClock(&pgmt);
	//LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();

	/******************NETWERK**TEST*****************************************************/

	//Maak nieuwe socket
	TCPSOCKET *sock;
	sock = NutTcpCreateSocket();
	//Connect met google.nl
	LogMsg_P(LOG_INFO, PSTR("Connecting client"));
	clientConnect(sock);
	//Zend http req
	clientSend(sock,buffer,sizeof(buffer));

	//Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram)
	char rcvbuffer [500];
	int rec;
	rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer));
	LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec);

	//0 terminate buffer(string)
	//rcvbuffer[499] = 0;

	//Print buffer(http response enz)
	LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer);
	
	//Sluit connectie
	clientClose(sock);
	/***********************************************************************************/

	//Main gui besturing??
    for (;;)
    {
        NutSleep(100);
        WatchDogRestart();
    }

    return(0);      
}
Beispiel #17
0
void clientConnect(TCPSOCKET *sock){
	//sock = NutTcpCreateSocket();
	if (NutTcpConnect(sock, inet_addr("173.194.67.94"), 80)) {
    LogMsg_P(LOG_INFO, PSTR("Fout bij connecten socket"));
	}
}