void sim800_buffermessage_http(char * tx_buffer, int tx_size){
	if(!sim800_initialised){
		serial_printf(cli_stdout, "sim800 not initialised",0);
	}else{
		char rxBuffer[SIM800_RXBUFFER_SIZE];
		memset(&rxBuffer, 0, sizeof(rxBuffer));

		UART_write(uart, sim800_at_httpdata, sizeof(sim800_at_httpdata));
		Task_sleep(600);
		UART_write(uart, tx_buffer, tx_size);
		UART_read(uart, rxBuffer, sizeof(rxBuffer));
		serial_printf(cli_stdout, "%s", rxBuffer);


		Task_sleep(11000);
		UART_write(uart, sim800_at_httpaction, strlen(sim800_at_httpaction));

		Task_sleep(300);
		UART_write(uart, sim800_at_httpread, strlen(sim800_at_httpread));

		Task_sleep(300);
		UART_write(uart, sim800_at_httpterm, strlen(sim800_at_httpterm));
		UART_read(uart, rxBuffer, sizeof(rxBuffer));

	}
}
//must be called from within a task - this function will block!
//returns 1 if modem responds with OK
int sim800_begin(){
	char rxBuffer[SIM800_RXBUFFER_SIZE];
	memset(&rxBuffer, 0, sizeof(rxBuffer));

	if(sim800_open()){
		UART_write(uart, sim800_at_echo_off, sizeof(sim800_at_echo_off));
		UART_read(uart, rxBuffer, sizeof(rxBuffer));
		Task_sleep(500);

		memset(&rxBuffer, 0, sizeof(rxBuffer));
		UART_write(uart, sim800_at_echo_off, sizeof(sim800_at_echo_off));
		UART_read(uart, rxBuffer, sizeof(rxBuffer));

		serial_printf(cli_stdout, "%s", rxBuffer);
		Task_sleep(500);

		if(!strcmp("\r\nOK\r\n", rxBuffer)){
			sim800_initialised = 1;
			return 1; //modem can now communicate with us
		}else{
			return 0;
		}
	}else{
		return 0;
	}
}
/**
 * @fn      SBL_TL_getRsp
 *
 * @brief   Get response message from the target device
 *
 * @param   pData - pointer to byte array to store data
 * @param   maxSize - size of byte array pointed to by pData
 * @param   len - will be set to the length of data written to pData
 *
 * @return  uint8_t - SBL_SUCCESS or SBL_FAILURE
 */
