thomas ya
/
LV_FGSE_Controller_Interface
for HTTP-3A
Diff: main.cpp
- Revision:
- 3:043e5e06f325
- Parent:
- 1:ec61ea9f67de
- Child:
- 4:c1438ffd88dd
--- a/main.cpp Mon Jun 26 09:28:54 2017 +0000 +++ b/main.cpp Thu Jul 11 09:03:23 2019 +0000 @@ -1,54 +1,60 @@ -#if !FEATURE_LWIP - #error [NOT_SUPPORTED] LWIP not supported for this target -#endif +#include "mbed.h" + +CAN can1(PB_8, PB_9); +Serial pc(USBTX, USBRX, 115200); +AnalogIn res(PA_0); -#include "mbed.h" -#include "EthernetInterface.h" -#include "TCPServer.h" -#include "TCPSocket.h" +Ticker ticker1; + +CANMessage can_msg_1; +CANMessage can_msg_send; +char data_msg[3] = {0x11,0x22,0x33}; +bool armed = false; -#define HTTP_STATUS_LINE "HTTP/1.0 200 OK" -#define HTTP_HEADER_FIELDS "Content-Type: text/html; charset=utf-8" -#define HTTP_MESSAGE_BODY "" \ -"<html>" "\r\n" \ -" <body style=\"display:flex;text-align:center\">" "\r\n" \ -" <div style=\"margin:auto\">" "\r\n" \ -" <h1>Hello World</h1>" "\r\n" \ -" <p>It works !</p>" "\r\n" \ -" </div>" "\r\n" \ -" </body>" "\r\n" \ -"</html>" + + +void CAN_RX1(void); -#define HTTP_RESPONSE HTTP_STATUS_LINE "\r\n" \ - HTTP_HEADER_FIELDS "\r\n" \ - "\r\n" \ - HTTP_MESSAGE_BODY "\r\n" +void sendCMD(void) +{ + //if(armed) + + can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard); + can1.write(can_msg_send); + + //printf("res: %f\n", res.read()); +} int main() { - printf("Basic HTTP server example\n"); - - EthernetInterface eth; - eth.connect(); - - printf("The target IP address is '%s'\n", eth.get_ip_address()); - - TCPServer srv; - TCPSocket clt_sock; - SocketAddress clt_addr; - - /* Open the server on ethernet stack */ - srv.open(ð); - - /* Bind the HTTP port (TCP 80) to the server */ - srv.bind(eth.get_ip_address(), 80); - - /* Can handle 5 simultaneous connections */ - srv.listen(5); - - while (true) { - srv.accept(&clt_sock, &clt_addr); - printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port()); - clt_sock.send(HTTP_RESPONSE, strlen(HTTP_RESPONSE)); + + + can1.attach(&CAN_RX1, CAN::RxIrq); //CAN1 Recieve Irq + ticker1.attach(&sendCMD, 1); //1sec + pc.printf("start\n"); + + can1.frequency(500000); + while(1) + { + + /*if(can1.read(can_msg_1)) + { + printf("Message received: %d\n", can_msg_1.data[1]); + } + */ + + + } + +} + + + +void CAN_RX1(void) +{ + if(can1.read(can_msg_1)) + { + pc.printf("CAN RX %d\n", can_msg_1.id); + } }