Esempio n. 1
0
void main()
{

	char num1[50],num2[50];
	int l1,l2;

	clrscr();

	textcolor(6);
	cprintf("\nENTER A NUMBER::\n\r");
	gets(num1);

	textcolor(6);
	cprintf("\nENTER ANOTHER NUMBER::\n\r");
	gets(num2);

	l1=strlen(num1);
	l2=strlen(num2);

	if(l1<l2)
		multiply(num2,num1,l2,l1);	 //FUNCTION CALL FOR MULTIPLICATION
	else
		multiply(num1,num2,l1,l2);

	if(l1<l2)
		presentation(num2,num1,l2,l1); //FUNCTION CALL FOR PRESENTATION
	else
		presentation(num1,num2,l1,l2);

	printf("\n\n\n\n\t\t");
	textcolor(14+128);
	cprintf("...YOUR OPERATION HAVE DONE SUCESSFULLY...\r");

	getch();
}
Esempio n. 2
0
int main()
{
    std::cout << "count" << std::endl;

    EI::StringMap options;

    EI::UDPTransport transport(options);
    EI::JSONPresentation presentation(options);
    EI::Receiver receiver(options, transport, presentation);

    ExampleListener listener;
    receiver.addDataListener(&listener);

    {
        EI::Sender sender(EI::Description("count", "dummy"), options, transport, presentation);
        EI::DataMessage msg = sender.createDataMessage();
        msg.setDouble("seconds", 15);
        sender.sendMessage(msg);
        boost::this_thread::sleep(boost::posix_time::milliseconds(250));
    }

    std::cin.get();

    std::cerr << count << "\n";
}
Esempio n. 3
0
    bool isSupported(QMailMessage::ContentType t, QMailViewerFactory::PresentationType pres) const 
    { 
        if ((pres != QMailViewerFactory::AnyPresentation) && (pres != presentation()))
            return false;

        return types().contains(t); 
    }