uint8_t SBL_TL_getRsp(uint8_t *pData, uint16_t maxSize, uint16_t *len)
{
  uint8_t hdr[SBL_HDR_SIZE];
  
  // Read Response header
  UART_read(sblUartHandle, hdr, sizeof(hdr));
  
  // Check if length of incoming response is too long
  if (maxSize < (hdr[SBL_HDR_LEN_IDX] - sizeof(hdr)))
  {
    return SBL_FAILURE;
  }

  // Read Response Payload
  UART_read(sblUartHandle, pData,hdr[SBL_HDR_LEN_IDX] - sizeof(hdr));
  
  // Verify Checksum
  if (hdr[SBL_HDR_CKS_IDX] != SBL_TL_CKS(0, pData, hdr[SBL_HDR_LEN_IDX] - sizeof(hdr)))
  {  
    return SBL_FAILURE;
  }

  // Set length parameter to length of payload data
  *len = hdr[SBL_HDR_LEN_IDX];
  
  // Respond with ACK
  return SBL_TL_sendACK(DEVICE_ACK);
}
Exemple #4
0
// -----------------------------------------------------------------------------
//! \brief      This callback is invoked on Read completion of readSize/receive
//!             timeout
//!
//! \param[in]  handle - handle to the UART port
//! \param[in]  ptr    - pointer to buffer to read data into
//! \param[in]  size   - size of the data
//!
//! \return     void
// -----------------------------------------------------------------------------
static void SDITLUART_readCallBack(UART_Handle handle, void *ptr, size_t size)
{
    ICall_CSState key;
    key = ICall_enterCriticalSection();
    uint8 errStatus = 0;

    if (errStatus = ((UARTCC26XX_Handle)handle->object)->status)
    {
      //report UART error status to application 
      if(incomingRXErrorStatusAppCBFunc != NULL)
        incomingRXErrorStatusAppCBFunc(UART_ERROR_EVT, &errStatus, sizeof(errStatus));
    }

    if (size)
    {
        if (size != SDITLUART_readIsrBuf(size))
        {
            // Buffer overflow imminent. Cancel read and pass to higher layers
            // for handling
#ifdef POWER_SAVING
            RxActive = FALSE;
#endif //POWER_SAVING
            if ( sdiTransmitCB )
            {
                sdiTransmitCB(SDI_TL_BUF_SIZE,TransportTxLen);
            }
        }
    }

#ifdef POWER_SAVING
    // Read has been cancelled by transport layer, or bus timeout and no bytes in FIFO
    //    - do not invoke another read
    if ( !UARTCharsAvail(((UARTCC26XX_HWAttrs const *)(uartHandle->hwAttrs))->baseAddr) &&
            mrdy_flag )
    {
        RxActive = FALSE;
        
        // If TX has also completed then we are safe to issue call back
        if ( !TxActive && sdiTransmitCB )
        {
            sdiTransmitCB(TransportRxLen,TransportTxLen);
        }
    }
    else
    {
        UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
    }
#else
    if ( sdiTransmitCB )
    {
        sdiTransmitCB(size,0);
    }
    TransportRxLen = 0;
    UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
#endif //POWER_SAVING

    ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief      This callback is invoked on Read completion of readSize/receive
//!             timeout
//!
//! \param[in]  handle - handle to the UART port
//! \param[in]  ptr    - pointer to buffer to read data into
//! \param[in]  size   - size of the data
//!
//! \return     void
// -----------------------------------------------------------------------------
static void NPITLUART_readCallBack(UART_Handle handle, void *ptr, size_t size)
{
    ICall_CSState key;
    key = ICall_enterCriticalSection();

    if (size)
    {
        if (size != NPITLUART_readIsrBuf(size))
        {
            // Buffer overflow imminent. Cancel read and pass to higher layers
            // for handling
#ifdef POWER_SAVING
            RxActive = FALSE;
#endif //POWER_SAVING
            if ( npiTransmitCB )
            {
                npiTransmitCB(NPI_TL_BUF_SIZE,TransportTxLen);
            }
        }
    }

#ifdef POWER_SAVING
    // Read has been cancelled by transport layer, or bus timeout and no bytes in FIFO
    //    - do not invoke another read
    if ( !UARTCharsAvail(((UARTCC26XX_HWAttrs const *)(uartHandle->hwAttrs))->baseAddr) &&
            mrdy_flag )
    {
        RxActive = FALSE;
        
        // If TX has also completed then we are safe to issue call back
        if ( !TxActive && npiTransmitCB )
        {
            npiTransmitCB(TransportRxLen,TransportTxLen);
        }
    }
    else
    {
        UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
    }
#else
    if ( npiTransmitCB )
    {
        npiTransmitCB(size,0);
    }
    TransportRxLen = 0;
    UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
#endif //POWER_SAVING

    ICall_leaveCriticalSection(key);
}
/**
 *  \brief  Interrupt Service Routine to handle UART Character Timeout Interrupt
 *
 *  \param  none
 *
 *  \return none
 */
void uart_ctoIsr(void)
{
	UART_read( hUart,buffer2,0,0);
	ptr = buffer2;
	gcount = 1;
  	UART_eventEnable(hUart,CSL_UART_XMITOR_REG_EMPTY_INTERRUPT);
}
void sim800_send_sms(char * tx_buffer, int tx_size){
	char rxBuffer[SIM800_RXBUFFER_SIZE];

	 if(sim800_initialised  && !sim800_locked){
		sim800_locked = 1;

		UART_write(uart, sim800_at_smgf, sizeof(sim800_at_smgf));
		Task_sleep(500);

		UART_write(uart, sim800_at_smgs, strlen(sim800_at_smgs));
		Task_sleep(1000);

		UART_write(uart, tx_buffer, tx_size);
		Task_sleep(5000);

		memset(&rxBuffer, 0, sizeof(rxBuffer));
		UART_write(uart, sim800_ctrl_z, sizeof(sim800_ctrl_z));
		UART_read(uart, rxBuffer, sizeof(rxBuffer));
		serial_printf(cli_stdout, "sms:%s", rxBuffer);

		sim800_locked = 0;
	 }else{
		serial_printf(cli_stdout, "sim800 not initialised",0);
	}

}
void sim800_init_http(SIM800_MIME mime_type){
	if(!sim800_initialised){
		serial_printf(cli_stdout, "sim800 not initialised",0);
	}else{
		char rxBuffer[SIM800_RXBUFFER_SIZE];
		int i;

		const char *init_http_cmdseq[] = {
			sim800_at_sapbr_apn,
			sim800_at_sapbr,
			sim800_at_httpinit,
			sim800_at_httppara_url,
			sim800_at_httppara_cid,
			""
		};

		//set selected mime type
		if(mime_type == MIME_OCTET_STREAM){
			init_http_cmdseq[5] = sim800_at_httppara_content_stream;
		}else{
			init_http_cmdseq[5] = sim800_at_httppara_content_text;
		}


		for(i=0; i<6; i++){
			memset(&rxBuffer, 0, sizeof(rxBuffer));
			UART_write(uart, init_http_cmdseq[i], strlen(init_http_cmdseq[i]));
			UART_read(uart, rxBuffer, sizeof(rxBuffer));
			Task_sleep(200);
		}


	}
}
int roveUART_Read(int tiva_pin, char* read_buffer, int bytes_to_read) {

    extern UART_Handle uart_2;
    extern UART_Handle uart_3;
    extern UART_Handle uart_4;
    extern UART_Handle uart_5;
    extern UART_Handle uart_6;
    extern UART_Handle uart_7;

    switch (tiva_pin) {

        case TEST_DEVICE_PIN:

            //uart 2 is just the only muxless 485 Jack wired to a uart onboard Horizon's MOB pcb
            bytes_to_read = UART_read(uart_2, read_buffer, bytes_to_read);

            //see the Mob Eagle file for details)

        break;

        default:

            printf("roveUARTRead was passed invalid UART: %d\n", tiva_pin);

        return ERROR;

    }//endswitch

    //now holds the number of bytes actually read
    return bytes_to_read;

}//endfnctn roveUARTRead
Exemple #10
0
void cmdTerp() {
	UART_Handle uart;
	UART_Params uartParams;

	UART_Params_init(&uartParams);
	uartParams.writeDataMode = UART_DATA_BINARY;
	uartParams.readDataMode = UART_DATA_BINARY;
	uartParams.readReturnMode = UART_RETURN_FULL;
	uartParams.readEcho = UART_ECHO_OFF;
	uartParams.baudRate = 9600;
	uart = UART_open(Board_UART1, &uartParams);
	globalUART = &uart;

	if (uart == NULL) {
	        System_abort("Error opening the UART");
	}

	char input[2];
	uint8_t duty;

	while(1) {
		UART_write(uart,">",1);
		UART_read(uart,input,1);
		UART_write(uart,input,1);

		cmdExecute(input,duty);
	}
}
Exemple #11
0
Void Task_UART(UArg arg0, UArg arg1)
{
    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";
    char input;    
    
    UART_Params_init(&uartParams);
    uartParams.writeMode = UART_MODE_BLOCKING;
    uartParams.readMode = UART_MODE_BLOCKING;
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;
    uartParams.parityType = UART_PAR_NONE;
    uartParams.dataLength = UART_LEN_8;
    uartParams.stopBits = UART_STOP_ONE;
    
    uart = UART_open(Board_UART0, &uartParams);
    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    System_printf("\nTask_UART");
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
    // Loop forever echoing 
    while (1) {
        UART_read(uart, &input, 1);
        input++;
        UART_write(uart, &input, 1);
    }
}
void COM_task()
{
	UINT8 uartData = 0;


#if(defined __18F8722_H) ||(defined __18F46K22_H)
	if( UART1_hasData() )
	{
		uartData = UART1_read();	

		UART1_write(uartData);
		UART1_transmit();
		return;

	}
#else
	if( UART_hasData() )
	{
		uartData = UART_read();	

		UART_write(uartData);
		UART_transmit();
		return;

	}

#endif

}
/*
 *  ======== echoFxn ========
 *  Task for this function is created statically. See the project's .cfg file.
 */
Void echoFxn(UArg arg0, UArg arg1)
{
    char input;
    UART_Handle uart;
    UART_Params uartParams;
    const char echoPrompt[] = "\fEchoing characters:\r\n";

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 9600;
    uart = UART_open(Board_UART0, &uartParams);

    if (uart == NULL) {
        System_abort("Error opening the UART");
    }

    UART_write(uart, echoPrompt, sizeof(echoPrompt));

    /* Loop forever echoing */
    while (1) {
        UART_read(uart, &input, 1);
        UART_write(uart, &input, 1);
    }
}
Exemple #14
0
int rs485_read(unsigned char *buffer, UInt size)
{
	int num;
	GPIO_write(Board_RS485_DE_RE_PIN, RS485_READ);
	num = UART_read(uart2, (char *)buffer, size);
	return num;
}
int uart_serial_getc(void *dev)
{
	uint8_t c;
	if (UART_read(((UART_SerialDevice *)dev)->uart, &c, 1) == 1) {
		return c;
	}
	return SERIAL_EOF;
}
Exemple #16
0
/*!
 *  @brief  gets a char from the UART Console
 *
 *  @param  	a - char to read into
 *  @return     None
 */
Void UARTConsole_getch(Char *a)
{
	/* Make sure UART is initialized */
	if (handle)
	{
		UART_read(handle, a, 1);
	}
}
Exemple #17
0
// -----------------------------------------------------------------------------
//! \brief      This routine reads data from the UART
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_readTransport(void)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();

#ifdef POWER_SAVING
    RxActive = TRUE;
#endif //POWER_SAVING

    TransportRxLen = 0;
    UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);

    NPIUtil_ExitCS(key);
}
Exemple #18
0
int main(void) {

	// Initilize UART and GPIO
	UART_init();
	GPIO_init();
	
	// Turn ON LED
	GPIO1DATA = (1 << PIO1_9);
	
	// UART Read with a callback
	UART_read(UART_RX_callback);
	
	while(1);
}
Exemple #19
0
/*
 *  ======== UARTUtils_deviceread ========
 */
