예제 #1
0
/*********************************************************************
 * @fn      uartPrintf_flush
 *
 * @brief   Printf-buffer flush function
 *
 *          In this implementation it is intended to be called by the
 *          Idle task when nothing else is running.
 *
 *          This is achieved by setting up the Idle task in the TI-RTOS
 *          configuration script like so:
 *
 *          var Idle = xdc.useModule('ti.sysbios.knl.Idle');
 *          Idle.addFunc('&uartPrintf_flush');
 *
 * @param   None. Relies on global state.
 *
 * @return  None.
 *
 * @post    ::uartPrintf_tail is incremented to where uartPrintf_head
 *          was at the time the function was called.
  */
void uartPrintf_flush()
{
	// Abort in case UART hasn't been initialized.
	if (NULL == hUart)
		return;

  // Lock head position to avoid race conditions
  uint16_t curHead = uartPrintf_head;

  // Find out how much data must be output, and how to output it.
	bool needWrap = curHead < uartPrintf_tail;
  uint16_t outLen = needWrap?(UART_PRINTF_BUF_LEN-uartPrintf_tail+curHead):(curHead-uartPrintf_tail);

	if (outLen)
	{
		if (needWrap)
		{
			UART_write(hUart, &uartPrintf_outArray[uartPrintf_tail], UART_PRINTF_BUF_LEN - uartPrintf_tail);
			UART_write(hUart, uartPrintf_outArray, curHead);
		}
		else
		{
			UART_write(hUart, &uartPrintf_outArray[uartPrintf_tail], outLen);
		}
	}

	uartPrintf_tail = curHead;
}
예제 #2
0
파일: App.c 프로젝트: supermk2/Tiva_C
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);
    }
}
/*
 *  ======== 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);
    }
}
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));

	}
}
예제 #5
0
alt_8 play_file(char no_args, char* arg_strings[])
{
	//first we need to open the file
	if(no_args!=1)
	{
		UART_write("This needs a file name\r\n");
		return -1;
	}
	euint8 FFound=0;
	SDfile File[200];
	SDfolder Folder[200];
	read_directory(File,Folder,currDir);
	euint16 i=0;
	for(i=0;i<20;i++)
	{
		if(File[i].valid==1)
		{
			euint8 fname[15];
			euint8 x=0,y=0;
			for(x=0;x<8;x++)
			{
				if(File[i].name[x]!=0x20 && File[i].name[x]!=0x00)
				{//if char is not null and is not space
					fname[y] = File[i].name[x];
					++y;
				}
				else
					x=12;
			}
			fname[y]='.';
			++y;
			for(x=0;x<3;x++)
			{
				if(File[i].extension[x]!=0x20 && File[i].extension[x]!=0x00)
				{//if char is not null and is not space
					fname[y] = File[i].extension[x];
					++y;
				}
				else
					x=12;
			}
			//file is a valid file
			fname[y]=0;//add null terminator
			if(strcompare2(fname,arg_strings[0])==0)
			{
				FFound=1;
				open_wav(File[i]);
			}
		}
	}
	/*
	euint8 buffer[512];
	read_file_chunk(File[6],buffer,512,0);
	*/
	if(FFound==0)
	{
		UART_write("That File cannot be found, check spelling and try again\r\n");
	}
	FFound=0;
}
//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;
	}
}
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);
	}

}
예제 #8
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);
	}
}
예제 #9
0
euint8 ls(SDfile* File,SDfolder* Folder)
{
	euint16 counter=0;
	euint8 empty=0;
	char buffer[64];
	for(counter=0;counter<20;counter++)
		if((File[counter].valid==1))
			{
				printf("%s.%s\t%dKB\n",File[counter].name,File[counter].extension,(File[counter].file_size/1024));
				sprintf(buffer,"%s.%s\t%dKB\r\n",File[counter].name,File[counter].extension,(File[counter].file_size/1024));
				UART_write(buffer);
				empty=1;
			}
	counter=0;
	for(counter=0;counter<20;counter++)
		if((Folder[counter].valid==1))
			{
				printf("%s\t<DIR>\n",Folder[counter].name);
				sprintf(buffer,"%s\t<DIR>\r\n",Folder[counter].name);
				UART_write(buffer);
				empty=1;
			}
	if(empty==0)
	{
		printf("Empty Folder\n");
		sprintf(buffer,"Empty Folder\r\n");
		UART_write(buffer);
	}
return 0;
}
void hm10_send(char * tx_buffer, int tx_size)
{
	if(hm10_initialised){
		UART_write(uart, tx_buffer, tx_size);
		UART_write(uart, "\n", 1);
	}else{
		serial_printf(cli_stdout, "TX failed. hm10 not init\n");
	}
}
예제 #11
0
 void pcReadUARTCallback(UART_Handle handle, void *buf, size_t count) {
 	if (count != UART_ERROR) {
 		// Write the data to the GSM
 		UART_write(uartGSM, buf, count);
 		// Write the data to the PC too
 		UART_write(uartPC, buf, count);
 		// Write the data to the PC too
 		UART_write(uartXBEE, buf, count);
 	}
 }