Esempio n. 4
0
int main() {
  Vincent::TestSuiteResult result;
  Vincent::TestSuite suite;
  suite.add(new CarTestCase());
  suite.run(result);
  Vincent::TextPresentation presentation(result);
  presentation.present();
}
Esempio n. 5
0
QtGuiltPatchChunk::QtGuiltPatchChunk(const QString &content, int startIndex, QtGuiltPatchFile *patchFile):
  QtGuiltTreeItem((QObject*)patchFile),
  m_content(content),
  m_startIndex(startIndex)
{
  m_type = PatchFileChunk;
  m_presentation = presentation(m_content);
}
void value (int b)
{
  int sign = (b >> 31) & 1;
  int exponenta = (b >> 23) & ((1 << 8) - 1);
  int mantissa = b & ((1 << 23) - 1);
  f.sign = sign;
  f.mantissa = mantissa;
  f.exponenta = exponenta;
  presentation(f);
}
Esempio n. 7
0
// Message delivered through _msg
void _processInternalMessages() {
	bool isMetric;
	uint8_t type = _msg.type;

	#if !defined(MY_DISABLE_REMOTE_RESET)
		if (type == I_REBOOT) {
			// Requires MySensors or other bootloader with watchdogs enabled
			hwReboot();
		} else
	#endif
		if (type == I_CONFIG) {
		// Pick up configuration from controller (currently only metric/imperial)
		// and store it in eeprom if changed
	 	if (_msg.getString() == NULL) {
			isMetric = true;
		} else {
			isMetric = _msg.getString()[0] == 'M';
		}
		_cc.isMetric = isMetric;
		hwWriteConfig(EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
	} else if (type == I_PRESENTATION) {
		if (!mGetAck(_msg)) {
			// Re-send node presentation to controller
			#if defined(MY_RADIO_FEATURE)
				transportPresentNode();
			#endif
			if (presentation)
				presentation();
		}
	} else if (type == I_HEARTBEAT) {
		sendHeartbeat();
	} else if (type == I_TIME) {
		// Deliver time to callback
		if (receiveTime)
			receiveTime(_msg.getULong());
	}
	#if defined(MY_REPEATER_FEATURE)
		if (type == I_CHILDREN) {
			if (_msg.getString()[0] == 'C') {
				// Clears child relay data for this node
				debug(PSTR("clear routing table\n"));
				uint8_t i = 255;
				do {
					hwWriteConfig(EEPROM_ROUTES_ADDRESS+i, BROADCAST_ADDRESS);
				} while (i--);
				// Clear parent node id & distance to gw
				hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, AUTO);
				hwWriteConfig(EEPROM_DISTANCE_ADDRESS, DISTANCE_INVALID);
				// Find parent node
				transportFindParentNode();
				_sendRoute(build(_msg, _nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_CHILDREN,false).set(""));
			}
		}
	#endif
}
Esempio n. 8
0
int main(int argc, char * argv[]) {
	Model model;
	model.start();

	QApplication app(argc, argv);

	Presentation presentation(model);
	presentation.resize(100, 30);
	presentation.show();

	model.setPresentation(&presentation);

	return app.exec();
}
Esempio n. 9
0
void CVCF::initialize(SynthProFactory* factory)
{
    VCF::initialize(factory);

    CInPort* in = dynamic_cast<CInPort*>(m_inPort);
    CInPort* cutOff = dynamic_cast<CInPort*>(m_inCutOffPort);
    COutPort* out = dynamic_cast<COutPort*>(m_out);
    CSelector* selector = dynamic_cast<CSelector*>(m_filterSelector);
    CDimmer* resonance = dynamic_cast<CDimmer*>(m_rDimmer);
    CDimmer* cutOffDimmer = dynamic_cast<CDimmer*>(m_cutOffDimmer);

    resonance->setValueFormat(formatResonance);

    dynamic_cast<PVCF*>(presentation())->initialize(in->presentation(), cutOff ->presentation(),
                                                    out->presentation(), selector->presentation(),
                                                    resonance->presentation(), cutOffDimmer->presentation());
}
Esempio n. 10
0
int main(void){


	// the watchdog
	WDT->WDT_MR = WDT_MR_WDDIS;
	// Set the clock up
	systemInit(); //84 MHZ
	
	presentation();
	
	runGame();
	
	while (1){	
		
		
	} // WHILE(1)
} //main
Esempio n. 11
0
void CLFO::initialize(SynthProFactory* factory)
{
    LFO::initialize(factory);

    COutPort* out = dynamic_cast<COutPort*>(m_out);
    CSelector* selector = dynamic_cast<CSelector*>(m_shapeSelector);
    CDimmer* k = dynamic_cast<CDimmer*>(m_kDimmer);
    CDimmer* range = dynamic_cast<CDimmer*>(m_rangeDimmer);
    CDimmer* offset= dynamic_cast<CDimmer*>(m_offsetDimmer);

    k->setValueFormat(formatK);
    range->setValueFormat(CDimmer::percentageFormat);
    offset->setValueFormat(formatOffset);

    dynamic_cast<PLFO*>(presentation())->initialize(out->presentation(), k->presentation(),
                                                    range->presentation(), offset->presentation(),
                                                    selector->presentation());
}
Esempio n. 12
0
void CADSR::initialize(SynthProFactory* factory)
{
    ADSR::initialize(factory);

    CInPort* gate = dynamic_cast<CInPort*>(m_gate);
    COutPort* out = dynamic_cast<COutPort*>(m_outPort);
    CDimmer* attack = dynamic_cast<CDimmer*>(m_attackDimmer);
    CDimmer* decay = dynamic_cast<CDimmer*>(m_decayDimmer);
    CDimmer* sustain = dynamic_cast<CDimmer*>(m_sustainDimmer);
    CDimmer* release = dynamic_cast<CDimmer*>(m_releaseDimmer);
    CPushButton* manual = dynamic_cast<CPushButton*>(m_manualControl);

    attack->setValueFormat(CDimmer::timeFormat);
    decay->setValueFormat(CDimmer::timeFormat);
    sustain->setValueFormat(CDimmer::percentageFormat);
    release->setValueFormat(CDimmer::timeFormat);

    dynamic_cast<PADSR*>(presentation())->initialize(gate->presentation(), out->presentation(),
                                                     attack->presentation(), decay->presentation(),
                                                     sustain->presentation(), release->presentation(),
                                                     manual->presentation());
}
Esempio n. 13
0
File: main.c Progetto: ralt/soach
int main(int argc, char* argv[])
{
	char* fvalue = NULL;

	if (argc < 2) {
		presentation();
		return EXIT_SUCCESS;
	}

	if (!handle_options(&fvalue, argc, argv)) {
		return EXIT_FAILURE;
	}

	struct SOACH_route_vector* routes =
		malloc(sizeof(struct SOACH_route_vector));
	if (routes == NULL) {
		fprintf(stderr, "%s\n", strerror(errno));
		return EXIT_FAILURE;
	}

	SOACH_route_vector_init(routes, DEFAULT_ROUTES_CAPACITY);

	if (!SOACH_conf_read(fvalue, routes)) {
		return EXIT_FAILURE;
	}

	for (int i = 0; i < routes->size; i++) {
		struct SOACH_route route = *SOACH_route_vector_get(routes, i);
		fprintf(stdout, "Route: %s, Service: %s\n", route.route,
				route.service);
	}

	SOACH_route_vector_free(routes);

	return EXIT_SUCCESS;
}
Esempio n. 14
0
/********************************************************************
*																	*
*						 Gestion du menu							*
*																	*
********************************************************************/
boolean MenuSelect(int object, int scan, int state, int button)
{
	int index, entree, key;

	if (object < 0)
	{
		/* attend qu'on relache la souris */
		NoClick();

		if (button < 0)
		{
			/* regarde la touche */
			key = scantoascii(scan);
			if (key == 0)
				key = scan & 0xFF00;	/* scan code */
			else
				key = UpperChar(key);

			for (index = 0; index < NbMenus; index++)
				for (entree = 0; entree < MenuShortCuts[index].nb_entrees; entree++)
					if (MenuShortCuts[index].menu[entree].key == key && MenuShortCuts[index].menu[entree].state == state)
					{
						if (ob_isstate(Menu, MenuShortCuts[index].menuid, DISABLED) == 0 && ob_isstate(Menu, MenuShortCuts[index].menu[entree].itemid, DISABLED) == 0)
						{
							object = MenuShortCuts[index].menu[entree].itemid;
							index = NbMenus;
						}
						break;
					}
		}
	}

	if (object < 0)
		return FALSE;	/* kein entsprechender Eintrag gefunden */

	/* Men�punkte 'Fenster wechseln' und 'Fenster schliežen' werden
	   inklusive der dazugeh”rigen Hotkeys automatisch verwaltet */

	switch (object)
	{
						/* menu Zorg */

		case INFORMATIONS:
			presentation();
			break;

						/* menu Etat */

		case INFORMATION:
			informations(Drive);
			break;

		case REPERTOIRE_LOUPE:
			if (ManageVFAT)
				open_directory_vfat();
			else
				open_directory_short();
			break;

		case TEST_STRUCTURE:
			if (ManageVFAT)
				structure_test_vfat(Drive);
			else
				structure_test_short(Drive);
			break;

		case STATISTIQUES:
			statistiques(Drive);
			break;

		case OCCUPATION:
			occupation(Drive);
			break;

		case TRACE_UN_FICHIER:
			trace_file();
			break;

		case QUITTER:
			if (Reset)
			{
				if (my_alert(1, 2, X_ICN_QUESTION, Messages(MENU_1), Messages(BOOT_32)) == 0)
					shutdown(TRUE);
			}
			else
			{
				button = my_alert(2, 3, X_ICN_QUESTION, Messages(MENU_2), Messages(MENU_4));
				if (button == 0 || button == 1 && (int)xbios(0x11) % 2)
					shutdown(FALSE);
			}
			break;

					/* menu Ouvre */

		case UNITE_LOGIQUE:
			open_disk();
			break;

		case OUVRE_DISQUETTE:
			raw_floppy(FALSE);
			break;

		case OUVRE_DISQUE_DUR:
			raw_hard(FALSE);
			break;

		case OUVRE_FICHIER:
			open_file();
			break;

		case OUVRE_FICHIER_FS:
			open_file_other_fs();
			break;

		case OUVRE_FICH_TEXTE:
			voir_fichier();
			break;

		case CREER_FICHIER:
			creer_fichier();
			break;

		case FERMER:
			fermer(Thefrontwin -> win -> handle);
			break;

		case LIRE_BOOT:
			lire_boot();
			break;

		case CHARGER_BOOT:
			charger_boot();
			break;

		case SAUVER_BOOT:
			sauver_boot();
			break;

		case ECRIRE_BOOT:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			ecrire_boot();
#endif
			break;

					/* menu Edition */

		case SAUVER_SECTEUR:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			save_secteur(Thefrontwin, MENU_EDITION);
#endif
			break;

		case COPIER_SECTEUR:
			copier_tampon(Thefrontwin);
			break;

		case COLLER_SECTEUR:
			coller_tampon(Thefrontwin);
			break;

		case ECHANGER_TAMPON:
			echanger_tampon(Thefrontwin);
			break;

		case RETOUR_INITIAL:
			load_secteur(Thefrontwin, MENU_EDITION);
			break;

		case OUVRIR_TAMPON:
			ouvrir_tampon();
			break;

		case SAUVER_TAMPON:
			sauver_tampon();
			break;

		case CHARGER_TB_ASCII:
			ascii_tampon();
			break;

		case EFFACER_TAMPON:
			effacer_tampon();
			break;

					/* menu Structure */

		case DEFRAGMENTATION:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			reconnect(Drive);
#endif
			break;

		case UNIQUE_LIBRE:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			compresse(Drive);
#endif
			break;

		case RESTO_COMPLETE:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

		/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			restauration_complete(Drive);
#endif
			break;

		case VIDE_CLST_LIBRES:
			nettoie_clusters_libres(Drive);
			break;

		case NETTOIE_REPERTOI:
#ifdef TEST_VERSION
			/* relache la souris */
			NoClick();

			/* on attend avant de redessiner */
			Event_Timer(0, 0, TRUE);

			my_alert(1, FAIL, X_ICN_STOP, Messages(MENU_6), NULL);
#else
			nettoie_repertoire(Drive);
#endif
			break;

					/* menu Deplacement */

		case SECTEUR_SUIVANT:
			next_secteur(Thefrontwin);
			break;

		case SECTEUR_PRECEDEN:
			previous_secteur(Thefrontwin);
			break;

		case BLOC_SUIVANT:
			next_bloc(Thefrontwin);
			break;

		case BLOC_PRECEDENT:
			previous_bloc(Thefrontwin);
			break;

		case MARQUER_POSITION:
			marquer_position(Thefrontwin);
			break;

		case ALLER_MARQUE:
			goto_marque(Thefrontwin);
			break;

		case ALLER_SECTEUR:
			goto_secteur(Thefrontwin);
			break;

		case CHERCHER_CHAINE:
			search_first(Thefrontwin);
			break;

		case CHERCHER_NOUVEAU:
			search_next(Thefrontwin);
			break;

					/* menu Fenˆtres */

		case CHOIX_FONTE:
			choix_fonte(Thefrontwin);
			break;

		case CHOIX_COULEURS:
			couleur(Thefrontwin);
			break;

		case TAILLE_IDEALE:
			taille_ideale(Thefrontwin);
			break;

		case ASCENSEURS:
			ascenseurs(Thefrontwin);
			break;

		case CYCLER_FENETRES:
			cycle_window();
			break;

		case WINDOW_LIST_1:
		case WINDOW_LIST_2:
		case WINDOW_LIST_3:
		case WINDOW_LIST_4:
		case WINDOW_LIST_5:
		case WINDOW_LIST_6:
		case WINDOW_LIST_7:
		case WINDOW_LIST_8:
		case WINDOW_LIST_9:
		case WINDOW_LIST_10:
			{
				windowptr thewin;

				for (thewin = Firstwindow; thewin; thewin = thewin -> next)
					if (thewin -> menu_entry == object - WINDOW_LIST_1)
						make_frontwin(thewin);
			}
			break;

						/* menu Options */

		case CONFIG_GENERALE:
			config_generale();
			break;

		case CONFIG_DSK:
			config_disques();
			break;

		case RACCOURCIS_CLAVI:
			raccourcis_clavier();
			break;

		case DONNEES_ZORG:
			from_zorg_inf(TRUE);
			break;

		case DONNEES_SYSTEME:
			from_zorg_inf(FALSE);
			break;

		case INVALIDE_CACHE:
			if (Kbshift(FAIL) & 4)
			{
				int i;

				for (i=0; i<MAX_DEVICES; i++)
					change_disque(i, FALSE);
			}
			else
				change_disque(Drive, TRUE);
			break;

		case UPDATE_SYSTEME:
			if (Kbshift(FAIL) & 4)
			{
				int i;

				for (i=0; i<MAX_DEVICES; i++)
					update_systeme(i);
			}
			else
				update_systeme(Drive);
			break;

		case VISU_TEXTE:
			really_voir_fichier(Thefrontwin -> fonction.fichier.nom);
			break;

		case VISU_ASCII:
			secteur_ascii(Thefrontwin);
			break;

		case VISU_HEXA:
			secteur_hexa(Thefrontwin);
			break;

		case AFFICHE_DECIMAL:
			affichage_decimal(Thefrontwin);
			break;

		case FICHIER_ASSOCIE:
			secteur_file(Thefrontwin);
			break;

		case CURSEUR_VISIBLE:
			curseur_on(Thefrontwin);
			break;

		case CLIPBOARD_GEM:
			clipboard_gem(Thefrontwin);
			break;

						/* menu Aide */

		case TABLE_ASCII:
			AsciiChar = m_ascii_box(AsciiChar, FALSE);
			break;

		case AIDE:
			aide();
			break;

		case EXECUTER_PROG:
			lance_prg();
			break;

		case RESET:
			if (Reset)
			{
				Reset = FALSE;
				menu_icheck(Menu, RESET, 0);
			}
			else
			{
				int button;

				button = my_alert(2, 3, X_ICN_QUESTION, Messages(MENU_3), Messages(MENU_5));
				if (button == 1)
					shutdown(TRUE);
				else
					if (button == 0)
						reset();
			}
			break;
	}

	return TRUE;
} /* MenuSelect */
bool gatewayTransportSend(MyMessage &message)
{
	bool ret = true;
	char *_ethernetMsg = protocolFormat(message);

    setIndication(INDICATION_GW_TX);

	_w5100_spi_en(true);
	#if defined(MY_CONTROLLER_IP_ADDRESS)
		#if defined(MY_USE_UDP)
			_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
			_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
			// returns 1 if the packet was sent successfully
			ret = _ethernetServer.endPacket();
		#else
			EthernetClient client;
			#if defined(MY_CONTROLLER_URL_ADDRESS)
	                	if (client.connected() || client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
	        	#else
	                	if (client.connected() || client.connect(_ethernetControllerIP, MY_PORT)) {
	        	#endif
	                	client.write(_ethernetMsg, strlen(_ethernetMsg));
	                }
	                else {
	                	// connecting to the server failed!
	                	ret = false;
	                }
		#endif
	#else
		// Send message to connected clients
		#if defined(MY_GATEWAY_ESP8266)
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
			{
				if (clients[i] && clients[i].connected())
				{
					clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
				}
			}
		#else
			_ethernetServer.write(_ethernetMsg);
		#endif
	#endif
	_w5100_spi_en(false);
	return ret;

}


#if defined(MY_GATEWAY_ESP8266)
	bool _readFromClient(uint8_t i) {
		while (clients[i].connected() && clients[i].available()) {
			char inChar = clients[i].read();
			if (inputString[i].idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString[i].string[inputString[i].idx] = 0;
					debug(PSTR("Client %d: %s\n"), i, inputString[i].string);
					inputString[i].idx = 0;
					if (protocolParse(_ethernetMsg, inputString[i].string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString[i].string[inputString[i].idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Client %d: Message too long\n"), i);
				inputString[i].idx = 0;
				// Finished with this client's message. Next loop() we'll see if there's more to read.
				break;
			}
		}
		return false;
	}
#else
	bool _readFromClient() {
		while (client.connected() && client.available()) {
			char inChar = client.read();
			if (inputString.idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString.string[inputString.idx] = 0;
					debug(PSTR("Eth: %s\n"), inputString.string);
					inputString.idx = 0;
					if (protocolParse(_ethernetMsg, inputString.string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString.string[inputString.idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Eth: Message too long\n"));
				inputString.idx = 0;
				// Finished with this client's message. Next loop() we'll see if there's more to read.
				break;
			}
		}
		return false;
	}
#endif


bool gatewayTransportAvailable()
{
	_w5100_spi_en(true);
	#if !defined(MY_IP_ADDRESS) && defined(MY_GATEWAY_W5100)
		// renew IP address using DHCP
		gatewayTransportRenewIP();
	#endif

	#ifdef MY_USE_UDP

		int packet_size = _ethernetServer.parsePacket();

		if (packet_size) {
			//debug(PSTR("UDP packet available. Size:%d\n"), packet_size);
            setIndication(INDICATION_GW_RX);
			#if defined(MY_GATEWAY_ESP8266)
				_ethernetServer.read(inputString[0].string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
				inputString[0].string[packet_size] = 0;
				debug(PSTR("UDP packet received: %s\n"), inputString[0].string);
				return protocolParse(_ethernetMsg, inputString[0].string);
			#else
				_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
				inputString.string[packet_size] = 0;
				debug(PSTR("UDP packet received: %s\n"), inputString.string);
				_w5100_spi_en(false);
				return protocolParse(_ethernetMsg, inputString.string);
			#endif
		}
	#else
		#if defined(MY_GATEWAY_ESP8266)
			// ESP8266: Go over list of clients and stop any that are no longer connected.
			// If the server has a new client connection it will be assigned to a free slot.
			bool allSlotsOccupied = true;
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
				if (!clients[i].connected()) {
					if (clientsConnected[i]) {
						debug(PSTR("Client %d disconnected\n"), i);
						clients[i].stop();
					}
					//check if there are any new clients
					if (_ethernetServer.hasClient()) {
						clients[i] = _ethernetServer.available();
						inputString[i].idx = 0;
						debug(PSTR("Client %d connected\n"), i);
						gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
						if (presentation)
							presentation();
					}
				}
				bool connected = clients[i].connected();
				clientsConnected[i] = connected;
				allSlotsOccupied &= connected;
			}
			if (allSlotsOccupied && _ethernetServer.hasClient()) {
				//no free/disconnected spot so reject
				debug(PSTR("No free slot available\n"));
				EthernetClient c = _ethernetServer.available();
				c.stop();
			}
				// Loop over clients connect and read available data
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
				if (_readFromClient(i)) {
                    setIndication(INDICATION_GW_RX);
					_w5100_spi_en(false);
					return true;
				}
			}
		#else
			// W5100/ENC module does not have hasClient-method. We can only serve one client at the time.
			EthernetClient newclient = _ethernetServer.available();
			// if a new client connects make sure to dispose any previous existing sockets
			if (newclient) {
				if (client != newclient) {
					client.stop();
					client = newclient;
					debug(PSTR("Eth: connect\n"));
					_w5100_spi_en(false);
					gatewayTransportSend(buildGw(_msg, I_GATEWAY_READY).set("Gateway startup complete."));
					_w5100_spi_en(true);
					if (presentation)
						presentation();
				}
			}
			if (client) {
				if (!client.connected()) {
					debug(PSTR("Eth: disconnect\n"));
					client.stop();
				} else {
					if (_readFromClient()) {
                        setIndication(INDICATION_GW_RX);
						_w5100_spi_en(false);
						return true;
					}
				}
			}
		#endif
	#endif
	_w5100_spi_en(false);
	return false;
}
Esempio n. 16
0
void _begin() {
	#if !defined(MY_DISABLED_SERIAL)
	    hwInit();
	#endif

	// Call before() in sketch (if it exists)
	if (before) 
		before();

	debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILITIES ", " LIBRARY_VERSION ")\n"));

	signerInit();

	#if defined(MY_RADIO_FEATURE)
		_failedTransmissions = 0;

		// Setup radio
		if (!transportInit()) {
			debug(PSTR("Radio init failed. Check wiring.\n"));
			// Nothing more we can do
			_infiniteLoop();
		} else {
			debug(PSTR("Radio init successful.\n"));
		}
	#endif

	#if defined(MY_GATEWAY_FEATURE)
		#if defined(MY_INCLUSION_BUTTON_FEATURE)
	    	inclusionInit();
		#endif

	    // initialize the transport driver
		if (!gatewayTransportInit()) {
			debug(PSTR("Transport driver init fail\n"));
			// Nothing more we can do
			_infiniteLoop();
		}

	#endif


	#if defined(MY_LEDS_BLINKING_FEATURE)
		ledsInit();
	#endif

	// Read latest received controller configuration from EEPROM
	hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
	if (_cc.isMetric == 0xff) {
		// Eeprom empty, set default to metric
		_cc.isMetric = 0x01;
	}

	#if defined(MY_GATEWAY_FEATURE)
		// Set configuration for gateway
		_nc.parentNodeId = GATEWAY_ADDRESS;
		_nc.distance = 0;
		_nc.nodeId = GATEWAY_ADDRESS;
	#elif defined(MY_RADIO_FEATURE)
		// Read settings from eeprom
		hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
		#ifdef MY_OTA_FIRMWARE_FEATURE
			// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
			hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
		#endif

		_autoFindParent = MY_PARENT_NODE_ID == AUTO;
		if (!_autoFindParent) {
			_nc.parentNodeId = MY_PARENT_NODE_ID;
			// Save static parent id in eeprom (used by bootloader)
			hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID);
			// We don't actually know the distance to gw here. Let's pretend it is 1.
			// If the current node is also repeater, be aware of this.
			_nc.distance = 1;
		} else if (!isValidParent(_nc.parentNodeId)) {
			// Auto find parent, but parent in eeprom is invalid. Try find one.
			transportFindParentNode();
		}

		if (MY_NODE_ID != AUTO) {
			// Set static id
			_nc.nodeId = MY_NODE_ID;
			// Save static id in eeprom
			hwWriteConfig(EEPROM_NODE_ID_ADDRESS, MY_NODE_ID);
		} else if (_nc.nodeId == AUTO && isValidParent(_nc.parentNodeId)) {
			// Try to fetch node-id from gateway
			transportRequestNodeId();
		}
	#endif

#ifdef MY_NODE_LOCK_FEATURE
	// Check if node has been locked down
	if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) {
		// Node is locked, check if unlock pin is asserted, else hang the node
		pinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP);
		// Make a short delay so we are sure any large external nets are fully pulled
		unsigned long enter = hwMillis();
		while (hwMillis() - enter < 2);
		if (digitalRead(MY_NODE_UNLOCK_PIN) == 0) {
			// Pin is grounded, reset lock counter
			hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
			// Disable pullup
			pinMode(MY_NODE_UNLOCK_PIN, INPUT);
			debug(PSTR("Node is unlocked.\n"));
		} else {
			// Disable pullup
			pinMode(MY_NODE_UNLOCK_PIN, INPUT);
			nodeLock("LDB"); //Locked during boot
		}
	} else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) {
		// Reset walue
		hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
	}
#endif

	// Call sketch setup
	if (setup)
		setup();


	#if defined(MY_RADIO_FEATURE)
		transportPresentNode();
	#endif
	if (presentation)
		presentation();

	debug(PSTR("Init complete, id=%d, parent=%d, distance=%d\n"), _nc.nodeId, _nc.parentNodeId, _nc.distance);
}