int UARTUtils_deviceread(int fd, char *buffer, unsigned size)
{
    Int ret;

    /* Return if a UART other than UART 0 was specified. */
    if (fd != 0) {
        return (-1);
    }

    /* Read character from the UART and block until a newline is received. */
    ret = UART_read(ports[fd].handle, buffer, size);

    return (ret);
}
// -----------------------------------------------------------------------------
//! \brief      This routine reads data from the UART
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_readTransport(void)
{
    ICall_CSState key;
    key = ICall_enterCriticalSection();
    
#ifdef POWER_SAVING
    RxActive = TRUE;
#endif //POWER_SAVING

    TransportRxLen = 0;
    UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);
    
    ICall_leaveCriticalSection(key);
}
// -----------------------------------------------------------------------------
//! \brief      This routine reads data from the UART
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_readTransport(void)
{
    ICall_CSState key;
    key = ICall_enterCriticalSection();

#if (NPI_FLOW_CTRL == 1)
    RxActive = TRUE;
#endif // NPI_FLOW_CTRL = 1

    TransportRxLen = 0;
    UART_read(uartHandle, &isrRxBuf[0], UART_ISR_BUF_SIZE);

    ICall_leaveCriticalSection(key);
}
const char* sim800_get_battery_voltage(){
	static char rxBuffer[SIM800_RXBUFFER_SIZE];
	memset(&rxBuffer, 0, sizeof(rxBuffer));

	if(sim800_initialised && !sim800_locked){
		UART_write(uart, sim800_at_cbc, sizeof(sim800_at_cbc));
		UART_read(uart, rxBuffer, sizeof(rxBuffer));
		Task_sleep(500);
		return rxBuffer;
	}else{
		serial_printf(cli_stdout, "sim800 not initialised",0);
		return 0;
	}
}
Exemple #23
0
/*!
 *  @brief  reads buffer from the UART Console
 *
 *  @param  	buffer - buffer to read in to
 *  @param  	size - number of bytes to read
 *  @return     bytes read
 */