예제 #12
0
/*
 * Write to a file. Returns 0 on success, negative on error, and the number
 * of characters _not_ written on partial success. This implementation sends
 * a buffer of size 'len' to the UART.
 */
int _sys_write(FILEHANDLE fh, const unsigned char * buf,
               unsigned len, int mode)
{
    int i;
    for(i=0;i<len;i++)
    {
        UART_write(buf[i]);

        // Fix for HyperTerminal
        if(buf[i]=='\n') UART_write('\r');
    }

    return 0;
}
// -----------------------------------------------------------------------------
//! \brief      This routine writes copies buffer addr to the transport layer.
//!
//! \param[in]  len - Number of bytes to write.
//!
//! \return     uint8 - number of bytes written to transport
// -----------------------------------------------------------------------------
uint16 NPITLUART_writeTransport(uint16 len)
{
    ICall_CSState key;
    key = ICall_enterCriticalSection();
    
    TransportTxLen = len;

#ifdef POWER_SAVING
    TxActive = TRUE;

    // Start reading prior to impending write transaction
    // We can only call UART_write() once MRDY has been signaled from Master
    // device
    NPITLUART_readTransport();
#else
    // Check to see if transport is successful. If not, reset TxLen to allow
    // another write to be processed
    if(UART_write(uartHandle, TransportTxBuf, TransportTxLen) == UART_ERROR )
    {
      TransportTxLen = 0;
    }
#endif //POWER_SAVING
    ICall_leaveCriticalSection(key);
    
    return TransportTxLen;
}
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);
		}


	}
}
// -----------------------------------------------------------------------------
//! \brief      This routine is called from the application context when REM RDY
//!             is de-asserted
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_handleRemRdyEvent(void)
{
  _npiCSKey_t key;
  key = NPIUtil_EnterCS();

  // If read has not yet been started, now is the time before Master
  // potentially starts to send data
  // There is the possibility that MRDY gets set high which
  // clears RxActive prior to us getting to this event. This will cause us to
  // read twice per transaction which will cause the transaction to never
  // complete
  if (!RxActive && !TxActive)
  {
    NPITLUART_readTransport();
  }

  // If write has already been initialized then kick off the driver write
  // now that Master has signalled it is ready
  if (TxActive)
  {
    // Check to see if transport is successful. If not, reset TxLen to allow
    // another write to be processed
    if (UART_write(uartHandle, npiTxBuf, TransportTxLen) == UART_ERROR)
    {
      TxActive = FALSE;
      TransportTxLen = 0;
    }
  }

  NPIUtil_ExitCS(key);
}
예제 #16
0
// -----------------------------------------------------------------------------
//! \brief      This routine is called from the application context when REM RDY
//!             is de-asserted
//!
//! \return     void
// -----------------------------------------------------------------------------
void NPITLUART_handleRemRdyEvent(void)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();

    remRdy_flag = 0;

    // If we haven't already begun reading, now is the time before Master
    //    potentially starts to send data
    // The !TxActive condition is because we will call UART_npiRead() prior to setting
    // TxActive true. There is the possibility that REM RDY gets set high which
    // clears RxActive prior to us getting to this event. This will cause us to
    // read twice per transaction which will cause the transaction to never
    // complete
    if (!RxActive && !TxActive)
    {
        NPITLUART_readTransport();
    }

    // If we have something to write, then the Master has signalled it is ready
    //    to receive. Time to write.
    if (TxActive)
    {
        // Check to see if transport is successful. If not, reset TxLen to allow
        // another write to be processed
        if (UART_write(uartHandle, npiTxBuf, TransportTxLen) == UART_ERROR)
        {
            TxActive = FALSE;
            TransportTxLen = 0;
        }
    }

    NPIUtil_ExitCS(key);
}
예제 #17
0
// -----------------------------------------------------------------------------
//! \brief      This routine writes copies buffer addr to the transport layer.
//!
//! \param[in]  len - Number of bytes to write.
//!
//! \return     uint16_t - number of bytes written to transport
// -----------------------------------------------------------------------------
uint16_t NPITLUART_writeTransport(uint16_t len)
{
    _npiCSKey_t key;
    key = NPIUtil_EnterCS();

    npiTxBuf[NPI_UART_MSG_SOF_IDX] = NPI_UART_MSG_SOF;
    npiTxBuf[len + 1] = NPITLUART_calcFCS((uint8_t *)&npiTxBuf[1],len);
    TransportTxLen = len + 2;

#ifdef POWER_SAVING
    TxActive = TRUE;

    // Start reading prior to impending write transaction
    // We can only call UART_write() once REM RDY has been signaled from Master
    // device
    NPITLUART_readTransport();
#else
    // Check to see if transport is successful. If not, reset TxLen to allow
    // another write to be processed
    if(UART_write(uartHandle, npiTxBuf, TransportTxLen) == UART_ERROR)
    {
        TransportTxLen = NPI_BUSY;
    }
#endif //POWER_SAVING

    NPIUtil_ExitCS(key);

    return len;
}
예제 #18
0
void COM_txCMD(UINT8 deviceAddress, 
			/*UINT8 cmd,*/ UINT8 *buffer , UINT8 length)
{
	UINT8 cmdPacket[45] = {0};
	UINT8 i,j,cs;

	i = 0;
	cmdPacket[i++]= CMD_SOP;
	cmdPacket[i++] = deviceAddress;
	cmdPacket[i++] = length;
//	cmdPacket[i++] = cmd;
	for( j =0; j < length ; j++)
	{
		cmdPacket[i+j] = buffer[j];
	}
	i+= j;
 	cs = checksum(&cmdPacket[1], i - 1 );
	while((cs == CMD_SOP ) || (cs == CMD_EOP)) //if check sum matches sop or eop
	{
		cmdPacket[2]++; 						// change length
		cs = checksum(&cmdPacket[1], i - 1 ); //recalculate check sum
	}
	cmdPacket[i++] = cs;
	cmdPacket[i++] = CMD_EOP;

	for( j = 0 ; j < i ; j++)
	{
		UART_write(cmdPacket[j]);
	}
	UART_transmit();

}		
예제 #19
0
alt_8 list_directory(char no_args, char* arg_strings[])
{
	if(no_args==0)
		putty_ls();
	else
		UART_write("ls only works on current dir\r\n");
}
int roveUART_Write(int tiva_pin, char* write_buffer, int bytes_to_write) {

    extern UART_Handle uart2;
    extern UART_Handle uart3;
    extern UART_Handle uart4;
    extern UART_Handle uart5;
    extern UART_Handle uart6;
    extern UART_Handle uart7;

    switch (tiva_pin) {

        case TEST_DEVICE_PIN:

            bytes_to_write = UART_write(uart2, write_buffer, bytes_to_write);

        break;

        default:

            printf("roveUARTWrite passed invalid device: %d\n", tiva_pin);

        return ERROR;

    }//end switch

    //roveUARTWrite timing issue?
    //ms_delay(1);

    return bytes_to_write;

}//endfnctn roveUARTWrite
예제 #21
0
/*
 * Writes a character to the output channel. This function is used
 * for last-resort error message output.
 */
