diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/README.md b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/README.md new file mode 100644 index 00000000..49722b03 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/README.md @@ -0,0 +1,510 @@ +# Edge Crowd Counting System + +## Introduction + +It's a demo of Edge-to-cloud collaboration to solve the crowd counting problem in SMART City. At present,in the crowd analysis prog of cameras on the market, the analysis of the crowd characteristics needs to upload images from the edge to the central server for unified analysis and processing,with poor real-time performance, but requiring high power consumption, big storage, and wide network bandwidth. So, This project proposes a real-time crowd density detection model based on deep learning, and deploys the model to the ARC MCU, analyzes the video in real time on the edge computing platform, and uploads the structured population information to the cloud center. +The crowd information analysis technology at the edge end greatly reduces the computing, network bandwidth and storage requirements for the cloud center. The video image is directly processed and analyzed at the edge, which improves the response speed, compensates for the shortcomings of cloud computing response, and high power consumption. It can meet the needs of the security industry in real-time business, urban security, etc., It has broad application prospects. + +### Function + +* **Crowd Count** + + Counting the number of people from pictures or video. + +* **Congestion Warning** + + When the total population of the region exceeds the threshold set by the system, the node will return the alarm information to the server. + +* **Data processing on the edge** + + To handle the data explosion problem in IoT era, preliminary data processing work is transferred from cloud server to edge node. In our system, edge node can handle simple data preprocessing works like data gathering, data cleaning etc. + +* **Analysis of Flow Trend** + + If multi-nodes is set in a large region, edge processing node can forecasting the flow of people. + +* **Data Transmission** + + Upload processed data to the cloud. + +### Architecture + +![屏幕快照 2019-07-24 下午6.28.14](http://ww3.sinaimg.cn/large/006tNc79ly1g5b3ukesxcj315c0m6k4a.jpg) + + + +Due to limited development time, we use raspberry pi 3b+ with picam as video processing nodes and ARC IoTDK as edge data processing node. Actually we believe that IoTDK can replace raspberry pi as video processing node in theoretically with MLI lib but more works have to be done. In our future work, we will try to move this part to IoTDK. + +## Hardware and Software Setup + +### Hardware Required List + +* ARC IoTDK or EMSK +* SD Card +* ESP01/ESP01S WiFi Module +* Raspberry pi 3b+ with picam + +### Set Up Software environment + +#### a. Raspberry Part + +* python2.7 +* tensorflow lite +* opencv +* socket + +#### b. ARC IoTDK or EMSK + +##### For EMSK + +- ESP01/ESP01S WiFi Module connectes to J5. +- Configure your EMSK with proper core configuration(EM9D). +- Insert SD Card + +##### For IoTDK + +- ESP01/ESP01S WiFi Module connects to PMOD B. +- Insert SD Card + +## User Manual + +### Crowd Counting Part + +This part is implement on Raspberry pi. + +* Prepare training data:[BaiduDisk](http://pan.baidu.com/s/1nuAYslz) + +* Train The Model + + ~~~python + #For tensorflow + #run from prompt + python3 train.py A(or B) + #Model is saved to modelA/ or modelB/ + ~~~ + +* Prepared the model + + ~~~bash + python3 train.py + ~~~ + +* Run this project + + ~~~bash + python3 main.py + ~~~ + +### Data Processing Node + +This part can implement on both ARC IoTDK and EMSK . + +#### Before Running + +- In the `main.c`, you need to replace WIFI_SSID and WIFI_PWD with your own SSID and PWD. + + ```C + #define WIFI_SSID "\"embarc\"" + #define WIFI_PWD "\"12344321\"" + ``` + + ##### For EMSK + + - In the `main.c`, you need to set the SD card header file. + + ``` + #include "emsk_sdcard.h" + #include "emsk_sdcard_spi.h" + ``` + + - In the `Makefile`, you need to set up SD card environment. + + ``` + MID_SEL = common fatfs + APPL_CSRC_DIR = . ./wifi ./emsk_sdcard + APPL_INC_DIR = ./inc ./inc/emsk_sdcard + ``` + + ##### For IoTDK + + - In the `main.c`, you need to set the SD card header file. + + ``` + #include "emsk_sdcard.h" + #include "emsk_sdcard_spi.h" + ``` + + - In the `Makefile`, you need to set up SD card environment. + + ``` + MID_SEL = common fatfs + APPL_CSRC_DIR = . ./wifi ./iotdk_sdcard + APPL_INC_DIR = ./inc ./inc/iotdk_sdcard + ``` +#### Run This Application + +This example outputs to the console. It is supported by IoTDK and EMSK. The commands to run this example are as follows: + + $ cd /embarc_applications-master/arc_design_contest/2019/ SUStech_EdgeCrowdCountingSystem/src + $ make BOARD=emsk BD_VER=22 CUR_CORE=arcem9d TOOLCHAIN=mw run +##### Sample Output + +``` +----------------------------------------------------------- + ____ _ ____ +| _ \ _____ _____ _ __ ___ __| | __ ) _ _ +| |_) / _ \ \ /\ / / _ \ '__/ _ \/ _` | _ \| | | | +| __/ (_) \ V V / __/ | | __/ (_| | |_) | |_| | +|_| \___/ \_/\_/ \___|_| \___|\__,_|____/ \__, | + |___/ + _ _ ____ ____ + ___ _ __ ___ | |__ / \ | _ \ / ___| + / _ \ '_ ` _ \| '_ \ / _ \ | |_) | | + | __/ | | | | | |_) / ___ \| _ <| |___ + \___|_| |_| |_|_.__/_/ \_\_| \_\\____| +------------------------------------------------------------ + +embARC Build Time: Jun 13 2019, 06:45:36 +Compiler Version: Metaware, 4.2.1 Compatible Clang 6.0.1 (branches/release_60) +FatFS initialized successfully! +============================ Init ============================ +[at_parser_init]57: obj->psio 0x8000af18 -> 0x80001868 +[at_send_cmd]131: at_out: "AT +" (4) +[at_get_reply]154: "AT + +OK" (9) +============================ Set Mode ============================ +[at_send_cmd]131: at_out: "AT+CWMODE_CUR? +" (16) +[at_get_reply]154: " +AT+CWMODE_CUR? ++CWMODE_CUR:1 + +OK" (38) +CWMODE_CUR = 1 +[at_send_cmd]131: at_out: "AT+CWMODE_CUR=3 +" (17) +[at_get_reply]15▒: " +AT+CWMODE_CUR=3 + +OK" (24) +============================ Connect WiFi ============================ +[at_send_cmd]131: at_out: "AT+CWLAP="embarc" +" (19) +[at_get_reply]154: " +AT+CWLAP="embarc" ++CWLAP:(3,"embarc",-20,"2e:ea:1d:bd:4f:8b",9,32767,0) + +OK" (81) +Searching for WIFI "embarc" ...... +WIFI "embarc" found! Try to connect +[at_send_cmd]131: at_out: "AT+CWMODE_CUR=1 +" (17) +[at_get_reply]154: " +AT+CWMODE_CUR=1 + +OK" (24) +[at_send_cmd]131: at_out: "AT+CWJAP_CUR="embarc","12344321" +" (34) +[at_get_reply]154: " +AT+CWJAP_CUR="embarc","12344321" +0,CONNECT FAIL +WIFI DISCONNECT +WIFI CONNECTED +WIFI GOT IP + +OK" (103) +WIFI "embarc" connect succeed +============================ Connect Server ============================ +[at_send_cmd]131: at_out: "AT+CIPMUX=1 +" (13) +[at_get_reply]154: " +AT+CIPMUX=1 + +OK" (20) +[at_send_cmd]131: at_out: "AT+CIPSERVER=1,80 +" (19) +[at_get_reply]154: " +AT+CIPSERVER=1,80 +no change + +OK" (37) +============================ Show IP ============================ +[at_send_cmd]131: at_out: "AT+CIFSR +" (10) +[at_get_reply]154: " +AT+CIFSR ++CIFSR:STAIP,"192.168.137.254" ++CIFSR:STAMAC,"3c:71:bf:36:e4:f4" + +OK" (84) + +============================== Receive Data ================================= + + ++IPD,0,19:A061020190725123625 + +============================ Receive Finished =============================== + +========================== Start Data Analysis ============================== + +============================= Number of people ================================ + +Number of people: The number of people in area A is:0610. +Number of people: The number of people in area B is:0000. +Number of people: The number of people in area C is:0000. + +============================== Crowd status ================================ + +Crowd status: The number of people in area A has increased. +A0610201907251A:0610 + +============================= Stores the data ================================= + + Data successfully saved! + +Number of people: The total number of people in the current region is: 0610 , ,at 25,Jul,2019, 12:36:25, + +======================== Data Analysis Finished ============================= +There are 610 people in the area. +========================= Data sent to the cloud =========================== + +[at_send_cmd]131: at_out: "AT+CIPSEND=0,50 +" (17) +[at_get_reply]154: "AT+CIPSEND=0,50 + +OK" (22) + +============================= Send finished ================================ + + +============================= Receive Data ================================ + + ++IPD,0,19:B054020190725123630 + +=========================== Receive Finished ============================== + +========================= Start Data Analysis ============================= + +========================== Number of people ============================= + +Number of people: The number of people in area A is:0610. +Number of people: The number of people in area B is:0540. +Number of people: The number of people in area C is:0000. + +========================== Crowd status ============================= + +Crowd status: The number of people in area B has increased. +B0540201907251B:0540 + +============================= Stores the data ================================= + + Data successfully saved! + +Number of people: The total number of people in the current region is: 1150 , ,at 25,Jul,2019, 12:36:30, + +======================== Data Analysis Finished ============================= +There are 1150 people in the area. +========================= Data sent to the cloud =========================== + +[at_send_cmd]131: at_out: "AT+CIPSEND=0,50 +" (17) +[at_get_reply]154: "AT+CIPSEND=0,50 + +OK" (22) + +============================= Send finished ================================ + + +============================== Receive Data ================================= + + ++IPD,0,19:C025020190725123635 + +============================ Receive Finished =============================== + +========================== Start Data Analysis ============================== + +============================= Number of people ================================ + +Number of people: The number of people in area A is:0610. +Number of people: The number of people in area B is:0540. +Number of people: The number of people in area C is:0250. + +================================ Crowd status ================================== + + +============================== Crowd status ================================ + +Crowd status: The number of people in area C has increased. +C0250201907251C:0250 + +============================= Stores the data ================================= + + Data successfully saved! + +=============================== Flow of crowd ================================= + +Flow of crowd: The crowd is gathering. +* * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * +* * * * * * * * * * * * * +* * * * * * * * * * * * +* * * ***** * ******** * * * ***** * +* * * * * ******** * * * * * * * * * +* * ***** * * * ******** * * * * * +* * * * * * * * +* * * * * * * * * * * * +* * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * + + + + + + + + + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* * * * * * * * * +* * * * * +* * ***** * +* * * * +* * * * +* * * * +* * * * * * * * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +Number of people: The total number of people in the current region is: 1400 , ,at 25,Jul,2019, 12:36:35, + +======================== Data Analysis Finished ============================= +There are 1400 people in the area. +========================= Data sent to the cloud =========================== + +[at_send_cmd]131: at_out: "AT+CIPSEND=0,50 +" (17) +[at_get_reply]154: "AT+CIPSEND=0,50 + +OK" (22) + +============================= Send finished ================================ + + +============================== Receive Data ================================= + + ++IPD,0,19:A059020190725123640 + +============================ Receive Finished =============================== + +========================== Start Data Analysis ============================== + +============================= Number of people ================================ + +Number of people: The number of people in area A is:0590. +Number of people: The number of people in area B is:0540. +Number of people: The number of people in area C is:0250. + +=============================== Crowd status ================================= + +Crowd status: The number of people in area A has decreased. +A0590201907251A:0590 + +============================= Stores the data ================================= + + Data successfully saved! + +=============================== Flow of crowd ================================= + +Flow of crowd: Crowds move from area A to area B and C. +* * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * * * * +* * * * ** * * * * * * * * * +* * * * * *** * * * * * * +* * * ***** * ******** * * * ***** * +* * * * * * ********* * * * * * * * * * +* * ***** * * * ******** * * * * * +* * * * *** * * * * +* * * * ** * * * * * * * * +* * * * * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * + + * * * + * * * + * * * + * ** * ** * + * * * * * + * * * + * + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* * * * * * * * * +* * * * * +* * ***** * +* * * * +* * * * +* * * * +* * * * * * * * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + +Number of people: The total number of people in the current region is: 1380 , ,at 25,Jul,2019, 12:36:40, + +======================== Data Analysis Finished ============================= +There are 1380 people in the area. +========================= Data sent to the cloud =========================== + +[at_send_cmd]131: at_out: "AT+CIPSEND=0,50 +" (17) +[at_get_reply]154: "AT+CIPSEND=0,50 + +OK" (22) + +============================= Send finished ================================ + +``` + +#### Function Module + +* Data aggregation + + ~~~C + int data_process(char *buff) + ~~~ + + This program is divided into two parts: data aggregation and data analysis. + + The data aggregation part receives data sent by each node through wifi, extracts data such as region and time, classifies data, aggregates multi-node data. + + The data analysis part is based on the current data and previous data of the nodes, reports the changes of the number of nodes, analyses the trend of crowd flow, and predicts the trend of the crowd. + +* Abnormal Data Process + + ~~~C + int abnormal_data_processing(float var, float ave) + ~~~ + + The program is based on the previous number information for data processing, according to the calculation results to determine whether the current data is abnormal, and eliminate abnormal data to ensure the authenticity of the data. + +* Data storage + + ~~~C + int data_storage(char *buff) + ~~~ + + The program saves the data information of the processed node in the local SD card to backup the data . + +* Cloud-side Collaborative Processing and Continuous transmission of breakpoints + + This program sends the aggregated information to the cloud server for the distribution and scheduling of the cloud, and when the server fails to send the information to the cloud server due to network outage, data will be backed up on the local SD card to prevent data loss. + +## Demo + +[DEMO]( https://v.youku.com/v_show/id_XNDI4ODA4MTY0NA==.html?spm=a2h4v.8841035.uerCenter.5!3~5~5!2~DL~DD!2~A&firsttime=437.67) + diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_1.jpg b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_1.jpg new file mode 100644 index 00000000..15fb15f6 Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_1.jpg differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_2.jpg b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_2.jpg new file mode 100644 index 00000000..0ff1bc7e Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_2.jpg differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_3.jpg b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_3.jpg new file mode 100644 index 00000000..1c776789 Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_3.jpg differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_4.jpg b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_4.jpg new file mode 100644 index 00000000..1f7550de Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_4.jpg differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_5.jpg b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_5.jpg new file mode 100644 index 00000000..90dd3c40 Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/data/IMG_5.jpg differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/main.py b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/main.py new file mode 100644 index 00000000..10688055 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/main.py @@ -0,0 +1,147 @@ +import time +import cv2 +import os +import sys +from itertools import cycle +import tensorflow as tf +import numpy as np +import socket + + +def conv2d(x, w): + return tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME') + + +def max_pool_2x2(x): + return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], + strides=[1, 2, 2, 1], padding='SAME') + + +def inf(x): + # tf.reset_default_graph() + # s net ########################################################### + w_conv1_1 = tf.get_variable('w_conv1_1', [5, 5, 1, 24]) + b_conv1_1 = tf.get_variable('b_conv1_1', [24]) + h_conv1_1 = tf.nn.relu(conv2d(x, w_conv1_1) + b_conv1_1) + + h_pool1_1 = max_pool_2x2(h_conv1_1) + + w_conv2_1 = tf.get_variable('w_conv2_1', [3, 3, 24, 48]) + b_conv2_1 = tf.get_variable('b_conv2_1', [48]) + h_conv2_1 = tf.nn.relu(conv2d(h_pool1_1, w_conv2_1) + b_conv2_1) + + h_pool2_1 = max_pool_2x2(h_conv2_1) + + w_conv3_1 = tf.get_variable('w_conv3_1', [3, 3, 48, 24]) + b_conv3_1 = tf.get_variable('b_conv3_1', [24]) + h_conv3_1 = tf.nn.relu(conv2d(h_pool2_1, w_conv3_1) + b_conv3_1) + + w_conv4_1 = tf.get_variable('w_conv4_1', [3, 3, 24, 12]) + b_conv4_1 = tf.get_variable('b_conv4_1', [12]) + h_conv4_1 = tf.nn.relu(conv2d(h_conv3_1, w_conv4_1) + b_conv4_1) + + # m net ########################################################### + w_conv1_2 = tf.get_variable('w_conv1_2', [7, 7, 1, 20]) + b_conv1_2 = tf.get_variable('b_conv1_2', [20]) + h_conv1_2 = tf.nn.relu(conv2d(x, w_conv1_2) + b_conv1_2) + + h_pool1_2 = max_pool_2x2(h_conv1_2) + + w_conv2_2 = tf.get_variable('w_conv2_2', [5, 5, 20, 40]) + b_conv2_2 = tf.get_variable('b_conv2_2', [40]) + h_conv2_2 = tf.nn.relu(conv2d(h_pool1_2, w_conv2_2) + b_conv2_2) + + h_pool2_2 = max_pool_2x2(h_conv2_2) + + w_conv3_2 = tf.get_variable('w_conv3_2', [5, 5, 40, 20]) + b_conv3_2 = tf.get_variable('b_conv3_2', [20]) + h_conv3_2 = tf.nn.relu(conv2d(h_pool2_2, w_conv3_2) + b_conv3_2) + + w_conv4_2 = tf.get_variable('w_conv4_2', [5, 5, 20, 10]) + b_conv4_2 = tf.get_variable('b_conv4_2', [10]) + h_conv4_2 = tf.nn.relu(conv2d(h_conv3_2, w_conv4_2) + b_conv4_2) + + # l net ########################################################### + w_conv1_3 = tf.get_variable('w_conv1_3', [9, 9, 1, 16]) + b_conv1_3 = tf.get_variable('b_conv1_3', [16]) + h_conv1_3 = tf.nn.relu(conv2d(x, w_conv1_3) + b_conv1_3) + + h_pool1_3 = max_pool_2x2(h_conv1_3) + + w_conv2_3 = tf.get_variable('w_conv2_3', [7, 7, 16, 32]) + b_conv2_3 = tf.get_variable('b_conv2_3', [32]) + h_conv2_3 = tf.nn.relu(conv2d(h_pool1_3, w_conv2_3) + b_conv2_3) + + h_pool2_3 = max_pool_2x2(h_conv2_3) + + w_conv3_3 = tf.get_variable('w_conv3_3', [7, 7, 32, 16]) + b_conv3_3 = tf.get_variable('b_conv3_3', [16]) + h_conv3_3 = tf.nn.relu(conv2d(h_pool2_3, w_conv3_3) + b_conv3_3) + + w_conv4_3 = tf.get_variable('w_conv4_3', [7, 7, 16, 8]) + b_conv4_3 = tf.get_variable('b_conv4_3', [8]) + h_conv4_3 = tf.nn.relu(conv2d(h_conv3_3, w_conv4_3) + b_conv4_3) + + # merge ########################################################### + h_conv4_merge = tf.concat([h_conv4_1, h_conv4_2, h_conv4_3], 3) + + w_conv5 = tf.get_variable('w_conv5', [1, 1, 30, 1]) + b_conv5 = tf.get_variable('b_conv5', [1]) + h_conv5 = conv2d(h_conv4_merge, w_conv5) + b_conv5 + + y_pre = h_conv5 + + return y_pre + + +graph1 = tf.Graph() +with graph1.as_default(): + x = tf.placeholder(tf.float32, [None, None, None, 1], name="input") + y_act = tf.placeholder(tf.float32, [None, None, None, 1]) + y_pre = inf(x) + +frame_path = './data/' +filenames = os.listdir(frame_path) +img_iter = cycle([cv2.imread(os.sep.join([frame_path, name]), 0) + for name in filenames]) + +key = 0 +cv2.namedWindow('image', cv2.WINDOW_NORMAL) +cv2.resizeWindow('image', 640, 480) + +SEVER_ADDR = ('192.168.31.67', 80) + +client_socket = socket(socket.AF_INET, socket.SOCK_STREAM) +client_socket.connect(SEVER_ADDR) +print('connect sever(%s) success' % str(SEVER_ADDR)) + +with tf.Session(graph=graph1) as sess: + saver = tf.train.Saver() + saver.restore(sess, 'modelA/model.ckpt') + + while key & 0xFF != 28: + img = next(img_iter) + img = np.array(img) + img = (img-127.5)/128 + data = [] + data.append([img]) + d = data[0] + x_in = d[0] + x_in = np.reshape(d[0], (1, d[0].shape[0], d[0].shape[1], 1)) + timea = time.time() + y_p_den = sess.run(y_pre, feed_dict={"input:0": x_in}) + timeb = time.time() + cv2.imshow('image', img) + + tm = time.strftime("%Y%m%d%H%M%S", time.localtime()) + real_num = "{:0>4d}".format(np.sum(y_p_den)) + send_data = 'A'+real_num+tm + client_socket.send(send_data.encode()) + + print("prediction result:%f" % real_num) + print('send message %s' % send_data) + print('=============================================================') + print('cost time: %.2f s' % (timea - timeb)) + + sys.stdout.flush() + key = cv2.waitKey(1000) diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/checkpoint b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/checkpoint new file mode 100644 index 00000000..febd7d54 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/checkpoint @@ -0,0 +1,2 @@ +model_checkpoint_path: "model.ckpt" +all_model_checkpoint_paths: "model.ckpt" diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.data-00000-of-00001 b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.data-00000-of-00001 new file mode 100644 index 00000000..d4f02edf Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.data-00000-of-00001 differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.index b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.index new file mode 100644 index 00000000..15a1c026 Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.index differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.meta b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.meta new file mode 100644 index 00000000..b18e473d Binary files /dev/null and b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/model.ckpt.meta differ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/modelA.txt b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/modelA.txt new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/modelA/modelA.txt @@ -0,0 +1 @@ + diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/network.py b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/network.py new file mode 100644 index 00000000..081bca33 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/data_collection_pi/network.py @@ -0,0 +1,134 @@ +import numpy as np +import cv2 +import tensorflow as tf + + +class MCNN: + def __init__(self, dataset=None): + self.dataset = dataset + self.LEARNING_RATE = 1e-4 + + self.x = tf.placeholder(tf.float32, [None, None, None, 1]) + self.y_act = tf.placeholder(tf.float32, [None, None, None, 1]) + self.y_pre = self.inf(self.x) + + # Loss - Euclidean Distance + self.loss = tf.sqrt(tf.reduce_mean(tf.square(self.y_act - self.y_pre))) + self.act_sum = tf.reduce_sum(self.y_act) + self.pre_sum = tf.reduce_sum(self.y_pre) + + # Mean Absolute Error + self.MAE = tf.abs(self.act_sum - self.pre_sum) + + self.train_step = tf.train.AdamOptimizer( + self.LEARNING_RATE).minimize(self.loss) + + def conv2d(self, x, w): + return tf.nn.conv2d(x, w, strides=[1, 1, 1, 1], padding='SAME') + + def max_pool_2x2(self, x): + return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], + strides=[1, 2, 2, 1], padding='SAME') + + def inf(self, x): + # tf.reset_default_graph() + # s net ########################################################### + w_conv1_1 = tf.get_variable('w_conv1_1', [5, 5, 1, 24]) + b_conv1_1 = tf.get_variable('b_conv1_1', [24]) + h_conv1_1 = tf.nn.relu(self.conv2d(x, w_conv1_1) + b_conv1_1) + + h_pool1_1 = self.max_pool_2x2(h_conv1_1) + + w_conv2_1 = tf.get_variable('w_conv2_1', [3, 3, 24, 48]) + b_conv2_1 = tf.get_variable('b_conv2_1', [48]) + h_conv2_1 = tf.nn.relu(self.conv2d(h_pool1_1, w_conv2_1) + b_conv2_1) + + h_pool2_1 = self.max_pool_2x2(h_conv2_1) + + w_conv3_1 = tf.get_variable('w_conv3_1', [3, 3, 48, 24]) + b_conv3_1 = tf.get_variable('b_conv3_1', [24]) + h_conv3_1 = tf.nn.relu(self.conv2d(h_pool2_1, w_conv3_1) + b_conv3_1) + + w_conv4_1 = tf.get_variable('w_conv4_1', [3, 3, 24, 12]) + b_conv4_1 = tf.get_variable('b_conv4_1', [12]) + h_conv4_1 = tf.nn.relu(self.conv2d(h_conv3_1, w_conv4_1) + b_conv4_1) + + # m net ########################################################### + w_conv1_2 = tf.get_variable('w_conv1_2', [7, 7, 1, 20]) + b_conv1_2 = tf.get_variable('b_conv1_2', [20]) + h_conv1_2 = tf.nn.relu(self.conv2d(x, w_conv1_2) + b_conv1_2) + + h_pool1_2 = self.max_pool_2x2(h_conv1_2) + + w_conv2_2 = tf.get_variable('w_conv2_2', [5, 5, 20, 40]) + b_conv2_2 = tf.get_variable('b_conv2_2', [40]) + h_conv2_2 = tf.nn.relu(self.conv2d(h_pool1_2, w_conv2_2) + b_conv2_2) + + h_pool2_2 = self.max_pool_2x2(h_conv2_2) + + w_conv3_2 = tf.get_variable('w_conv3_2', [5, 5, 40, 20]) + b_conv3_2 = tf.get_variable('b_conv3_2', [20]) + h_conv3_2 = tf.nn.relu(self.conv2d(h_pool2_2, w_conv3_2) + b_conv3_2) + + w_conv4_2 = tf.get_variable('w_conv4_2', [5, 5, 20, 10]) + b_conv4_2 = tf.get_variable('b_conv4_2', [10]) + h_conv4_2 = tf.nn.relu(self.conv2d(h_conv3_2, w_conv4_2) + b_conv4_2) + + # l net ########################################################### + w_conv1_3 = tf.get_variable('w_conv1_3', [9, 9, 1, 16]) + b_conv1_3 = tf.get_variable('b_conv1_3', [16]) + h_conv1_3 = tf.nn.relu(self.conv2d(x, w_conv1_3) + b_conv1_3) + + h_pool1_3 = self.max_pool_2x2(h_conv1_3) + + w_conv2_3 = tf.get_variable('w_conv2_3', [7, 7, 16, 32]) + b_conv2_3 = tf.get_variable('b_conv2_3', [32]) + h_conv2_3 = tf.nn.relu(self.conv2d(h_pool1_3, w_conv2_3) + b_conv2_3) + + h_pool2_3 = self.max_pool_2x2(h_conv2_3) + + w_conv3_3 = tf.get_variable('w_conv3_3', [7, 7, 32, 16]) + b_conv3_3 = tf.get_variable('b_conv3_3', [16]) + h_conv3_3 = tf.nn.relu(self.conv2d(h_pool2_3, w_conv3_3) + b_conv3_3) + + w_conv4_3 = tf.get_variable('w_conv4_3', [7, 7, 16, 8]) + b_conv4_3 = tf.get_variable('b_conv4_3', [8]) + h_conv4_3 = tf.nn.relu(self.conv2d(h_conv3_3, w_conv4_3) + b_conv4_3) + + # merge ########################################################### + h_conv4_merge = tf.concat([h_conv4_1, h_conv4_2, h_conv4_3], 3) + + w_conv5 = tf.get_variable('w_conv5', [1, 1, 30, 1]) + b_conv5 = tf.get_variable('b_conv5', [1]) + h_conv5 = self.conv2d(h_conv4_merge, w_conv5) + b_conv5 + + y_pre = h_conv5 + + return y_pre + + def predict(self, img_path='./data/IMG_3.jpg'): + with tf.Session() as sess: + saver = tf.train.Saver() + saver.restore(sess, 'model' + self.dataset + '/model.ckpt') + + # img_path = '.\\data\\original\\ + # shanghaitech\\part_'+ self.dataset +'\\test_data\\images\\' + + print('Image Loading!') + + data = [] + img = cv2.imread(img_path, 0) + img = np.array(img) + img = (img - 127.5) / 128 + data.append([img]) + + print('Image loaded!') + + d = data[0] + x_in = d[0] + + x_in = np.reshape(d[0], (1, d[0].shape[0], d[0].shape[1], 1)) + y_p_den = sess.run(self.y_pre, feed_dict={self.x: x_in}) + y_p = np.sum(y_p_den) + print('y_p : ', y_p) + return y_p_den, y_p diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard.c new file mode 100644 index 00000000..07fa6fd1 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard.c @@ -0,0 +1,100 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +/** + * \defgroup BOARD_EMSK_DRV_MID_FS_SDCARD EMSK Fatfs Middleware SDCard Driver + * \ingroup BOARD_EMSK_DRIVER + * \brief EMSK Fatfs Middleware SDCard Interface Driver + * \details + * Realize the sdcard driver for fatfs based on the middleware fatfs diskio abstract + * layer, sdcard interface can be spi or sdio and so on. + */ + +/** + * \file + * \ingroup BOARD_EMSK_DRV_MID_FS_SDCARD + * \brief sdcard driver for fatfs of emsk board + */ + +/** + * \addtogroup BOARD_EMSK_DRV_MID_FS_SDCARD + * @{ + */ +#ifdef MID_FATFS /* only available when enable fatfs middleware */ + +#include "embARC_toolchain.h" +#include "ff_diskio.h" +#include "emsk_sdcard.h" +#include + +uint32_t diskio_get_fattime(void) +{ + struct tm *p_tm; + time_t cur_time; + uint32_t fattime; + + cur_time = time(NULL); + p_tm = localtime(&cur_time); + fattime = ((p_tm->tm_year+1900-1980)&0x7f) << 25; + fattime |= ((p_tm->tm_mon+1)&0xf) << 21; + fattime |= ((p_tm->tm_mday)&0x1f) << 16; + fattime |= ((p_tm->tm_hour)&0x1f) << 11; + fattime |= ((p_tm->tm_min)&0x3f) << 5; + fattime |= ((p_tm->tm_sec>>1)&0x1f); + + return fattime; +} + +FATFS_DISKIO *get_fatfs_diskio(uint32_t drvid) +{ + switch (drvid) { +#if (USE_EMSK_SDCARD_SPI_0) + case EMSK_SDCARD_0_DRVID: + return &sdcard_spi_0_diskio; + break; +#endif + default: + break; + } + return NULL; +} + +/** update in 1ms period interrupt for disk status update */ +void emsk_sdcard_1ms_update(void) +{ +#if (USE_EMSK_SDCARD_SPI_0) + sdcard_spi_0_diskio.diskio_timerproc(); +#endif +} + + +#endif /* MID_FATFS */ + +/** @} end of group BOARD_EMSK_DRV_MID_FS_SDCARD */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard_spi.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard_spi.c new file mode 100644 index 00000000..0c89c41d --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/emsk_sdcard/emsk_sdcard_spi.c @@ -0,0 +1,145 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +/** + * \defgroup BOARD_EMSK_DRV_MID_FS_SDCARD_SPI EMSK SDCard SPI Interface Driver + * \ingroup BOARD_EMSK_DRV_MID_FS_SDCARD + * \brief EMSK Fatfs SDCard SPI Interface Driver + * \details + * Realize the sdcard driver using spi interface for fatfs, under the abstract of + * fatfs diskio. + */ + +/** + * \file + * \ingroup BOARD_EMSK_DRV_MID_FS_SDCARD_SPI + * \brief sdcard driver using spi interface for fatfs + */ + +/** + * \addtogroup BOARD_EMSK_DRV_MID_FS_SDCARD_SPI + * @{ + */ +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include +#include + +#include "arc.h" +#include "arc_builtin.h" +#include "embARC_toolchain.h" +#include "embARC_error.h" +#include "arc_exception.h" + +#include "dev_spi.h" +#include "board.h" + +#ifdef ENABLE_OS +#include "os_hal_inc.h" +#endif + +#include "ff_diskio.h" +#include "ff_sdcard.h" + +#include "emsk_sdcard_spi.h" + +#if USE_EMSK_SDCARD_SPI_0 + +#define EMSK_SDCARD_SPI_0_ID (DW_SPI_0_ID) +#define EMSK_SDCARD_SPI_0_LINE BOARD_SDCARD_SPI_LINE + +/** SDCARD SPI FREQ & CLK MODE SETTINGS */ +#define EMSK_SDCARD_SPI_0_FREQ BOARD_SPI_FREQ +#define EMSK_SDCARD_SPI_0_CLKMODE SPI_CLK_MODE_0 + +#define EMSK_SDCARD_SPI_0_CPULOCK_ENABLE + + +static int32_t sdcard_spi_card_is_writeprotect(void) +{ + return 0; +} + +static int32_t sdcard_spi_card_is_inserted(void) +{ + return 1; +} + +static int32_t sdcard_spi_0_diskio_initialize(void) +{ + return sdcard_spi_diskio_initialize(&sdcard_spi_0_diskio); +} + +static int32_t sdcard_spi_0_diskio_status(void) +{ + return sdcard_spi_diskio_status(&sdcard_spi_0_diskio); +} + +static int32_t sdcard_spi_0_diskio_read(void *buf, uint32_t sector, uint32_t count) +{ + return sdcard_spi_diskio_read(&sdcard_spi_0_diskio, buf, sector, count); +} + +static int32_t sdcard_spi_0_diskio_write(const void *buf, uint32_t sector, uint32_t count) +{ + return sdcard_spi_diskio_write(&sdcard_spi_0_diskio, buf, sector, count); +} + +static int32_t sdcard_spi_0_diskio_ioctl(uint32_t cmd, void *buf) +{ + return sdcard_spi_diskio_ioctl(&sdcard_spi_0_diskio, cmd, buf); +} + +static void sdcard_spi_0_diskio_timerproc(void) +{ + sdcard_spi_diskio_timerproc(&sdcard_spi_0_diskio); +} + +static FS_SDCARD_SPI_CTRL sdcard_spi_0_ctrl = { + 0, 0, 0, + SDCARD_SPI_FREQ_400K, EMSK_SDCARD_SPI_0_FREQ, EMSK_SDCARD_SPI_0_CLKMODE, + DW_SPI_0_ID, BOARD_SDCARD_SPI_LINE, + sdcard_spi_card_is_writeprotect, + sdcard_spi_card_is_inserted +}; + +FATFS_DISKIO sdcard_spi_0_diskio = { + (void *)&sdcard_spi_0_ctrl, + sdcard_spi_0_diskio_initialize, + sdcard_spi_0_diskio_status, + sdcard_spi_0_diskio_read, + sdcard_spi_0_diskio_write, + sdcard_spi_0_diskio_ioctl, + sdcard_spi_0_diskio_timerproc +}; + +#endif /* USE_EMSK_SDCARD_SPI_0 */ + +#endif /* MID_FATFS */ +/** @} end of group BOARD_EMSK_DRV_MID_FS_SDCARD_SPI */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/FreeRTOSConfig.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/FreeRTOSConfig.h new file mode 100644 index 00000000..ec631777 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/FreeRTOSConfig.h @@ -0,0 +1,113 @@ +/* + FreeRTOS V8.0.0 - Copyright (C) 2014 Real Time Engineers Ltd. + All rights reserved + + VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. + + *************************************************************************** + * * + * FreeRTOS provides completely free yet professionally developed, * + * robust, strictly quality controlled, supported, and cross * + * platform software that has become a de facto standard. * + * * + * Help yourself get started quickly and support the FreeRTOS * + * project by purchasing a FreeRTOS tutorial book, reference * + * manual, or both from: http://www.FreeRTOS.org/Documentation * + * * + * Thank you! * + * * + *************************************************************************** + + This file is part of the FreeRTOS distribution. + + FreeRTOS is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License (version 2) as published by the + Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception. + + >>! NOTE: The modification to the GPL is included to allow you to distribute + >>! a combined work that includes FreeRTOS without being obliged to provide + >>! the source code for proprietary components outside of the FreeRTOS + >>! kernel. + + FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. Full license text is available from the following + link: http://www.freertos.org/a00114.html + + 1 tab == 4 spaces! + + *************************************************************************** + * * + * Having a problem? Start by reading the FAQ "My application does * + * not run, what could be wrong?" * + * * + * http://www.FreeRTOS.org/FAQHelp.html * + * * + *************************************************************************** + + http://www.FreeRTOS.org - Documentation, books, training, latest versions, + license and Real Time Engineers Ltd. contact details. + + http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products, + including FreeRTOS+Trace - an indispensable productivity tool, a DOS + compatible FAT file system, and our tiny thread aware UDP/IP stack. + + http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High + Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS + licenses offer ticketed support, indemnification and middleware. + + http://www.SafeRTOS.com - High Integrity Systems also provide a safety + engineered and independently SIL3 certified version for use in safety and + mission critical applications that require provable dependability. + + 1 tab == 4 spaces! +*/ + +#ifndef FREERTOS_CONFIG_H +#define FREERTOS_CONFIG_H + +#include +/*----------------------------------------------------------- + * Application specific definitions. + * + * These definitions should be adjusted for your particular hardware and + * application requirements. + * + * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * + * See http://www.freertos.org/a00110.html. + *----------------------------------------------------------*/ + +#define configUSE_PREEMPTION 1 +#define configUSE_IDLE_HOOK 0 +#define configUSE_TICK_HOOK 0 +#define configCPU_CLOCK_HZ ( ( unsigned long ) BOARD_CPU_CLOCK ) +#define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) +#define configMAX_PRIORITIES ( 10 ) +#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 104 ) +#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 32 * 1024 ) ) +#define configMAX_TASK_NAME_LEN ( 10 ) +#define configUSE_TRACE_FACILITY 0 +#define configUSE_16_BIT_TICKS 0 +#define configIDLE_SHOULD_YIELD 1 +#define configUSE_MUTEXES 1 + +/* Co-routine definitions. */ +#define configUSE_CO_ROUTINES 0 +#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) + + +/* Set the following definitions to 1 to include the API function, or zero +to exclude the API function. */ + +#define INCLUDE_vTaskPrioritySet 1 +#define INCLUDE_uxTaskPriorityGet 1 +#define INCLUDE_vTaskDelete 1 +#define INCLUDE_vTaskCleanUpResources 0 +#define INCLUDE_vTaskSuspend 1 +#define INCLUDE_vTaskDelayUntil 1 +#define INCLUDE_vTaskDelay 1 +#define INCLUDE_xTaskGetCurrentTaskHandle 1 + +#endif /* FREERTOS_CONFIG_H */ \ No newline at end of file diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/at_parser.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/at_parser.h new file mode 100644 index 00000000..e5bda319 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/at_parser.h @@ -0,0 +1,81 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +#ifndef _AT_PARSER_H_ +#define _AT_PARSER_H_ + +#include "ez_sio.h" +#include "embARC_error.h" + +#define AT_OK 0 +#define AT_ERROR -1 +#define AT_OK_STR "OK" +#define AT_ERROR_STR "ERROR" + +#define AT_RX_BUFSIZE 512 +#define AT_TX_BUFSIZE 128 + +#define AT_NORMAL_TIMEOUT 100 +#define AT_LONG_TIMEOUT 5000 +#define AT_EXTRA_TIMEOUT 20000 + +typedef enum { + AT_LIST, + AT_READ, + AT_WRITE, + AT_EXECUTE +} AT_MODE; + +typedef char *AT_STRING; + +/** AT_PARSER type */ +typedef struct { + uint32_t uart_id; + EZ_SIO *psio; +} AT_PARSER_DEF, *AT_PARSER_DEF_PTR; + +#define AT_PARSER_DEFINE(NAME, UART_ID) \ + AT_PARSER_DEF __ ## NAME = { \ + .uart_id = UART_ID, \ + .psio = NULL, \ + }; \ + AT_PARSER_DEF_PTR NAME = &__ ## NAME + +int32_t at_parser_init(AT_PARSER_DEF_PTR obj, uint32_t baudrate); +void at_parser_deinit(AT_PARSER_DEF_PTR obj); +int32_t at_read(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt); +int32_t at_write(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt); +int32_t at_send_cmd(AT_PARSER_DEF_PTR obj, AT_MODE mode, AT_STRING command, ...); +int32_t at_get_reply(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout); +int32_t at_get_reply1(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout); + +int32_t at_test(AT_PARSER_DEF_PTR obj); + +#endif /*_AT_PARSER_H_*/ \ No newline at end of file diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard.h new file mode 100644 index 00000000..6f602851 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard.h @@ -0,0 +1,63 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +/** + * \file + * \ingroup BOARD_EMSK_DRV_MID_FS_SDCARD + * \brief header file of sdcard driver for fatfs of emsk board + */ + +/** + * \addtogroup BOARD_EMSK_DRV_MID_FS_SDCARD + * @{ + */ +#ifndef _EMSK_SDCARD_H_ +#define _EMSK_SDCARD_H_ +#include "embARC_toolchain.h" + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "emsk_sdcard_spi.h" + +#define EMSK_SDCARD_0_DRVID (0) + +#endif /* MID_FATFS */ + +#ifdef __cplusplus +extern "C" { +#endif + +extern void emsk_sdcard_1ms_update(void); + +#ifdef __cplusplus +} +#endif + +#endif /** _EMSK_SDCARD_H_ */ + +/** @} end of group BOARD_EMSK_DRV_MID_FS_SDCARD */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard_spi.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard_spi.h new file mode 100644 index 00000000..1d183283 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/emsk_sdcard/emsk_sdcard_spi.h @@ -0,0 +1,71 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +/** + * \file + * \ingroup BOARD_EMSK_DRV_MID_FS_SDCARD_SPI + * \brief header file of sdcard driver using spi interface for fatfs + */ + +/** + * \addtogroup BOARD_EMSK_DRV_MID_FS_SDCARD_SPI + * @{ + */ +#ifndef _EMSK_SDCARD_SPI_H_ +#define _EMSK_SDCARD_SPI_H_ + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "ff_diskio.h" + +#define USE_EMSK_SDCARD_SPI_0 1 + +#define SDCARD_SPI_FREQ_400K (400000) /*!< sdcard spi freq:400KHz */ +#define SDCARD_SPI_FREQ_1M (1000000) /*!< sdcard spi freq:2MHz */ +#define SDCARD_SPI_FREQ_2M (2000000) /*!< sdcard spi freq:2MHz */ +#define SDCARD_SPI_FREQ_4M (4000000) /*!< sdcard spi freq:4MHz */ + +#ifdef __cplusplus +extern "C" { +#endif + +#if USE_EMSK_SDCARD_SPI_0 +extern FATFS_DISKIO sdcard_spi_0_diskio; +#endif /* USE_EMSK_SDCARD_SPI_0 */ + +#ifdef __cplusplus +} +#endif + + + +#endif /* MID_FATFS */ + +#endif /** _EMSK_SDCARD_SPI_H_ */ + +/** @} end of group BOARD_EMSK_DRV_MID_FS_SDCARD_SPI */ \ No newline at end of file diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/esp8266.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/esp8266.h new file mode 100644 index 00000000..6cca0a40 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/esp8266.h @@ -0,0 +1,101 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +#ifndef _ESP8266_H_ +#define _ESP8266_H_ + +#include "at_parser.h" +#include "board.h" + + +/** uart id which esp8266 uses */ +#ifndef ESP8266_UART_ID //you can define this at board header file (e.g. emsk.h) +#if defined(BOARD_EMSK) || defined(BOARD_HSDK) +#define ESP8266_UART_ID DW_UART_0_ID +#elif defined(BOARD_EMSDP)|| defined(BOARD_IOTDK) +#define ESP8266_UART_ID DFSS_UART_1_ID +#else +#warning esp8266 is not supported on this board! +#endif +#endif + +typedef enum{ + ESP8266_STA=1, + ESP8266_AP, + ESP8266_AP_STA +}ESP8266_WIFI_MODE; + +typedef enum{ + ESP8266_NORMALSEND=0, + ESP8266_PASSTHR +}ESP8266_TRANS_MODE; + +typedef struct{ + AT_PARSER_DEF_PTR p_at; + //add other members here if needed + bool wifi_connected; + ESP8266_TRANS_MODE trans_mode; +}ESP8266_DEF, *ESP8266_DEF_PTR; + +#define ESP8266_DEFINE(NAME) \ + ESP8266_DEF __ ## NAME = { \ + .p_at = NULL, \ + }; \ + ESP8266_DEF_PTR NAME = &__ ## NAME + +int32_t esp8266_init(ESP8266_DEF_PTR obj, uint32_t baudrate); +void esp8266_deinit(ESP8266_DEF_PTR obj); +int32_t esp8266_test(ESP8266_DEF_PTR obj); + +int32_t esp8266_wifi_mode_get(ESP8266_DEF_PTR obj, bool flash); +int32_t esp8266_wifi_mode_set(ESP8266_DEF_PTR obj, ESP8266_WIFI_MODE, bool flash); +int32_t esp8266_wifi_scan(ESP8266_DEF_PTR obj, char *rcv_buf, char *ssid); +int32_t esp8266_wifi_connect(ESP8266_DEF_PTR obj, AT_STRING ssid, AT_STRING pwd, bool flash); +int32_t esp8266_wifi_disconnect(ESP8266_DEF_PTR obj); +int32_t esp8266_address_get(ESP8266_DEF_PTR obj); +int32_t esp8266_conn_status(ESP8266_DEF_PTR obj); + +int32_t esp8266_dns_lookup(ESP8266_DEF_PTR obj, char *domain_ip, AT_STRING domain_name); +int32_t esp8266_tcp_connect(ESP8266_DEF_PTR obj, AT_STRING server_IP, uint32_t port); +int32_t esp8266_tcp_server_open(ESP8266_DEF_PTR obj, uint32_t port); +int32_t esp8266_tcp_server_close(ESP8266_DEF_PTR obj, uint32_t port); + +int32_t esp8266_transmission_mode(ESP8266_DEF_PTR obj, ESP8266_TRANS_MODE mode); +int32_t esp8266_passthr_start(ESP8266_DEF_PTR obj); +int32_t esp8266_passthr_end(ESP8266_DEF_PTR obj); +int32_t esp8266_passthr_write(ESP8266_DEF_PTR obj, char *buf, uint32_t cnt); +uint32_t esp8266_normal_write(ESP8266_DEF_PTR obj, char *buf, uint32_t cnt); +uint32_t esp8266_connect_write(ESP8266_DEF_PTR obj, char *buf, char *connect, uint32_t cnt); +int32_t esp8266_read(ESP8266_DEF_PTR obj, char *buf, uint32_t timeout); +uint32_t esp8266_nread(ESP8266_DEF_PTR obj, char *buf, uint32_t n); + +int32_t esp8266_CIPCLOSE(ESP8266_DEF_PTR obj, char *conn_buf); + +#endif \ No newline at end of file diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard.h new file mode 100644 index 00000000..310aa1f3 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard.h @@ -0,0 +1,50 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#ifndef _IOTDK_SDCARD_H_ +#define _IOTDK_SDCARD_H_ +#include "embARC_toolchain.h" + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "sdcard_sdio.h" + +#define IOTDK_SDCARD_0_DRVID (0) + +#endif /* MID_FATFS */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /** _IOTDK_SDCARD_H_ */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard_sdio.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard_sdio.h new file mode 100644 index 00000000..4ec5cd07 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/iotdk_sdcard/sdcard_sdio.h @@ -0,0 +1,53 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#ifndef _IOTDK_SDCARD_SDIO_H_ +#define _IOTDK_SDCARD_SDIO_H_ + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "ff_diskio.h" + +#define USE_IOTDK_SDCARD_SDIO_0 1 + + +#ifdef __cplusplus +extern "C" { +#endif + +#if USE_IOTDK_SDCARD_SDIO_0 +extern FATFS_DISKIO sdcard_sdio_0_diskio; +#endif /* USE_IOTDK_SDCARD_SDIO_0 */ + +#ifdef __cplusplus +} +#endif + +#endif /* MID_FATFS */ + +#endif /** _IOTDK_SDCARD_SDIO_H_ */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/state.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/state.h new file mode 100644 index 00000000..c1a5049e --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/inc/state.h @@ -0,0 +1,8 @@ +void state_III(); +void state_IID(); +void state_IDD(); +void state_DDD(); +void state_DDI(); +void state_DID(); +void state_DII(); +void state_IDI(); diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.c new file mode 100644 index 00000000..f45ee4b1 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.c @@ -0,0 +1,71 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#include "embARC_toolchain.h" + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "ff_diskio.h" +#include "sdcard.h" +#include + +uint32_t diskio_get_fattime(void) +{ + struct tm *p_tm; + time_t cur_time; + uint32_t fattime; + + cur_time = time(NULL); + p_tm = localtime(&cur_time); + fattime = ((p_tm->tm_year+1900-1980)&0x7f) << 25; + fattime |= ((p_tm->tm_mon+1)&0xf) << 21; + fattime |= ((p_tm->tm_mday)&0x1f) << 16; + fattime |= ((p_tm->tm_hour)&0x1f) << 11; + fattime |= ((p_tm->tm_min)&0x3f) << 5; + fattime |= ((p_tm->tm_sec>>1)&0x1f); + + return fattime; +} + +FATFS_DISKIO *get_fatfs_diskio(uint32_t drvid) +{ + switch (drvid) { +#if (USE_IOTDK_SDCARD_SDIO_0 ) + + case IOTDK_SDCARD_0_DRVID: + return &sdcard_sdio_0_diskio; + break; +#endif + + default: + break; + } + + return NULL; +} +#endif /* MID_FATFS */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.h new file mode 100644 index 00000000..310aa1f3 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard.h @@ -0,0 +1,50 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#ifndef _IOTDK_SDCARD_H_ +#define _IOTDK_SDCARD_H_ +#include "embARC_toolchain.h" + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "sdcard_sdio.h" + +#define IOTDK_SDCARD_0_DRVID (0) + +#endif /* MID_FATFS */ + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /** _IOTDK_SDCARD_H_ */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.c new file mode 100644 index 00000000..041d15b6 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.c @@ -0,0 +1,105 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include +#include + +#include "arc.h" +#include "arc_builtin.h" +#include "embARC_toolchain.h" +#include "embARC_error.h" +#include "arc_exception.h" + +#include "board.h" + +#ifdef ENABLE_OS +#include "os_hal_inc.h" +#endif + +#include "ff_diskio.h" +#include "ff_sdcard.h" + +#include "sdcard_sdio.h" + + +#define SDCARD_SDIO_ID 0 + +#if (USE_IOTDK_SDCARD_SDIO_0) + +static FS_SDCARD_SDIO_CTRL sdcard_sdio0 = { + .id = 0, + .drv_status = STA_NOINIT +}; + +static int32_t sdcard_sdio_0_diskio_initialize(void) +{ + sdcard_sdio0.host = (void *)sdio_get_dev(SDCARD_SDIO_ID); + return sdcard_sdio_diskio_initialize(&sdcard_sdio_0_diskio); +} + +static int32_t sdcard_sdio_0_diskio_status(void) +{ + return sdcard_sdio_diskio_status(&sdcard_sdio_0_diskio); +} + +static int32_t sdcard_sdio_0_diskio_read(void *buf, uint32_t sector, uint32_t count) +{ + return sdcard_sdio_diskio_read(&sdcard_sdio_0_diskio, buf, sector, count); +} + +static int32_t sdcard_sdio_0_diskio_write(const void *buf, uint32_t sector, uint32_t count) +{ + return sdcard_sdio_diskio_write(&sdcard_sdio_0_diskio, buf, sector, count); +} + +static int32_t sdcard_sdio_0_diskio_ioctl(uint32_t cmd, void *buf) +{ + return sdcard_sdio_diskio_ioctl(&sdcard_sdio_0_diskio, cmd, buf); +} + +static void sdcard_sdio_0_diskio_timerproc(void) +{ + return; +} + + +FATFS_DISKIO sdcard_sdio_0_diskio = { + (void *) &sdcard_sdio0, + sdcard_sdio_0_diskio_initialize, + sdcard_sdio_0_diskio_status, + sdcard_sdio_0_diskio_read, + sdcard_sdio_0_diskio_write, + sdcard_sdio_0_diskio_ioctl, + sdcard_sdio_0_diskio_timerproc +}; + +#endif /* USE_IOTDK_SDCARD_SDIO_0 */ + +#endif /* MID_FATFS */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.h b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.h new file mode 100644 index 00000000..4ec5cd07 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/iotdk_sdcard/sdcard_sdio.h @@ -0,0 +1,53 @@ +/* ------------------------------------------ + * Copyright (c) 2017, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#ifndef _IOTDK_SDCARD_SDIO_H_ +#define _IOTDK_SDCARD_SDIO_H_ + +#ifdef MID_FATFS /* only available when enable fatfs middleware */ +#include "ff_diskio.h" + +#define USE_IOTDK_SDCARD_SDIO_0 1 + + +#ifdef __cplusplus +extern "C" { +#endif + +#if USE_IOTDK_SDCARD_SDIO_0 +extern FATFS_DISKIO sdcard_sdio_0_diskio; +#endif /* USE_IOTDK_SDCARD_SDIO_0 */ + +#ifdef __cplusplus +} +#endif + +#endif /* MID_FATFS */ + +#endif /** _IOTDK_SDCARD_SDIO_H_ */ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/main.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/main.c new file mode 100644 index 00000000..eba74f0d --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/main.c @@ -0,0 +1,998 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#include +#include +#include +#include +// EMSK +#include +#include + +// IoTDk +// #include +// #include + + +#include +#include + +#include +#include + + + + +#define WIFI_SSID "\"embarc\"" +#define WIFI_PWD "\"12344321\"" + +static char http_get[] = "+IPD,0,"; +static char http_IDP[] = "+IPD,"; +static char http_server_buf[2048]; +// static char http_sddata_buf[2048]; +static char data_request[] = "Upload SD Card Data"; + + +char data_save[100]; +char flag_buff[3]; // State of ABC regions. +char vaild_buff[1]; + +int line; +char *time_get_1; +char *time_get_2; + +struct DATA { + char year[4]; + char month[2]; + char day[2]; + char hour[2]; + char minute[2]; + char second[2]; + int people_num; + int people_num_pre; // historical data + int people_num_pre_pre; // Earlier historical data + int people_num_buf; + int people_num_pre_buf; +} device_A, device_B, device_C; + + + +char *num_get; // Number of people +int total_people_num; // The total number of people +int total_people_num_pre; // historical data +int total_people_num_vaild; // Valid data for non-outliers + +char Month_trans[] = "month"; +char Date_trans; +char *Warning = "Warning! Too many people in the area! "; +char *data; +char *time_all; +char *time_year; +char *time_month; +char *time_day; +char *time_hour; +char *time_minute; +char *time_second; +char *send_to_server_first = " There are "; +char *send_to_server_last = " people in the area. At "; +char *colon = ":"; +char *full_stop = "."; + + + + +/************************************************************/ +// Create queues to calculate cumulative values +struct Queue { + int *pBase; + int front; + int rear; + int len; +}; + +void initQueue(struct Queue * q, int len); +bool inQueue(struct Queue * q, int total_people_num); +bool outQueue(struct Queue * q); +bool isEmpty(struct Queue * q); +bool isFull(struct Queue * q); +void printList(struct Queue * q); +void clearQueue(struct Queue * q); +void average(struct Queue * q, int* sum, float* ave); +void variance(struct Queue * q, float* var, float ave); + +// Abnormal Data Processing +int abnormal_data_processing(float var, float ave); +// Data Storage in SD Card +int data_storage(char *buff); +// Data Storage in SD Card +int data_save_send(char *buff, int line); +// Output analysis results and population status +void print_process(char *buff); + +int data_retransmit(char *buff); +// Converts an integer type to a string type +char *itoa(int num, char *str, int radix); +// Take a piece of data from a string +char* substring(char* ch, int pos, int length); +// String concatenation +char *word_strcat(char *first_word, char *mid_word, char *last_word); + +int data_save_send(char *buff, int line); +int data_read(char *buff, int line); + + +// Using Mean and Variance to Find Outlier Data +int sum = 0; // sum total +float ave = 0.0; // average value +float var = 0.0; // variance + + +char *conn_buf; + + +/*******************************************************************/ + +int main(void) { + // char *conn_buf; + // ESP8266 Init + EMBARC_PRINTF("========================== Init ===" + "=========================\n"); + + ESP8266_DEFINE(esp8266); + esp8266_init(esp8266, UART_BAUDRATE_115200); + + at_test(esp8266->p_at); + board_delay_ms(100, 1); + + // Set Mode + EMBARC_PRINTF("============================ Set Mode ===" + "=========================\n"); + + esp8266_wifi_mode_get(esp8266, false); + board_delay_ms(100, 1); + esp8266_wifi_mode_set(esp8266, 3, false); + board_delay_ms(100, 1); + + // Connect WiFi + EMBARC_PRINTF("============================ Connect WiFi ===" + "=========================\n"); + + do { + esp8266_wifi_scan(esp8266, http_server_buf, WIFI_SSID); + EMBARC_PRINTF("Searching for WIFI %s ......\n", WIFI_SSID); + board_delay_ms(100, 1); + } while (strstr(http_server_buf, WIFI_SSID) == NULL); + + EMBARC_PRINTF("WIFI %s found! Try to connect\n", WIFI_SSID); + + while (esp8266_wifi_connect(esp8266, WIFI_SSID, WIFI_PWD, false) != AT_OK) { + EMBARC_PRINTF("WIFI %s connect failed\n", WIFI_SSID); + board_delay_ms(100, 1); + } + + EMBARC_PRINTF("WIFI %s connect succeed\n", WIFI_SSID); + + // Creat Server + EMBARC_PRINTF("============================ Connect Server ====" + "========================\n"); + + esp8266_tcp_server_open(esp8266, 80); + + // Show IP + EMBARC_PRINTF("============================ Show IP ===" + "=========================\n"); + + esp8266_address_get(esp8266); + board_delay_ms(100, 1); + + char http_server_buf_1[2048]; + + int data_process(char *buff); + + +// Initialize queues as data buffers + int* p1 = ∑ + float* p2 = &ave; + float* p3 = &var; + struct Queue q; + initQueue(&q, 12); + + + while (1) { + // Initialize array + memset(http_server_buf, 0, sizeof(http_server_buf)); + memset(http_server_buf_1, 0, sizeof(http_server_buf_1)); + // Receive WIFI data + at_read(esp8266->p_at , http_server_buf , 1000); + // board_delay_ms(1000, 1); + // strcpy(http_server_buf_1, http_server_buf); + snprintf(http_server_buf_1, sizeof(http_server_buf_1), "%s", + http_server_buf); + data_process(http_server_buf); + +// cloud_side_collaborative_rocessing(http_server_buf,total_people_num); + + if (strstr(http_server_buf, http_get) != NULL) { + inQueue(&q, total_people_num); + outQueue(&q); + // printList(&q); + average(&q, p1, p2); + variance(&q, p3, ave); + } +// Send the processed data to the cloud + // cloud_side_collaborative_rocessing(http_server_buf,total_people_num); + if (strstr(http_server_buf, http_get) != NULL) { + // char *char_total_people_num[4]; + char char_total_people_num[4]; + abnormal_data_processing(var, ave); + // EMBARC_PRINTF("%d,velid", total_people_num_vaild); + + if (total_people_num_vaild > 2000) { + EMBARC_PRINTF("\nThere are %d people in the area." + "\n ", total_people_num_vaild); + EMBARC_PRINTF("Warning! Too many people in the area! \n \n"); + + int length = 58; + itoa(total_people_num_vaild, char_total_people_num, 10); + char *send_to_server = + (char *)malloc(strlen(send_to_server_first) + + strlen(char_total_people_num)); + + snprintf(send_to_server, sizeof(send_to_server), "%s", + send_to_server_first); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, char_total_people_num); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, send_to_server_last); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_hour); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, colon); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_minute); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, colon); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_second); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, full_stop); + + send_to_server[length] = '\0'; + + EMBARC_PRINTF("\n======================= Data sent to the cloud" + "============================\n\n"); + + conn_buf = strstr(esp8266, http_IDP) + 5; + *(conn_buf + 1) = 0; + esp8266_connect_write(esp8266, send_to_server, conn_buf, 50); + board_delay_ms(100, 1); + esp8266_connect_write(esp8266, Warning, conn_buf, 40); + board_delay_ms(100, 1); + + EMBARC_PRINTF("\n=========================== Send finished ===" + "=============================\n\n"); +// The number of people below the threshold will not be reported to the cloud + } else if (total_people_num_vaild > 500 + && total_people_num_vaild < 2000) { + EMBARC_PRINTF("There are %d people in the " + "area. ", total_people_num_vaild); + + int length = 58; + itoa(total_people_num_vaild, char_total_people_num, 10); + char *send_to_server = + (char *) malloc(strlen(send_to_server_first) + + strlen(char_total_people_num)); + snprintf(send_to_server, sizeof(send_to_server), "%s", + send_to_server_first); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, char_total_people_num); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, send_to_server_last); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_hour); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, colon); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_minute); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, colon); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, time_second); + snprintf(send_to_server, sizeof(send_to_server), "%s%s", + send_to_server, full_stop); + + + // EMBARC_PRINTF("%s",send_to_server); + + send_to_server[length] = '\0'; + EMBARC_PRINTF("\n======================= Data sent to the cloud" + "===========================\n\n"); + + conn_buf = strstr(http_server_buf, http_IDP) + 5; + *(conn_buf + 1) = 0; + esp8266_connect_write(esp8266, send_to_server, conn_buf, 50); + board_delay_ms(50, 1); + + EMBARC_PRINTF("\n=========================== Send finished" + " ================================\n\n"); + } + } + board_delay_ms(500, 1); + } + + return E_OK; +} + +// Data aggregation, processing and analysis +int data_process(char *buff) { + if (strstr(buff, http_get) != NULL) { + time_year = substring(buff, 17, 4); + time_month = substring(buff, 21, 2); + time_day = substring(buff, 23, 2); + time_hour = substring(buff, 25, 2); + time_minute = substring(buff, 27, 2); + time_second = substring(buff, 29, 2); + time_all = substring(buff, 17, 31); + + if (strstr(time_month, "01") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Jan");} + if (strstr(time_month, "02") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Feb");} + if (strstr(time_month, "03") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Mar");} + if (strstr(time_month, "04") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Apr");} + if (strstr(time_month, "05") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "May");} + if (strstr(time_month, "06") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Jun");} + if (strstr(time_month, "07") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Jul");} + if (strstr(time_month, "08") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Agu");} + if (strstr(time_month, "09") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Sept");} + if (strstr(time_month, "10") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Oct");} + if (strstr(time_month, "11") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Nov");} + if (strstr(time_month, "12") != NULL) + {snprintf(Month_trans, sizeof(Month_trans), "%s", "Dec");} + + switch (buff[12]) { + case 'A': { + EMBARC_PRINTF("\n============================== Receive Data ===" + "==============================\n\n"); + EMBARC_PRINTF("%s\n", buff); + EMBARC_PRINTF("\n============================ Receive Finished ===" + "============================\n"); + EMBARC_PRINTF("\n========================== Start Data Analysis ===" + "===========================\n"); + // int people_num_pre; + num_get = substring(buff, 13, 4); + // String type to integer type + device_A.people_num = atoi(num_get); + memcpy(data_save, &buff[12], 15); + EMBARC_PRINTF("\n============================= Number of people ===" + "=============================\n\n"); + EMBARC_PRINTF("Number of people: The number of people" + " in area A is:%04d.\r\n", device_A.people_num); + EMBARC_PRINTF("Number of people: The number of people" + " in area B is:%04d.\r\n", device_B.people_num); + EMBARC_PRINTF("Number of people: The number of people" + " in area C is:%04d.\r\n", device_C.people_num); + + + if (device_A.people_num > device_A.people_num_pre_buf) + { EMBARC_PRINTF("\n============================ Crowd status" + " ================================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people" + " in area A has increased. \r\n"); + } + if (device_A.people_num < device_A.people_num_pre_buf) + { EMBARC_PRINTF("\n============================= Crowd status" + " =================================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people" + " in area A has decreased.\r\n"); + } + (device_A.people_num > device_A.people_num_pre_buf) ? ( + flag_buff[0] = 'I') : (flag_buff[0] = 'D'); + + device_A.people_num_pre_pre = device_A.people_num_pre; + device_A.people_num_pre = device_A.people_num_buf; + device_A.people_num_pre_buf = device_A.people_num; + device_A.people_num_buf = device_A.people_num; + + + + if (device_A.people_num > device_A.people_num_pre && + device_A.people_num_pre > device_A.people_num_pre_pre) + { EMBARC_PRINTF("\n========================= Crowd status " + "estimation =============================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people" + " in area A may continue increased.\r\n"); + } + if (device_A.people_num < device_A.people_num_pre && + device_A.people_num_pre < device_A.people_num_pre_pre) + { EMBARC_PRINTF("\n========================= Crowd status " + "estimation =============================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people" + " in area A may continue decreased.\r\n"); + } + // square[i++] = device_A.last_num; + // sprintf(&data_save[14], "A:%04d\r\n", device_A.people_num); + EMBARC_PRINTF(data_save); + total_people_num_pre = total_people_num; + total_people_num = device_A.people_num + + device_B.people_num + device_C.people_num; + + data_storage(buff); + data_save_send(buff, line); + print_process(flag_buff); + board_delay_ms(500, 1); + + EMBARC_PRINTF("\nNumber of people: The total number of people" + " in the current region is: %04d , " + " ,at %s,%s,%s, %s:%s:%s,\n", + total_people_num, time_day, Month_trans, time_year, + time_hour, time_minute, time_second); + EMBARC_PRINTF("\n======================== Data Analysis Finished" + " =============================\n"); + } break; + + case 'B': { + EMBARC_PRINTF("\n============================= Receive Data" + " ================================\n\n"); + EMBARC_PRINTF("%s\n", buff); + EMBARC_PRINTF("\n=========================== Receive Finished" + " ==============================\n"); + EMBARC_PRINTF("\n========================= Start Data Analysis" + " =============================\n"); + // int people_num_pre; + num_get = substring(buff, 13, 4); + // String type to integer type + device_B.people_num = atoi(num_get); + memcpy(data_save, &buff[12], 15); + EMBARC_PRINTF("\n========================== Number of people" + " =============================\n\n"); + EMBARC_PRINTF("Number of people: The number of people in area" + " A is:%04d.\r\n", device_A.people_num); + EMBARC_PRINTF("Number of people: The number of people in area" + " B is:%04d.\r\n", device_B.people_num); + EMBARC_PRINTF("Number of people: The number of people in area" + " C is:%04d.\r\n", device_C.people_num); + + + + if (device_B.people_num > device_B.people_num_pre_buf) + { EMBARC_PRINTF("\n========================== Crowd status" + " =============================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area B" + " has increased. \r\n"); + } + if (device_B.people_num < device_B.people_num_pre_buf) + { EMBARC_PRINTF("\n=========================== Crowd status" + " ===============================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area B" + " has decreased.\r\n"); + } + (device_B.people_num > device_B.people_num_pre_buf) ? ( + flag_buff[1] = 'I') : (flag_buff[1] = 'D'); + + device_B.people_num_pre_pre = device_B.people_num_pre; + device_B.people_num_pre = device_B.people_num_buf; + device_B.people_num_pre_buf = device_B.people_num; + device_B.people_num_buf = device_B.people_num; + + + + if (device_B.people_num > device_B.people_num_pre && + device_B.people_num_pre > device_B.people_num_pre_pre) + { EMBARC_PRINTF("\n====================== Crowd status estimation" + " ==========================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area B" + " may continue increased.\r\n"); + } + if (device_B.people_num < device_B.people_num_pre && + device_B.people_num_pre < device_B.people_num_pre_pre) + { EMBARC_PRINTF("\n====================== Crowd status estimation" + " ==========================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area B" + " may continue decreased.\r\n"); + } + + // square[i++] = device_A.last_num; + // sprintf(&data_save[14], "B:%04d\r\n", device_B.people_num); + EMBARC_PRINTF(data_save); + total_people_num_pre = total_people_num; + total_people_num = device_A.people_num + + device_B.people_num + device_C.people_num; + data_storage(buff); + data_save_send(buff, line); + print_process(flag_buff); + board_delay_ms(500, 1); + EMBARC_PRINTF("\nNumber of people: The total number of people" + " in the current region is: %04d ," + " ,at %s,%s,%s, %s:%s:%s,\n", + total_people_num, time_day, Month_trans, + time_year, time_hour, time_minute, time_second); + EMBARC_PRINTF("\n====================== Data Analysis Finished" + " =============================\n"); + } break; + + case 'C': { + EMBARC_PRINTF("\n============================== Receive Data" + " =================================\n\n"); + EMBARC_PRINTF("%s\n", buff); + EMBARC_PRINTF("\n============================ Receive Finished" + " ===============================\n"); + EMBARC_PRINTF("\n========================== Start Data Analysis" + " ==============================\n"); + // int people_num_pre; + num_get = substring(buff, 13, 4); + // String type to integer type + device_C.people_num = atoi(num_get); + memcpy(data_save, &buff[12], 15); + EMBARC_PRINTF("\n============================= Number of people ===" + "=============================\n\n"); + EMBARC_PRINTF("Number of people: The number of people in area" + " A is:%04d.\r\n", device_A.people_num); + EMBARC_PRINTF("Number of people: The number of people in area" + " B is:%04d.\r\n", device_B.people_num); + EMBARC_PRINTF("Number of people: The number of people in area" + " C is:%04d.\r\n", device_C.people_num); + + EMBARC_PRINTF("\n============================== Crowd status" + " ==================================\n\n"); + if (device_C.people_num > device_C.people_num_pre_buf) + { EMBARC_PRINTF("\n============================ Crowd status" + " ================================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area C" + " has increased. \r\n"); + } + if (device_C.people_num < device_C.people_num_pre_buf) + { EMBARC_PRINTF("\n============================ Crowd status" + " ================================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area C" + " has decreased.\r\n"); + } + (device_C.people_num > device_C.people_num_pre_buf) ? ( + flag_buff[2] = 'I') : (flag_buff[2] = 'D'); + + device_C.people_num_pre_pre = device_C.people_num_pre; + device_C.people_num_pre = device_C.people_num_buf; + device_C.people_num_pre_buf = device_C.people_num; + device_C.people_num_buf = device_C.people_num; + + + + if (device_C.people_num > device_C.people_num_pre && + device_C.people_num_pre > device_C.people_num_pre_pre) + { EMBARC_PRINTF("\n========================= Crowd status" + " estimation ===========================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area C" + " may continue increased.\r\n"); + } + if (device_C.people_num < device_C.people_num_pre && + device_C.people_num_pre < device_C.people_num_pre_pre) + { EMBARC_PRINTF("\n========================= Crowd status" + " estimation ===========================\n\n"); + EMBARC_PRINTF("Crowd status: The number of people in area C" + " may continue decreased.\r\n"); + } + // square[i++] = device_A.last_num; + // sprintf(&data_save[14], "C:%04d\r\n", device_C.people_num); + EMBARC_PRINTF(data_save); + total_people_num_pre = total_people_num; + total_people_num = device_A.people_num + device_B.people_num + + device_C.people_num; + data_storage(buff); + data_save_send(buff, line); + print_process(flag_buff); + board_delay_ms(500, 1); + EMBARC_PRINTF("\nNumber of people: The total number of people" + " in the current region is: %04d , ,at %s,%s,%s," + " %s:%s:%s,\n", total_people_num, time_day, + Month_trans, time_year, time_hour, time_minute, + time_second); + EMBARC_PRINTF("\n======================== Data Analysis Finished" + " =============================\n"); + } break; + + default: break; + } + } + return total_people_num; +} + +// Abnormal Data Processing +int abnormal_data_processing(float var, float ave) { + if (total_people_num < ave + 5 * var || total_people_num > ave - 5 * var) { + total_people_num_vaild = total_people_num; + } else { + total_people_num_vaild = total_people_num_vaild; + } + + // EMBARC_PRINTF("%dtotal_people_num", total_people_num); + // EMBARC_PRINTF("%dtotal_people_num_pre", total_people_num_pre); + // EMBARC_PRINTF("%dtotal_people_num_vaild", total_people_num_vaild); + (ave - 5 * var < total_people_num < ave + 5 * var) ? ( + vaild_buff[0] = 'T') : (vaild_buff[0] = 'F'); + return total_people_num_vaild; +} + +// Data Storage in SD Card +int data_storage(char *buff) { + FILE *fp = fopen("/sd/data_storage.txt", "a"); + fprintf(fp, "%s\r\n", buff); + fprintf(fp, "A:%04d,B:%04d,C:%04d,total:%04d\r\n", device_A.people_num, + device_B.people_num, device_C.people_num, total_people_num); + fclose(fp); + EMBARC_PRINTF("\n============================= Stores the data" + " =================================\n\n"); + EMBARC_PRINTF(" Data successfully saved!\r\n"); + return E_OK; +} + + + +int data_save_send(char *buff, int line) { + int time_all_1; + int time_all_2; + line++; + time_get_1 = substring(buff, 17, 9); + time_get_1 = substring(buff, 27, 5); + time_all_1 = atoi(time_get_1); + time_all_2 = atoi(time_get_2); // String type to integer type + + FILE *fp = fopen("/sd/data_save.txt", "a"); + fprintf(fp, "%4d%9d%5d\r\n", total_people_num, time_all_1, time_all_2); + fprintf(fp, "%s", time_get_1); + fprintf(fp, "%s", time_get_2); + fclose(fp); + return E_OK; +} +/*int data_read(char *buff, int line) { + FILE *fp = fopen("/sd/data_save.txt", "r+"); + int size = 20 * line; + int read_buff[size]; + // printf("\n***Test Begin***\n"); + for (int i = 0; i < size; i++) + { + read_buff[i] = fgetc( fp ); + // printf("%c",read_buff[i] ); + } + + fclose(fp); + return E_OK; + +}*/ + + +void print_process(char *buff) { + // The number of peoplein A,B and C increase. + if (memcmp(buff, "III", 3) == 0) { + EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: The crowd is gathering. \n"); + state_III(); + } + // The number of peoplein A,B and C decrease(DDD). + if (memcmp(buff, "DDD", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: The crowd is evacuating. \n"); + state_DDD(); + } + if (memcmp(buff, "IID", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area C" + " to area A and B.\n"); + state_IID(); + } + if (memcmp(buff, "IDI", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area" + " B to area A and C \n"); + state_IDI(); + } + if (memcmp(buff, "DII", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area" + " A to area B and C. \n"); + state_DII(); + } + if (memcmp(buff, "DDI", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area" + " A and B to area C \n"); + state_DDI(); + } + if (memcmp(buff, "DID", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area" + " A and C to area B \n"); + state_DID(); + } + if (memcmp(buff, "IDD", 3) == 0) + { EMBARC_PRINTF("\n============================= Flow of crowd" + " =================================\n\n"); + EMBARC_PRINTF("Flow of crowd: Crowds move from area" + " B and C to area A \n"); + state_IDD(); + } +} + + + +/*int data_retransmit(char *buff) { + if (strstr(buff, data_request) != NULL) + { + + } + + return E_OK; +} +*/ + +// Converts an integer type to a string type +char *itoa(int num, char *str, int radix) { + char index[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + unsigned unum; + int i = 0, j, k; + if (radix == 10 && num < 0) { + unum = (unsigned) - num; + str[i++] = '-'; + } else { + unum = (unsigned)num; + } + do { + str[i++] = index[unum % (unsigned)radix]; + unum /= radix; + } while (unum); + str[i] = '\0'; + if (str[0] == '-') { + k = 1; + } else { + k = 0; + } + char temp; + for (j = k; j <= (i - k - 1) / 2.0; j++) { + temp = str[j]; + str[j] = str[i - j - 1]; + str[i - j - 1] = temp; + } + return str; +} + + +// Take a piece of data from a string +char* substring(char* ch, int pos, int length) { + char* pch = ch; + char* subch = (char*) calloc(sizeof(char), length + 1); + int i; + pch = pch + pos; + for (i = 0; i < length; i++) { + subch[i] = *(pch++); + } + subch[length] = '\0'; + return subch; +} + +// String concatenation +/*char *word_strcat(char *first_word, char *mid_word, char *last_word) { + int length = 38; + char *send_to_server_mid = + malloc(strlen(first_word) + + strlen(mid_word)); + strcpy(send_to_server_mid, first_word); + strcat(send_to_server_mid, mid_word); + + char *send_to_server_all = + malloc(strlen(send_to_server_mid) + + strlen(last_word)); + strcpy(send_to_server_all, send_to_server_mid); + strcat(send_to_server_all, last_word); + + send_to_server_all[length] = '\0'; + return send_to_server_all; + EMBARC_PRINTF("%s\n", send_to_server_all); +}*/ +// Create queues to calculate cumulative values +void initQueue(struct Queue * q, int len) { + q->pBase = (int *)malloc(sizeof(int) * len); + q->len = len; + q->front = 0; + q->rear = 0; +} + +bool inQueue(struct Queue * q, int total_people_num) { + if (isFull(q)) { + return false; + } + int* p = q->pBase + q->rear; + *p = total_people_num; + q->rear = (q->rear + 1) % q->len; + return true; +} + +bool outQueue(struct Queue * q) { + if (isEmpty(q)) { + return false; + } + + if (isFull(q) == 0) { + return false; + } + + if (isFull(q)) { + printf("output:%d\n", *(q->pBase + q->front)); + q->front = (q->front + 1) % q->len; + return true; + } else { + return false; + } +} + +bool isEmpty(struct Queue * q) { + if (q->front == q->rear) { + printf("fifo empty\n"); + return true; + } + return false; +} + +bool isFull(struct Queue * q) { + if ((q->rear + 1) % q->len == q->front) { + printf("fifo full\n"); + return true; + } + return false; +} + +void printList(struct Queue * q) { + int temp = q->front; + // int sum = 0; + while ((temp != q->rear) && !isEmpty(q)) { + printf("%d\n", *(q->pBase + temp)); + temp = (temp + 1) % q->len; + } +} + +void clearQueue(struct Queue * q) { + while (!isEmpty(q)) { + q->front = (q->front + 1) % q->len; + } +} +void average(struct Queue * q, int* sum, float * ave) { + int temp = q->front; + *sum = 0; + + while ((temp != q->rear) && !isEmpty(q)) { + *sum = *sum + *(q->pBase + temp); + temp = (temp + 1) % q->len; + } + *ave = (float)(*sum) / (q->len - 2); + return; +} +void variance(struct Queue * q, float * var, float ave) { + int temp = q->front; + while ((temp != q->rear) && !isEmpty(q)) { + *var = (float)(*(q->pBase + temp) - ave) + * (*(q->pBase + temp) - ave) / (q->len - 2); + temp = (temp + 1) % q->len; + } + return; +} + +/*int cloud_side_collaborative_rocessing(char *buff,int total_people_num_vaild) { + + //ESP8266_DEFINE(esp8266); + + //char *conn_buf; + // + + if (strstr(buff, http_get) != NULL) + { + int total_people_num_pre; + char *char_total_people_num[4]; + abnormal_data_processing(int total_people_num_pre, float var,float ave) + total_people_num_pre=total_people_num; + if (total_people_num_vaild > 2000) + { + EMBARC_PRINTF("\nThere are %d people in the area.\n ", total_people_num_vaild); + EMBARC_PRINTF("Warning! Too many people in the area! \n \n"); + + int length = 58; + itoa(total_people_num_vaild, char_total_people_num, 10); + char *send_to_server = (char *) malloc(strlen(send_to_server_first) + strlen(char_total_people_num)); + strcpy(send_to_server, send_to_server_first); + strcat(send_to_server, char_total_people_num); + strcat(send_to_server, send_to_server_last); + strcat(send_to_server, time_hour); + strcat(send_to_server, colon); + strcat(send_to_server, time_minute); + strcat(send_to_server, colon); + strcat(send_to_server, time_second); + strcat(send_to_server, full_stop); + + send_to_server[length] = '\0'; //加上字符串结束符。 + + EMBARC_PRINTF("\n============================ Data sent to the cloud =============================\n\n"); + + conn_buf = strstr(esp8266, http_IDP) + 5; + *(conn_buf + 1) = 0; + esp8266_connect_write(esp8266, send_to_server, conn_buf, 50); + board_delay_ms(50, 1); + esp8266_connect_write(esp8266, Warning, conn_buf, 40); + board_delay_ms(50, 1); + + EMBARC_PRINTF("\n================================ Send finished =================================\n\n"); + + } else if (total_people_num_vaild > 500 && total_people_num_vaild < 2000 ) + { + + EMBARC_PRINTF("There are %d people in the area. ", total_people_num); + + int length = 58; + itoa(total_people_num_vaild, char_total_people_num, 10); + char *send_to_server = (char *) malloc(strlen(send_to_server_first) + strlen(char_total_people_num)); + strcpy(send_to_server, send_to_server_first); + strcat(send_to_server, char_total_people_num); + strcat(send_to_server, send_to_server_last); + strcat(send_to_server, time_hour); + strcat(send_to_server, colon); + strcat(send_to_server, time_minute); + strcat(send_to_server, colon); + strcat(send_to_server, time_second); + strcat(send_to_server, full_stop); + + //EMBARC_PRINTF("%s",send_to_server); + + send_to_server[length] = '\0'; //加上字符串结束符。 + EMBARC_PRINTF("\n============================ Data sent to the cloud ============================\n\n"); + + conn_buf = strstr(http_server_buf, http_IDP) + 5; + *(conn_buf + 1) = 0; + esp8266_connect_write(esp8266, send_to_server, conn_buf, 50); + board_delay_ms(50, 1); + + EMBARC_PRINTF("\n================================ Send finished =================================\n\n"); + } + + } + board_delay_ms(50, 1); +} + +*/ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/makefile b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/makefile new file mode 100644 index 00000000..b5c05afb --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/makefile @@ -0,0 +1,46 @@ +# Application name +APPL ?= Edge_Crowd_Counting_System + +# Optimization Level +# Please Refer to toolchain_xxx.mk for this option +OLEVEL ?= O2 + +## +# Current Board And Core +## +BOARD ?= emsk +BD_VER ?= 22 +CUR_CORE ?= arcem9d + +## +# select debugging jtag +## +JTAG ?= usb + +## +# Set toolchain +## +TOOLCHAIN ?= mw + +# +# root dir of embARC +# +EMBARC_ROOT = ../../../../.. +# Selected OS +OS_SEL ?= freertos + +MID_SEL = common fatfs + +# application source dirs +APPL_CSRC_DIR = . ./wifi ./emsk_sdcard +APPL_ASMSRC_DIR = . + +# application include dirs +APPL_INC_DIR = ./inc ./inc/emsk_sdcard + +# include current project makefile +COMMON_COMPILE_PREREQUISITES += makefile + +### Options above must be added before include options.mk ### +# include key embARC build system makefile +include $(EMBARC_ROOT)/options/options.mk \ No newline at end of file diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/state.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/state.c new file mode 100644 index 00000000..4f9d3492 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/state.c @@ -0,0 +1,801 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#include +void state_DDI() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * " + "* * \r\n"); + printf("* * * * " + "* * * * * * * * *\r\n"); + printf("* * * * * " + "* * * * *\r\n"); + printf("* * * * * ******** " + "* * * * *\r\n"); + printf("* * * * * ******** " + "* * * * * * * * *\r\n"); + printf("* * ***** * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * * " + "* * * * * *\r\n"); + printf("* * * * * " + "* * * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * ** * ** * " + " * ** * ** *\r\n"); + printf(" * * * * * " + " * * * * *\r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * " + " *\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * * " + " *\r\n"); + printf("* * ***** " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * *\r\n"); +} + +void state_III() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * " + "* * \r\n"); + printf("* * * * " + "* * * * * * * * * \r\n"); + printf("* * * * * * " + "* * * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * ******** " + "* * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * " + "* * * *\r\n"); + printf("* * * * " + "* * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * * " + " *\r\n"); + printf("* * *****" + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * *\r\n"); +} + +void state_IID() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * * " + "* * \r\n"); + printf("* * * * ** " + "* * * * * * * * * \r\n"); + printf("* * * * * * *** " + "* * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * ********* " + "* * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * *** " + "* * * *\r\n"); + printf("* * * * ** " + "* * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * " + " * \r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * * * * * " + " * * * * *\r\n"); + printf(" * ** * ** * " + " * ** * ** *\r\n"); + printf(" * * * " + " * * * \r\n"); + printf(" * * * " + " * * *\r\n"); + printf(" * * * " + " * * *\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * *****" + " *\r\n"); + printf("* * * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * *\r\n"); +} + +void state_IDD() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * " + "* * \r\n"); + printf("* * * * " + "* * * * * * * * * \r\n"); + printf("* * * * * * " + "* * * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * ******** " + "* * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * " + "* * * *\r\n"); + printf("* * * * " + "* * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * * * * * " + " \r\n"); + printf(" * ** * ** * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * ****" + "* *\r\n"); + printf("* * * *" + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * * *\r\n"); +} + +void state_DDD() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * " + "* * \r\n"); + printf("* * * * " + "* * * * * * * * *\r\n"); + printf("* * * * * " + "* * * * *\r\n"); + printf("* * * * * ******** " + "* * * * *\r\n"); + printf("* * * * * ******** " + "* * * * * * * * *\r\n"); + printf("* * ***** * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * * " + "* * * * * *\r\n"); + printf("* * * * * " + "* * * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf(" " + " \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * *" + " *\r\n"); + printf("* * *" + " *\r\n"); + printf("* * ***" + "** *\r\n"); + printf("* * * " + "* *\r\n"); + printf("* * *" + " *\r\n"); + printf("* * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); +} + +void state_DID() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * * " + "* *\r\n"); + printf("* * * * ** " + "* * * * * * * * *\r\n"); + printf("* * * * * *** " + "* * * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * * ********* " + "* * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * *** " + "* * * *\r\n"); + printf("* * * * ** " + "* * * * * * * *\r\n"); + printf("* * * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" " + " * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * * * * * \r\n"); + printf(" " + " * ** * ** * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * * * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * ****" + "* *\r\n"); + printf("* * * *" + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * * *\r\n"); +} + +void state_DII() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * * " + "* *\r\n"); + printf("* * * * ** " + "* * * * * * * * *\r\n"); + printf("* * * * * *** " + "* * * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * * ********* " + "* * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * *** " + "* * * *\r\n"); + printf("* * * * ** " + "* * * * * * * *\r\n"); + printf("* * * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * ** * ** * " + " \r\n"); + printf(" * * * * * " + " \r\n"); + printf(" * * * " + " \r\n"); + printf(" * " + " \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * *" + " *\r\n"); + printf("* * ****" + "* *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * *" + " * * * * * * * * * * * * *\r\n"); +} + +void state_IDI() { + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("* * * " + "* * \r\n"); + printf("* * * * ** " + "* * * * * * * * * \r\n"); + printf("* * * * * * *** " + "* * * * *\r\n"); + printf("* * * ***** * ******** " + "* * * ***** *\r\n"); + printf("* * * * * ********* " + "* * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** " + "* * * * *\r\n"); + printf("* * * * *** " + "* * * *\r\n"); + printf("* * * * ** " + "* * * * * * * *\r\n"); + printf("* * " + "* *\r\n"); + printf("* * * * * * * * * * * * * * " + "* * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * ** * ** * \r\n"); + printf(" " + " * * * * * \r\n"); + printf(" " + " * * * \r\n"); + printf(" " + " * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * * \r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * " + " *\r\n"); + printf("* * * * " + " *\r\n"); + printf("* * *****" + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * " + " *\r\n"); + printf("* * * * * * * " + " *\r\n"); + printf("* " + " *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * " + "* * * * * * * * * * * * *\r\n"); +} + +/* +void state_DDI() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * \r\n"); + printf("* * * * * * * * * * * * *\r\n"); + printf("* * * * * * * * * *\r\n"); + printf("* * * * * ******** * * * * *\r\n"); + printf("* * * * * ******** * * * * * * * * *\r\n"); + printf("* * ***** * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * * * * * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * * * * *\r\n"); + printf(" * * * * * *\r\n"); + printf(" * * * * * *\r\n"); + printf(" * ** * ** * * ** * ** *\r\n"); + printf(" * * * * * * * * * *\r\n"); + printf(" * * * * * *\r\n"); + printf(" * *\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_III() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * \r\n"); + printf("* * * * * * * * * * * * * \r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * ******** * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_IID() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * * \r\n"); + printf("* * * * ** * * * * * * * * * \r\n"); + printf("* * * * * * *** * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * ********* * * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * *** * * * *\r\n"); + printf("* * * * ** * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * \r\n"); + printf(" * * * * * *\r\n"); + printf(" * * * * * * * * * *\r\n"); + printf(" * ** * ** * * ** * ** *\r\n"); + printf(" * * * * * * \r\n"); + printf(" * * * * * *\r\n"); + printf(" * * * * * *\r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_IDD() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * \r\n"); + printf("* * * * * * * * * * * * * \r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * ******** * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * \r\n"); + printf(" * * * \r\n"); + printf(" * * * * * \r\n"); + printf(" * ** * ** * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_DDD() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * \r\n"); + printf("* * * * * * * * * * * * *\r\n"); + printf("* * * * * * * * * *\r\n"); + printf("* * * * * ******** * * * * *\r\n"); + printf("* * * * * ******** * * * * * * * * *\r\n"); + printf("* * ***** * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * * * * * * * *\r\n"); + printf("* * * * * * * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf(" \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_DID() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * * * ** * * * * * * * * *\r\n"); + printf("* * * * * *** * * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * * ********* * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * *** * * * *\r\n"); + printf("* * * * ** * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * \r\n"); + printf(" * * * \r\n"); + printf(" * * * * * \r\n"); + printf(" * ** * ** * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_DII() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * * * ** * * * * * * * * *\r\n"); + printf("* * * * * *** * * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * * ********* * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * *** * * * *\r\n"); + printf("* * * * ** * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * ** * ** * \r\n"); + printf(" * * * * * \r\n"); + printf(" * * * \r\n"); + printf(" * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); +} + +void state_IDI() { + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("* * * * * \r\n"); + printf("* * * * ** * * * * * * * * * \r\n"); + printf("* * * * * * *** * * * * *\r\n"); + printf("* * * ***** * ******** * * * ***** *\r\n"); + printf("* * * * * ********* * * * * * * * * * *\r\n"); + printf("* * ***** * * * ******** * * * * *\r\n"); + printf("* * * * *** * * * *\r\n"); + printf("* * * * ** * * * * * * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + printf("\r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * * * \r\n"); + printf(" * ** * ** * \r\n"); + printf(" * * * * * \r\n"); + printf(" * * * \r\n"); + printf(" * \r\n"); + printf("\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \r\n"); + printf("* *\r\n"); + printf("* * * * * * * * *\r\n"); + printf("* * * * *\r\n"); + printf("* * ***** *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * *\r\n"); + printf("* * * * * * * *\r\n"); + printf("* *\r\n"); + printf("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\r\n"); + +} +*/ diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/at_parser.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/at_parser.c new file mode 100644 index 00000000..541c06ed --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/at_parser.c @@ -0,0 +1,196 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ + +#include "embARC_error.h" +#include "string.h" +#include "board.h" +#include "at_parser.h" +//#include "embARC_error.h" + +#define DBG_MORE +#include "embARC_debug.h" + +/* if \r\n is needed to be attached at the end of AT comand, define AT_ADD_POSTFIX +* otherwise comment out this line +*/ +#define AT_ADD_POSTFIX + +#define AT_PREFIX "AT" +#define AT_POSTFIX "\r\n" + +#define AT_TIMENOW() OSP_GET_CUR_MS() + +#define AT_MAX_LEN 128 +#define AT_MAX_PARAMETER 8 + + +int32_t at_parser_init(AT_PARSER_DEF_PTR obj, uint32_t baudrate) +{ + obj->psio = ez_sio_open(obj->uart_id, baudrate, AT_TX_BUFSIZE, AT_RX_BUFSIZE); + dbg_printf(DBG_MORE_INFO, "[%s]%d: obj->psio 0x%x -> 0x%x\r\n", __FUNCTION__, __LINE__, obj->psio, *obj->psio); + return (obj->psio != NULL) ? AT_OK : AT_ERROR; +} + +void at_parser_deinit(AT_PARSER_DEF_PTR obj) +{ + ez_sio_close(obj->psio); + return; +} + +int32_t at_read(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt) +{ + return ez_sio_read(obj->psio, buf, cnt); +} + +int32_t at_write(AT_PARSER_DEF_PTR obj, char *buf, uint32_t cnt) +{ + return ez_sio_write(obj->psio, buf, cnt); +} + +/* +* please use NULL as last parameter +*/ +int32_t at_send_cmd(AT_PARSER_DEF_PTR obj, AT_MODE mode, AT_STRING command, ...) +{ + va_list vl; + char at_out[AT_MAX_LEN] = AT_PREFIX; + char *str = command; + + if (str == NULL) { + // dbg_printf(DBG_MORE_INFO, "[%s]%d: command is NULL, send AT test command\r\n", __FUNCTION__, __LINE__); + } else { + strcat(at_out,"+"); + strcat(at_out, command); + + switch (mode) { + case AT_LIST: + strcat(at_out, "=?"); + break; + + case AT_READ: + strcat(at_out, "?"); + break; + + case AT_WRITE: + strcat(at_out, "="); + va_start(vl, command); + + for (int i = 0; i < AT_MAX_PARAMETER; i++) { + str = va_arg(vl, AT_STRING); + + if (str == NULL) { + break; + } + + if (i != 0) { + strcat(at_out, ","); + } + + strcat(at_out, str); + } + + va_end(vl); + break; + + case AT_EXECUTE: + default: + break; + } + } + +#ifdef AT_ADD_POSTFIX + strcat(at_out, AT_POSTFIX); +#endif /*AT_ADD_POSTFIX*/ + dbg_printf(DBG_LESS_INFO, "[%s]%d: at_out: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, at_out, strlen(at_out)); + return at_write(obj, at_out, strlen(at_out)); +} + +/* make sure the buf is large enough*/ +int32_t at_get_reply(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout) +{ + uint32_t cur_ofs = 0; + uint32_t read_cnt; + uint32_t cur_time; + cur_time = AT_TIMENOW(); + + do { + read_cnt = at_read(obj, &buf[cur_ofs], 1); + cur_ofs += read_cnt; + buf[cur_ofs] = '\0'; + + if ((strstr(buf, AT_OK_STR)!= NULL) || (strstr(buf, AT_ERROR_STR)!= NULL)) { + break; + } + } while ((AT_TIMENOW()-cur_time) < timeout); + + buf[cur_ofs] = '\0'; + dbg_printf(DBG_LESS_INFO, "[%s]%d: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, buf, strlen(buf)); + + if (strstr(buf, AT_OK_STR)!= NULL) { + return AT_OK; + } + + return AT_ERROR; +} + +int32_t at_get_reply1(AT_PARSER_DEF_PTR obj, char *buf, uint32_t timeout) +{ + uint32_t cur_ofs = 0; + uint32_t read_cnt; + uint32_t cur_time; + cur_time = AT_TIMENOW(); + + do { + read_cnt = at_read(obj, &buf[cur_ofs], 1); + cur_ofs += read_cnt; + buf[cur_ofs] = '\0'; + + if ((strstr(buf, AT_OK_STR)!= NULL) || (strstr(buf, AT_ERROR_STR)!= NULL)) { + break; + } + } while ((AT_TIMENOW()-cur_time) < timeout); + + buf[cur_ofs] = '\0'; + //dbg_printf(DBG_LESS_INFO, "[%s]%d: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, buf, strlen(buf)); + + if (strstr(buf, AT_OK_STR)!= NULL) { + return AT_OK; + } + + return AT_ERROR; +} + +int32_t at_test(AT_PARSER_DEF_PTR obj) +{ + char rcv_buf[64]; + at_send_cmd(obj, AT_LIST, NULL); + return at_get_reply(obj, rcv_buf, AT_NORMAL_TIMEOUT); +} + diff --git a/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/esp8266.c b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/esp8266.c new file mode 100644 index 00000000..9f21a685 --- /dev/null +++ b/arc_design_contest/2019/SUStech_EdgeCrowdCountingSystem/src/wifi/esp8266.c @@ -0,0 +1,418 @@ +/* ------------------------------------------ + * Copyright (c) 2018, Synopsys, Inc. All rights reserved. + + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + + * 1) Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + + * 2) Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + + * 3) Neither the name of the Synopsys, Inc., nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +--------------------------------------------- */ +#include "esp8266.h" +#include "stdlib.h" +#include "stdio.h" +#include "string.h" +#include "stdarg.h" + +#define DBG_MORE +#include "embARC_debug.h" + +int32_t esp8266_init(ESP8266_DEF_PTR obj, uint32_t baudrate) +{ + obj->p_at = malloc(sizeof(AT_PARSER_DEF)); + + if (obj->p_at == NULL) { + return E_NOMEM; + } + + memset(obj->p_at, 0, sizeof(AT_PARSER_DEF)); + obj->p_at->uart_id = ESP8266_UART_ID; + // add any esp8266 init code here + obj->wifi_connected = false; + obj->trans_mode = ESP8266_NORMALSEND; + return at_parser_init(obj->p_at, baudrate); +} + +void esp8266_deinit(ESP8266_DEF_PTR obj) +{ + if (obj->wifi_connected) { + esp8266_wifi_disconnect(obj); + } + + at_parser_deinit(obj->p_at); + // add any esp8266 deinit code here + obj->trans_mode = ESP8266_NORMALSEND; + free(obj->p_at); +} + +int32_t esp8266_test(ESP8266_DEF_PTR obj) +{ + return at_test(obj->p_at); +} + +//TODO: MAC address functions +//uint32_t AT_MAC_get();// AT+CIPSTAMAC_CUR? +//uint32_t AT_MAC_set();// AT+CIPSTAMAC_CUR="18:fe:35:98:d3:7b" + +int32_t esp8266_wifi_mode_get(ESP8266_DEF_PTR obj, bool flash) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + char *pos; + uint32_t ret = 0; + at_send_cmd(p_at, AT_READ, flash?"CWMODE_DEF":"CWMODE_CUR", NULL); + + if (at_get_reply(p_at, rcv_buf, AT_NORMAL_TIMEOUT)==AT_OK) { + pos = strstr(rcv_buf, flash?"CWMODE_DEF:":"CWMODE_CUR:"); + + if (sscanf(pos, flash?"CWMODE_DEF:%d":"CWMODE_CUR:%d", &ret)>0) { + dbg_printf(DBG_LESS_INFO, flash?"CWMODE_DEF = %d\n":"CWMODE_CUR = %d\n", ret); + return ret; + } + } + + return AT_ERROR; +} + +int32_t esp8266_wifi_mode_set(ESP8266_DEF_PTR obj, ESP8266_WIFI_MODE mode, bool flash) +{ + char rcv_buf[512]; + char mode_str[4]= {0}; + sprintf(mode_str, "%d", mode); + at_send_cmd(obj->p_at, AT_WRITE, flash?"CWMODE_DEF":"CWMODE_CUR", mode_str, NULL); + return at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); +} + +/* rcv_buf should be large enough for scan result */ +int32_t esp8266_wifi_scan(ESP8266_DEF_PTR obj, char *rcv_buf, char *ssid) +{ + char cmd_str[512]= {0}; + sprintf(cmd_str, "CWLAP=%s", ssid); + at_send_cmd(obj->p_at, AT_EXECUTE, cmd_str); + return at_get_reply(obj->p_at, rcv_buf, AT_LONG_TIMEOUT); +} + +/* +* obj: ESP8266_DEF_PTR (esp8266 struct pointer object) +* ssid: AP ssid, need to be quoted +* pwd: AP password, need to be quoted +* flash: configuration save (true) or not save (false) in the flash +* +* Return Value: +* AT_OK == 0, success +* AT_ERROR == -1, error occurs +* CWJAP==1, connection timeout +* CWJAP==2, wrong password +* CWJAP==3, cannot find the target AP +* CWJAP==4, connection failed +*/ +int32_t esp8266_wifi_connect(ESP8266_DEF_PTR obj, AT_STRING ssid, AT_STRING pwd, bool flash) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + char *pos; + uint32_t ret = 0; + + if ( esp8266_wifi_mode_set(obj, ESP8266_STA, false) == AT_OK) { + memset(rcv_buf, 0, sizeof(rcv_buf)); + at_send_cmd(p_at, AT_WRITE, flash?"CWJAP_DEF":"CWJAP_CUR", ssid, pwd, NULL); + + if (at_get_reply(p_at, rcv_buf, AT_EXTRA_TIMEOUT)==AT_OK) { + pos = strstr(rcv_buf, "CWJAP:"); + + //check if any error happen during connection setting up + if (sscanf(pos, "CWJAP:%d", &ret)>0) { + dbg_printf(DBG_LESS_INFO, "CWJAP = %d\n", ret); + return ret; + } else { + obj->wifi_connected = true; + return AT_OK; + } + } + } + + return AT_ERROR; +} + +int32_t esp8266_wifi_disconnect(ESP8266_DEF_PTR obj) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + at_send_cmd(p_at, AT_EXECUTE, "CWQAP"); + + if (at_get_reply(p_at, rcv_buf, AT_NORMAL_TIMEOUT)== AT_OK) { + obj->wifi_connected = false; + return AT_OK; + } else { + return AT_ERROR; + } +} + +int32_t esp8266_address_get(ESP8266_DEF_PTR obj) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + at_send_cmd(p_at, AT_EXECUTE, "CIFSR"); + return at_get_reply(p_at, rcv_buf, AT_NORMAL_TIMEOUT); +} + +/* +* Return Value: +* AT_ERROR == -1, error occurs +* STATUS==2, The ESP8266 Station is connected to an AP and its IP is obtained +* STATUS==3, The ESP8266 Station has created a TCP or UDP transmission +* STATUS==4, The TCP or UDP transmission of ESP8266 Station is disconnected +* STATUS==5, The ESP8266 Station does NOT connect to an AP +*/ +int32_t esp8266_conn_status(ESP8266_DEF_PTR obj) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + char *pos; + uint32_t ret = 0; + at_send_cmd(p_at, AT_EXECUTE, "CIPSTATUS"); + + if (at_get_reply(p_at, rcv_buf, AT_NORMAL_TIMEOUT)==AT_OK) { + pos = strstr(rcv_buf, "STATUS:"); + + if (sscanf(pos, "STATUS:%d", &ret)>0) { + dbg_printf(DBG_LESS_INFO, "STATUS = %d\n", ret); + return ret; + } + } + + return AT_ERROR; +} + +int32_t esp8266_dns_lookup(ESP8266_DEF_PTR obj, char *domain_ip, AT_STRING domain_name) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + char *pos; + int len=0; + at_send_cmd(p_at, AT_WRITE, "CIPDOMAIN", domain_name, NULL); + + if (at_get_reply(p_at, rcv_buf, AT_LONG_TIMEOUT)==AT_OK) { + dbg_printf(DBG_MORE_INFO, "rcv_buf = %s\n", rcv_buf); + pos = strstr(rcv_buf, "CIPDOMAIN:"); + + if (pos!=NULL) { + pos += strlen("CIPDOMAIN:"); + dbg_printf(DBG_LESS_INFO, "domain_ip = %s, len = %d\n", pos, strlen(pos)); + len=strstr(pos, "\r\n") - pos; + strncpy(domain_ip, pos, len); + domain_ip[len]='\0'; + dbg_printf(DBG_LESS_INFO, "domain_ip = %s, len = %d\n", domain_ip, strlen(domain_ip)); + return AT_OK; + } + } + + return AT_ERROR; +} + +int32_t esp8266_tcp_connect(ESP8266_DEF_PTR obj, AT_STRING server_IP, uint32_t port) +{ + char rcv_buf[512]; + char IP_Str[32], port_Str[16]; + sprintf(IP_Str, "\"%s\"", server_IP); + sprintf(port_Str, "%d", port); + at_send_cmd(obj->p_at, AT_WRITE, "CIPSTART", "\"TCP\"", IP_Str, port_Str, NULL); + return at_get_reply(obj->p_at, rcv_buf, 800); +} + +static int32_t esp8266_tcp_server(ESP8266_DEF_PTR obj, uint32_t mode, uint32_t port) +{ + char rcv_buf[512]; + char mode_buf[5]; + char port_buf[10]; + + sprintf(mode_buf, "%d", mode); + sprintf(port_buf, "%d", port); + + AT_PARSER_DEF_PTR p_at = obj->p_at; + at_send_cmd(p_at, AT_WRITE, "CIPSERVER", mode_buf, port_buf, NULL); + return at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); +} + +int32_t esp8266_tcp_server_open(ESP8266_DEF_PTR obj, uint32_t port) +{ + char rcv_buf[512]; + AT_PARSER_DEF_PTR p_at = obj->p_at; + at_send_cmd(p_at, AT_WRITE, "CIPMUX", "1", NULL); + + if (at_get_reply(p_at, rcv_buf, AT_LONG_TIMEOUT)==AT_OK) { + return esp8266_tcp_server(obj, 1, port); + } +} + +int32_t esp8266_tcp_server_close(ESP8266_DEF_PTR obj, uint32_t port) +{ + return esp8266_tcp_server(obj, 0, port); +} + +int32_t esp8266_transmission_mode(ESP8266_DEF_PTR obj, ESP8266_TRANS_MODE mode) +{ + char rcv_buf[512]; + uint32_t ret; + char mode_str[4]= {0}; + sprintf(mode_str, "%d", mode); + at_send_cmd(obj->p_at, AT_WRITE, "CIPMODE", mode_str, NULL); + ret = at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); + + if (ret == AT_OK) { + obj->trans_mode = mode; + return AT_OK; + } else { + return AT_ERROR; + } +} + +int32_t esp8266_passthr_start(ESP8266_DEF_PTR obj) +{ + char rcv_buf[512]; + + if (obj->wifi_connected) { + if (esp8266_transmission_mode(obj, ESP8266_PASSTHR)==AT_OK) { + at_send_cmd(obj->p_at, AT_EXECUTE, "CIPSEND"); + return at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); + } + } + + return AT_ERROR; +} + +int32_t esp8266_passthr_end(ESP8266_DEF_PTR obj) +{ + char passthr_end_symbol[] = "+++"; + //uint32_t ret; + //board_delay_ms(500, OSP_DELAY_OS_COMPAT_ENABLE); + //ret = at_write(obj->p_at, passthr_end_symbol, 3);//do not send '\0' as string ending + at_write(obj->p_at, passthr_end_symbol, 3);//do not send '\0' as string ending + //board_delay_ms(500, OSP_DELAY_OS_COMPAT_ENABLE); + //if(ret == 3){ + obj->trans_mode = ESP8266_NORMALSEND; + return AT_OK; + //} else { + // return AT_ERROR; + //} +} + +int32_t esp8266_passthr_write(ESP8266_DEF_PTR obj, char *buf, uint32_t cnt) +{ + if (obj->wifi_connected && obj->trans_mode == ESP8266_PASSTHR) { + return at_write(obj->p_at, buf, cnt); + } + + return AT_ERROR; +} + +uint32_t esp8266_normal_write(ESP8266_DEF_PTR obj, char *buf, uint32_t cnt) +{ + char rcv_buf[512]; + char cnt_str[16]= {0}; + + if (obj->wifi_connected) { + if (obj->trans_mode != ESP8266_NORMALSEND) { + if (esp8266_transmission_mode(obj, ESP8266_NORMALSEND)!=AT_OK) { + return AT_ERROR; + } else { + obj->trans_mode = ESP8266_NORMALSEND; + } + } + + sprintf(cnt_str, "%d", cnt); + at_send_cmd(obj->p_at, AT_WRITE, "CIPSEND", cnt_str, NULL); + + if (at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT)==AT_OK) { + at_write(obj->p_at, buf, cnt); + return at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); + } + } + + return AT_ERROR; +} + +uint32_t esp8266_connect_write(ESP8266_DEF_PTR obj, char *buf, char *connect, uint32_t cnt) +{ + char rcv_buf[512]; + char cnt_str[16]= {0}; + + if (obj->wifi_connected) { + if (obj->trans_mode != ESP8266_NORMALSEND) { + if (esp8266_transmission_mode(obj, ESP8266_NORMALSEND)!=AT_OK) { + return AT_ERROR; + } else { + obj->trans_mode = ESP8266_NORMALSEND; + } + } + + sprintf(cnt_str, "%d", cnt); + at_send_cmd(obj->p_at, AT_WRITE, "CIPSEND", connect, cnt_str, NULL); + + if (at_get_reply(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT)==AT_OK) { + at_write(obj->p_at, buf, cnt); + return at_get_reply1(obj->p_at, rcv_buf, AT_NORMAL_TIMEOUT); + } + } + + return AT_ERROR; +} + +int32_t esp8266_read(ESP8266_DEF_PTR obj, char *buf, uint32_t timeout) +{ + uint32_t cur_ofs = 0; + uint32_t read_cnt; + uint32_t cur_time; + + if (obj->wifi_connected && obj->trans_mode == ESP8266_PASSTHR) { + cur_time = OSP_GET_CUR_MS(); + + do { + read_cnt = at_read(obj->p_at, &buf[cur_ofs], 1); + cur_ofs += read_cnt; + } while ((OSP_GET_CUR_MS()-cur_time) < timeout); + + buf[cur_ofs] = '\0'; + dbg_printf(DBG_LESS_INFO, "[%s]%d: \"%s\" (%d)\r\n", __FUNCTION__, __LINE__, buf, strlen(buf)); + return AT_OK; + } + + return AT_ERROR; +} + +uint32_t esp8266_nread(ESP8266_DEF_PTR obj, char *buf, uint32_t n) +{ + if (obj->wifi_connected) { + return at_read(obj->p_at, buf, n); + } + + return AT_ERROR; +} + + +//at_httpserver +int32_t esp8266_CIPCLOSE(ESP8266_DEF_PTR obj, char *conn_buf) +{ + char rcv_buf[512]; + at_send_cmd(obj->p_at, AT_WRITE, "CIPCLOSE", conn_buf, NULL); + return at_get_reply(obj->p_at, rcv_buf, AT_EXTRA_TIMEOUT); +} \ No newline at end of file