示例#1
0
void printErrorCb(AtCommandResponse& r, uintptr_t data) {
	Print *p = (Print*)data;
	if (!r.isOk()) {
		p->print(F("Error sending "));
		p->write(r.getCommand(), 2);
		p->print(F(" command. Status: "));
		p->println(r.getStatus());
	}
}
示例#2
0
void printResponseCb(AtCommandResponse& at, uintptr_t data) {
	Print *p = (Print*)data;
	p->println("AtCommandResponse received:");
	p->print(F("  Command: "));
	p->write(at.getCommand(), 2);
	p->println();
	printField(p, F("  Status: 0x"), at.getStatus());
	if (at.getValueLength()) {
		p->print(F("  Value: "));
		printHex(*p, at.getValue(), at.getValueLength(), F(" "), NULL);
		p->println();
	}
}
示例#3
0
void XBeeActive::search_XBee()
{
	d0Value[0] = 0xFE;
	commandValueLength = 0x1;
	atRequest.setCommand(NTCmd);
	sendAtCommand();
	delay(250);
	arRequestMod.clearCommandValue();
	delay(100);
	atRequest.setCommand(NDCmd);
	int search_list = 0;
	int i10;
	Serial.println("\nSending command search XBee");
	xbee.send(atRequest);
	while (true)
	{
		if (xbee.readPacket(5000)) // подождите до 5 секунд для ответа состояния
		{
			if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) // Должна быть команда отклика AT
			{
				xbee.getResponse().getAtCommandResponse(atResponse);

				if (atResponse.isOk())
				{
					Serial.print("Command [");
					Serial.print(atResponse.getCommand()[0]);
					Serial.print(atResponse.getCommand()[1]);
					Serial.println("] was successful!");

					if (atResponse.getValueLength() > 0)
					{
						Len_XBee = atResponse.getValueLength();
						Serial.print("Command value length is - ");
						Serial.println(atResponse.getValueLength(), DEC);
						Serial.print("Command value: ");

						for (i10 = 0; i10 < atResponse.getValueLength(); i10++)
						{
							info_XBee_data[i10] = atResponse.getValue()[i10];
							Serial.print(info_XBee_data[i10], HEX);
							Serial.print(" ");
						}
						Serial.println("");
						search_list++;
					}
				}
				else
				{
					Serial.print("Command return error code: ");
					Serial.println(atResponse.getStatus(), HEX);
				}
			}
			else
			{
				Serial.print("Expected AT response but got ");
				Serial.println(xbee.getResponse().getApiId(), HEX);
			}
		}
		else
		{
			if (xbee.getResponse().isError())             // at command failed
			{
				Serial.print("Error reading packet.  Error code: ");
				Serial.println(xbee.getResponse().getErrorCode());
			}
			else
			{
				Serial.println("\nNo response from radio1");
				return;
			}
		}

	}
}
示例#4
0
void XBeeActive::sendAtCommand_ar()
{
	int i10;

	Serial.println("\nSending command sendAtCommand_ar to the XBee");
	xbee.send(arRequestMod);      // send the command

								  // wait up to 5 seconds for the status response
	if (xbee.readPacket(5000))
	{

		// should be an AT command response
		if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE)
		{
			xbee.getResponse().getAtCommandResponse(atResponse);

			if (atResponse.isOk())
			{

				//myGLCD.setColor(255 , 0, 0);

				//	Serial.print("Command [");
				//	Serial.print(atResponse.getCommand()[0]);
				//	Serial.print(atResponse.getCommand()[1]);
				//	Serial.println("] was successful!");

				if (atResponse.getValueLength() > 0)
				{
					Len_XBee = atResponse.getValueLength();
					//  Serial.print("Command value length is ");
					//  Serial.println(atResponse.getValueLength(), DEC);
					//  Serial.print("Command value: ");
					int i11 = Len_XBee - 1;
					info_XBee_data1[0] = 0;
					info_XBee_data1[1] = 0;
					info_XBee_data1[2] = 0;
					info_XBee_data1[3] = 0;

					for (i10 = 0; i10 < atResponse.getValueLength(); i10++)
					{
						info_XBee_data[i10] = atResponse.getValue()[i10];
						Serial.print(info_XBee_data[i10], HEX);
						info_XBee_data1[i11] = info_XBee_data[i10];
						i11--;
					}

					// Serial.println("");
				}
			}
			else
			{
				Serial.print("Command return error code: ");
				Serial.println(atResponse.getStatus(), HEX);

				//myGLCD.setColor(255, 0, 0);
				//myGLCD.fillRoundRect(278, 92, 318, 132);
				//myGLCD.setColor(255, 255, 255);
				//myGLCD.drawRoundRect(278, 92, 318, 132);
				//myGLCD.setBackColor(0, 0, 0);
				//delay(200);
				////XBee_alarm();
				//delay(1000);
				//myGLCD.setColor(0, 0, 0);
				//myGLCD.fillRoundRect(278, 92, 318, 132);
				//myGLCD.setColor(0, 0, 0);
				//myGLCD.drawRoundRect(278, 92, 318, 132);
				//	mcp_Out1.digitalWrite(Beep, LOW);                    // 
				delay(300);
			}
		}
		else
		{
			Serial.print("Expected AT response but got ");
			Serial.println(xbee.getResponse().getApiId(), HEX);
		}
	}
	else
	{
		// at command failed
		if (xbee.getResponse().isError())
		{
			Serial.print("Error reading packet.  Error code: ");
			Serial.println(xbee.getResponse().getErrorCode());
		}
		else
		{
			Serial.println("No response from radio2");
		}
	}
}