void _ttywrch(int ch)
{
    // Convert correctly for endianness change
    char ench=ch;

    UART_write(ench);
}
예제 #22
0
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

}
예제 #23
0
void COM_txData()
{
	UINT8 bcc = 0;
	UINT8 i= 0;

	bcc = checksum(communication.txPacketBuffer, communication.txPacketLength);

#if(defined __18F8722_H) ||(defined __18F46K22_H)

	UART1_write(communication.tx_sop);

	for( i = 0; i < communication.txPacketLength; i++ )
	{
		UART1_write(communication.txPacketBuffer[i]);
	}

	UART1_write(bcc);
	UART1_write(communication.tx_eop);


#ifdef __RESPONSE_ENABLED__
	UART1_transmit();
#endif


#else 	//(defined __18F8722_H) ||(defined __18F46K22_H)
	
	UART_write(communication.tx_sop);

	for( i = 0; i < communication.txPacketLength; i++ )
	{
		UART_write(communication.txPacketBuffer[i]);
	}

	UART_write(bcc);
	UART_write(communication.tx_eop);


#ifdef __RESPONSE_ENABLED__
	UART_transmit();
#endif
	ClrWdt();

#endif
	
}
예제 #24
0
alt_8 change_directory(char no_args, char* arg_strings[])
{
	if(no_args==1)
		if(putty_cd(arg_strings[0])!=0)
		{
			UART_write("Cannot cd to that directory, does it exist?\r\n");
		}
}
예제 #25
0
/**
 * usage: this method does the work, checkes the queue, writes to the UART and post's
 * 		  the Event
 * @method uart_method
 * @author: patrik.szabo
 * @param arg0 - not used param for the task
 * @return *none*
 */
