version with updated libs
Dependencies: F7_Ethernet mbed MbedJSONValue LCD_DISCO_F746NG mbed-rtos BSP_DISCO_F746NG CANMsg NetworkAPI SDFileSystem_Warning_Fixed GroveStreamsmodified LcdDiscoF746NgTracer JSON
main.cpp@4:fbbf5d1785e7, 2020-09-02 (annotated)
- Committer:
- jeanpierreaulas
- Date:
- Wed Sep 02 14:43:31 2020 +0000
- Branch:
- jpa
- Revision:
- 4:fbbf5d1785e7
- Parent:
- 3:2de8e4771674
- Child:
- 5:ceefd0cfa233
ethernet ok, can ok, usb ok, serial 2 ok not tested, serial 7 ok not tested, display ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
38domo | 0:48863a0964f5 | 1 | /* -------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 2 | // test compile ok 31/07/2020 |
38domo | 0:48863a0964f5 | 3 | |
38domo | 0:48863a0964f5 | 4 | // 30/08/2020 : emission CAN OK en Wifi sur tasmota ou udp bridge |
38domo | 0:48863a0964f5 | 5 | // mais pb reception caracteres sur port serie ( idem port series pc ouu serial 7 |
38domo | 0:48863a0964f5 | 6 | |
38domo | 0:48863a0964f5 | 7 | // 02/08/2020 |
38domo | 0:48863a0964f5 | 8 | // add sd parameters: read ok |
38domo | 0:48863a0964f5 | 9 | // ip address |
38domo | 0:48863a0964f5 | 10 | // ethernet actif |
38domo | 0:48863a0964f5 | 11 | // wifi actif |
38domo | 0:48863a0964f5 | 12 | // can actif |
38domo | 0:48863a0964f5 | 13 | // serial actif |
38domo | 0:48863a0964f5 | 14 | // fonction |
38domo | 0:48863a0964f5 | 15 | // Touche1 status (0/1) |
38domo | 0:48863a0964f5 | 16 | // Touche1 backcolor |
38domo | 0:48863a0964f5 | 17 | // touche1 text color |
38domo | 0:48863a0964f5 | 18 | // Touche1 text |
38domo | 0:48863a0964f5 | 19 | // Touche1 text1 |
38domo | 0:48863a0964f5 | 20 | // Touche2 |
38domo | 0:48863a0964f5 | 21 | // Touche3 |
38domo | 0:48863a0964f5 | 22 | // Touche4 |
38domo | 0:48863a0964f5 | 23 | // Temp1 text |
38domo | 0:48863a0964f5 | 24 | // Temp2 text |
38domo | 0:48863a0964f5 | 25 | |
38domo | 0:48863a0964f5 | 26 | // works ok 31/07/2020 |
38domo | 0:48863a0964f5 | 27 | // updated package from jpa |
38domo | 0:48863a0964f5 | 28 | // added fonts in bsp_disco_f746ng/utilities/fonts |
38domo | 0:48863a0964f5 | 29 | // fonts.h updated to manage added fonts |
38domo | 0:48863a0964f5 | 30 | // grovestream.cpp & grovesttream.h updated |
38domo | 0:48863a0964f5 | 31 | // remove stm32746ng_dicovery_sd in /bsp_disco_f746ng/drivers/stm32746ng_discovery |
38domo | 0:48863a0964f5 | 32 | // mainSDAcardJPA issue: add sdcardjpa.cpp in lib /sdfilesystem_warning_fixed |
38domo | 0:48863a0964f5 | 33 | // isue with big fonts: replace /bsp_disco_f746ng/drivers/stm32746ng-discovery/stm32746ng-discovery_lcd.c &.h |
38domo | 0:48863a0964f5 | 34 | |
38domo | 0:48863a0964f5 | 35 | // need to add CAN and WiFi |
38domo | 0:48863a0964f5 | 36 | |
38domo | 0:48863a0964f5 | 37 | STM32F746 GroveStreams Stream Feed via Ethernet |
38domo | 0:48863a0964f5 | 38 | |
38domo | 0:48863a0964f5 | 39 | This GroveStreams example is designed for the STM32F746. |
38domo | 0:48863a0964f5 | 40 | https://www.grovestreams.com/developers/getting_started_stm32F746.html |
38domo | 0:48863a0964f5 | 41 | |
38domo | 0:48863a0964f5 | 42 | The STM32 uses DHCP and DNS for a simpler network setup. |
38domo | 0:48863a0964f5 | 43 | |
38domo | 0:48863a0964f5 | 44 | */ |
38domo | 0:48863a0964f5 | 45 | |
38domo | 0:48863a0964f5 | 46 | #if !FEATURE_LWIP |
38domo | 0:48863a0964f5 | 47 | #error [NOT_SUPPORTED] LWIP not supported for this target |
38domo | 0:48863a0964f5 | 48 | #endif |
38domo | 0:48863a0964f5 | 49 | |
38domo | 0:48863a0964f5 | 50 | #include "mbed.h" |
38domo | 0:48863a0964f5 | 51 | #include "LcdDiscoF746NgTracer.h" |
38domo | 0:48863a0964f5 | 52 | #include "GroveStreams.h" |
38domo | 0:48863a0964f5 | 53 | #include "MbedJSONValue.h" |
38domo | 0:48863a0964f5 | 54 | #include "stm32746g_discovery_lcd.h" |
38domo | 0:48863a0964f5 | 55 | #include "stm32746g_discovery_ts.h" |
38domo | 0:48863a0964f5 | 56 | #include "CANMsg.h" |
jeanpierreaulas | 3:2de8e4771674 | 57 | //#include "ManageBufferJPA.h" |
38domo | 0:48863a0964f5 | 58 | |
38domo | 0:48863a0964f5 | 59 | #include "main.h" |
38domo | 0:48863a0964f5 | 60 | |
jeanpierreaulas | 3:2de8e4771674 | 61 | |
38domo | 0:48863a0964f5 | 62 | //#include "touchScreen.cpp" |
38domo | 0:48863a0964f5 | 63 | int touchInitJPA1(); |
38domo | 0:48863a0964f5 | 64 | int touchJPA1(); |
38domo | 0:48863a0964f5 | 65 | int touchInitGuiJPA1(); |
38domo | 0:48863a0964f5 | 66 | int sendTouchJPA(int xx); |
38domo | 0:48863a0964f5 | 67 | time_t lastToucheTime = 0; |
38domo | 0:48863a0964f5 | 68 | int touchButtonJPA1(int numButton); |
38domo | 0:48863a0964f5 | 69 | |
38domo | 0:48863a0964f5 | 70 | //#include "GuiJPA.cpp" |
38domo | 0:48863a0964f5 | 71 | int initDisplayTemp(); |
38domo | 0:48863a0964f5 | 72 | int initDatasGuiJPA(); |
38domo | 0:48863a0964f5 | 73 | int setTemp1(std::string temp1); |
38domo | 0:48863a0964f5 | 74 | int setTemp2(std::string temp2); |
38domo | 0:48863a0964f5 | 75 | int sendInitDatasJPA(int xx); |
38domo | 0:48863a0964f5 | 76 | |
38domo | 0:48863a0964f5 | 77 | //#SDCARD |
38domo | 0:48863a0964f5 | 78 | int mainSDCardJPA(); //in sdcardjpa.cpp in lib /sdfilesystem_warning_fixedd |
38domo | 0:48863a0964f5 | 79 | |
38domo | 0:48863a0964f5 | 80 | //GroveStreams Stream IDs. Stream IDs tell GroveStreams which component streams the values will be assigned to. |
38domo | 0:48863a0964f5 | 81 | //Don't change these unless you edit your GroveStreams component definition and change the stream IDs to match these. |
jeanpierreaulas | 3:2de8e4771674 | 82 | const char gsStreamId1[] = "voltage"; |
jeanpierreaulas | 3:2de8e4771674 | 83 | const char gsStreamId2[] = "temperature"; |
jeanpierreaulas | 3:2de8e4771674 | 84 | char gsStreamIPdatas[] = "192.168.1.49"; |
jeanpierreaulas | 3:2de8e4771674 | 85 | char ethernet_actif[] = "O"; |
jeanpierreaulas | 3:2de8e4771674 | 86 | char wifi_actif[] = "O"; |
jeanpierreaulas | 3:2de8e4771674 | 87 | char can_actif[] = "O"; |
jeanpierreaulas | 3:2de8e4771674 | 88 | char serial_actif[] = "O"; |
jeanpierreaulas | 3:2de8e4771674 | 89 | char read_sd[] = ""; |
jeanpierreaulas | 3:2de8e4771674 | 90 | uint8_t text2[30]; |
jeanpierreaulas | 3:2de8e4771674 | 91 | uint8_t counter = 0; |
jeanpierreaulas | 3:2de8e4771674 | 92 | float voltage; |
jeanpierreaulas | 3:2de8e4771674 | 93 | |
jeanpierreaulas | 3:2de8e4771674 | 94 | Timer timer; |
38domo | 0:48863a0964f5 | 95 | AnalogIn analogIn(A0); |
38domo | 0:48863a0964f5 | 96 | |
38domo | 0:48863a0964f5 | 97 | // CAN ------------------------------------------------------------ |
jeanpierreaulas | 3:2de8e4771674 | 98 | CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name |
jeanpierreaulas | 3:2de8e4771674 | 99 | CANMsg rxMsg; |
jeanpierreaulas | 3:2de8e4771674 | 100 | CANMsg txMsg; |
38domo | 0:48863a0964f5 | 101 | |
38domo | 0:48863a0964f5 | 102 | // Other Settings |
jeanpierreaulas | 3:2de8e4771674 | 103 | int updateFrequency = 20; // Update frequency in seconds. Change this to change your sample frequency. |
jeanpierreaulas | 3:2de8e4771674 | 104 | |
jeanpierreaulas | 3:2de8e4771674 | 105 | AnalogIn adc_temp(ADC_TEMP); |
jeanpierreaulas | 3:2de8e4771674 | 106 | AnalogIn adc_vref(ADC_VREF); |
jeanpierreaulas | 3:2de8e4771674 | 107 | DigitalOut myled(LED1); |
38domo | 0:48863a0964f5 | 108 | |
jeanpierreaulas | 3:2de8e4771674 | 109 | void initSerial(); |
jeanpierreaulas | 3:2de8e4771674 | 110 | void sendSerialUSB(char * str); |
jeanpierreaulas | 3:2de8e4771674 | 111 | void receiveSerialUSB(); |
jeanpierreaulas | 4:fbbf5d1785e7 | 112 | void sendSerial2(char * str); |
jeanpierreaulas | 4:fbbf5d1785e7 | 113 | void receiveSerial2(); |
jeanpierreaulas | 4:fbbf5d1785e7 | 114 | void sendSerial7(char * str); |
jeanpierreaulas | 4:fbbf5d1785e7 | 115 | void receiveSerial7(); |
38domo | 0:48863a0964f5 | 116 | |
jeanpierreaulas | 4:fbbf5d1785e7 | 117 | //extern volatile char bufferSerialUSB[]; |
jeanpierreaulas | 3:2de8e4771674 | 118 | extern volatile int msgSerialUSB; |
jeanpierreaulas | 4:fbbf5d1785e7 | 119 | extern volatile int msgSerial2; |
jeanpierreaulas | 4:fbbf5d1785e7 | 120 | extern volatile int msgSerial7; |
jeanpierreaulas | 3:2de8e4771674 | 121 | |
jeanpierreaulas | 3:2de8e4771674 | 122 | //extern Serial serialUSB(USBTX, USBRX); // serial PC |
jeanpierreaulas | 3:2de8e4771674 | 123 | //extern Serial serial2(PC_6, PC_7); // TX, RX for udp bridge |
jeanpierreaulas | 3:2de8e4771674 | 124 | //extern Serial serial7(PF_7, PF_6); // TX, RX for extension |
38domo | 0:48863a0964f5 | 125 | |
38domo | 0:48863a0964f5 | 126 | #define BOARD1 1 // comment out this line when compiling for board #2 |
38domo | 0:48863a0964f5 | 127 | const unsigned int RX_ID = 0x101; |
38domo | 0:48863a0964f5 | 128 | const unsigned int TX_ID = 0x100; |
jeanpierreaulas | 3:2de8e4771674 | 129 | |
38domo | 0:48863a0964f5 | 130 | |
38domo | 0:48863a0964f5 | 131 | // --------------------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 132 | //* @brief Prints CAN message to PC's serial terminal |
38domo | 0:48863a0964f5 | 133 | void printMsg(CANMessage& msg, int dir) |
38domo | 0:48863a0964f5 | 134 | { if (dir ==0) |
38domo | 0:48863a0964f5 | 135 | { //BSP_LCD_DisplayStringAt(0, LINE(6), (uint8_t *)"Message sent ", LEFT_MODE); |
jeanpierreaulas | 2:462b5c0d3472 | 136 | printf(" Can message sent ok\n"); |
jeanpierreaulas | 2:462b5c0d3472 | 137 | printf("ID = 0x%.3X Data=", msg.id); |
jeanpierreaulas | 2:462b5c0d3472 | 138 | for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); |
jeanpierreaulas | 2:462b5c0d3472 | 139 | printf("\r\n"); |
38domo | 0:48863a0964f5 | 140 | } |
38domo | 0:48863a0964f5 | 141 | else |
jeanpierreaulas | 2:462b5c0d3472 | 142 | { |
jeanpierreaulas | 4:fbbf5d1785e7 | 143 | /* |
jeanpierreaulas | 2:462b5c0d3472 | 144 | printf(" Can message receive ok\n"); |
jeanpierreaulas | 2:462b5c0d3472 | 145 | printf(" ID = 0x%.3X\r\n", msg.id); |
jeanpierreaulas | 2:462b5c0d3472 | 146 | printf(" Type = %d\r\n", msg.type); |
jeanpierreaulas | 2:462b5c0d3472 | 147 | printf(" Format = %d\r\n", msg.format); |
jeanpierreaulas | 2:462b5c0d3472 | 148 | printf(" Length = %d\r\n", msg.len); |
jeanpierreaulas | 4:fbbf5d1785e7 | 149 | printf("ID = 0x%.3X Data=", msg.id); |
jeanpierreaulas | 4:fbbf5d1785e7 | 150 | */ |
jeanpierreaulas | 2:462b5c0d3472 | 151 | printf(" Data ="); |
jeanpierreaulas | 4:fbbf5d1785e7 | 152 | for(int i = 0; i < msg.len; i++) printf(" 0x%.2X", msg.data[i]); |
jeanpierreaulas | 2:462b5c0d3472 | 153 | printf("\r\n"); |
38domo | 0:48863a0964f5 | 154 | } |
38domo | 0:48863a0964f5 | 155 | |
38domo | 0:48863a0964f5 | 156 | } |
38domo | 0:48863a0964f5 | 157 | |
38domo | 0:48863a0964f5 | 158 | /** ----------------------------------------------------------------------------------------- |
38domo | 0:48863a0964f5 | 159 | * @brief Handles received CAN messages |
38domo | 0:48863a0964f5 | 160 | * @note Called on 'CAN message received' interrupt. |
38domo | 0:48863a0964f5 | 161 | */ |
jeanpierreaulas | 2:462b5c0d3472 | 162 | int CanRcv = 0; |
38domo | 0:48863a0964f5 | 163 | void onCanReceived(void) |
jeanpierreaulas | 2:462b5c0d3472 | 164 | { |
jeanpierreaulas | 2:462b5c0d3472 | 165 | can.read(rxMsg); |
jeanpierreaulas | 2:462b5c0d3472 | 166 | CanRcv = 1; |
38domo | 0:48863a0964f5 | 167 | } |
jeanpierreaulas | 3:2de8e4771674 | 168 | |
38domo | 0:48863a0964f5 | 169 | |
38domo | 0:48863a0964f5 | 170 | // ------------------------------------------------------------------------------------------ |
38domo | 0:48863a0964f5 | 171 | int main() |
jeanpierreaulas | 3:2de8e4771674 | 172 | { |
jeanpierreaulas | 3:2de8e4771674 | 173 | initSerial(); |
jeanpierreaulas | 3:2de8e4771674 | 174 | |
38domo | 0:48863a0964f5 | 175 | |
jeanpierreaulas | 2:462b5c0d3472 | 176 | // attach ISR to handle received messages |
38domo | 0:48863a0964f5 | 177 | timer.start(); // start timer |
jeanpierreaulas | 3:2de8e4771674 | 178 | sendSerialUSB("CAN_Hello board serialUSB #1\r\n"); |
jeanpierreaulas | 3:2de8e4771674 | 179 | |
jeanpierreaulas | 3:2de8e4771674 | 180 | |
38domo | 0:48863a0964f5 | 181 | printf("\nInit SDCard ...\n"); |
38domo | 0:48863a0964f5 | 182 | mainSDCardJPA() ; // init SD - read prog parameters from SD (from sdcardjpa.cpp in sdfilesystem_warning_fixed lib |
38domo | 0:48863a0964f5 | 183 | // reaf following datas |
38domo | 0:48863a0964f5 | 184 | // IP address, Ethernet actif, Wifi actif, Can actif, serial actif,fonction, buttons parameters |
38domo | 0:48863a0964f5 | 185 | // store local variables from sd |
38domo | 0:48863a0964f5 | 186 | //extern char gsStreamIPdatas[]; |
38domo | 0:48863a0964f5 | 187 | //extern char ethernet_actif[] ; |
38domo | 0:48863a0964f5 | 188 | //extern char wifi_actif[]; |
38domo | 0:48863a0964f5 | 189 | //extern char can_actif[]; |
38domo | 0:48863a0964f5 | 190 | //extern char serial_actif[]; |
38domo | 0:48863a0964f5 | 191 | printf("\nFin init SDCard ...\n"); |
38domo | 0:48863a0964f5 | 192 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // clear LCD |
38domo | 0:48863a0964f5 | 193 | uint8_t text[300]; |
38domo | 0:48863a0964f5 | 194 | printf("Start Prog\n"); |
38domo | 0:48863a0964f5 | 195 | std::string temp1; |
38domo | 0:48863a0964f5 | 196 | std::string temp2; |
38domo | 0:48863a0964f5 | 197 | |
38domo | 0:48863a0964f5 | 198 | //lastSuccessfulUploadTime is used for upload frequency. |
38domo | 0:48863a0964f5 | 199 | time_t lastSuccessfulUploadTime = 0; |
38domo | 0:48863a0964f5 | 200 | printf("\n Init touchJPA1 ...\n"); |
38domo | 0:48863a0964f5 | 201 | int yy; |
38domo | 0:48863a0964f5 | 202 | printf("\n Init initDisplayTemp ...\n"); |
38domo | 0:48863a0964f5 | 203 | yy = initDisplayTemp(); // from guijpa.cpp - Init display |
38domo | 0:48863a0964f5 | 204 | printf("\ninit touchInitJPA1 ...\n"); |
38domo | 0:48863a0964f5 | 205 | yy = touchInitJPA1(); // from touchscreen.cpp - init touchscreen |
38domo | 0:48863a0964f5 | 206 | yy = touchInitGuiJPA1(); // from touchscreen.cpp |
38domo | 0:48863a0964f5 | 207 | printf("\ninit initDatasGuiJPA ...\n"); |
38domo | 0:48863a0964f5 | 208 | yy = initDatasGuiJPA(); // from guijpa.cpp - config buttons |
38domo | 0:48863a0964f5 | 209 | ////lcd.printf("Starting..."); |
38domo | 0:48863a0964f5 | 210 | printf("Starting...\n"); |
38domo | 0:48863a0964f5 | 211 | lastToucheTime = time(NULL); |
38domo | 0:48863a0964f5 | 212 | char data[5]; |
jeanpierreaulas | 2:462b5c0d3472 | 213 | |
jeanpierreaulas | 2:462b5c0d3472 | 214 | // config can -------------------------------------- |
jeanpierreaulas | 2:462b5c0d3472 | 215 | can.frequency(125000); // set CAN bit rate to 125 kbps |
jeanpierreaulas | 2:462b5c0d3472 | 216 | //can.filter(RX_ID, 0xFFF, CANStandard, 0); // set filter #0 to accept only standard messages with ID == RX_ID |
jeanpierreaulas | 3:2de8e4771674 | 217 | can.attach(onCanReceived, CAN::RxIrq); |
jeanpierreaulas | 2:462b5c0d3472 | 218 | |
jeanpierreaulas | 3:2de8e4771674 | 219 | // main loop --------------------------------------------------- |
38domo | 0:48863a0964f5 | 220 | while (true) { |
jeanpierreaulas | 2:462b5c0d3472 | 221 | |
jeanpierreaulas | 2:462b5c0d3472 | 222 | if (CanRcv > 0) |
jeanpierreaulas | 2:462b5c0d3472 | 223 | { |
jeanpierreaulas | 2:462b5c0d3472 | 224 | CanRcv = 0; |
jeanpierreaulas | 2:462b5c0d3472 | 225 | printMsg(rxMsg,1); |
jeanpierreaulas | 2:462b5c0d3472 | 226 | BSP_LCD_DisplayStringAt(0, LINE(5), (uint8_t *)"Can msg rec", CENTER_MODE); |
jeanpierreaulas | 2:462b5c0d3472 | 227 | if (rxMsg.id == RX_ID) { |
jeanpierreaulas | 2:462b5c0d3472 | 228 | rxMsg >> counter; |
jeanpierreaulas | 2:462b5c0d3472 | 229 | rxMsg >> voltage; |
jeanpierreaulas | 3:2de8e4771674 | 230 | //serialUSB.printf(" counter = %d\r\n", counter); |
jeanpierreaulas | 3:2de8e4771674 | 231 | //serialUSB.printf(" voltage = %e V\r\n", voltage); |
jeanpierreaulas | 2:462b5c0d3472 | 232 | } |
jeanpierreaulas | 2:462b5c0d3472 | 233 | } |
jeanpierreaulas | 3:2de8e4771674 | 234 | |
jeanpierreaulas | 3:2de8e4771674 | 235 | if (msgSerialUSB > 0) {receiveSerialUSB();} |
jeanpierreaulas | 4:fbbf5d1785e7 | 236 | if (msgSerial2 > 0) {receiveSerial2();} |
jeanpierreaulas | 4:fbbf5d1785e7 | 237 | if (msgSerial7 > 0) {receiveSerial7();} |
jeanpierreaulas | 3:2de8e4771674 | 238 | |
38domo | 0:48863a0964f5 | 239 | // timer send can |
jeanpierreaulas | 3:2de8e4771674 | 240 | if(timer.read_ms() >= 10000) // check for timeout |
38domo | 0:48863a0964f5 | 241 | { timer.stop(); // stop the timer |
38domo | 0:48863a0964f5 | 242 | timer.reset(); // reset the timer |
jeanpierreaulas | 2:462b5c0d3472 | 243 | counter = (counter+1) & 1; // increment the counter |
jeanpierreaulas | 2:462b5c0d3472 | 244 | voltage = 0;////(analogIn * 3.3f)/4096.0f;// read the small drifting voltage from analog input |
38domo | 0:48863a0964f5 | 245 | txMsg.clear(); // clear the Tx message storage |
38domo | 0:48863a0964f5 | 246 | //txMsg.id = TX_ID; // set ID |
jeanpierreaulas | 2:462b5c0d3472 | 247 | //txMsg.type=0; |
jeanpierreaulas | 2:462b5c0d3472 | 248 | //txMsg.format=4; |
jeanpierreaulas | 2:462b5c0d3472 | 249 | txMsg.id = 0x100130CA;//TX_ID; // set the message ID |
38domo | 0:48863a0964f5 | 250 | txMsg.format = CANExtended ; //extended |
38domo | 0:48863a0964f5 | 251 | // We are about to transmit two data items to the CAN bus. |
38domo | 0:48863a0964f5 | 252 | // counter: uint_8 (unsigned eight bits int) value (one byte). |
38domo | 0:48863a0964f5 | 253 | // voltage: floating point value (four bytes). |
38domo | 0:48863a0964f5 | 254 | // So the total length of payload data is five bytes. |
38domo | 0:48863a0964f5 | 255 | // We'll use the "<<" (append) operator to add data to the CAN message. |
38domo | 0:48863a0964f5 | 256 | // The usage is same as of the similar C++ io-stream operators. |
38domo | 0:48863a0964f5 | 257 | // NOTE: The data length of CAN message is automatically updated when using "<<" operators. |
jeanpierreaulas | 2:462b5c0d3472 | 258 | txMsg.len=2; |
jeanpierreaulas | 2:462b5c0d3472 | 259 | txMsg.data[0]=8;txMsg.data[1]=counter; // append data (total data length must be <= 8 bytes!) |
38domo | 0:48863a0964f5 | 260 | |
38domo | 0:48863a0964f5 | 261 | if(can.write(txMsg)) // transmit message |
38domo | 0:48863a0964f5 | 262 | { //if(can->write(txMsg)) { // transmit the CAN message |
38domo | 0:48863a0964f5 | 263 | printMsg(txMsg,0); |
38domo | 0:48863a0964f5 | 264 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:48863a0964f5 | 265 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 266 | } |
38domo | 0:48863a0964f5 | 267 | else |
jeanpierreaulas | 3:2de8e4771674 | 268 | { //serialUSB.printf("Transmission error\r\n"); |
38domo | 0:48863a0964f5 | 269 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:48863a0964f5 | 270 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 271 | } |
jeanpierreaulas | 2:462b5c0d3472 | 272 | timer.start(); // insert transmission lag |
38domo | 0:48863a0964f5 | 273 | } // end if timer |
38domo | 0:48863a0964f5 | 274 | //touch screen |
38domo | 0:48863a0964f5 | 275 | int xx = touchJPA1(); // |
38domo | 0:48863a0964f5 | 276 | if (xx > 0) |
jeanpierreaulas | 3:2de8e4771674 | 277 | { |
jeanpierreaulas | 3:2de8e4771674 | 278 | if (xx == 4) |
38domo | 0:48863a0964f5 | 279 | { // send trame to can |
jeanpierreaulas | 3:2de8e4771674 | 280 | txMsg.id = 0x100130CB;//TX_ID; // set the message ID |
jeanpierreaulas | 3:2de8e4771674 | 281 | txMsg.format = CANExtended ; //extended |
jeanpierreaulas | 3:2de8e4771674 | 282 | txMsg.len=2; |
jeanpierreaulas | 3:2de8e4771674 | 283 | txMsg.data[0]=8;txMsg.data[1]=2; // append data (total data length must be <= 8 bytes!) |
jeanpierreaulas | 3:2de8e4771674 | 284 | |
38domo | 0:48863a0964f5 | 285 | if(can.write(txMsg)) // transmit message |
jeanpierreaulas | 3:2de8e4771674 | 286 | { |
38domo | 0:48863a0964f5 | 287 | printMsg(txMsg,0); |
38domo | 0:48863a0964f5 | 288 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"TX CAN OK", CENTER_MODE); |
38domo | 0:48863a0964f5 | 289 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"--------", CENTER_MODE); |
jeanpierreaulas | 3:2de8e4771674 | 290 | } |
38domo | 0:48863a0964f5 | 291 | else |
jeanpierreaulas | 3:2de8e4771674 | 292 | { |
38domo | 0:48863a0964f5 | 293 | BSP_LCD_DisplayStringAt(0, LINE(4), (uint8_t *)"TX CAN Fail", CENTER_MODE); |
38domo | 0:48863a0964f5 | 294 | BSP_LCD_DisplayStringAt(0, LINE(3), (uint8_t *)"-----------", CENTER_MODE); |
38domo | 0:48863a0964f5 | 295 | } |
38domo | 0:48863a0964f5 | 296 | } |
38domo | 0:48863a0964f5 | 297 | xx = sendTouchJPA(xx); |
38domo | 0:48863a0964f5 | 298 | |
38domo | 0:48863a0964f5 | 299 | lastToucheTime = time(NULL); |
38domo | 0:48863a0964f5 | 300 | |
38domo | 0:48863a0964f5 | 301 | } |
38domo | 0:48863a0964f5 | 302 | else |
38domo | 0:48863a0964f5 | 303 | { lastToucheTime = 0; |
38domo | 0:48863a0964f5 | 304 | } // send mqtt |
38domo | 0:48863a0964f5 | 305 | // Update sensor data to GroveStreams |
jeanpierreaulas | 3:2de8e4771674 | 306 | time_t seconds = time(NULL); |
38domo | 0:48863a0964f5 | 307 | if(seconds - lastSuccessfulUploadTime > updateFrequency) { |
38domo | 0:48863a0964f5 | 308 | ////lcd.clear(); |
38domo | 0:48863a0964f5 | 309 | ////lcd.printf("Getting Samples..."); |
38domo | 0:48863a0964f5 | 310 | printf("Getting Samples...\n"); |
38domo | 0:48863a0964f5 | 311 | //Assemble the samples into URL parameters which are seperated with the "&" character |
38domo | 0:48863a0964f5 | 312 | // Example: &s1=6.2&s2=78.231 |
jeanpierreaulas | 2:462b5c0d3472 | 313 | int temperature = 0; //adc_temp.read() * 100.0f; |
jeanpierreaulas | 2:462b5c0d3472 | 314 | int voltage = 0; //adc_vref.read() * 100.0f; |
38domo | 0:48863a0964f5 | 315 | char samples[64] = {0}; |
38domo | 0:48863a0964f5 | 316 | sprintf(samples, "&%s=%d&%s=%d", gsStreamId1, voltage, gsStreamId2, temperature); |
38domo | 0:48863a0964f5 | 317 | //Append on command requests (request stream values) |
38domo | 0:48863a0964f5 | 318 | //This will indicate to GroveStreams to return the last value |
38domo | 0:48863a0964f5 | 319 | // of each request stream during the sample upload |
38domo | 0:48863a0964f5 | 320 | strcat(samples, "&rsid=freq&rsid=led"); |
38domo | 0:48863a0964f5 | 321 | char resultBuffer[700]= {0}; |
38domo | 0:48863a0964f5 | 322 | //Sending Samples (and returning current command stream values) |
38domo | 0:48863a0964f5 | 323 | time_t connectAttemptTime = time(NULL); |
38domo | 0:48863a0964f5 | 324 | int sendResult = groveStreams.send(myMac, samples, gsCompName, gsCompTmplId, resultBuffer, sizeof resultBuffer); //receive mqtt |
38domo | 0:48863a0964f5 | 325 | |
38domo | 0:48863a0964f5 | 326 | if (sendResult == 0) { |
38domo | 0:48863a0964f5 | 327 | ////lcd.printf("Send Successful"); |
38domo | 0:48863a0964f5 | 328 | printf("Send Successful\n"); |
38domo | 0:48863a0964f5 | 329 | lastSuccessfulUploadTime = connectAttemptTime; |
38domo | 0:48863a0964f5 | 330 | //Handle command streams |
38domo | 0:48863a0964f5 | 331 | if (strlen(resultBuffer) > 0 && resultBuffer[0] == '{') { |
38domo | 0:48863a0964f5 | 332 | MbedJSONValue mbedJson; |
38domo | 0:48863a0964f5 | 333 | parse(mbedJson, resultBuffer); |
38domo | 0:48863a0964f5 | 334 | sprintf((char*)text, "HTTP string : %s\n", resultBuffer); |
38domo | 0:48863a0964f5 | 335 | //BSP_LCD_DisplayStringAt(0, LINE(1), (uint8_t *)&text, LEFT_MODE); |
38domo | 0:48863a0964f5 | 336 | if (mbedJson.hasMember("Temp1")) { |
38domo | 0:48863a0964f5 | 337 | int pp=setTemp1(mbedJson["Temp1"].get<std::string>()); |
38domo | 0:48863a0964f5 | 338 | } |
38domo | 0:48863a0964f5 | 339 | if (mbedJson.hasMember("Temp2")) { |
38domo | 0:48863a0964f5 | 340 | int tt=setTemp2(mbedJson["Temp2"].get<std::string>()); |
38domo | 0:48863a0964f5 | 341 | } |
38domo | 0:48863a0964f5 | 342 | if (mbedJson.hasMember("led")) { |
38domo | 0:48863a0964f5 | 343 | //Change LED |
38domo | 0:48863a0964f5 | 344 | myled = mbedJson["led"].get<bool>() ? 1 : 0; |
38domo | 0:48863a0964f5 | 345 | ////lcd.printf("LED: %s", mbedJson["led"].get<bool>() ? "On" : "Off"); |
38domo | 0:48863a0964f5 | 346 | printf("LED: %s\n", mbedJson["led"].get<bool>() ? "On" : "Off"); |
38domo | 0:48863a0964f5 | 347 | } |
38domo | 0:48863a0964f5 | 348 | } |
38domo | 0:48863a0964f5 | 349 | } |
38domo | 0:48863a0964f5 | 350 | } |
38domo | 0:48863a0964f5 | 351 | |
38domo | 0:48863a0964f5 | 352 | } |
38domo | 0:48863a0964f5 | 353 | } |
38domo | 0:48863a0964f5 | 354 | |
38domo | 0:48863a0964f5 | 355 |