int UARTConsole_read(char *buffer, unsigned size)
{
	int ret;

	/* Return if a UART not open. */
	if (handle == NULL)
	{
		return (-1);
	}

	/* Read character from the UART and block until a newline is received. */
	ret = UART_read(handle, (uint8_t *) buffer, size - 1);

	return (ret);
}
Exemple #24
0
int main() {
	char str[100];
	char *c = str;

	UART_write_str("Send me a string and I'll echo it back!\n");

	c--;
	do {
		c++;
		*c = UART_read();
	} while ((*c != '\n') && (c < (str+99)));
	*c = '\0';

	printf("%s\n", str);
	return 0;
}
// -----------------------------------------------------------------------------
//! \brief      This routine reads data from the UART
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_readTransport(void)
{
  _npiCSKey_t key;
  key = NPIUtil_EnterCS();
  
#if (NPI_FLOW_CTRL == 1)
  RxActive = TRUE;
#endif // NPI_FLOW_CTRL = 1

  TransportRxLen = 0;
  
  // UART driver will automatically reject this read if already in use
  UART_read(uartHandle, npiRxBuf, NPI_UART_MSG_SOF_LEN);
  
  NPIUtil_ExitCS(key);
}
/*********************************************************************
 * @fn      rpcTransportRead
 *
 * @brief   Reads from the the serial port to the CC253x.
 *
 * @param   fd - file descriptor of the UART device
 *
 * @return  status
 */
