updated version with parameters loaded from sdcard
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
Diff: main.cpp
- Branch:
- jpa
- Revision:
- 10:41aff2b7acc6
- Parent:
- 9:332bd237b98f
- Child:
- 11:b198b2f2676f
--- a/main.cpp Tue Sep 08 15:01:08 2020 +0000 +++ b/main.cpp Tue Sep 15 19:11:11 2020 +0000 @@ -1,6 +1,9 @@ /* -------------------------------------------------------------------------- // test compile ok 31/07/2020 +// 01/09/2020 : update JPA serial et CAN : tests OK sur CAN et 1 srial 2 + : attention 1 seul serial operationnel serial 2 - serial 7 ne marche pas en reception +// : test ok send/receive tasmota sur serial 2 // 30/08/2020 : emission CAN OK en Wifi sur tasmota ou udp bridge // mais pb reception caracteres sur port serie ( idem port series pc ouu serial 7 @@ -58,6 +61,9 @@ #include "main.h" +extern char textButton[5][8]; +extern char text1Button[5][8]; +extern char textTempTitle[3][30]; //#include "touchScreen.cpp" int touchInitJPA1(); @@ -82,11 +88,49 @@ const char gsStreamId1[] = "voltage"; const char gsStreamId2[] = "temperature"; char gsStreamIPdatas[] = "192.168.1.49"; -char ethernet_actif[] = "O"; -char wifi_actif[] = "O"; -char can_actif[] = "O"; -char serial_actif[] = "O"; +int ethernet_actif = '0'; +int wifi_actif = '1'; +int can_actif = '1'; +int serial_actif = '1'; char read_sd[] = ""; +char function_mod[]= "O"; + + char touch1_status[]= "0"; + char touch1_back_color[]= "0xFF404040"; + char touch1_text_color[]= "0xFFFFFF00"; + char touch1_text[]= "Touch1"; + char touch1_text1[]= "Text1"; + + char touch2_status[]= "0"; + char touch2_back_color[]= "0xFF404040"; + char touch2_text_color[]= "0xFFFFFF00"; + char touch2_text[]= "Touch2"; + char touch2_text1[]= "Text2"; + + char touch3_status[]= "0"; + char touch3_back_color[]= "0xFF404040"; + char touch3_text_color[]= "0xFFFFFF00"; + char touch3_text[]= "Touch3"; + char touch3_text1[]= "Text3"; + + char touch4_status[]= "0"; + char touch4_back_color[]= "0xFF404040"; + char touch4_text_color[]= "0xFFFFFF00"; + char touch4_text[]= "Touch4"; + char touch4_text1[]= "Text4"; + + char temp1_text[]= "Temp1"; + char temp1_back_color[]= "0xFF404040"; + char temp1_text_color[]= "0xFFFFFF00"; + + char temp2_text[]= "Temp2"; + char temp2_back_color[]= "0xFF404040"; + char temp2_text_color[]= "0xFFFFFF00"; + + + +int len_line_sd = 0; + uint8_t text2[30]; uint8_t counter = 0; float voltage; @@ -147,8 +191,7 @@ printf("\n"); } else - { - printf(" Can message receive : "); + { printf(" Can message receive : "); /* printf(" ID = 0x%.3X\r\n", msg.id); printf(" Type = %d\r\n", msg.type); @@ -167,21 +210,17 @@ */ int CanRcv = 0; void onCanReceived(void) -{ - can.read(rxMsg); +{ can.read(rxMsg); CanRcv = 1; } - // ------------------------------------------------------------------------------------------ int main() -{ - initSerial(); - - +{ initSerial(); // attach ISR to handle received messages timer.start(); // start timer sendSerialUSB("CAN_Hello board serialUSB #1\r\n"); + sendSerial2("CAN_Hello board serial2 #1\r\n"); sendSerial7("CAN_Hello board serial7 #1\r\n"); @@ -190,11 +229,15 @@ // reaf following datas // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters // store local variables from sd - //extern char gsStreamIPdatas[]; - //extern char ethernet_actif[] ; - //extern char wifi_actif[]; - //extern char can_actif[]; - //extern char serial_actif[]; + // gsStreamIPdatas[]; + // ethernet_actif[] ; wifi_actif[];can_actif[]; serial_actif[]; function_mod[]= "O"; + // touch1_status[]= "0"; touch1_back_color[]= "0xFF404040"; touch1_text_color[]= "0xFFFFFF00"; touch1_text[]= "Touch1"; touch1_text1[]= "Text1"; + // touch2_status[]= "0"; touch2_back_color[]= "0xFF404040"; touch2_text_color[]= "0xFFFFFF00"; touch2_text[]= "Touch2"; touch2_text1[]= "Text2"; + // touch3_status[]= "0"; touch3_back_color[]= "0xFF404040"; touch3_text_color[]= "0xFFFFFF00"; touch3_text[]= "Touch3"; touch3_text1[]= "Text3"; + // touch4_status[]= "0"; touch4_back_color[]= "0xFF404040"; touch4_text_color[]= "0xFFFFFF00"; touch4_text[]= "Touch4"; touch4_text1[]= "Text4"; + // temp1_text[]= "Temp1"; temp1_back_color[]= "0xFF404040"; temp1_text_color[]= "0xFFFFFF00"; + // temp2_text[]= "Temp2"; temp2_back_color[]= "0xFF404040"; temp2_text_color[]= "0xFFFFFF00"; + printf("\nFin init SDCard ...\n"); BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD uint8_t text[300]; @@ -210,9 +253,9 @@ yy = initDisplayTemp(); // from guijpa.cpp - Init display printf("\ninit touchInitJPA1 ...\n"); yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen - yy = touchInitGuiJPA1(); // from touchscreen.cpp + yy = touchInitGuiJPA1(); // from touchscreen.cpp - display buttons printf("\ninit initDatasGuiJPA ...\n"); - yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons + yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons - ethernet connection ////lcd.printf("Starting..."); printf("Starting...\n"); lastToucheTime = time(NULL); @@ -225,36 +268,67 @@ BSP_LCD_DisplayOff(); BSP_LCD_DisplayOn(); + //BSP_LCD_SetBackColor(LCD_COLOR_RED); + BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + BSP_LCD_SetBackColor(LCD_COLOR_RED); + BSP_LCD_SetTextColor(LCD_COLOR_WHITE); + int pp = setTemp1("temp1"); // display temp1 on lcd + BSP_LCD_DisplayStringAt(0, LINE(7), (uint8_t *)"displ temp1", CENTER_MODE); + // main loop --------------------------------------------------- - while (true) { - + while (true) { if (CanRcv > 0) - { - CanRcv = 0; + { CanRcv = 0; printMsg(rxMsg,1); BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE); - if (rxMsg.id == RX_ID) { - rxMsg >> counter; + if (rxMsg.id == RX_ID) + { rxMsg >> counter; rxMsg >> voltage; //serialUSB.printf(" counter = %d\r\n", counter); //serialUSB.printf(" voltage = %e V\r\n", voltage); - } } - + } if (msgSerialUSB > 0) {receiveSerialUSB();} if (stringSerialUSBok == 1) {printf("Trame SerialUSB : %s",stringSerialUSB);stringSerialUSBok=0;} if (msgSerial2 > 0) {receiveSerial2();} - if (stringSerial2ok == 1) {printf("Trame Serial2 : %s",stringSerial2);stringSerial2ok=0;} - + if (stringSerial2ok == 1) + { printf("Trame Serial2 : %s",stringSerial2); + stringSerial2ok=0; + // decodage json datas + // trame reçue : {"Temp1":"25","Temp2":"30"} + char resultBuffer[100]= {0}; + //resultBuffer = stringSerial2; + //if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') + if (strlen(stringSerial2) > 0 && stringSerial2[0] == '{') + { MbedJSONValue mbedJson; + //parse(mbedJson, resultBuffer); + parse(mbedJson, stringSerial2); + //sprintf((char*)text, "HTTP string : %s\n", resultBuffer); + sprintf((char*)text, "HTTP string : %s\n", stringSerial2); + //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE); + if (mbedJson.hasMember("Temp1")) { + printf("Serial2 temp1: %s",stringSerial2); + //int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); + int pp = setTemp1(mbedJson["Temp1"].get<std::string>()); // display temp1 on lcd + + } + if (mbedJson.hasMember("Temp2")) { + int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); + + } + + } + + + + } if (msgSerial7 > 0) {receiveSerial7();} if (stringSerial7ok == 1) {printf("Trame Serial7 : %s",stringSerial7);stringSerial7ok=0;} // timer send can if(timer.read_ms() >= 10000) // check for timeout - { - - timer.stop(); // stop the timer + { timer.stop(); // stop the timer timer.reset(); // reset the timer counter = (counter+1) & 1; // increment the counter voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input @@ -262,8 +336,7 @@ txMsg.id = 0x100130CA;//TX_ID; // set the message ID txMsg.format = CANExtended ; //extended txMsg.len=2; - txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!) - + txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!) if(can.write(txMsg)) // transmit message { //if(can->write(txMsg)) { // transmit the CAN message printMsg(txMsg,0); @@ -280,8 +353,7 @@ //touch screen int xx = touchJPA1(); // if (xx > 0) - { - if (xx == 4) + { if (xx == 4) { // send trame to can txMsg.id = 0x100130CB;//TX_ID; // set the message ID txMsg.format = CANExtended ; //extended @@ -289,21 +361,17 @@ txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!) if(can.write(txMsg)) // transmit message - { - printMsg(txMsg,0); + { printMsg(txMsg,0); BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); } else - { - BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); + { BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); } } - xx = sendTouchJPA(xx); - - lastToucheTime = time(NULL); - + xx = sendTouchJPA(xx); + lastToucheTime = time(NULL); } else { lastToucheTime = 0;