void uart_method(UArg arg0) {

	// char input;
	UART_Handle uart;
	UART_Params uartParams;

	/* 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");
	}

	QueueObject* queueObjectPointer;

	char altData[22] = "";
	char pressData[16] = "";
	char tempData[18] = "";

	while (1) {
		while (!Queue_empty(uartQueue)) {
			queueObjectPointer = Queue_dequeue(uartQueue);
			sprintf(altData, "Altitude: %d | ",
					(int) queueObjectPointer->myInformationPointer->alt);
			System_printf("%s", altData);
			UART_write(uart, altData, sizeof(altData));
			sprintf(pressData, "Pressure: %d | ",
					queueObjectPointer->myInformationPointer->press);
			System_printf("%s", pressData);
			UART_write(uart, pressData, sizeof(pressData));
			sprintf(tempData, "Temparature: %d\n\r",
					queueObjectPointer->myInformationPointer->temp);
			System_printf("%s", tempData);
			UART_write(uart, tempData, sizeof(tempData));
			Event_post(uartReadyEvent, Event_Id_02);
		}
		Task_sleep(500);
	}
}
예제 #26
0
파일: BtStack.c 프로젝트: sudo-g/Matilda
int8_t BtStack_push(const BtStack_Frame* frame)
{
	// special character declarations
	const char escapedEnd[] = {SLIP_ESC, SLIP_ESC_END};	// escaped 0xC0
	const char escapedEsc[] = {SLIP_ESC, SLIP_ESC_ESC};	// escaped 0xDB

	char sendStream[KFP_WORST_SIZE];
	uint8_t sentChar = 0;

	// append start character
	sendStream[0] = SLIP_END;
	sentChar++;

	// iterate through frame adding ESC characters where necessary
	uint8_t i;
	for (i=0; i<KFP_FRAME_SIZE-2; i++)
	{
		switch(frame->b8[i])
		{
		case(SLIP_END):
				// escape END character
				strncat(sendStream, escapedEnd, 2);
				sentChar+=2;
				break;
		case(SLIP_ESC):
				// escape ESC character
				strncat(sendStream, escapedEsc, 2);
				sentChar+=2;
				break;
		default:
				sendStream[sentChar] = frame->b8[i];
				sentChar++;
		}
	}

	// append end character
	sendStream[sentChar] = SLIP_END;
	sentChar++;

	// prepare UART socket
	UART_Handle s;
	UART_Params params;
	UART_Params_init(&params);
	params.baudRate = uartBaud;
	params.writeMode = UART_MODE_BLOCKING;
	params.writeDataMode = UART_DATA_BINARY;
	params.readDataMode = UART_DATA_BINARY;
	params.readReturnMode = UART_RETURN_FULL;
	params.readEcho = UART_ECHO_OFF;
	s = UART_open(Board_BT1, &params);

	// write to socket and close once complete
	int8_t ret = UART_write(s, sendStream, sentChar);
	UART_close(s);

	return ret;
}
예제 #27
0
char parser(char* cmdLine) {

	unsigned char i;

	char *pch;

	init_PipedStruct(&InitialParse);

	pch = strtok(cmdLine, pipeDel);
	while (pch != NULL) {
		SaveNext_Pipe(pch, &InitialParse);
		pch = strtok(NULL, pipeDel);
	}

	if (InitialParse.nToken > MAX_PIPE) {
		UART_write(TOO_PIPED_CMD, TOO_PIPED_CMDN);
		return 1;
	}
	if ( InitialParse.Token[0][0]=='\0' ) {
		return 1;
	}

	for (i=MAX_PIPE; i>0; i--) {
		init_TokenStruct(&(CmdStruct[MAX_PIPE-i]));

		pch = strtok(InitialParse.Token[MAX_PIPE-i],tokenDel);
		while (pch != NULL) {
			SaveNext_Token(pch, &(CmdStruct[MAX_PIPE-i]));
			pch = strtok(NULL, tokenDel);
		}
	}

	parserCall = ParseCmd(CmdStruct[0]);
	if (parserCall != NULL) {
		(*parserCall)(CmdStruct);
		parserCall = NULL;
		return 0;
	}
	else {
		UART_write(UNKNOW_CMD, UNKNOW_CMDN);
		return 1;
	}
	//return 0;
}
예제 #28
0
/*********************************************************************
 * @fn      rpcTransportWrite
 *
 * @brief   Write to the the serial port to the CC253x.
 *
 * @param   fd - file descriptor of the UART device
 *
 * @return  status
 */
void rpcTransportWrite(uint8_t* buf, uint8_t len)
{
	if (uart != NULL)
	{
		// call TI-RTOS driver function
		UART_write(uart, (void*) buf, (size_t) len);
	}

	return;
}
예제 #29
0
void parser_timer(TokenStruct TokenC[MAX_PIPE]) {

	char mode;
	unsigned int interval;

	if ( TokenC[0].Token[1][0] != '\0' ) {
	// Parsing modo
		if(strcmp(TokenC[0].Token[1],"off")==0) mode = 0;
		else if(strcmp(TokenC[0].Token[1],"on")==0) mode = 1;
		else if(strcmp(TokenC[0].Token[1],"periodic")==0) mode = 2;
		else {
			UART_write(MODE_UNKNOWN,MODE_UNKNOWN_N);
			return;
		}
	}
	else {
		UART_write(MODELESS,MODELESS_N);
		return;
	}
	if ( TokenC[0].Token[2][0] != '\0' ) {

		if (atol(TokenC[0].Token[2]) <= 65534 && atol(TokenC[0].Token[2])>=500) interval = atol(TokenC[0].Token[2]);
		else {
			UART_write(OUTOFTIME,OUTOFTIME_N);
			return;
		}
	}
	else {
		if (mode != 0) {
				UART_write(TIMELESS,TIMELESS_N);
				return;
		}
	}

	if (TokenC[1].Token[0][0] != '\0') {
					function = ParseCmd(TokenC[1]);
					copyTokenStruct(&TempTimerCmd[0], &TokenC[1]);
				}

	TimerExec(mode,interval);

}
예제 #30
0
/**
 * @fn      SBL_TL_sendCmd
 *
 * @brief   Sends a SBL command to target device
 *
 * @param   cmd - command ID
 * @param   pData - pointer to command payload
 * @param   len - length of command payload
 *
 * @return  uint8_t - SBL_SUCCESS
 */
uint8_t SBL_TL_sendCmd(uint8_t cmd, uint8_t *pData, uint16_t len)
{
  uint8_t hdr[SBL_HDR_SIZE + 1]; // Header + CMD byte
  
  // Initialize Header
  hdr[SBL_HDR_LEN_IDX] = len + sizeof(hdr);             // Length
  hdr[SBL_HDR_CKS_IDX] = SBL_TL_CKS(cmd, pData, len);   // Checksum
  hdr[2] = cmd;                                         // Command

  // Send Header
  UART_write(sblUartHandle, hdr, sizeof(hdr));
  
  // Send Packet
  if (len)
  {
    UART_write(sblUartHandle, pData, len);
  }

  return SBL_TL_getRspACK();
}