// UART DATA To Raspberry
// Raspberry To Web
void SendToWeb() {
	UARTClass * uart = UARTClass::getInstance();
	uart->setup();
	uart->startCommunicate();

	while (true) {
		try {
			ClientSocket client("218.150.181.154", 10000);
			while (true) {
				try {
					client << uart->getMsg(); // 웹으로 메세지 보내기
											  //cout << uart->getMsg() << endl;
					uart->clear();
				}
				catch (SocketException& e) {
					cout << "Exception was caught: " << e.description() << "\n";
				}
				delay(1000);	// 10sec 
			}
		}
		catch (SocketException& e) {
			cout << "ClientSocket Constructor Exception" << e.description() << endl;
		}
		delay(100);
	}
}
int main() {
	UARTClass * uart = UARTClass::getInstance();
	AltitudeController *altiCon = AltitudeController::getInstance();
	UltrasonicClass *sonar = UltrasonicClass::getInstance();
	DroneController *drone = DroneController::getInstance();

	uart->setup();
	uart->startCommunicate();

	// *************** ( ^_^ )*****************
	thread serverTh([&]() { RecvFromWeb(); });
	serverTh.detach();
	//thread clientTh([&]() { SendToWeb(); });
	//clientTh.detach();
	// *****************************************
	delay(3000);

	while (1) {
		uart->SendSerial(drone->get_pwm_string());
		cout << "throttle : " << drone->get_pwm(droneControlType::throttle) << endl;
		if (is_takeoff) {
			altiCon->calculate();
		}
		delay(100);
	}

	return 0;
}
int _write (int fd, char *ptr, int len)
{
   char *p = ptr;

   int res = UART_SUCCESS;

   (void)fd;
   (void)len;

   while (*p != '\n') {
      UART.WriteChar(*p++);

      if (res != UART_SUCCESS) {
         break;
      }

   }

   if(*p == '\n') {
         UART.WriteChar('\r');
         UART.WriteChar('\n');
   }

   return res;

}
void initVariant() 
{ 
	Serial.begin(115200);
	Serial1.begin(115200);
    Serial2.begin(115200);
    Serial3.begin(115200);
    Serial4.begin(115200);
}
void check_for_reset()
  {
	if(Serial.isResetReceived() || Serial1.isResetReceived())
	{
		SCB->AIRCR = 0x05FA0004;
		//BOOT_reset();
	}
  }
