Skip to content

Contribute XDU_Intelligent-Bus-Station Application to embARC Applications #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}


Original file line number Diff line number Diff line change
@@ -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");
}


Loading