-
Notifications
You must be signed in to change notification settings - Fork 82
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
ICEREALM1
wants to merge
26
commits into
foss-for-synopsys-dwc-arc-processors:master
Choose a base branch
from
ICEREALM1:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c99ebd2
Create XDU_Intelligent-bus-station
ICEREALM1 405c27d
Delete XDU_Intelligent-bus-station
ICEREALM1 6185421
Add files via upload
ICEREALM1 cd35f64
Add files via upload
ICEREALM1 2273977
Create Video Link
ICEREALM1 f5d6043
Create ReadMe
ICEREALM1 3670fdc
Delete ReadMe
ICEREALM1 dc8eb4b
Add files via upload
ICEREALM1 b8b6165
Add files via upload
ICEREALM1 69a3044
Delete ReadMe.md
ICEREALM1 f99c942
Add files via upload
ICEREALM1 6e65812
Add files via upload
ICEREALM1 ef800ea
Update Intrainout.c
ICEREALM1 0fb2bcf
Update esp8266_gagent_common.c
ICEREALM1 1c91d2d
Update Intrainout.c
ICEREALM1 a0ec228
Update esp8266_gagent_user.c
ICEREALM1 f0838b6
Update esp8266_gagent_common.c
ICEREALM1 d0fb54d
Update esp8266_gagent_user.c
ICEREALM1 c2f948f
Update ledrgb.c
ICEREALM1 244ca47
Update setupAP2.c
ICEREALM1 4602c67
Update main.c
ICEREALM1 a02b597
Update esp8266_gagent_common.c
ICEREALM1 292eac1
Update esp8266_gagent_user.c
ICEREALM1 308aa06
Update ledrgb.c
ICEREALM1 9415baa
Update setupAP4.c
ICEREALM1 c27f595
Update main.c
ICEREALM1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
...gn_contest/2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/Intrainout.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" //GPIO API头文件 | ||
#include "../../../board/emsk/drivers/mux/mux.h" // Pmod端口配置API` | ||
#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); //延迟10ms再进行读数 | ||
|
||
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; | ||
} | ||
|
||
|
214 changes: 214 additions & 0 deletions
214
...2018/XDU_Intelligent-Bus-Station/Code/Code for bus/esp8266_gagent/esp8266_gagent_common.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
|
||
uint8_t sn = 0; | ||
|
||
/* | ||
函数功能:MCU向WiFi模组回复设备信息。 | ||
包括:通用串口协议版本号 | ||
业务协议版本号 | ||
硬件版本号 | ||
软件版本号 | ||
产品标识码(在机智云创建产品时分配的全网唯一标识码,从机智云获取) | ||
设备属性 | ||
产品密匙(与产品标识码对应的产品密匙,从机智云获取) | ||
|
||
*/ | ||
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; //获取包序号 | ||
|
||
//计算校验和(包长度至校验和前一byte所有数据之和对256取余) | ||
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"); | ||
|
||
} | ||
|
||
|
||
/* | ||
函数功能:MCU向WiFi发送心跳包。 | ||
当WiFi模组超过55秒没有收到MCU的数据包,应向MCU发送心跳包。MCU收到心跳包后马上回复。 | ||
当WiFi模组连续3次没有收到MCU的心跳回复,进行报警。 | ||
|
||
*/ | ||
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; //获取包序号 | ||
|
||
//计算校验和(包长度至校验和前一byte所有数据之和对256取余) | ||
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); | ||
} | ||
|
||
|
||
/* | ||
函数功能:MCU向WiFi发送指令,通知WiFi模组进入配置模式。 | ||
当WiFi模组收到进入配置模式的指令后,让设备进入对应的SoftAP或AirLink等OnBoarding配置方式� | ||
�� | ||
参数:mode 配置模式,1为SoftAP方式,2为AirLink方式; | ||
配置方式不合法时,默认进入AirLink配置方式, | ||
超时时间1分钟。softAp配置,超时时间5分钟 | ||
|
||
*/ | ||
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; //获取包序号 | ||
|
||
/*设置配置方式,1为SoftAP方式,2为AirLink方式; | ||
配置方式不合法时,默认进入AirLink配置方式,超时时间1分钟。softAp配置,超时时间5分� | ||
�*/ | ||
send_data[8] = mode; | ||
|
||
//计算校验和(包长度至校验和前一byte所有数据之和对256取余) | ||
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); | ||
} | ||
|
||
|
||
/* | ||
函数功能:MCU向WiFi发送指令,重置WiFi模组。 | ||
重置的内容包括WiFi模组保存的局域网WiFi SSID和密码,DID,Passcode等信息。 | ||
重置后模组重启进入AirLink配置模式,超时时间5分钟。 | ||
|
||
*/ | ||
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; //获取包序号 | ||
|
||
//计算校验和(包长度至校验和前一byte所有数据之和对256取余) | ||
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); | ||
} | ||
|
||
|
||
/* | ||
函数功能:WiFi模组向MCU推送WiFi状态后,MCU向WiFi回复信息。 | ||
同时打印WiFi状态。 | ||
*/ | ||
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"); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the character encoding in this file