void serialEventRun(void)
{
if (Serial.available() && serialEvent) serialEvent();
if (Serial1.available() && serialEvent) serialEvent();
if (Serial2.available() && serialEvent) serialEvent();
if (Serial3.available() && serialEvent) serialEvent();
if (Serial4.available() && serialEvent) serialEvent();

}
void serialEventRun(void)
{
  if (Serial.available()) serialEvent();
  if (Serial1.available()) serialEvent1();
  if (Serial2.available()) serialEvent2();
  if (Serial3.available()) serialEvent3();
}
Example #8
0
void UART0_Stop()
{
  if (UART0_State == UART0_State_NotStarted)
    return;

  // Wait for any outstanding data to be sent
  Serial.flush();

  NRF_UART0->TASKS_STOPTX = 1;
  NRF_UART0->TASKS_STOPRX = 1;

  NRF_UART0->ENABLE       = (UART_ENABLE_ENABLE_Disabled << UART_ENABLE_ENABLE_Pos);

  // Disable UART interrupt in NVIC
  detachInterrupt(UART0_IRQn);

  // Disconnect high drive tx pin
  int tx_pin = NRF_UART0->PSELTXD;
  NRF_GPIO->PIN_CNF[tx_pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
              | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
              | (GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)
              | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
              | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);                    

  UART0_State = UART0_State_NotStarted;
}
Example #9
0
// IT handlers
unsigned long
uart5IntFunction(void *pvCBData, unsigned long ulEvent,
        unsigned long ulMsgParam,void *pvMsgData)
{
//	while(Serial5.uartInt()==0);
	Serial5.uartInt();
	return 0;
}
Example #10
0
//void UART0_IRQHandler( void )
static void UART0_handler( void )
{	
	 Serial.irq_handler();
/*
	if( NRF_UART0->EVENTS_RXDRDY )
	{
		NRF_UART0->EVENTS_RXDRDY = 0;
		
		uint8_t dat = NRF_UART0->RXD;
		
		if( UART0_CheckRXError() )
			return;
			
		rx_buffer->store_char( dat );	
	}
*/
}
int _read(int fd, char *ptr, int len)
{

   (void)fd;
   (void)len;

   while(read_ch == false);

   *ptr = Rx_char;

   UART.WriteChar(*ptr);
   printf("\n");

   read_ch = false;

   return 1;
}
Example #12
0
void Rx3_Handler(void){
  Serial3.RxHandler();
}
Example #13
0
void Tx3_Handler(void){
  Serial3.TxHandler();
}
Example #14
0
void Rx2_Handler(void){
  Serial2.RxHandler();
}
Example #15
0
void Tx2_Handler(void){
  Serial2.TxHandler();
}
Example #16
0
void Rx1_Handler(void){
  Serial1.RxHandler();
}
void LEUART0_IRQHandler(void)
{
  Serial1.IrqHandler();
}
Example #18
0
void Tx1_Handler(void){
  Serial1.TxHandler();
}
void LEUART1_IRQHandler(void)
{
  Serial2.IrqHandler();
}
// IT handlers
void UART1_Handler(void)
{
    Serial1.IrqHandler();
}
Example #21
0
// IT handlers
void USART0_Handler(void)
{
  Serial1.IrqHandler();
}
void USART2_RX_IRQHandler(void)
{
  Serial4.IrqHandler();
}
Example #23
0
// IT handlers
void UART0_Interrupt()
{
  Serial.IrqHandler();
}
void print_gpio_regs(void)
{
  char port[6] = {'A','B','C','D','E','F'};
  Serial.printf("\r\n");
  for(int i = 0; i < 6; i++) {
    Serial.printf("PORT %c:\r\n",port[i]);
    Serial.printf(" CTRL    = %x\r\n",GPIO->P[i].CTRL);
    Serial.printf(" MODEL   = %x\r\n",GPIO->P[i].MODEL);
    Serial.printf(" MODEH   = %x\r\n",GPIO->P[i].MODEH);
    Serial.printf(" DOUT    = %x\r\n",GPIO->P[i].DOUT);
    Serial.printf(" DOUTSET = %x\r\n",GPIO->P[i].DOUTSET);
    Serial.printf(" DOUTCLR = %x\r\n",GPIO->P[i].DOUTCLR);
    Serial.printf(" DOUTTGL = %x\r\n",GPIO->P[i].DOUTTGL);
    Serial.printf(" DIN     = %x\r\n",GPIO->P[i].DIN);
  }
  Serial.printf(" GPIO->EXTIPSELL = %x\r\n",GPIO->EXTIPSELL);
  Serial.printf(" GPIO->EXTIPSELH = %x\r\n",GPIO->EXTIPSELH);
  Serial.printf(" GPIO->EXTIRISE  = %x\r\n",GPIO->EXTIRISE);
  Serial.printf(" GPIO->EXTIFALL  = %x\r\n",GPIO->EXTIFALL);
  Serial.printf(" IEN             = %x\r\n",GPIO->IEN);
  Serial.printf(" IF              = %x\r\n",GPIO->IF);
}
Example #25
0
void Tx4_Handler(void){
  Serial4.TxHandler();
}
// IT handlers
void UART_Handler(void)
{
  Serial.IrqHandler();
}
Example #27
0
void Rx4_Handler(void){
  Serial4.RxHandler();
}
Example #28
0
// delegate to serial for syscalls/write and error messages
void UART0_TX( const uint8_t uc_data )
{
  Serial.write( uc_data );
}
bool Serial1_available() {
  return Serial1.available();
}
// IT handlers
void USART1_RX_IRQHandler(void)
{
  Serial.IrqHandler();
}