diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/Intrainout.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/Intrainout.c new file mode 100644 index 00000000..ff7d657b --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/Intrainout.c @@ -0,0 +1,125 @@ + +#include "embARC.h" +#include "embARC_debug.h" + +#include "dev_gpio.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + +#define BUTTON_MASK 0x7 + +uint8_t ct = 0; + +uint8_t crowd = 0; +uint8_t CT = 0; + + +uint8_t intra_inout (void) + +{ + uint8_t cp = 0; //下车人数 + uint32_t cn; //人数确认时间计数 + DEV_GPIO * gpio_read_port; + DEV_GPIO * gpio_write_port; + + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_GPIO_AC | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_SPI_M1 | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd1, ercd2; + + gpio_read_port = gpio_get_dev (DW_GPIO_PORT_A); + gpio_write_port = gpio_get_dev (DW_GPIO_PORT_C); + ercd1 = dw_gpio_open (gpio_read_port, 0x0); + ercd2 = dw_gpio_open (gpio_write_port, 0xfffff); + + if (ercd2 == E_OPNED) + dw_gpio_control (gpio_write_port, GPIO_CMD_SET_BIT_DIR_OUTPUT, 0xfffff); + + uint32_t data; + + while (1) + { + dw_gpio_read (gpio_read_port, &data, 0x4400); + board_delay_ms (10, 1); + + if (data == 1024) + { + board_delay_ms (10, 1); + dw_gpio_read (gpio_read_port, &data, 0x4400); + + if (data == 0) + { + ct++; //此时仅检测到有人上车 + EMBARC_PRINTF ("ct=%d\r\n", ct); + board_delay_ms (10, 1); + continue; + } + else + continue; + } + else if (data == 0x4000) + { + board_delay_ms (10, 1); + dw_gpio_read (gpio_read_port, &data, 0x4000); + + if (data == 0) + { + cp++; //此时仅有人下车 + EMBARC_PRINTF ("cp=%d\r\n", cp); + board_delay_ms (10, 1); + continue; + } + else + continue; + } + else if (data == 0) + { + dw_gpio_read (gpio_read_port, &data, 0x4400); + cn = 0; + + while (1) + { + board_delay_ms (10, 1); + dw_gpio_read (gpio_read_port, &data, 0x4400); + + if (data == 0) + { + cn++; //计入0的个数 + + if (cn > 1000) + { + ct = ct - cp; + EMBARC_PRINTF ("ct=%d\r\n", ct); + return ct; + } + else + continue; + } + else + { + break; + } + } + } + else + continue; + } +} + + +uint32_t ct2crowd (void) +{ + CT = intra_inout (); + + if (CT <= 10) + crowd = 1; + else + { + if (CT <= 20) + crowd = 2; + else + crowd = 3; + } + + return crowd; +} + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_common.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_common.c new file mode 100644 index 00000000..8090b7b1 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_common.c @@ -0,0 +1,176 @@ + +uint8_t sn = 0; + + +void mcu2wifi_product_info (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x73] = + { + 0xFF, 0xFF, // 包头 + 0x00, 0x6F, //包长度 + 0x02, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x35, + 0x61, 0x31, 0x30, 0x36, 0x37, 0x38, 0x35, 0x66, + 0x62, 0x61, 0x39, 0x65, 0x34, 0x35, 0x39, 0x30, + 0x62, 0x39, 0x36, 0x63, 0x63, 0x65, 0x35, 0x31, + 0x62, 0x37, 0x63, 0x65, 0x35, 0x36, 0x63, 0x39, + 0x00, 0x00, //可绑定失效时间 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, + 0x31, 0x37, 0x62, 0x62, 0x32, 0x39, 0x66, 0x63, + 0x31, 0x39, 0x32, 0x65, 0x34, 0x32, 0x30, 0x36, + 0x61, 0x34, 0x63, 0x61, 0x38, 0x64, 0x38, 0x36, + 0x32, 0x66, 0x65, 0x62, 0x36, 0x61, 0x33, 0x31, + 0xEE //校验和 + }; + send_data[2] = (0x73 - 0x04) >> 8; + send_data[3] = (0x73 - 0x04) % 256; + send_data[5] = sn; + + + for (uint8_t i = 2; i < 0x73 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x73 - 1] = checksum; + + //发送数据包 + esp8266_uart->uart_write (send_data, 0x73); + EMBARC_PRINTF ("product info is ok \r\n"); + +} + +void mcu2wifi_heartbeat (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x08, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; + + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + //printf("%s",send_data); + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_set_cfg_mode (uint8_t mode) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0a] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x09, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00, // + 0x00 //校验和 + }; + send_data[2] = (0x0a - 0x04) >> 8; + send_data[3] = (0x0a - 0x04) % 256; + send_data[5] = ++sn; + + + send_data[8] = mode; + + for (uint8_t i = 2; i < 0x0a - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0a - 1] = checksum; + + //发送数据包 + esp8266_uart->uart_write (send_data, 0x0a); +} + + + +void mcu2wifi_reset_wifi (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, + 0x00, 0x00, + 0x0b, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = ++sn; + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_wifi_statu (uint8_t * receive_data) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, + 0x00, 0x05, + 0x0E, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + esp8266_uart->uart_write (send_data, 0x09); + + uint16_t statu = receive_data[8] *256 + receive_data[9]; + + if ((statu) % 2 == 1) + EMBARC_PRINTF ("SoftAP mode is open\r\n"); + + if ((statu >> 1) % 2 == 1) + EMBARC_PRINTF ("Station mode is open\r\n"); + + if ((statu >> 2) % 2 == 1) + EMBARC_PRINTF ("OnBoarding mode is open\r\n"); + + if ((statu >> 3) % 2 == 1) + EMBARC_PRINTF ("Binding mode is open\r\n"); + + if ((statu >> 4) % 2 == 1) + EMBARC_PRINTF ("The WiFi module is connected to the wireless router,the RSSI = %d\r\n", (statu >> 8) % 8); + + if ((statu >> 5) % 2 == 1) + EMBARC_PRINTF ("The WiFi module is connected to the M2M server\r\n"); +} + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_user.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_user.c new file mode 100644 index 00000000..98d9d4fd --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_user.c @@ -0,0 +1,164 @@ + +uint8_t buf = 0; +uint8_t SN = 0; +uint8_t CR = 0; +uint8_t crow = 0; +uint16_t temp = 0; + +#define DEV_STATUS_BYTES (2) + + +#define ATTR_FLAGS_BYTES (1) + + +#define ATTR_VALS_BYTES (2) + + +void mcu2wifi_wifi_ctrl_dev (uint8_t * receive_data) +{ + + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x00, //包长度 + 0x04, //命令 + 0x01, //包序号 + 0x00, 0x00, //flags + 0x14 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; //获取包序号 + + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_wifi_read_dev (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x04, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x03, //action; + 0x00, 0x00, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x14 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = sn; //获取包序号 + + // SN + send_data[9] = SN; + + // CR + send_data[10] = CR; + + // temp + //send_data[11] = temp >> 8; + // temp + send_data[11] = temp % 256; + + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + + + +void mcu2wifi_dev_report_status (uint8_t SN1, uint8_t CR1) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x08, //包长度 + 0x05, //命令 + 0x00, //包序号 + 0x00, 0x00, //flagsflags + 0x04, //action; + 0x11, 0x11, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x00 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + // SN + send_data[9] = SN1; + + // CR + send_data[10] = CR1; + + + send_data[11] = temp % 256; + + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + + + + +void mcu2wifi_dev_write (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x0A, //包长度 + 0x05, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x04, //action; + 0x11, 0x11, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x00 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + + // SN + + /*send_data[9] = SN; + // CR + send_data[10] = CR; + + send_data[11] = temp >> 8;*/ + + send_data[11] = temp % 256; + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/lookforrssi.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/lookforrssi.c new file mode 100644 index 00000000..a7619539 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/lookforrssi.c @@ -0,0 +1,449 @@ + + +//PMOD5下行端口,接AT-wifi指令,扫描station发出的Rssi。 +#include "embARC.h" +#include "embARC_debug.h" +#include +#include + +#include "dev_uart.h" //UART API 头文件` +#include "../../../board/emsk/drivers/mux/mux.h" // Pmod端口配置API` +#include "../../../board/emsk/drivers/mux/mux_hal.h" + + +#define BUTTON_MASK 0x7 +#define MAX_READ_CNT 32 + + +int32_t lookforrssi1 (void) +{ + DEV_UART_PTR uart2; + + set_uart_map (0xE4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_I2C_HRI | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + uart2 = uart_get_dev (DW_UART_2_ID); + ercd = uart2->uart_open (115200); + char send_string1[64] = "AT+CWMODE=1\r\n"; + + ercd = uart2->uart_write (send_string1, sizeof (send_string1)); + board_delay_ms (1000, 0); + char receive_string1[64] = + { + 0 + }; + uint32_t rd_avail = 0; + + while (1) + { + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string1, rd_avail); + EMBARC_PRINTF ("receive_string1=%s\r\n", receive_string1); //打印出模式置位1的回复 + break; + } + } + + char send_string2[64] = "AT+CWLAP=\"S1\"\r\n"; + char receive_string2[64] = + { + 0 + }; + rd_avail = 0; + uint32_t rssi; + + while (1) + { + ercd = uart2->uart_write (send_string2, sizeof (send_string2)); + + while (1) + { + + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string2, rd_avail); + EMBARC_PRINTF ("receive_string2=%s\r\n", receive_string2); //打印出含rssi的一串字符 + + char * temp = strtok (receive_string2, ","); + uint32_t c; + + for (c = 0; c < 3; c++) + { + temp = strtok (NULL, ","); + + if (c == 1) + { + EMBARC_PRINTF ("temp=%s\r\n", temp); + + if (temp != "0") + { + rssi = atoi (temp); + + if (rssi != 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + + if (rssi > -50 || rssi < 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + return 1; + } + else + ; + } + else + ; + } + else + ; + } + else + ; + } + } + else + { + board_delay_ms (1000, 0); + break; //返回外循环,重新扫描RSSI + } + } + } + +} + + +int32_t lookforrssi2 (void) +{ + DEV_UART_PTR uart2; + + set_uart_map (0xE4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_I2C_HRI | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + uart2 = uart_get_dev (DW_UART_2_ID); + ercd = uart2->uart_open (115200); + char send_string1[64] = "AT+CWMODE=1\r\n"; + + ercd = uart2->uart_write (send_string1, sizeof (send_string1)); + board_delay_ms (1000, 0); + char receive_string1[64] = + { + 0 + }; + uint32_t rd_avail = 0; + + while (1) + { + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string1, rd_avail); + EMBARC_PRINTF ("receive_string1=%s\r\n", receive_string1); //打印出模式置位1的回复 + break; + } + } + + char send_string2[64] = "AT+CWLAP=\"S2\"\r\n"; + char receive_string2[64] = + { + 0 + }; + rd_avail = 0; + uint32_t rssi; + + while (1) + { + ercd = uart2->uart_write (send_string2, sizeof (send_string2)); + + while (1) + { + + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string2, rd_avail); + EMBARC_PRINTF ("receive_string2=%s\r\n", receive_string2); //打印出含rssi的一串字符 + + char * temp = strtok (receive_string2, ","); + uint32_t c; + + for (c = 0; c < 3; c++) + { + temp = strtok (NULL, ","); + + if (c == 1) + { + EMBARC_PRINTF ("temp=%s\r\n", temp); + + if (temp != "0") + { + rssi = atoi (temp); + + if (rssi != 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + + if (rssi > -50 || rssi < 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + return 2; + } + else + ; + } + else + ; + } + else + ; + } + else + ; + } + } + else + { + board_delay_ms (1000, 0); + break; //返回外循环,重新扫描RSSI + } + } + } + +} + + +int32_t lookforrssi3 (void) +{ + DEV_UART_PTR uart2; + + set_uart_map (0xE4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_I2C_HRI | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + uart2 = uart_get_dev (DW_UART_2_ID); + ercd = uart2->uart_open (115200); + char send_string1[64] = "AT+CWMODE=1\r\n"; + + ercd = uart2->uart_write (send_string1, sizeof (send_string1)); + board_delay_ms (1000, 0); + char receive_string1[64] = + { + 0 + }; + uint32_t rd_avail = 0; + + while (1) + { + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string1, rd_avail); + EMBARC_PRINTF ("receive_string1=%s\r\n", receive_string1); //打印出模式置位1的回复 + break; + } + } + + char send_string2[64] = "AT+CWLAP=\"S3\"\r\n"; + char receive_string2[64] = + { + 0 + }; + rd_avail = 0; + uint32_t rssi; + + while (1) + { + ercd = uart2->uart_write (send_string2, sizeof (send_string2)); + + while (1) + { + + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string2, rd_avail); + EMBARC_PRINTF ("receive_string2=%s\r\n", receive_string2); //打印出含rssi的一串字符 + + char * temp = strtok (receive_string2, ","); + uint32_t c; + + for (c = 0; c < 3; c++) + { + temp = strtok (NULL, ","); + + if (c == 1) + { + EMBARC_PRINTF ("temp=%s\r\n", temp); + + if (temp != "0") + { + rssi = atoi (temp); + + if (rssi != 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + + if (rssi > -50 || rssi < 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + return 3; + } + else + ; + } + else + ; + } + else + ; + } + else + ; + } + } + else + { + board_delay_ms (1000, 0); + break; //返回外循环,重新扫描RSSI + } + } + } + +} + + +int32_t lookforrssi4 (void) +{ + DEV_UART_PTR uart2; + + set_uart_map (0xE4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_I2C_HRI | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + uart2 = uart_get_dev (DW_UART_2_ID); + ercd = uart2->uart_open (115200); + char send_string1[64] = "AT+CWMODE=1\r\n"; + + ercd = uart2->uart_write (send_string1, sizeof (send_string1)); + board_delay_ms (1000, 0); + char receive_string1[64] = + { + 0 + }; + uint32_t rd_avail = 0; + + while (1) + { + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string1, rd_avail); + EMBARC_PRINTF ("receive_string1=%s\r\n", receive_string1); //打印出模式置位1的回复 + break; + } + } + + char send_string2[64] = "AT+CWLAP=\"S4\"\r\n"; + char receive_string2[64] = + { + 0 + }; + rd_avail = 0; + uint32_t rssi; + + while (1) + { + ercd = uart2->uart_write (send_string2, sizeof (send_string2)); + + while (1) + { + + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string2, rd_avail); + EMBARC_PRINTF ("receive_string2=%s\r\n", receive_string2); //打印出含rssi的一串字符 + + char * temp = strtok (receive_string2, ","); + uint32_t c; + + for (c = 0; c < 3; c++) + { + temp = strtok (NULL, ","); + + if (c == 1) + { + EMBARC_PRINTF ("temp=%s\r\n", temp); + + if (temp != "0") + { + rssi = atoi (temp); + + if (rssi != 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + + if (rssi > -50 || rssi < 0) + { + EMBARC_PRINTF ("rssi=%d\r\n", rssi); + return 4; + } + else + ; + } + else + ; + } + else + ; + } + else + ; + } + } + else + { + board_delay_ms (1000, 0); + break; //返回外循环,重新扫描RSSI + } + } + } + +} + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/main.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/main.c new file mode 100644 index 00000000..dde21b0e --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/main.c @@ -0,0 +1,486 @@ + +#include "embARC.h" +#include "embARC_debug.h" +#include "dev_gpio.h" +#include "dev_uart.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + +static DEV_GPIO_PTR esp8266_rst; + +#define ESP8266_RST_PORT DW_GPIO_PORT_A +#define ESP8266_RST_MASK (0x100) +#define ESP8266_RST_DIR (0x100) + +static DEV_UART_PTR esp8266_uart; + +#define ESP8266_UART_ID DW_UART_0_ID +#define ESP8266_UART_BAUDRATE UART_BAUDRATE_9600 + +#define MAX_READ_CNT 32 + +#include "./esp8266_gagent/esp8266_gagent_common.c" +#include "./esp8266_gagent/esp8266_gagent_user.c" +#include "./esp8266_gagent/Intrainout.c" +#include "./esp8266_gagent/lookforrssi.c" + + +static void delay_ms (int z) //1ms +{ + uint32_t volatile x, y; + + for (x = 1400; x > 0; x--) + for (y = z; y > 0; y--) + ; +} + + +void esp8266_init (void) +{ + // set pmod mux and uart map + set_uart_map (0xe4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A); + + // Get devices structure pointer + esp8266_uart = uart_get_dev (ESP8266_UART_ID); + esp8266_rst = gpio_get_dev (ESP8266_RST_PORT); + int32_t ercd; + + // Open devices + esp8266_rst->gpio_close (); + + if ((ercd = esp8266_rst->gpio_open (ESP8266_RST_DIR)) == E_OK) + { + EMBARC_PRINTF ("ESP8266_RST_PORT open successfully!!\r\n"); + } + else if (ercd == E_OPNED) + { + EMBARC_PRINTF ("ESP8266_RST_PORT open failed,because opend with different direction!!\r\n"); + esp8266_rst->gpio_control (GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *) (ESP8266_RST_MASK)); + + } + else + { + EMBARC_PRINTF ("ESP8266_RST_PORT open failed, unknow why!!\r\n"); + } + + esp8266_uart->uart_close (); + + if (esp8266_uart->uart_open (ESP8266_UART_BAUDRATE) != E_OK) + { + EMBARC_PRINTF ("ESP8266_UART open failed!!\r\n"); + } + else + { + EMBARC_PRINTF ("ESP8266_UART open successfully!!\r\n"); + } + + //esp8266_uart->uart_control(UART_CMD_SET_RXCB,esp8266_uart_rxcb); + //esp8266_uart->uart_control(UART_CMD_SET_RXINT,CONV2VOID(1)); +} + + +int main (void) +{ + cpu_lock (); + + //Board initialization; + board_init (); + + //esp8266 initialization; + esp8266_init (); + cpu_unlock (); + uint8_t StaNum = 0; + uint8_t gjm = 0; + uint8_t i = 0; + uint8_t j = 0; + uint8_t Crowd = 0; + uint32_t crowd = 0; + uint16_t rd_cnt = 0; + uint8_t read_data[MAX_READ_CNT]; + uint32_t rd_avail; + + while (1) //机智云设备上线初始化 + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + { + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + } + + case 0x03: //Wifi控制设备,MCU读入改变的数据点 + { + mcu2wifi_wifi_ctrl_dev (read_data); //MCU回复wifi的控制指令 + j++; + break; + } + + case 0x06: + break; + + case 0x07: + { + mcu2wifi_heartbeat (); //MCU回复心跳包 + j++; + break; + } + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + { + mcu2wifi_wifi_statu (read_data); + i++; + break; //wifi将最新的工作状态推送至MCU + } + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + + if (i == 4 || j == 1) + break; + } + + + while (gjm != 1) + { + gjm = lookforrssi1 (); //当rssi满足条件,返回gjm=1,跳出循环,进行下一步对于机智云的操作 + StaNum = 1; //得到此时的公交所在站点,衡量水平为StaNum,此时值为1。 + } + + crowd = ct2crowd (); //通过红外脉冲模块计算车载的拥挤程度,衡量水平为crowd + + while (1) //ARC板子读取wifi发送的数据函数,MCU完成回复,必不可少。 + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + + case 0x03: //Wifi控制设备,MCU读入改变的数据点 + { + mcu2wifi_wifi_ctrl_dev (read_data); //MCU回复wifi的控制指令 + break; + } + + case 0x06: + break; + + case 0x07: + { + mcu2wifi_heartbeat (); //MCU回复心跳包 + break; + } + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + mcu2wifi_wifi_statu (read_data); + break; //wifi将最新的工作状态推送至MCU + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + + //crowd=ct2crowd(); //通过红外脉冲模块计算车载的拥挤程度,衡量水平为crowd + break; //得到此时的StaNum与crowd,跳出while循环 + } + + EMBARC_PRINTF ("StaNum=%d,crowd=%d\r\n", StaNum, crowd); + mcu2wifi_dev_report_status (StaNum, crowd); //将数据传入云端 + delay_ms (10000); + + /*————————————————————————第一个公交站牌的数据上传由小 + 车完成,第二个,第四个站牌由云端读入改变数据,小灯发生 + 相应改变。——————————*/ + while (gjm != 2) + { + gjm = lookforrssi2 (); //当rssi满足条件,返回gjm=2,跳出循环,进行下一步对于机智云的操作 + StaNum = 2; //得到此时的公交所在站点,衡量水平为StaNum,此时值为2。 + } + + crowd = ct2crowd (); //通过红外脉冲模块计算车载的拥挤程度,衡量水平为crowd + + while (1) //ARC板子读取wifi发送的数据函数,MCU完成回复,必不可少。 + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + + case 0x03: //Wifi控制设备,MCU读入改变的数据点 + { + mcu2wifi_wifi_ctrl_dev (read_data); //MCU回复wifi的控制指令 + break; + } + + case 0x06: + break; + + case 0x07: + { + mcu2wifi_heartbeat (); //MCU回复心跳包 + break; + } + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + mcu2wifi_wifi_statu (read_data); + break; //wifi将最新的工作状态推送至MCU + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + + break; //得到此时的StaNum与crowd,跳出while循环 + } + + EMBARC_PRINTF ("StaNum=%d,crowd=%d\r\n", StaNum, crowd); + mcu2wifi_dev_report_status (StaNum, crowd); //将数据传入云端 + delay_ms (10000); + + /*————————————————————————第二个公交站牌的数据上传由小 + 车完成,第二个,第四个站牌由云端读入改变数据,小灯发生 + 相应改变。——————————*/ + while (gjm != 3) + { + gjm = lookforrssi3 (); //当rssi满足条件,返回gjm=2,跳出循环,进行下一步对于机智云的操作 + StaNum = 3; //得到此时的公交所在站点,衡量水平为StaNum,此时值为2。 + } + + crowd = ct2crowd (); //通过红外脉冲模块计算车载的拥挤程度,衡量水平为crowd + + while (1) //ARC板子读取wifi发送的数据函数,MCU完成回复,必不可少。 + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + + case 0x03: //Wifi控制设备,MCU读入改变的数据点 + { + mcu2wifi_wifi_ctrl_dev (read_data); //MCU回复wifi的控制指令 + break; + } + + case 0x06: + break; + + case 0x07: + { + mcu2wifi_heartbeat (); //MCU回复心跳包 + break; + } + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + mcu2wifi_wifi_statu (read_data); + break; //wifi将最新的工作状态推送至MCU + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + + break; //得到此时的StaNum与crowd,跳出while循环 + } + + EMBARC_PRINTF ("StaNum=%d,crowd=%d\r\n", StaNum, crowd); + mcu2wifi_dev_report_status (StaNum, crowd); //将数据传入云端 + delay_ms (10000); + + /*————————————————————————第三个公交站牌的数据上传由小 + 车完成,第四个站牌由云端读入改变数据,小灯发生相应改变。 + ——————————*/ + while (gjm != 4) + { + gjm = lookforrssi4 (); //当rssi满足条件,返回gjm=2,跳出循环,进行下一步对于机智云的操作 + StaNum = 4; //得到此时的公交所在站点,衡量水平为StaNum,此时值为2。 + } + + crowd = ct2crowd (); //通过红外脉冲模块计算车载的拥挤程度,衡量水平为crowd + + while (1) //ARC板子读取wifi发送的数据函数,MCU完成回复,必不可少。 + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + + case 0x03: //Wifi控制设备,MCU读入改变的数据点 + { + mcu2wifi_wifi_ctrl_dev (read_data); //MCU回复wifi的控制指令 + break; + } + + case 0x06: + break; + + case 0x07: + { + mcu2wifi_heartbeat (); //MCU回复心跳包 + break; + } + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + mcu2wifi_wifi_statu (read_data); + break; //wifi将最新的工作状态推送至MCU + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + + break; //得到此时的StaNum与crowd,跳出while循环 + } + + EMBARC_PRINTF ("StaNum=%d,crowd=%d\r\n", StaNum, crowd); + mcu2wifi_dev_report_status (StaNum, crowd); //将数据传入云端 + delay_ms (10000); + + /*————————————————————————第四个公交站牌的数据上传由小 + 车完成,第四个站牌由云端读入改变数据,小灯发生相应改变。 + ——————————*/ + return E_SYS; +} + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_common.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_common.c new file mode 100644 index 00000000..6e780f3b --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_common.c @@ -0,0 +1,132 @@ +uint8_t sn =0; + +void mcu2wifi_product_info(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x73] = { + 0xFF,0xFF, + 0x00,0x6F, + 0x02, + 0x00, + 0x00,0x00, //flags + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x36, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + + 0x61,0x31,0x30,0x36,0x37,0x38,0x35,0x66, + 0x62,0x61,0x39,0x65,0x34,0x35,0x39,0x30, + 0x62,0x39,0x36,0x63,0x63,0x65,0x35,0x31, + 0x62,0x37,0x63,0x65,0x35,0x36,0x63,0x39, + + 0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02, + + 0x31,0x37,0x62,0x62,0x32,0x39,0x66,0x63, + 0x31,0x39,0x32,0x65,0x34,0x32,0x30,0x36, + 0x61,0x34,0x63,0x61,0x38,0x64,0x38,0x36, + 0x32,0x66,0x65,0x62,0x36,0x61,0x33,0x31, + + 0xEE + }; + send_data[2] = (0x73-0x04)>>8; + send_data[3] = (0x73-0x04)%256; + send_data[5] = sn; //获取包序号 + for(uint8_t i=2;i<0x73-1;i++) checksum = checksum + send_data[i]; + send_data[0x73-1] =checksum; + esp8266_uart->uart_write(send_data,0x73); + EMBARC_PRINTF("product info is ok \r\n"); + +} + + +void mcu2wifi_heartbeat(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x09] = { + 0xFF,0xFF, + 0x00,0x05, + 0x08, + 0x00, + 0x00,0x00, //flags + 0x00 + }; + send_data[2] = (0x09-0x04)>>8; + send_data[3] = (0x09-0x04)%256; + send_data[5] = sn; + for(uint8_t i=2;i<0x09-1;i++) checksum = checksum + send_data[i]; + send_data[0x09-1] =checksum; + //printf("%s",send_data); + esp8266_uart->uart_write(send_data,0x09); +} + +void mcu2wifi_set_cfg_mode(uint8_t mode) +{ + uint8_t checksum=0; + uint8_t send_data[0x0a] = { + 0xFF,0xFF, + 0x00,0x05, + 0x09, + 0x00, + 0x00,0x00, //flags + 0x00, + 0x00 + }; + send_data[2] = (0x0a-0x04)>>8; + send_data[3] = (0x0a-0x04)%256; + send_data[5] = ++sn; + + send_data[8] = mode; + for(uint8_t i=2;i<0x0a-1;i++) checksum = checksum + send_data[i]; + send_data[0x0a-1] =checksum; + esp8266_uart->uart_write(send_data,0x0a); +} + + +void mcu2wifi_reset_wifi(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x09] = { + 0xFF,0xFF, + 0x00,0x00, + 0x0b, + 0x00, + 0x00,0x00, //flags + 0x00 + }; + send_data[2] = (0x09-0x04)>>8; + send_data[3] = (0x09-0x04)%256; + send_data[5] = ++sn; + for(uint8_t i=2;i<0x09-1;i++) checksum = checksum + send_data[i]; + send_data[0x09-1] =checksum; + esp8266_uart->uart_write(send_data,0x09); +} + + +void mcu2wifi_wifi_statu(uint8_t *receive_data) +{ + uint8_t checksum=0; + uint8_t send_data[0x09] = { + 0xFF,0xFF, + 0x00,0x05, + 0x0E, + 0x00, + 0x00,0x00, //flags + 0x00 + }; + send_data[2] = (0x09-0x04)>>8; + send_data[3] = (0x09-0x04)%256; + send_data[5] = sn; + for(uint8_t i=2;i<0x09-1;i++) checksum = checksum+send_data[i]; + send_data[0x09-1] =checksum; + esp8266_uart->uart_write(send_data,0x09); + + uint16_t statu = receive_data[8]*256+receive_data[9]; + + if((statu) %2 == 1) EMBARC_PRINTF("SoftAP mode is open\r\n"); + if((statu>>1)%2 == 1) EMBARC_PRINTF("Station mode is open\r\n"); + if((statu>>2)%2 == 1) EMBARC_PRINTF("OnBoarding mode is open\r\n"); + if((statu>>3)%2 == 1) EMBARC_PRINTF("Binding mode is open\r\n"); + if((statu>>4)%2 == 1) EMBARC_PRINTF("The WiFi module is connected to the wireless router,the RSSI = %d\r\n",(statu>>8)%8); + if((statu>>5)%2 == 1) EMBARC_PRINTF("The WiFi module is connected to the M2M server\r\n"); +} diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_user.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_user.c new file mode 100644 index 00000000..54e0849a --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/esp8266_gagent_user.c @@ -0,0 +1,117 @@ +uint8_t SN = 1; +uint8_t CR = 2; +uint8_t buf = 0; +uint8_t crow = 0; +uint16_t temp = 0; +#define DEV_STATUS_BYTES (2) + + +#define ATTR_FLAGS_BYTES (1) +#define ATTR_VALS_BYTES (2) +void mcu2wifi_wifi_ctrl_dev(uint8_t *receive_data) +{ + uint8_t checksum=0; + uint8_t send_data[0x09] = { + 0xFF,0xFF, + 0x00,0x00, + 0x04, + 0x01, + 0x00,0x00, //flags + 0x14 + }; + send_data[2] = (0x09-0x04)>>8; + send_data[3] = (0x09-0x04)%256; + send_data[5] = sn; + for(uint8_t i=2;i<0x09-1;i++) checksum = checksum + send_data[i]; + send_data[0x09-1] =checksum; + + esp8266_uart->uart_write(send_data,0x09); +} + +void mcu2wifi_wifi_read_dev(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = { + 0xFF,0xFF, + 0x00,0x05, + 0x04, + 0x00, + 0x00,0x00, //flags + 0x03, //action; + 0x00,0x00, + 0x14 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES-0x04)>>8; + send_data[3] = (0x0A + DEV_STATUS_BYTES-0x04)%256; + send_data[5] = sn; + + // SN + send_data[9] = SN; + // CR + send_data[10] = CR; + + //send_data[11] = temp >> 8; + + send_data[11] = temp % 256; + for(uint8_t i=2;i<0x0A + DEV_STATUS_BYTES-1;i++) checksum = checksum + send_data[i]; + send_data[0x0A + DEV_STATUS_BYTES-1] =checksum; + + esp8266_uart->uart_write(send_data,0x0A + DEV_STATUS_BYTES); +} + + + +void mcu2wifi_dev_report_status(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = { + 0xFF,0xFF, + 0x00,0x08, + 0x05, + 0x00, + 0x00,0x00, //flagsflags + 0x04, //action; + 0x11,0x11, + 0x00 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES-0x04)>>8; + send_data[3] = (0x0A + DEV_STATUS_BYTES-0x04)%256; + send_data[5] = ++sn; + // SN + send_data[9] = SN; + // CR + send_data[10] = CR; + send_data[11] = temp % 256; + for(uint8_t i=2;i<0x0A + DEV_STATUS_BYTES-1;i++) checksum = checksum + send_data[i]; + send_data[0x0A + DEV_STATUS_BYTES-1] =checksum; + esp8266_uart->uart_write(send_data,0x0A + DEV_STATUS_BYTES); +} + + + +void mcu2wifi_dev_write(void) +{ + uint8_t checksum=0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = { + 0xFF,0xFF, + 0x00,0x0A, + 0x05, + 0x00, + 0x00,0x00, //flags + 0x04, //action; + 0x11,0x11, + 0x00 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES-0x04)>>8; + send_data[3] = (0x0A + DEV_STATUS_BYTES-0x04)%256; + send_data[5] = ++sn; + // SN + /*send_data[9] = SN; + // CR + send_data[10] = CR; + send_data[11] = temp >> 8;*/ + send_data[11] = temp % 256; + for(uint8_t i=2;i<0x0A + DEV_STATUS_BYTES-1;i++) checksum = checksum + send_data[i]; + send_data[0x0A + DEV_STATUS_BYTES-1] =checksum; + esp8266_uart->uart_write(send_data,0x0A + DEV_STATUS_BYTES); +} diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/ledrgb.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/ledrgb.c new file mode 100644 index 00000000..5a9c43f3 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/ledrgb.c @@ -0,0 +1,85 @@ +#include "embARC.h" +#include "embARC_debug.h" + +#include "dev_gpio.h" //GPIO API头文件 +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + +#define BUTTON_MASK 0x7 + + +void LEDRGB(int8_t buf,int8_t cro) +{ +DEV_GPIO * gpio_write_port; +set_pmod_mux(PM1_UR_UART_0 | PM1_LR_GPIO_A| PM2_GPIO_AC| PM3_GPIO_AC | PM4_GPIO_AC | PM5_UR_GPIO_C | PM5_LR_UART_2| PM6_UR_SPI_M0 | PM6_LR_GPIO_A ); +int32_t ercd; +gpio_write_port = gpio_get_dev(DW_GPIO_PORT_C); +ercd = dw_gpio_open(gpio_write_port,0xfffffff); +EMBARC_PRINTF("%d %d\r\n",ercd,E_OK); +if(ercd == E_OK) + EMBARC_PRINTF("gpio open successfully!\r\n"); +else if(ercd == E_OPNED) + dw_gpio_control(gpio_write_port,GPIO_CMD_SET_BIT_DIR_OUTPUT,0xfffffff); + else ; + +if(buf == 1) +{ + dw_gpio_write(gpio_write_port, 0x0000000, 0xfff0000); + board_delay_ms(10, 1); + if(cro == 1) + { + dw_gpio_write(gpio_write_port, 0x0007000, 0xffffff); + board_delay_ms(10, 1); + } + else if(cro == 2) + { + dw_gpio_write(gpio_write_port, 0x0005000, 0xffffff); + board_delay_ms(10, 1); + } + else if(cro == 3) + { + dw_gpio_write(gpio_write_port, 0x000d000, 0xffffff); + board_delay_ms(10, 1); + } + else + { + dw_gpio_write(gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms(10, 1); + } + +} + +else if(buf == 2) +{ + dw_gpio_write(gpio_write_port, 0x0000000, 0xff0f000); + board_delay_ms(10, 1); + if(cro == 1) + { + dw_gpio_write(gpio_write_port, 0x0070000, 0xfffffff); + board_delay_ms(10, 1); + } + else if(cro == 2) + { + dw_gpio_write(gpio_write_port, 0x0050000, 0xfffffff); + board_delay_ms(10, 1); + } + else if(cro == 3) + { + dw_gpio_write(gpio_write_port, 0x00d0000, 0xfffffff); + board_delay_ms(10, 1); + } + else + { + dw_gpio_write(gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms(10, 1); + } +} + +else +{ + dw_gpio_write(gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms(10, 1); +} + + return; +} diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/setupAP2.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/setupAP2.c new file mode 100644 index 00000000..701c73ba --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/esp8266_gagent/setupAP2.c @@ -0,0 +1,44 @@ +#include "embARC.h" +#include "embARC_debug.h" +#include +#include + +#include "dev_uart.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + + +#define BUTTON_MASK 0x7 +#define MAX_READ_CNT 32 +void setupAP2(void) +{ + DEV_UART_PTR uart2; + set_uart_map(0xE4); + set_pmod_mux(PM1_UR_UART_0 | PM1_LR_GPIO_A| PM2_I2C_HRI| PM3_GPIO_AC| PM4_I2C_GPIO_D| PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A ); + int32_t ercd; + uart2=uart_get_dev(DW_UART_2_ID); + ercd=uart2->uart_open(115200); + char send_string1[64]= "AT+CWMODE=2\r\n"; + ercd =uart2->uart_write(send_string1, sizeof(send_string1)); + board_delay_ms(3000,0); + char send_string2[64]= "AT+CWSAP=\"S2\",\"123456789\",5,4\r\n"; + ercd =uart2->uart_write(send_string2, sizeof(send_string2)); + + char receive_string[32]={0}; + uint32_t rd_avail=0; + uint32_t rssi; + while(1) + { + board_delay_ms(1000,0); + uart2->uart_control(UART_CMD_GET_RXAVAIL,(void *)(&rd_avail)); + if(rd_avail>0) + { + EMBARC_PRINTF("rd_avail is %d\r\n",rd_avail); + + uart2->uart_read(receive_string,rd_avail); + EMBARC_PRINTF("%s\r\n",receive_string); + break; + } + + } +} diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/main.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/main.c new file mode 100644 index 00000000..b909643d --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 2/main.c @@ -0,0 +1,136 @@ +#include "embARC.h" +#include "embARC_debug.h" +#include "dev_gpio.h" +#include "dev_uart.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + + +static DEV_GPIO_PTR esp8266_rst; +#define ESP8266_RST_PORT DW_GPIO_PORT_A +#define ESP8266_RST_MASK (0x100) +#define ESP8266_RST_DIR (0x100) + +static DEV_GPIO_PTR led; +#define LED_PORT DW_GPIO_PORT_B +#define LED_MASK 0x1ff +#define LED_DIR 0x1ff + +static DEV_UART_PTR esp8266_uart; +#define ESP8266_UART_ID DW_UART_0_ID +#define ESP8266_UART_BAUDRATE UART_BAUDRATE_9600 + +#define MAX_READ_CNT 32 + +#include "./esp8266_gagent/esp8266_gagent_common.c" +#include "./esp8266_gagent/esp8266_gagent_user.c" +#include "./esp8266_gagent/ledrgb.c" +#include "./esp8266_gagent/setupAP2.c" + +static void delay_ms( int z) //1ms +{ + uint32_t volatile x,y; + for(x=1400;x>0;x--) + for(y=z;y>0;y--); +} + +void esp8266_init(void) +{ + // set pmod mux and uart map + set_uart_map(0xe4); + set_pmod_mux(PM1_UR_UART_0 | PM1_LR_GPIO_A| PM2_I2C_HRI| PM3_GPIO_AC| PM4_I2C_GPIO_D| PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A ); + // Get devices structure pointer + esp8266_uart = uart_get_dev(ESP8266_UART_ID); + esp8266_rst = gpio_get_dev(ESP8266_RST_PORT); + int32_t ercd; + // Open devices + esp8266_rst->gpio_close(); + if((ercd = esp8266_rst->gpio_open(ESP8266_RST_DIR) ) == E_OK) + { + EMBARC_PRINTF("ESP8266_RST_PORT open successfully!!\r\n"); + } + else if(ercd == E_OPNED) + { + EMBARC_PRINTF("ESP8266_RST_PORT open failed,because opend with different direction!!\r\n"); + esp8266_rst->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT,(void *)(ESP8266_RST_MASK)); + + } + else + { + EMBARC_PRINTF("ESP8266_RST_PORT open failed, unknow why!!\r\n"); + } + + esp8266_uart->uart_close(); + if(esp8266_uart->uart_open(ESP8266_UART_BAUDRATE) != E_OK) + { + EMBARC_PRINTF("ESP8266_UART open failed!!\r\n"); + }else + { + EMBARC_PRINTF("ESP8266_UART open successfully!!\r\n"); + } + +} + +int main(void) +{ + cpu_lock(); + //Board initialization; + board_init(); + //esp8266 initialization; + esp8266_init(); + cpu_unlock(); + uint8_t StaNum=0; + uint8_t Crowd=0; + uint16_t rd_cnt = 0; + uint8_t read_data[MAX_READ_CNT]; + uint32_t rd_avail; + setupAP2(); + + while(1) + { + esp8266_uart->uart_control(UART_CMD_GET_RXAVAIL,(void *)(&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail)?rd_avail:MAX_READ_CNT; + board_delay_ms(100,0); + if(rd_avail>0) + { + esp8266_uart->uart_read((void *)read_data,rd_cnt); + for(uint8_t i=0;i> 8; + send_data[3] = (0x73 - 0x04) % 256; + send_data[5] = sn; //获取包序号 + + for (uint8_t i = 2; i < 0x73 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x73 - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x73); + EMBARC_PRINTF ("product info is ok \r\n"); + +} + + + +void mcu2wifi_heartbeat (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x08, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; //获取包序号 + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + + //printf("%s",send_data); + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_set_cfg_mode (uint8_t mode) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0a] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x09, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00, // + 0x00 //校验和 + }; + send_data[2] = (0x0a - 0x04) >> 8; + send_data[3] = (0x0a - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + + send_data[8] = mode; + + for (uint8_t i = 2; i < 0x0a - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0a - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x0a); +} + + + +void mcu2wifi_reset_wifi (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x00, //包长度 + 0x0b, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_wifi_statu (uint8_t * receive_data) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x0E, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x00 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + esp8266_uart->uart_write (send_data, 0x09); + + uint16_t statu = receive_data[8] *256 + receive_data[9]; + + if ((statu) % 2 == 1) + EMBARC_PRINTF ("SoftAP mode is open\r\n"); + + if ((statu >> 1) % 2 == 1) + EMBARC_PRINTF ("Station mode is open\r\n"); + + if ((statu >> 2) % 2 == 1) + EMBARC_PRINTF ("OnBoarding mode is open\r\n"); + + if ((statu >> 3) % 2 == 1) + EMBARC_PRINTF ("Binding mode is open\r\n"); + + if ((statu >> 4) % 2 == 1) + EMBARC_PRINTF ("The WiFi module is connected to the wireless router,the RSSI = %d\r\n", (statu >> 8) % 8); + + if ((statu >> 5) % 2 == 1) + EMBARC_PRINTF ("The WiFi module is connected to the M2M server\r\n"); +} + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/esp8266_gagent_user.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/esp8266_gagent_user.c new file mode 100644 index 00000000..61523944 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/esp8266_gagent_user.c @@ -0,0 +1,147 @@ +uint8_t SN = 1; +uint8_t CR = 2; +uint8_t buf = 0; +uint8_t crow = 0; +uint16_t temp = 0; + +#define DEV_STATUS_BYTES (2) + +#define ATTR_FLAGS_BYTES (1) + +#define ATTR_VALS_BYTES (2) + + +void mcu2wifi_wifi_ctrl_dev (uint8_t * receive_data) +{ + uint8_t checksum = 0; + uint8_t send_data[0x09] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x00, //包长度 + 0x04, //命令 + 0x01, //包序号 + 0x00, 0x00, //flags + 0x14 //校验和 + }; + send_data[2] = (0x09 - 0x04) >> 8; + send_data[3] = (0x09 - 0x04) % 256; + send_data[5] = sn; + + + for (uint8_t i = 2; i < 0x09 - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x09 - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x09); +} + + + +void mcu2wifi_wifi_read_dev (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x05, //包长度 + 0x04, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x03, //action; + 0x00, 0x00, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x14 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = sn; //获取包序号 + + // SN + send_data[9] = SN; + + // CR + send_data[10] = CR; + + //send_data[11] = temp >> 8; + send_data[11] = temp % 256; + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + + + +void mcu2wifi_dev_report_status (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x08, //包长度 + 0x05, //命令 + 0x00, //包序号 + 0x00, 0x00, //flagsflags + 0x04, //action; + 0x11, 0x11, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x00 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + // SN + send_data[9] = SN; + + // CR + send_data[10] = CR; + + send_data[11] = temp % 256; + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + + + +void mcu2wifi_dev_write (void) +{ + uint8_t checksum = 0; + uint8_t send_data[0x0A + DEV_STATUS_BYTES] = + { + 0xFF, 0xFF, //包头 + 0x00, 0x0A, //包长度 + 0x05, //命令 + 0x00, //包序号 + 0x00, 0x00, //flags + 0x04, //action; + 0x11, 0x11, //设备状态,具体字节长度由DEV_STATUS_BYTES决定 + 0x00 //校验和 + }; + send_data[2] = (0x0A + DEV_STATUS_BYTES - 0x04) >> 8; + send_data[3] = (0x0A + DEV_STATUS_BYTES - 0x04) % 256; + send_data[5] = ++sn; //获取包序号 + + // SN + + /*send_data[9] = SN; + // CR + send_data[10] = CR; + send_data[11] = temp >> 8;*/ + send_data[11] = temp % 256; + + for (uint8_t i = 2; i < 0x0A + DEV_STATUS_BYTES - 1; i++) + checksum = checksum + send_data[i]; + + send_data[0x0A + DEV_STATUS_BYTES - 1] = checksum; + + esp8266_uart->uart_write (send_data, 0x0A + DEV_STATUS_BYTES); +} + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/ledrgb.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/ledrgb.c new file mode 100644 index 00000000..51d3d3ec --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/ledrgb.c @@ -0,0 +1,148 @@ +#include "embARC.h" +#include "embARC_debug.h" + +#include "dev_gpio.h" //GPIO API头文件 +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + +#define BUTTON_MASK 0x7 + + +void LEDRGB (int8_t buf, int8_t cro) +{ + DEV_GPIO * gpio_write_port; + + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_GPIO_AC | PM3_GPIO_AC | PM4_GPIO_AC | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + gpio_write_port = gpio_get_dev (DW_GPIO_PORT_C); + ercd = dw_gpio_open (gpio_write_port, 0xfffffff); + EMBARC_PRINTF ("%d %d\r\n", ercd, E_OK); + + if (ercd == E_OK) + EMBARC_PRINTF ("gpio open successfully!\r\n"); + else if (ercd == E_OPNED) + dw_gpio_control (gpio_write_port, GPIO_CMD_SET_BIT_DIR_OUTPUT, 0xfffffff); + else + ; + + if (buf == 1) + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xfff0000); + board_delay_ms (10, 1); + + if (cro == 1) + { + dw_gpio_write (gpio_write_port, 0x0007000, 0xffffff); + board_delay_ms (10, 1); + } + else if (cro == 2) + { + dw_gpio_write (gpio_write_port, 0x0005000, 0xffffff); + board_delay_ms (10, 1); + } + else if (cro == 3) + { + dw_gpio_write (gpio_write_port, 0x000d000, 0xffffff); + board_delay_ms (10, 1); + } + else + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms (10, 1); + } + + } + + else if (buf == 2) + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xff0f000); + board_delay_ms (10, 1); + + if (cro == 1) + { + dw_gpio_write (gpio_write_port, 0x0070000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 2) + { + dw_gpio_write (gpio_write_port, 0x0050000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 3) + { + dw_gpio_write (gpio_write_port, 0x00d0000, 0xfffffff); + board_delay_ms (10, 1); + } + else + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms (10, 1); + } + } + + else if (buf == 3) + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xf0ff000); + board_delay_ms (10, 1); + + if (cro == 1) + { + dw_gpio_write (gpio_write_port, 0x0700000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 2) + { + dw_gpio_write (gpio_write_port, 0x0500000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 3) + { + dw_gpio_write (gpio_write_port, 0x0d00000, 0xfffffff); + board_delay_ms (10, 1); + } + else + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms (10, 1); + } + } + + else if (buf == 4) + { + dw_gpio_write (gpio_write_port, 0x0000000, 0x0fff000); + board_delay_ms (10, 1); + + if (cro == 1) + { + dw_gpio_write (gpio_write_port, 0x7000000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 2) + { + dw_gpio_write (gpio_write_port, 0x5000000, 0xfffffff); + board_delay_ms (10, 1); + } + else if (cro == 3) + { + dw_gpio_write (gpio_write_port, 0xd000000, 0xfffffff); + board_delay_ms (10, 1); + } + else + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms (10, 1); + } + } + + else + { + dw_gpio_write (gpio_write_port, 0x0000000, 0xffff000); + board_delay_ms (10, 1); + } + + return; +} + + +/** @} */ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/setupAP4.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/setupAP4.c new file mode 100644 index 00000000..8d5d8d8f --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/esp8266_gagent/setupAP4.c @@ -0,0 +1,56 @@ +#include "embARC.h" +#include "embARC_debug.h" +#include +#include + +#include "dev_uart.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + + +#define BUTTON_MASK 0x7 +#define MAX_READ_CNT 32 + + +void setupAP4 (void) +{ + DEV_UART_PTR uart2; + + set_uart_map (0xE4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A | PM2_I2C_HRI | PM3_GPIO_AC | PM4_I2C_GPIO_D | PM5_UR_GPIO_C | PM5_LR_UART_2 | PM6_UR_SPI_M0 | PM6_LR_GPIO_A); + int32_t ercd; + + uart2 = uart_get_dev (DW_UART_2_ID); + ercd = uart2->uart_open (115200); + char send_string1[64] = "AT+CWMODE=2\r\n"; + + ercd = uart2->uart_write (send_string1, sizeof (send_string1)); + board_delay_ms (3000, 0); + char send_string2[64] = "AT+CWSAP=\"S4\",\"123456789\",5,4\r\n"; + + ercd = uart2->uart_write (send_string2, sizeof (send_string2)); + + char receive_string[32] = + { + 0 + }; + uint32_t rd_avail = 0; + uint32_t rssi; + + while (1) + { + board_delay_ms (1000, 0); + uart2->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + + if (rd_avail > 0) + { + EMBARC_PRINTF ("rd_avail is %d\r\n", rd_avail); + + uart2->uart_read (receive_string, rd_avail); + EMBARC_PRINTF ("%s\r\n", receive_string); + break; + } + + } +} + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/main.c b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/main.c new file mode 100644 index 00000000..20ec0128 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for stop/Stop 4/main.c @@ -0,0 +1,177 @@ + +#include "embARC.h" +#include "embARC_debug.h" +#include "dev_gpio.h" +#include "dev_uart.h" +#include "../../../board/emsk/drivers/mux/mux.h" +#include "../../../board/emsk/drivers/mux/mux_hal.h" + + +static DEV_GPIO_PTR esp8266_rst; + +#define ESP8266_RST_PORT DW_GPIO_PORT_A +#define ESP8266_RST_MASK (0x100) +#define ESP8266_RST_DIR (0x100) + +static DEV_GPIO_PTR led; + +#define LED_PORT DW_GPIO_PORT_B +#define LED_MASK 0x1ff +#define LED_DIR 0x1ff + +static DEV_UART_PTR esp8266_uart; + +#define ESP8266_UART_ID DW_UART_0_ID +#define ESP8266_UART_BAUDRATE UART_BAUDRATE_9600 + +#define MAX_READ_CNT 32 + +#include "./esp8266_gagent/esp8266_gagent_common.c" +#include "./esp8266_gagent/esp8266_gagent_user.c" +#include "./esp8266_gagent/ledrgb.c" +#include "./esp8266_gagent/setupAP4.c" + + +static void delay_ms (int z) //1ms +{ + uint32_t volatile x, y; + + for (x = 1400; x > 0; x--) + for (y = z; y > 0; y--) + ; +} + + +void esp8266_init (void) +{ + // set pmod mux and uart map + set_uart_map (0xe4); + set_pmod_mux (PM1_UR_UART_0 | PM1_LR_GPIO_A); + + // Get devices structure pointer + esp8266_uart = uart_get_dev (ESP8266_UART_ID); + esp8266_rst = gpio_get_dev (ESP8266_RST_PORT); + int32_t ercd; + + // Open devices + esp8266_rst->gpio_close (); + + if ((ercd = esp8266_rst->gpio_open (ESP8266_RST_DIR)) == E_OK) + { + EMBARC_PRINTF ("ESP8266_RST_PORT open successfully!!\r\n"); + } + else if (ercd == E_OPNED) + { + EMBARC_PRINTF ("ESP8266_RST_PORT open failed,because opend with different direction!!\r\n"); + esp8266_rst->gpio_control (GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *) (ESP8266_RST_MASK)); + + } + else + { + EMBARC_PRINTF ("ESP8266_RST_PORT open failed, unknow why!!\r\n"); + } + + esp8266_uart->uart_close (); + + if (esp8266_uart->uart_open (ESP8266_UART_BAUDRATE) != E_OK) + { + EMBARC_PRINTF ("ESP8266_UART open failed!!\r\n"); + } + else + { + EMBARC_PRINTF ("ESP8266_UART open successfully!!\r\n"); + } + +} + + +int main (void) +{ + cpu_lock (); + + //Board initialization; + board_init (); + + //esp8266 initialization; + esp8266_init (); + cpu_unlock (); + uint8_t StaNum = 0; + uint8_t Crowd = 0; + uint16_t rd_cnt = 0; + uint8_t read_data[MAX_READ_CNT]; + uint32_t rd_avail; + + setupAP4 (); + + while (1) + { + esp8266_uart->uart_control (UART_CMD_GET_RXAVAIL, (void *) (&rd_avail)); + rd_cnt = (MAX_READ_CNT > rd_avail) ? rd_avail: MAX_READ_CNT; + board_delay_ms (100, 0); + + if (rd_avail > 0) + { + esp8266_uart->uart_read ((void *) read_data, rd_cnt); + + for (uint8_t i = 0; i < rd_cnt; i++) + EMBARC_PRINTF ("%2x ", read_data[i]); + + EMBARC_PRINTF ("\r\n"); + + //判断是否为合法数据包,合法数据包以固定包头0xFFFF开始。 + if (read_data[0] == 0xFF && read_data[1] == 0xFF) + { + sn = read_data[5]; + + switch (read_data[4]) //读取命令位的代码 + { + case 0x01: + mcu2wifi_product_info (); + break; //MCU传入产品的Key与Secret + + case 0x03: + { + if (read_data[9] == 01) + { + StaNum = read_data[10]; + } + else if (read_data[9] == 02) + { + Crowd = read_data[11]; + } + + //EMBARC_PRINTF("SN=%d,CR=%d\r\n",StaNum,Crowd); + LEDRGB (StaNum, Crowd); + mcu2wifi_wifi_ctrl_dev (read_data); + break; + } + + case 0x06: + break; + + case 0x07: + mcu2wifi_heartbeat (); + break; + + case 0x0a: + break; + + case 0x0c: + break; + + case 0x0d: + mcu2wifi_wifi_statu (read_data); + break; + + default: + EMBARC_PRINTF ("Undefine commond or error!!!\r\n"); + break; + } + } + + } + } + + return E_SYS; +} + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Performance.pptx b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Performance.pptx new file mode 100644 index 00000000..bcdd8a45 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Performance.pptx differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/All.jpg b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/All.jpg new file mode 100644 index 00000000..d7e19788 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/All.jpg differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Bus.jpg b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Bus.jpg new file mode 100644 index 00000000..6248ac07 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Bus.jpg differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop2.jpg b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop2.jpg new file mode 100644 index 00000000..7f70494a Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop2.jpg differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop4.jpg b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop4.jpg new file mode 100644 index 00000000..6d30d19f Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Photos/Stop4.jpg differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/ReadMe.md b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/ReadMe.md new file mode 100644 index 00000000..a6090145 --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/ReadMe.md @@ -0,0 +1,62 @@ +#the front-end system of intelligent bus sign based on ARC EM + +**the front-end system of intelligent bus sign based on ARC EM** can show the location of the bus and the degree of crowding,which can provide a lot of convenience to the waiting people。The intelligent bus stop is based on the ARC processor,and communicates with bus by Wifi and Gizwits. Finanlly, three color LED lights display bus position and degree of crowding information on bus stop sign.In the later promotion process,We can add corresponding functions,such as the voice recognition system, environment monitoring system and intelligent transfer functions, to respond to the development of smart city and smart transportation and to maximize passenger convenience. + +* [Introduction](#Introduction) + * [Function](#Function) + * [System Architecture](#System Architecture) +* [Hardware and Software Setup](#Hardware and Software Setup) + * [Required Hardware](#Required Hardware) + * [Required Software](#Required Software) + * [Hardware Connection](#Hardware Connection) + +## Introduction +**the front-end system of intelligent bus sign based on ARC EM** +### Function +- show the location of the bus + +- show the degree of crowding +### System Architecture + +![Alt text](http://m.qpic.cn/psb?/V13Yp3s72D3BU5/WPga2xFL3vOhUm5jRQTNqA1eprNwct36C.q6ga.K2.A!/b/dC0BAAAAAAAA&bo=wgIXAwAAAAADF.Y!&rf=viewer_4 "optional title") + +## Hardware and Software Setup +### Required Hardware + +- 3 [DesignWare ARC EM Starter Kit(EMSK)][30] + +- 6 [WiFi ESP8266 (ESP-01S)][31] + +- 8 [LED RGB][30] + +- 2 [Infrared ejection module ][30] + +- 3 [SD Card][30] + + The physical picture of wearable node is as follows::![Alt text](http://m.qpic.cn/psb?/V13Yp3s72D3BU5/fvQN3DB5*LbEKRkxP6P2.WMgVrDSo8yCcl6F0AKTwW8!/b/dDIBAAAAAAAA&bo=9gS6AwAAAAARJ1s!&rf=viewer_4 "optional title") +### Required Software + +- Metaware or ARC GNU Toolset +- Serial port terminal, such as putty, tera-term or minicom +- Gizwits +### Hardware Connection + +EMSK 1 Realize the bus number counting function.We can get the number of people on the vehicle by subtracting the data from the data of the vehicle infrared radiation module + +- Pmod1,Pmod5 connect to WiFi + +- Pmod2,Pmod3,Pmod4and Pmod5 connect to LED RGB + + EMSK 2 and EMSK 3 display the arrival position of bus stop and the degree of congestion.Through the WiFi on the station card, the rssi signal sent by the WiFi on the bus is sensed and the data sent by the smart cloud is received,We can show the arrival position and the degree of congestion by the position and color of the lights + +- Pmod1 connect to Infrared ejection module and WiFi module + +- Pmod2 connect to Infrared ejection module , and Pmod5 connect to WiFi module + + + + + + + + diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Technical Documents.docx b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Technical Documents.docx new file mode 100644 index 00000000..3edd2927 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Technical Documents.docx differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Video Link b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Video Link new file mode 100644 index 00000000..3058514b --- /dev/null +++ b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/Video Link @@ -0,0 +1,3 @@ +http://v.youku.com/v_show/id_XMzYyOTkyOTc4NA==.html?spm=a2h3j.8428770.3416059.1 + +For YOUKU diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/1.png b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/1.png new file mode 100644 index 00000000..a2f951d3 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/1.png differ diff --git a/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/2.jpg b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/2.jpg new file mode 100644 index 00000000..542b4280 Binary files /dev/null and b/arc_design_contest/2018/XDU_Intelligent-Bus-Station/readmephoto/2.jpg differ