uint8_t rpcTransportRead(uint8_t* buf, uint8_t len)
{
	uint8_t ret = 0;
	int bytes;

	if (uart != NULL)
	{
		// call TI-RTOS driver function
		bytes = UART_read(uart, (void*) buf, (size_t) len);
		if (bytes != UART_ERROR)
		{
			// return number of read bytes
			ret = (uint8_t) bytes;
		}
	}

	return ret;
}
Exemple #27
0
/**
 * @fn      SBL_TL_getRspACK
 *
 * @brief   Get ACK/NACK response from the target device
 *
 * @param   None.
 *
 * @return  uint8_t - SBL_DEV_ACK, SBL_DEV_NACK, or SBL_FAILURE if neither ACK/NACK
 */
uint8_t SBL_TL_getRspACK(void)
{
  uint8_t rsp[SBL_ACK_SIZE];
  
  UART_read(sblUartHandle, rsp, sizeof(rsp));
  
  if (memcmp(rsp, ACK, sizeof(rsp)))
  {
    return SBL_DEV_ACK;
  }
  else if (memcmp(rsp, NACK, sizeof(rsp)))
  {
    return SBL_DEV_NACK;
  }
  else
  {
    return SBL_FAILURE;
  }
}
/* function checks if new data has been received via BLE module and starts a new UART_read.
 * Returns 1 if new data was received, 0 if no new data is present.
 */
