예제 #1
0
파일: main.c 프로젝트: keeepcool/Backup
int32_t loopback_tcpc(uint8_t sn, uint8_t* destip, uint16_t destport){
	
	int32_t ret; // return value for SOCK_ERRORs

	// Destination (TCP Server) IP info (will be connected)
	// >> loopback_tcpc() function parameter
	// >> Ex)
	//	uint8_t destip[4] = 	{192, 168, 34, 131};
	//	uint16_t destport = 	5000;

	// Port number for TCP client (will be increased)
	uint16_t any_port = 	2;

	// Socket Status Transitions
	// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
	switch(getSn_SR(sn))
	{
		case SOCK_ESTABLISHED :
		if(getSn_IR(sn) & Sn_IR_CON)	// Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
		{
			sprintf(gPtrintBuff, "%d:Connected to - %d.%d.%d.%d : %u\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
			uartPuts(gPtrintBuff);
			setSn_IR(sn, Sn_IR_CON);  // this interrupt should be write the bit cleared to '1'
		}

		break;

		case SOCK_CLOSE_WAIT :
		if((ret=disconnect(sn)) != SOCK_OK) return ret;
		
			sprintf(gPtrintBuff, "%d:Socket Closed\r\n", sn);
			uartPuts(gPtrintBuff);
		break;

		case SOCK_INIT :
		
		sprintf(gPtrintBuff, "%d:Try to connect to the %d.%d.%d.%d : %u\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
		uartPuts(gPtrintBuff);
		
		if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret;	//	Try to TCP connect to the TCP server (destination)
		break;

		case SOCK_CLOSED:
		close(sn);
		if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) return ret; // TCP socket open with 'any_port' port number
		
		sprintf(gPtrintBuff, "%d:TCP client loopback start\r\n",sn);
		uartPuts(gPtrintBuff);
		sprintf(gPtrintBuff, "%d:Socket opened\r\n",sn);
		uartPuts(gPtrintBuff);
		break;
		default:
		break;
	}
	return 1;
}
예제 #2
0
파일: main.c 프로젝트: keeepcool/Backup
void printNetInfo(void){
	
	wiz_NetInfo readBack;
	
	uint8_t version = getVERSIONR();
	wizchip_getnetinfo(&readBack);
	if(readBack.dhcp == NETINFO_DHCP){
		sprintf(gPtrintBuff, "\n=== NET CONF : DHCP ===\n");
		uartPuts(gPtrintBuff);
	}
	else {
		sprintf(gPtrintBuff, "\n=== NET CONF : STATIC ===\n");
		uartPuts(gPtrintBuff);
	}
	sprintf(gPtrintBuff, "====== HW ID : %i ======\n", version);
	uartPuts(gPtrintBuff);
	sprintf(gPtrintBuff, " MAC : %02X:%02X:%02X:%02X:%02X:%02X\n", readBack.mac[0], readBack.mac[1], readBack.mac[2], readBack.mac[3], readBack.mac[4], readBack.mac[5]);
	uartPuts(gPtrintBuff);	
	sprintf(gPtrintBuff, " IP : %d.%d.%d.%d\n", readBack.ip[0], readBack.ip[1], readBack.ip[2], readBack.ip[3]);
	uartPuts(gPtrintBuff);
	sprintf(gPtrintBuff, " GW : %d.%d.%d.%d\n", readBack.gw[0], readBack.gw[1], readBack.gw[2], readBack.gw[3]);
	uartPuts(gPtrintBuff);
	sprintf(gPtrintBuff, " SN : %d.%d.%d.%d\n", readBack.sn[0], readBack.sn[1], readBack.sn[2], readBack.sn[3]);
	uartPuts(gPtrintBuff);
	//readBack.dns
	sprintf(gPtrintBuff, "=======================================\r\n");
	uartPuts(gPtrintBuff);
	
}
예제 #3
0
파일: main.c 프로젝트: keeepcool/Backup
void printCSV(void){
	
	char Lbuff[64];
	sprintf(Lbuff, "%4.2f,%4.2f,%4.2f,%4.2f\n", BME280_readTempC(), BME280_readFloatPressure(), BME280_readFloatAltitudeMeters(), BME280_readFloatHumidity());
	uartPuts(Lbuff);

}
예제 #4
0
파일: main.c 프로젝트: keeepcool/Backup
int main(void){
	
	uint16_t byteCount = 0;
	char buffer0[32];
	
	HAL_Init();
	SYS_TimerInit();
	PHY_Init();
	NWK_Init();
	//SYS_INIT()
	timer3Init();
	uartInit();
	sei();

	while (1){
		
		SYS_TaskHandler();
		
		byteCount = uartAvailable();
		
		if(byteCount > 0){
			HAL_UartBytesReceived(byteCount);
			sprintf(buffer0, "Bytes to send: %i\n", byteCount);
			uartPuts(buffer0);
		}
		APP_TaskHandler();
	}
}
예제 #5
0
파일: main.c 프로젝트: tgfuellner/Basteln
static void showCountValue(U32 pulse) {
    char buffer[10];

    // Berechnung der Kapazitaet
    #define ZWEIPI 39.44    //=(2*Pi hoch 2)
    #define L 10E-3         //Referenzinduktivitaet 10mH
    #define C0 20.0     //parasitaere Systemkapazitaet
    float C = 0.0;
    float F = 0.0;

    F=(float)pulse*(float)pulse;        //Frequenz quadrieren
    C=1/(ZWEIPI*L*F);                  //Kapatitaet berechnen
    C=C*1E12-C0;                      //auf pF skalieren und offset abz.
    //Cfix=(U32)(C*10);                    //auf LongInt wandel + eine Kommast.
    U32 Cfix = (U32)C;

    uartPuts("Pulse: ");
    uartPuts(ltoa(pulse, buffer, 10));
    uartPuts(" C: ");
    uartPuts(ltoa(Cfix, buffer, 10));
    uartPuts("pF\r\n");
}
예제 #6
0
파일: main.c 프로젝트: keeepcool/Backup
void i2cScanner(void){
	
	uartPutsP("\n[Starting I2C scan]\n");
	uartPutsP(">Enabling Pull-up's\n");
	uint8_t retVal;
	
	for(int i=0; i<120; i++){
		
		sprintf(gPtrintBuff, ">Found: %x\r", i);
		retVal = 2;
		retVal = i2c_start(i<<1);
		_delay_ms(1);
		i2c_stop();
		_delay_ms(10);
		
		if(retVal == 0){
			sprintf(gPtrintBuff, ">Found: %x\r", i);
			uartPuts(gPtrintBuff);
		}
	}
	
	uartPutsP("[I2C Scan Complete!]\n");
}
예제 #7
0
파일: main.c 프로젝트: keeepcool/Backup
int main(void){
	
	sysInit();
	
	SPCR = (1 << SPE)  | (1 << MSTR) | (0 << CPOL) | (0 << CPHA) | (0 << SPR1);
	SPSR = (1<<SPI2X);
	W5500_Init();
	
	_delay_ms(10);
	sprintf(gPtrintBuff, "Version: %u\n",getVERSIONR());
	uartPuts(gPtrintBuff);
	//i2cScanner();
	
	si70xx_init();
	
	uartPutsP("\nInto Loop\n");
	
    while (1){
		
		if(milis() - loopTime >= 50){
			
			hsv2rgb(hue_value,255,80, &Rpwm, &Gpwm, &Bpwm, 250);			
			OCR1A = Rpwm;
			OCR1B = Gpwm;
			OCR1C = Bpwm;
			hue_value++;
			if(hue_value > 359){
				hue_value = 0;
			}
			
			float temperature = si70xx_get_temperature();
			float humidity = si70xx_get_humidity();
			
			/*
			while(getSn_SR(SOCK_ID_TCP) != SOCK_ESTABLISHED){
				loopback_tcpc(SOCK_ID_TCP, dIP, dport);
			}
			*/
			
			sprintf(gDATABUF, "%u | Temp: %.2f RH: %.2f \n\0", i , temperature, humidity);
			
			retVal = send(SOCK_ID_TCP, gDATABUF, sizeof(gDATABUF));
			//close(SOCK_ID_TCP);
			
			sprintf(gPtrintBuff, "%u | Sent: %i Sizeof: %u\n", i ,  retVal, sizeof(gDATABUF));
			uartPuts(gPtrintBuff);
			
			i++;
			
			loopTime = milis();
			
		}
		
		
		loopback_tcpc(SOCK_ID_TCP, dIP, dport);
		//send(TCP_)
		char temp = uartGetc();
		if(temp == 'S'){
			printNetInfo();
			//uartPutc(temp);
		}
		
		if(temp == 's'){
			send(SOCK_ID_TCP, 'a', sizeof('a'));
			//uartPutc(temp);
		}
    }
}