Example #1
0
void _print_num ( const char __flash * s, UINT16 Num)
{
  char* pi2a;
  __no_init char i2a_locbuf[6];
  pi2a=&i2a_locbuf[0];
  i2a(pi2a, Num);
  while (*s) UART_TX (*s++);
//  UART_TX(':'); 
  while (*pi2a) UART_TX(*pi2a++);  
  UART_TX(',');
  UART_TX(' '); 
}
Example #2
0
void
Esp8266WiFiPhy::ListStationAP(StationAccessPoint sap){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWLAP";
	if (!sap.m_ssid.empty()){
		ATCommand += "=" + StringEscape(sap.m_ssid);
		if (!sap.m_bssidmac.empty()){
			ATCommand += "," + StringEscape(sap.m_bssidmac);
			if (sap.m_channel != -1){
				ATCommand += "," + IntegerToString(sap.m_channel); // not to be escaped, since number!
			}
		}
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWLAP\r\n");
		return;
	}
	dbgprintf("+CWLAP:(<ECN>,<SSID>,<RSSI>,<MAC>,<CH>,<FREQ OFFSET>,<FREQ CALIB>)\r\n");
	testprintf("Ended!\r\n");
}
Example #3
0
string
Esp8266WiFiPhy::GetSoftAPMac(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CIPAPMAC_";
	// store
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CIPAPMAC\?\r\n");
		return "";
	}
	size_t from = 0;
	string stamac = StringUnescape(GetStringBetweenTokens(':','\r',m_lastATreply, from));

	dbgprintf("SoftAP MAC ADDRESS: <%s>\r\n", stamac.c_str());
	testprintf("Ended!\r\n");
	return stamac;
}
Example #4
0
void
Esp8266WiFiPhy::SetWiFiMode(uint8_t mode, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWMODE_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + IntegerToString((int)mode);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWMODE_xxx=\r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Example #5
0
void
Esp8266WiFiPhy::SetSoftAPMac(string mac_addr, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CIPAPMAC_";
	// store
	if (flashStore){
		// NB: DISABLED: WARNING!!! THIS CHANGES THE DEVICE PHYSICAL MAC ADDRESS!!
		// ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + StringEscape(mac_addr);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CIPAPMAC_xxx\r\n");
		return;
	}
	m_softAPInterfaceMac = mac_addr;
	testprintf("Ended!\r\n");
}
Example #6
0
int
main(int argc, char* argv[])
 {

  UART_Init();

  UART_TX((uint8_t*)"UART Initialized!\n", sizeof("UART Initialized!\n"));


  I2C_Init();

  setup();

//  while(1){
//      char buf[10]={0};
//
//      UART_TX((uint8_t *)buf, sprintf(buf,"%u\r\n", HAL_GetTick()));
//  }

  // if programming failed, don't try to do anything
  while (!dmpReady){}

  loop();

}
Example #7
0
int8_t
Esp8266WiFiPhy::GetWiFiMode(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWMODE_";
	// stored?
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	//tail
	ATCommand += "\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWMODE\?\r\n");
		return -1;
	}

	// parsing
	char ch = m_lastATreply.at(m_lastATreply.find(":") + 1);
	dbgprintf("WiFi Mode: %c\r\n", ch);
	testprintf("Ended!\r\n");
	return (int8_t) (ch - '0');
}
Example #8
0
StationAccessPoint
Esp8266WiFiPhy::GetConnectedStationAP(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWJAP_";
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWJAP\?\r\n");
		return StationAccessPoint("","","");
	}

	size_t from = 0;
	string ssid = StringUnescape(GetStringBetweenTokens(':',',',m_lastATreply, from));
	string bssid = StringUnescape(GetStringBetweenTokens(',',',',m_lastATreply, from));
	string channel = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string rssi = GetStringBetweenTokens(',','\r',m_lastATreply, from);

	dbgprintf("AccessPoint: <%s>,<%s>,<%s>,<%s>\r\n", ssid.c_str(), bssid.c_str(), channel.c_str(), rssi.c_str());
	testprintf("Ended!\r\n");
	return StationAccessPoint(ssid,bssid,StringToInteger(channel),StringToInteger(rssi));
}
Example #9
0
void
Esp8266WiFiPhy::ConfigureSoftAP(SoftAccessPoint sap, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWSAP_";
	// store
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand += "=" + StringEscape(sap.m_ssid);
	ATCommand += "," + StringEscape(sap.m_password);
	ATCommand += "," + IntegerToString(sap.m_channel);
	ATCommand += "," + IntegerToString(sap.m_encryption);
	ATCommand += "," + IntegerToString(sap.m_maxconnections);
	ATCommand += "," + IntegerToString(sap.m_ssidbroadcast);
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!DoubleWaitFor("OK","ERROR")){
		printf("Error: Missed OK reply - AT+CWSAP_xxx\r\n");
		return;
	}
	// assign to internal variable
	m_softAP = sap;
	testprintf("Ended!\r\n");
}
Example #10
0
void
Esp8266WiFiPhy::AutoConnectToStationAtBoot(bool enable){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWAUTOCONN=";
	if (enable){
		ATCommand += "1";
	}
	else{
		ATCommand += "0";
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: AT+CWAUTOCONN! \r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Example #11
0
void UART_Float_TX(float f){
//  int c = Float2String(*pData);

  char buf[10]={0};
  //      float f = 3.1415;
  ////      sprintf(buf,"%d.%02u\r\n", (int)f , ((int) (((f)-(int)f) * 10000)));
  UART_TX((uint8_t *)buf, sprintf(buf,"%d.%02u\t", (int)f , ((int) (((f)-(int)f) * 10000))));

//  if(HAL_UART_Transmit(&UartHandle, (uint8_t*)str, c, 5000)!= HAL_OK)
//  {
//    /* Turn LED5 (RED) on */
//    BSP_LED_On(LED5);
//    while(1)
//    {
//    }
//  }
}
Example #12
0
void
Esp8266WiFiPhy::QuitStationAP(void){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWQAP\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: AT+CWQAP! \r\n");
		return;
	}
	testprintf("Ended!\r\n");
}
Example #13
0
SoftAccessPoint
Esp8266WiFiPhy::GetConfigurationSoftAP(bool flashStored){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWSAP_";
	// store
	if (flashStored){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}
	ATCommand +="\?\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());
	if(!WaitFor("OK")){
		printf("Error: Missed OK reply - AT+CWSAP\?\r\n");
		return SoftAccessPoint("","",-1,-1,-1,-1);
	}

	size_t from = 0;
	string ssid = StringUnescape(GetStringBetweenTokens(':',',',m_lastATreply, from));
	string password = StringUnescape(GetStringBetweenTokens(',',',',m_lastATreply, from));
	string channel = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string encryption = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string max_conn = GetStringBetweenTokens(',',',',m_lastATreply, from);
	string ssid_bcast = GetStringBetweenTokens(',','\r',m_lastATreply, from);

	dbgprintf("AccessPoint: <%s>,<%s>,<%s>,<%s>,<%s>,<%s>\r\n", ssid.c_str(), password.c_str(), channel.c_str(), encryption.c_str(), max_conn.c_str(), ssid_bcast.c_str());
	testprintf("Ended!\r\n");
	return SoftAccessPoint(ssid,password,StringToInteger(channel),StringToInteger(encryption),StringToInteger(max_conn),StringToInteger(ssid_bcast));

}
Example #14
0
bool
Esp8266WiFiPhy::ConnectToStationAP (StationAccessPoint sap, bool flashStore){
	string ATCommand;

	testprintf("\r\nEntering %s ...", __PRETTY_FUNCTION__);
	// header
	ATCommand = "AT+CWJAP_";
	if (flashStore){
		ATCommand += "DEF";
	}
	else {
		ATCommand += "CUR";
	}

	ATCommand += "=" + StringEscape(sap.m_ssid) + ",";
	ATCommand += StringEscape(sap.m_password);
	if (!(sap.m_bssidmac.empty())) {
		ATCommand += "," + StringEscape(sap.m_bssidmac);
	}
	//tail
	ATCommand += "\r\n";

	// resets the buffer from any spurious previous output and send
	m_UART->rxBufferFlush();
	UART_TX(ATCommand);
	dbgprintf("SEND:\r\n%s",ATCommand.c_str());

	if(!DoubleWaitFor("OK","FAIL")){
		printf("Error: +CWJAP: Error Code (1<=>4)==(TIMEOUT,WRONG PASSWORD,AP NOT FOUND,FAIL)\r\n");
		return false;
	}
	// assign to internal variable
	m_stationAP = sap;
	testprintf("Ended!\r\n");
	return true;
}
Example #15
0
void loop() {
  while(1){
    mpuInterrupt = false;

//    char buf[10]={0};
//
//    UART_TX((uint8_t *)buf, sprintf(buf,"%u\r\n", HAL_GetTick()));

    // wait for MPU interrupt or extra packet(s) available
    while (!mpuInterrupt && fifoCount < packetSize) {

//	cnt++;
//	time_now = HAL_GetTick();
//	if((time_now-time_old) >= 1000){
//	    time_old = time_now;
//	    char buffer[10]={0};
//	    UART_TX((uint8_t *)buffer, sprintf(buffer,"%u\r\n", (int)cnt ));
//	    UART_TX((uint8_t*)"\r\n", sizeof("\r\n"));
//	    cnt=0;
//	}

//	UART_TX((uint8_t*)"x=", sizeof("x="));
//	UART_Float_TX( (ypr[2] * 180/M_PI) );
//
//	UART_TX((uint8_t*)"y=", sizeof("y="));
//	UART_Float_TX( (ypr[1] * 180/M_PI) );
//
//	UART_TX((uint8_t*)"z=", sizeof("z="));
//	UART_Float_TX( (ypr[0] * 180/M_PI) );
//	UART_TX((uint8_t*)"\n\r", sizeof("\n\r"));

//	BSP_LED_Toggle(LED4);
//	   UART_TX((uint8_t*)"MAIN\r\n", sizeof("MAIN\r\n"));

        // other program behavior stuff here
        // .
        // .
        // .
        // if you are really paranoid you can frequently test in between other
        // stuff to see if mpuInterrupt is true, and if so, "break;" from the
        // while() loop to immediately process the MPU data
        // .
        // .
        // .
    }

    // reset interrupt flag and get INT_STATUS byte
    mpuIntStatus = mpu.getIntStatus();

    // get current FIFO count
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus == 0x10) || fifoCount == 1024) {
        // reset so we can continue cleanly
        mpu.resetFIFO();
        UART_TX((uint8_t*)"FIFO Overflow\r\n", sizeof("FIFO Overflow\r\n"));
        BSP_LED_Toggle(LED5);
    }

    // otherwise, check for DMP data ready interrupt (this should happen frequently)
    else if(mpuIntStatus == 0x01) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();

        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);

        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize;

        #ifdef OUTPUT_READABLE_QUATERNION
            // display quaternion values in easy matrix form: w x y z
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            Serial.print("quat\t");
            Serial.print(q.w);
            Serial.print("\t");
            Serial.print(q.x);
            Serial.print("\t");
            Serial.print(q.y);
            Serial.print("\t");
            Serial.println(q.z);
        #endif

        #ifdef OUTPUT_READABLE_EULER
            // display Euler angles in degrees
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetEuler(euler, &q);
            Serial.print("euler\t");
            Serial.print(euler[0] * 180/M_PI);
            Serial.print("\t");
            Serial.print(euler[1] * 180/M_PI);
            Serial.print("\t");
            Serial.println(euler[2] * 180/M_PI);
        #endif

        #ifdef OUTPUT_READABLE_YAWPITCHROLL
            // display Euler angles in degrees
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
//            trace_printf("ypr\t");
//            trace_printf("%f", ypr[0] * 180/M_PI);
//            trace_printf("\t");
//            trace_printf("%d", ypr[1] * 180/M_PI);
//            trace_printf("\t");
//            trace_printf("%d\n", ypr[2] * 180/M_PI);

        #endif

        #ifdef OUTPUT_READABLE_REALACCEL
            // display real acceleration, adjusted to remove gravity
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetAccel(&aa, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
            Serial.print("areal\t");
            Serial.print(aaReal.x);
            Serial.print("\t");
            Serial.print(aaReal.y);
            Serial.print("\t");
            Serial.println(aaReal.z);
        #endif

        #ifdef OUTPUT_READABLE_WORLDACCEL
            // display initial world-frame acceleration, adjusted to remove gravity
            // and rotated based on known orientation from quaternion
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetAccel(&aa, fifoBuffer);
            mpu.dmpGetGravity(&gravity, &q);
            mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
            mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
            Serial.print("aworld\t");
            Serial.print(aaWorld.x);
            Serial.print("\t");
            Serial.print(aaWorld.y);
            Serial.print("\t");
            Serial.println(aaWorld.z);
        #endif

        #ifdef OUTPUT_TEAPOT
            // display quaternion values in InvenSense Teapot demo format:
            teapotPacket[2] = fifoBuffer[0];
            teapotPacket[3] = fifoBuffer[1];
            teapotPacket[4] = fifoBuffer[4];
            teapotPacket[5] = fifoBuffer[5];
            teapotPacket[6] = fifoBuffer[8];
            teapotPacket[7] = fifoBuffer[9];
            teapotPacket[8] = fifoBuffer[12];
            teapotPacket[9] = fifoBuffer[13];
            Serial.write(teapotPacket, 14);
            teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
        #endif

        // blink LED to indicate activity
//       BSP_LED_Toggle(LED3);
    }
  }
}
Example #16
0
void _print_fstr (const char __flash * s)
{
  while (*s) UART_TX (*s++);
}
Example #17
0
//Print 0x0A,0x0B
void _print_rn (void)
{ 
  UART_TX(0x0A);
  UART_TX(0x0D);
}