Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <assert.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "LPC177x_8x.h"
- #include "system_LPC177x_8x.h"
- #include <retarget.h>
- #include "at.h"
- #include <DRV\drv_sdram.h>
- #include <DRV\drv_lcd.h>
- #include <DRV\drv_uart.h>
- #include <DRV\drv_touchscreen.h>
- #include <DRV\drv_led.h>
- #include <utils\timer_software.h>
- #include <utils\timer_software_init.h>
- struct at_parser at_parser;
- char* at_command_simple="AT\r\n";
- char* at_command_csq = "AT+CSQ\r\n";
- timer_software_handler_t my_timer_handler;
- LCD_PIXEL foreground = {0, 255, 0, 0};
- LCD_PIXEL background = {0, 0, 0, 0};
- void timer_callback_1(timer_software_handler_t h)
- {
- }
- void testLCD()
- {
- uint32_t i,j;
- LCD_PIXEL foreground = {0, 255, 0, 0};
- LCD_PIXEL background = {0, 0, 0, 0};
- for (i = 0; i < LCD_HEIGHT; i++)
- {
- for (j = 0; j < LCD_WIDTH / 3; j++)
- {
- DRV_LCD_PutPixel(i, j, 255, 0, 0);
- }
- for (j = LCD_WIDTH / 3; j < 2 * (LCD_WIDTH / 3); j++)
- {
- DRV_LCD_PutPixel(i, j, 230, 220, 0);
- }
- for (j = 2 * (LCD_WIDTH / 3); j < LCD_WIDTH; j++)
- {
- DRV_LCD_PutPixel(i, j, 0, 0, 255);
- }
- }
- DRV_LCD_Puts("Hello", 20, 30, foreground, background, TRUE);
- DRV_LCD_Puts("Hello", 20, 60, foreground, background, FALSE);
- }
- void TouchScreenCallBack(TouchResult* touchData)
- {
- printf("touched X=%3d Y=%3d\n", touchData->X, touchData->Y);
- }
- void BoardInit()
- {
- timer_software_handler_t handler;
- TIMER_SOFTWARE_init_system();
- DRV_SDRAM_Init();
- initRetargetDebugSystem();
- DRV_LCD_Init();
- DRV_LCD_ClrScr();
- DRV_LCD_PowerOn();
- DRV_TOUCHSCREEN_Init();
- DRV_TOUCHSCREEN_SetTouchCallback(TouchScreenCallBack);
- //DRV_LCD_Puts(at_command_csq, 20, 30, foreground, background, TRUE);
- DRV_LED_Init();
- printf ("Hello\n");
- handler = TIMER_SOFTWARE_request_timer();
- TIMER_SOFTWARE_configure_timer(handler, MODE_1, 100, 1);
- TIMER_SOFTWARE_set_callback(handler, timer_callback_1);
- TIMER_SOFTWARE_start_timer(handler);
- }
- void SendCommand(const char *command)
- {
- DRV_UART_FlushRX(UART_3);
- DRV_UART_FlushTX(UART_3);
- DRV_UART_Write(UART_3, (uint8_t*)command, strlen(command));
- }
- void GetCommandResponse() {
- int parser_response;
- uint8_t ch;
- BOOLEAN ready = false;
- my_timer_handler = TIMER_SOFTWARE_request_timer();
- TIMER_SOFTWARE_configure_timer(my_timer_handler, MODE_1, 1000, true);
- TIMER_SOFTWARE_start_timer(my_timer_handler);
- TIMER_SOFTWARE_reset_timer(my_timer_handler);
- TIMER_SOFTWARE_start_timer(my_timer_handler);
- while ((!TIMER_SOFTWARE_interrupt_pending(my_timer_handler)) && (ready == FALSE))
- {
- while (DRV_UART_BytesAvailable(UART_3) > 0)
- {
- DRV_UART_ReadByte(UART_3, &ch);
- parser_response = parse(ch);
- if (parser_response == 2 || parser_response == 1)
- {
- ready = TRUE;
- at_parser = getData();
- }
- }
- }
- }
- void ExecuteCommand(const char *command)
- {
- SendCommand(command);
- GetCommandResponse();
- }
- int ExtractData()
- {
- int j = 0;
- int flag =0, rezultat=0;
- for(j=0;j<strlen(at_parser.data[0]);j++)
- {
- if(at_parser.data[0][j] == ':')
- flag = 1;
- if(flag == 1)
- {
- j++;
- rezultat = atoi(&at_parser.data[0][j]);
- }
- }
- return rezultat;
- }
- int CommandResponseValid()
- {
- if(at_parser.response == 1)
- return 0;
- else return 1;
- }
- int ConvertAsuToDbmw(uint32_t arg) {
- int val = 2 * arg - 113;
- return val;
- }
- int main(void)
- {
- timer_software_handler_t handler1;
- int i;
- uint32_t rssi_value_asu;
- uint32_t rssi_value_dbmw;
- BoardInit();
- //testLCD();
- handler1 = TIMER_SOFTWARE_request_timer();
- DRV_UART_Configure(UART_3, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
- DRV_UART_Configure(UART_2, UART_CHARACTER_LENGTH_8, 115200, UART_PARITY_NO_PARITY, 1, TRUE, 3);
- TIMER_SOFTWARE_configure_timer(handler1, MODE_1, 1000, true);
- TIMER_SOFTWARE_start_timer(handler1);
- for(i=0;i<3;i++)
- {
- DRV_UART_Write(UART_3, (uint8_t*)at_command_simple, strlen(at_command_simple));
- TIMER_SOFTWARE_Wait(1000);
- }
- while(1)
- {
- if(TIMER_SOFTWARE_interrupt_pending(handler1) != 0)
- {
- ExecuteCommand(at_command_csq);
- if (CommandResponseValid())
- {
- rssi_value_asu = ExtractData();
- rssi_value_dbmw = ConvertAsuToDbmw(rssi_value_asu);
- DRV_LCD_Puts((char*)rssi_value_asu, 20, 30, foreground, background, TRUE);
- }
- TIMER_SOFTWARE_clear_interrupt(handler1);
- }
- }
- /*while(1)
- {
- DRV_LED_Toggle(LED_4);
- }
- while(1)
- {
- DRV_UART_SendByte(UART_3, 'A');
- // TIMER_SOFTWARE_Wait(1000);
- }
- while(1)
- {
- if (DRV_UART_ReadByte(UART_3, &ch) == OK)
- {
- DRV_UART_SendByte(UART_3, ch);
- }
- }
- while(1)
- {
- if (DRV_UART_ReadByte(UART_0, &ch) == OK)
- {
- DRV_UART_SendByte(UART_3, ch);
- }
- if (DRV_UART_ReadByte(UART_3, &ch) == OK)
- {
- DRV_UART_SendByte(UART_0, ch);
- }
- if (DRV_UART_ReadByte(UART_2, &ch) == OK)
- {
- DRV_UART_SendByte(UART_0, ch);
- }
- }
- while(1)
- {
- DRV_UART_Process();
- DRV_TOUCHSCREEN_Process();
- }*/
- //return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement