Abolished http2can.csv

This commit is contained in:
nopnop2002
2021-07-09 15:35:48 +09:00
parent aca2be1d88
commit ffc958e5b5
4 changed files with 16 additions and 93 deletions
+2 -12
View File
@@ -142,19 +142,9 @@ CAN-ID is a decimal number, not a hexadecimal number.
``` ```
# Definition from HTTP to CANbus # Definition from HTTP to CANbus
When the Built-in HTTP server receives an HTTP POST, it is sent by CANBus according to csv/http2can.csv. Not exist.
Other than this, it is the same as csv/can2http.csv. You can send any CAN-ID.
In the last column you have to specify the HTTP-POST-Path of built-in HTTP server.
```
S,201,/receive
E,201,/receive
S,203,/receive
E,203,/receive
```
If you POST {"canid": 513, "frame": "standard", "data": [16, 17, 18]}, send a standard CAN frame with ID 0x201.
If you POST {"canid": 513, "frame": "extended", "data": [16, 17, 18]}, send a extended CAN frame with ID 0x201.
# Send CANBus frame using curl # Send CANBus frame using curl
``` ```
-11
View File
@@ -1,11 +0,0 @@
#The file mqtt2can.csv has three columns.
#In the first column you need to specify the CAN Frame type.
#The CAN frame type is either S(Standard frame) or E(Extended frame).
#In the second column you have to specify the CAN-ID as a __hexdecimal number__.
#In the last column you have to specify the PATH of built-in web server.
#Each CAN-ID is allowed to appear only once in the whole file.
S,201,/receive
E,201,/receive
S,203,/receive
E,203,/receive
1 #The file mqtt2can.csv has three columns.
2 #In the first column you need to specify the CAN Frame type.
3 #The CAN frame type is either S(Standard frame) or E(Extended frame).
4 #In the second column you have to specify the CAN-ID as a __hexdecimal number__.
5 #In the last column you have to specify the PATH of built-in web server.
6 #Each CAN-ID is allowed to appear only once in the whole file.
7 S,201,/receive
8 E,201,/receive
9 S,203,/receive
10 E,203,/receive
+1 -47
View File
@@ -28,8 +28,6 @@ static const char *TAG = "SERVER";
//static SemaphoreHandle_t ctrl_task_sem; //static SemaphoreHandle_t ctrl_task_sem;
extern QueueHandle_t xQueue_twai_tx; extern QueueHandle_t xQueue_twai_tx;
extern TOPIC_t *subscribe;
extern int16_t nsubscribe;
#define SCRATCH_BUFSIZE (1024) #define SCRATCH_BUFSIZE (1024)
@@ -43,41 +41,11 @@ typedef struct rest_server_context {
static esp_err_t root_get_handler(httpd_req_t *req) static esp_err_t root_get_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "root_get_handler req->uri=[%s]", req->uri); ESP_LOGI(TAG, "root_get_handler req->uri=[%s]", req->uri);
for(int index=0;index<nsubscribe;index++) {
ESP_LOGI(TAG, "subscribe[%d] frame=%d canid=0x%x topic=[%s] topic_len=%d",
index, subscribe[index].frame, subscribe[index].canid, subscribe[index].topic, subscribe[index].topic_len);
}
/* Send HTML header */
httpd_resp_sendstr_chunk(req, "<!DOCTYPE html><html><body>");
httpd_resp_sendstr_chunk(req, "<table border=\"1\">");
httpd_resp_sendstr_chunk(req, "<thead><tr><th>Frame Type</th><th>Frame ID</th><th>HTTP Path</th></tr></thead>");
char chunk[64];
for(int index=0;index<nsubscribe;index++) {
char frameType[16];
strcpy(frameType, "Standard");
if (subscribe[index].frame == 1) strcpy(frameType, "Entended");
httpd_resp_sendstr_chunk(req, "<tr>");
sprintf(chunk, "<td align=\"center\">%16s</td>", frameType);
httpd_resp_sendstr_chunk(req, chunk);
sprintf(chunk, "<td align=\"center\">%x</td>", subscribe[index].canid);
httpd_resp_sendstr_chunk(req, chunk);
sprintf(chunk, "<td align=\"center\">%s</td>", subscribe[index].topic);
httpd_resp_sendstr_chunk(req, chunk);
httpd_resp_sendstr_chunk(req, "</tr>");
}
/* Finish the table */
httpd_resp_sendstr_chunk(req, "</tbody></table>");
/* Send remaining chunk of HTML file to complete it */
httpd_resp_sendstr_chunk(req, "</body></html>");
/* Send empty chunk to signal HTTP response completion */ /* Send empty chunk to signal HTTP response completion */
httpd_resp_sendstr_chunk(req, NULL); httpd_resp_sendstr_chunk(req, NULL);
return ESP_OK; return ESP_OK;
} }
@@ -238,12 +206,6 @@ static esp_err_t twai_send_handler(httpd_req_t *req)
if (parse) { if (parse) {
ESP_LOGI(TAG, "twai_send_handler frame=%d canid=%x data_len=%d", frame, canid, data_len); ESP_LOGI(TAG, "twai_send_handler frame=%d canid=%x data_len=%d", frame, canid, data_len);
ESP_LOG_BUFFER_HEX(TAG, data_value, data_len); ESP_LOG_BUFFER_HEX(TAG, data_value, data_len);
bool isMatch = false;
for(int index=0;index<nsubscribe;index++) {
ESP_LOGI(TAG, "subscribe[%d] frame=%d canid=%x topic=[%s] topic_len=%d",
index, subscribe[index].frame, subscribe[index].canid, subscribe[index].topic, subscribe[index].topic_len);
if (subscribe[index].frame == frame && subscribe[index].canid == canid) {
isMatch = true;
twai_message_t tx_msg; twai_message_t tx_msg;
tx_msg.extd = frame; tx_msg.extd = frame;
tx_msg.ss = 1; tx_msg.ss = 1;
@@ -258,14 +220,6 @@ static esp_err_t twai_send_handler(httpd_req_t *req)
ESP_LOGE(TAG, "xQueueSend Fail"); ESP_LOGE(TAG, "xQueueSend Fail");
} }
httpd_resp_sendstr(req, "twai send successfully"); httpd_resp_sendstr(req, "twai send successfully");
break;
} // end if
} // end for
if (isMatch == false) {
ESP_LOGE(TAG, "Not found canid in csv");
httpd_resp_sendstr(req, "Not found canid in csv");
}
} else { } else {
ESP_LOGE(TAG, "Request parameter not correct"); ESP_LOGE(TAG, "Request parameter not correct");
httpd_resp_sendstr(req, "Request parameter not correct"); httpd_resp_sendstr(req, "Request parameter not correct");
-10
View File
@@ -74,8 +74,6 @@ QueueHandle_t xQueue_twai_tx;
TOPIC_t *publish; TOPIC_t *publish;
int16_t npublish; int16_t npublish;
TOPIC_t *subscribe;
int16_t nsubscribe;
static void event_handler(void* arg, esp_event_base_t event_base, static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data) int32_t event_id, void* event_data)
@@ -428,14 +426,6 @@ void app_main()
} }
dump_table(publish, npublish); dump_table(publish, npublish);
// build subscribe table
ret = build_table(&subscribe, "/spiffs/http2can.csv", &nsubscribe);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "build subscribe table fail");
while(1) { vTaskDelay(1); }
}
dump_table(subscribe, nsubscribe);
/* Get the local IP address */ /* Get the local IP address */
tcpip_adapter_ip_info_t ip_info; tcpip_adapter_ip_info_t ip_info;
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info)); ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));