int hm10_receive(char* rxdata, int* stringlength)
{
	if(hm10_callback == 1)
	{
		(*stringlength) = hm10_rxCount;

		memcpy(rxdata,hm10_rxBuffer,hm10_rxCount);

		hm10_callback = 0;
		if(hm10_initialised)
		{
			//generate next read command
			UART_read(uart, hm10_rxBuffer, sizeof(hm10_rxBuffer));
			return 1;
		}
		else
		{
			serial_printf(cli_stdout, "RX failed. hm10 not init\n");
		}
	}
	return 0;
}
Exemple #29
0
/*
 * Read from a file. Can return:
 *  - zero if the read was completely successful
 *  - the number of bytes _not_ read, if the read was partially successful
 *  - the number of bytes not read, plus the top bit set (0x80000000), if
 *    the read was partially successful due to end of file
 *  - -1 if some error other than EOF occurred
 * This function receives a character from the UART, processes the character
 * if required (backspace) and then echo the character to the Terminal
 * Emulator, printing the correct sequence after successive keystrokes.
 */
int _sys_read(FILEHANDLE fh, unsigned char * buf,
              unsigned len, int mode)
{
    int pos=0;

    do {


        buf[pos]=UART_read();

        // Advance position in buffer
        pos++;

        // Handle backspace
        if(buf[pos-1] == '\b')
        {
            // More than 1 char in buffer
            if(pos>1)
            {
                // Delete character on terminal
                UART_write('\b');
                UART_write(' ');
                UART_write('\b');

                // Update position in buffer
                pos-=2;
            }
            else if (pos>0) pos--; // Backspace pressed, empty buffer
        }
        else UART_write(buf[pos-1]); // Echo normal char to terminal


    }while(buf[pos-1] != '\r');

    buf[pos]= '\0'; // Ensure Null termination

    return 0;
}
Exemple #30
0
void rxFxn(UArg param0, UArg param1)
{
	// Declare state variables
	Bool inFrame = FALSE;
	uint8_t frIndex = 0;

	// Buffers
	char tempRx[1];
	BtStack_Frame tempFr;

	while(TRUE)
	{
		// open socket
		UART_Handle s;
		UART_Params params;
		UART_Params_init(&params);
		params.baudRate = uartBaud;
		params.writeDataMode = UART_DATA_BINARY;
		params.readMode = UART_MODE_BLOCKING;
		params.readDataMode = UART_DATA_BINARY;
		params.readReturnMode = UART_RETURN_FULL;
		params.readEcho = UART_ECHO_OFF;
		s = UART_open(Board_BT1, &params);

		// read UART buffer and decode
		UART_read(s, tempRx, 1);
		switch(tempRx[0])
		{
		case(SLIP_END):
				if (inFrame)
				{
					if (frIndex == (KFP_FRAME_SIZE-2))
					{
						// end of frame, call callback to interpret it
						if (rxCallback != NULL)
						{
							rxCallback(&tempFr);
						}
					}

					// ignore corrupt frames
					frIndex = 0;
					inFrame = FALSE;

					break;
				}
				else
				{
					inFrame = TRUE;		// start new frame
					frIndex = 0;
					break;
				}
		case(SLIP_ESC):
				if (inFrame)
				{
					UART_read(s, tempRx, 1);
					switch(tempRx[0])
					{
					case(SLIP_ESC_END):
							tempFr.b8[frIndex] = SLIP_END;
							frIndex++;
							break;
					case(SLIP_ESC_ESC):
							tempFr.b8[frIndex] = SLIP_ESC;
							frIndex++;
							break;
					default:
						break;	// invalid post ESC character
					}
					break;
				}
				else
				{
					break;		// ignore corrupt frames
				}
		default:
			if (inFrame)
			{
				// standard character store
				tempFr.b8[frIndex] = tempRx[0];
				frIndex++;
				break;
			}
		}
	}
}