Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos AMC7812B EthernetInterface TextLCD
Revision 3:820e3a42c06b, committed 2021-08-06
- Comitter:
- mmdonatti
- Date:
- Fri Aug 06 13:07:37 2021 +0000
- Parent:
- 2:7a49ed074968
- Commit message:
- Last release
Changed in this revision
diff -r 7a49ed074968 -r 820e3a42c06b HTTP_SERVER.cpp --- a/HTTP_SERVER.cpp Mon Apr 26 11:22:48 2021 +0000 +++ b/HTTP_SERVER.cpp Fri Aug 06 13:07:37 2021 +0000 @@ -1,113 +1,10 @@ -#include "HTTP_SERVER.h" - -#ifndef DEBUG -//#define DEBUG -#endif +//#define HTTP_DEBUG -//HTML file - with Javascript -const char *index_html = "<html><head><title>DCM Heaters Driver</title><link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"http://cnpem.br/wp-content/uploads/2018/01/LNLS_Sirius-02-293x300.png\" />\n\ -<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\"></script></head>\n\ -<script language=\"javascript\" type=\"text/javascript\">\n\ -function loop(){\n\ -$.post(\"read_data\", function(data){\n\ -if(data.length >0)\n\ -{\n\ -var str = data;\n\ -var res = str.split(\" \");\n\ -if(res.length == 97){\n\ -var table = '<div id=\"data_table\">'+\n\ -'<table width=\"100%\" border=\"1\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#E3EBFB\">'+\n\ -'<tr align=\"center\" valign=\"middle\">'+\n\ -'<td width=\"50\" height=\"40\"><strong>Channel</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Voltage (V)</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Current (A)</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Duty Cycle PWM (%)</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Current Limit (A)</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Failure</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Overload</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>No Load</font></strong></td>'+\n\ -'<td width=\"96\" height=\"40\"><strong>Enable</font></strong></td></tr>';\n\ -for(var i=0;i<8;i++){\n\ -table = table + '<tr align=\"center\" valign=\"middle\">'+\n\ -'<td width=\"50\" height=\"31\"bgcolor=\"#FFFFFF\"><span style=\"font-weight:bold;\">'+(i+1)+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"#FFFFFF\"><span style=\"font-weight:bold;\">'+res[i*12]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"#FFFFFF\"><span style=\"font-weight:bold;\">'+res[i*12+1]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"#FFFFFF\"><span style=\"font-weight:bold;\">'+res[i*12+2]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"#FFFFFF\"><span style=\"font-weight:bold;\">'+res[i*12+3]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"'+res[i*12+4]+'\"><span style=\"font-weight:bold;\">'+res[i*12+5]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"'+res[i*12+6]+'\"><span style=\"font-weight:bold;\">'+res[i*12+7]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"'+res[i*12+8]+'\"><span style=\"font-weight:bold;\">'+res[i*12+9]+'</span></td>'+\n\ -'<td width=\"96\" height=\"28\"bgcolor=\"'+res[i*12+10]+'\"><span style=\"font-weight:bold;\">'+res[i*12+11]+'</span></td>'+\n\ -'</tr>';\n\ -}\n\ -table = table + '</table></div>';\n\ -document.getElementById(\"data_table\").innerHTML = table;\n\ -}}\n\ -});\n\ -setTimeout(function(){ loop() }, 2000);\n\ -}\n\ -</script>\n\ -<body onLoad=\"loop()\">\n\ -<table width=\"100%\"border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-weight:normal;\">\n\ -<tr>\n\ -<td width=\"25%\" height=\"142\" align=\"center\" valign=\"middle\" style=\"border-bottom: #000000 solid 1px;\">\n\ -<a href=\"http://www.lnls.cnpem.br/\"><img src=\"http://lnls.cnpem.br/wp-content/themes/lnls-v2/assets/images/logo-header.svg\" alt=\"LNLS\" width=\"305\" height=\"142\" /></a></td>\n\ -<td colspan=\"5\" height=\"142\" align=\"center\" scope=\"col\" style=\"border-bottom: #000000 solid 1px;\"><p><span class=\"style7\">DCM HEATERS DRIVER<br /><br/>\n\ -<strong>DIAGNOSTICS<br/></strong></span></p>\n\ -<p><span class=\"style7\"><strong><em> <a href=\"http://www.lnls.cnpem.br\">LNLS</a></em></strong></span></p></td>\n\ -<td width=\"25%\" height=\"142\" align=\"center\" style=\"border-bottom: #000000 solid 1px;\">\n\ -<a href=\"http://www.lnls.cnpem.br/grupos/gae/\"><img src=\"http://www.gae.agency/wp-content/uploads/2016/03/Logo_gae_hp_blue.png\" alt=\"GAE\" width=\"305\" height=\"99\" /></a></td>\n\ -</tr>\n\ -</table>\n<div id=\"data_table\"></div></body></html>\0"; +#include "HTTP_SERVER.h" //table colors vector const char *color[] = {"#C8FFC8\0","#FF0000\0"}; -int index_html_len; //index with html length - -char buffer[MAX_BUFFER_SIZE]; //receive and transmit buffer -char tmp_buffer[200]; //aux buffer -int status_code; //http status code -char reason_phrase[30]; //http reason phrase - -char httpmethod[20]; //http method -char filepath[20]; //file requested -char http_ver[20]; //http version - -int idx_buffer; //index buffer - -//Debug functions -namespace HTTP_SERVER -{ -void DEBUG_PRINT_LINE(const char* arg_line) -{ -#ifdef DEBUG - printf("(HTTP_SERVER) ") - printf(arg_line); - printf("\r\n"); -#endif -} -template<typename T> -void DEBUG_PRINT_LINE(const char* arg_line, T arg_t) -{ -#ifdef DEBUG - printf("(HTTP_SERVER) "); - printf(arg_line, arg_t); - printf("\r\n"); -#endif -} -template<typename T1, typename T2> -void DEBUG_PRINT_LINE(const char* arg_line, T1 arg_t1, T2 arg_t2) -{ -#ifdef DEBUG - printf("(HTTP_SERVER) "); - printf(arg_line, arg_t1, arg_t2); - printf("\r\n"); -#endif -} -} -using namespace HTTP_SERVER; - HttpServer::HttpServer() { buffer[0] = '\0'; //constructor @@ -116,8 +13,11 @@ HttpServer::~HttpServer() { } -bool HttpServer::init() +bool HttpServer::init(char *html_pointer,int html_len) { + index_html = html_pointer; + index_html_len = html_len; + // TCP Socket setup // To open Server-side PORT if(tcpsvr.bind(TCP_PORT)< 0) { @@ -131,12 +31,11 @@ return false; } - index_html_len = strlen(index_html); //calculate string length - + return true; } -bool HttpServer::run(channel *CH) +bool HttpServer::run(channel *CH,char* name) { if(tcpsvr.accept(tcpcon) < 0) { //printf("(HTTP_SERVER) failed to accept connection.\r\n"); @@ -150,79 +49,80 @@ // Request Analysis // - DEBUG_PRINT_LINE("DEBUG MODE"); + HTTP_PRINTF("DEBUG MODE"); + httpmethod = NULL; + filepath = NULL; + http_ver = NULL; switch(tcpcon.receive(buffer, 1023)) { case 0: - //DEBUG_PRINT_LINE("received buffer is empty."); + //HTTP_PRINTF("received buffer is empty."); status_code = 400; sprintf(reason_phrase,"No Request\0"); - httpmethod[0] = '\0'; - filepath[0] = '\0'; - http_ver[0] = '\0'; break; case -1: - DEBUG_PRINT_LINE("failed to read data from client."); + HTTP_PRINTF("failed to read data from client."); status_code = 500; sprintf(reason_phrase,"Internal Server Error\0"); - httpmethod[0] = '\0'; - filepath[0] = '\0'; - http_ver[0] = '\0'; break; default: - DEBUG_PRINT_LINE("Received Data: %d",strlen(buffer)); - DEBUG_PRINT_LINE("-->\r\n"); - DEBUG_PRINT_LINE("%.*s[End of Request]",strlen(buffer),buffer); + HTTP_PRINTF("Received Data: %d",strlen(buffer)); + HTTP_PRINTF("-->\r\n"); + HTTP_PRINTF("%.*s[End of Request]",strlen(buffer),buffer); // get HTTP method, File path, HTTP version - sprintf(httpmethod,strtok(buffer," ")); - filepath[0] = '\0'; - sprintf(http_ver,"HTTP/1.1\0"); - DEBUG_PRINT_LINE("httpmethod: %s", httpmethod); - DEBUG_PRINT_LINE("file path: %s", filepath); - DEBUG_PRINT_LINE("http ver : %s", http_ver); + httpmethod = strtok(buffer," "); + filepath = strtok(NULL, " "); + http_ver = strtok(NULL, "\r\n"); + HTTP_PRINTF("httpmethod: %s", httpmethod); + HTTP_PRINTF("file path: %s", filepath); + HTTP_PRINTF("http ver : %s", http_ver); break; } - if (httpmethod[0] == '\0') { + if (httpmethod == NULL) { buffer[MAX_BUFFER_SIZE - 1] = '\0'; sprintf(buffer,"%s %d %s\r\nConnection: Close\r\n\r\n\0", http_ver, status_code, reason_phrase); - DEBUG_PRINT_LINE("echo back done."); + HTTP_PRINTF("echo back done."); break; } // Response if (strcmp(httpmethod,"GET") == 0 ) //GET request - always index.html stoed in index_html { - DEBUG_PRINT_LINE("GET request incomming."); + HTTP_PRINTF("GET request incomming."); - buffer[MAX_BUFFER_SIZE-1] = '\0'; - status_code = 200; - sprintf(reason_phrase,"OK\0"); - - sprintf(buffer,"%s %d %s\r\nConnection: Close\r\nContent-Type: text/html\r\nKeep-Alive: timeout=15\r\n\r\n\0", http_ver, status_code, reason_phrase); - tcpcon.send_all(buffer,strlen(buffer)); - tcpcon.send_all((char*)index_html,index_html_len); + if(strcmp(filepath,"/")==0){ + buffer[MAX_BUFFER_SIZE-1] = '\0'; + status_code = 200; + sprintf(reason_phrase,"OK"); + + sprintf(buffer,"%s %d %s\r\nConnection: Close\r\nContent-Type: text/html\r\nKeep-Alive: timeout=15\r\n\r\n", http_ver, status_code, reason_phrase); + tcpcon.send_all(buffer,strlen(buffer)); + tcpcon.send_all((char*)index_html,index_html_len); + } break; } if (strcmp(httpmethod,"POST") == 0 ) //POST request - javascript request { - DEBUG_PRINT_LINE("POST request incomming."); - status_code = 200; - sprintf(reason_phrase,"OK\0"); - - sprintf(buffer,"%s %d %s\r\nConnection: Close\r\n\r\n\0", http_ver, status_code, reason_phrase); - - for(idx_buffer=0;idx_buffer<=7;idx_buffer++) + if(strcmp(filepath,"/read_data")==0){ + HTTP_PRINTF("POST read_data request incomming."); + for(i=0;i<=7;i++) + { + sprintf(tmp_buffer,"%4.2f %3.2f %.1f %3.2f %d %d %d %d \0",CH[i].voltage,CH[i].current,CH[i].control,CH[i].limit,\ + CH[i].failure,CH[i].overload>ERROR_REP,\ + CH[i].noload>ERROR_REP,CH[i].enable); + tcpcon.send_all(tmp_buffer,strlen(tmp_buffer)); + + } + } + + if(strcmp(filepath,"/device_name")==0) { - sprintf(tmp_buffer,"%4.2f %3.2f %d %3.2f %s %d %s %d %s %d %s %d \0",CH[idx_buffer].voltage,CH[idx_buffer].current,CH[idx_buffer].control,CH[idx_buffer].limit,\ - color[CH[idx_buffer].failure>0],CH[idx_buffer].failure,\ - color[CH[idx_buffer].overload>ERROR_REP],CH[idx_buffer].overload>ERROR_REP,\ - color[CH[idx_buffer].noload>ERROR_REP],CH[idx_buffer].noload>ERROR_REP,\ - color[CH[idx_buffer].enable==0],CH[idx_buffer].enable); - strcat(buffer,tmp_buffer); - + HTTP_PRINTF("POST device_name request incomming."); + sprintf(buffer,"%s",name); + tcpcon.send_all(buffer,strlen(buffer)); } - tcpcon.send_all(buffer,strlen(buffer)); + break;
diff -r 7a49ed074968 -r 820e3a42c06b HTTP_SERVER.h --- a/HTTP_SERVER.h Mon Apr 26 11:22:48 2021 +0000 +++ b/HTTP_SERVER.h Fri Aug 06 13:07:37 2021 +0000 @@ -6,8 +6,17 @@ #include "definitions.h" #include "string.h" +//Debug interface +#ifdef HTTP_DEBUG + #define HTTP_PRINTF(fmt, ...) printf("HTTP: " fmt "\r\n", ##__VA_ARGS__) + +#else + #define HTTP_PRINTF(fmt,...) __NOP() +#endif + #define MAX_BUFFER_SIZE 1024 + using namespace std; enum PortNum { @@ -29,18 +38,34 @@ * @retval TRUE SACCESS * @retval FALSE */ - bool init(); + bool init(char *html_pointer,int html_len); /** Run the surver service while listening flag is true. * * @return state ending. * @retval TRUE at error end. * @retval FALSE at normal end. */ - bool run(channel *CH); + bool run(channel *CH,char* name); // Handlers TCPSocketServer tcpsvr; // TCP server TCPSocketConnection tcpcon; // TCP server connection clerk + +private: + //HTML file - with Javascript + char *index_html; + int index_html_len; //index with html length + + char* httpmethod; + char* filepath; + char* http_ver; + + char buffer[MAX_BUFFER_SIZE]; //receive and transmit buffer + char tmp_buffer[200]; //aux buffer + int status_code; //http status code + char reason_phrase[30]; //http reason phrase + + int i; //index buffer }; #endif \ No newline at end of file
diff -r 7a49ed074968 -r 820e3a42c06b definitions.h --- a/definitions.h Mon Apr 26 11:22:48 2021 +0000 +++ b/definitions.h Fri Aug 06 13:07:37 2021 +0000 @@ -20,8 +20,8 @@ #define DEFINITIONS_H //Limit and digital filtering constants -#define CURR_MAX_LIMIT 1.5 //Maximum current limit allowed -#define DEFAULT_CURR_LIMIT 0.5 //Default current limit. If the config file does not exist, it will be created with this value +#define CURR_MAX_LIMIT 2.5 //Maximum current limit allowed +#define DEFAULT_CURR_LIMIT 1.5 //Default current limit. If the config file does not exist, it will be created with this value #define ERROR_REP 10 //number of consecutive errors (no load or overcurrent) to trigger failure output //Time constants @@ -29,25 +29,39 @@ #define DISPLAY_DELAY 2 //Delay to change channel display in seconds #define DISPLAY_ADJ_DELAY 0.6 //Delay to blink display in adjust mode in seconds #define HEARTBEAT_DELAY 0.7 //HeatBeat Delay in seconds -#define CONV_DELAY 0.01 //Convertion time in seconds. Define the samplin rate. One convertion with calculation takes about 500us +#define CONV_DELAY 0.01 //Convertion time in seconds. Define the sampling rate. One convertion with calculation takes about 500us + +//buffer lengths constants +#define HTML_MAX_SIZE 4500 //Calibration constants #define I_OFF 1.0 //Current measurement offset in volts - linear coefficient -#define I_K 2.2427 //Current measurement constant of proportionality (in V/A) - angular coefficent +#define I_K 1.9839 //Current measurement constant of proportionality (in V/A) - angular coefficent -#ifdef SUPPLY_24V //adjusterments for 24V supply - #define V_K 0.2 //Voltage measurement constant of proportionality (in V/V) - angular coefficent (zeo offset) - #define VC_OFF 4.4 //Control measurement offset in volts - linear coefficient - #define VC_K -0.04 //Control measurement constant of proportionality (in V/V) - angular coefficent +#ifdef SUPPLY_24V //adjusterments for 24V supply (adjusted to 26V input) + #define V_K 0.2 //Voltage measurement constant of proportionality (in V/V) - angular coefficent (zeo offset) + #ifndef CAL + #define VC_OFF 99.915 //Control measurement offset in volts - linear coefficient + #define VC_K -23.675 //Control measurement constant of proportionality (in V/V) - angular coefficent + #else + #define VC_OFF 0 //Control measurement offset in volts - linear coefficient + #define VC_K 100 //Control measurement constant of proportionality (in V/V) - angular coefficent + #endif #else - #define V_K 0.3341 //Voltage measurement constant of proportionality (in V/V) - angular coefficent (zeo offset) - #define VC_OFF 4.4407 //Control measurement offset in volts - linear coefficient - #define VC_K -0.0441 //Control measurement constant of proportionality (in V/V) - angular coefficent + #define V_K 0.333 //Voltage measurement constant of proportionality (in V/V) - angular coefficent (zeo offset) + #ifndef CAL + #define VC_OFF 101.82 //Control measurement offset in volts - linear coefficient + #define VC_K -22.036 //Control measurement constant of proportionality (in V/V) - angular coefficent + #else + #define VC_OFF 0 //Control measurement offset in volts - linear coefficient + #define VC_K 100 //Control measurement constant of proportionality (in V/V) - angular coefficent + #endif + #endif //Digital Filter Constants -#define FILTC 0.8 -#define FILTC2 0.2 +#define FILTC 0.85 //IIR filter constant 1 +#define FILTC2 0.15 //IIR filter constant 2 //MBED LPC1768 pins attribution //LCD Module Pins @@ -76,10 +90,25 @@ #define AL_U4 p16 //U4 Alarm output #define DAV_U4 p17 //U4 Data Available output +//Error interface +#ifdef ERROR_INTERFACE + #define ERROR_PRINTF(fmt, ...) printf("ERROR: " fmt "\r\n", ##__VA_ARGS__) +#else + #define ERROR_PRINTF(fmt, ...) __NOP() +#endif + +//Debug interface +#ifdef DEBUG_INTERFACE + #define DEBUG_PRINTF(fmt, ...) printf("DEBUG: " fmt "\r\n", ##__VA_ARGS__) + +#else + #define DEBUG_PRINTF(fmt,...) __NOP() +#endif + struct channel{ float voltage; float current; - int control; //Control in % + float control; //Control in % float limit; //Current Limit char enable; //Enable Bit char failure; //Failure Bit
diff -r 7a49ed074968 -r 820e3a42c06b main.cpp --- a/main.cpp Mon Apr 26 11:22:48 2021 +0000 +++ b/main.cpp Fri Aug 06 13:07:37 2021 +0000 @@ -19,24 +19,29 @@ *******************************************************************/ #define SUPPLY_24V +//#define CAL #include "mbed.h" #include "TextLCD.h" #include "EthernetInterface.h" #include "amc7812b.h" + +#define ERROR_INTERFACE +//#define DEBUG_INTERFACE + #include "definitions.h" #include "HTTP_SERVER.h" -#define VERSION "v3.0-2018-08\0" //Firmware Version +#define VERSION "v4.1-2021-07\0" //Firmware Version #define DEVICE_NAME "DH-8CH-001\0" //Device Name - Ethernet default hostname #define PORT 6767 //Socket Port (EPICS data) - - //SPI constructor SPI spi(MOSI,MISO,SCLK); //mosi, miso, sclk +Serial pc(USBTX, USBRX, 115200); + //Digital Output constructors DigitalOut cs_u4(CS_U4); DigitalOut cs_u5(CS_U5); @@ -87,7 +92,8 @@ uint16_t data; }rx,tx; -FILE *cfg_file; //Config file variable +FILE *cfg_file; //Config file variable +FILE *html_file; //Html file variable int tmp,i; //auxiliary integers int LCD_index=0; //LCD index (displayed channel changes from 1 to 8) @@ -168,10 +174,33 @@ volatile int save_cfg_time; +char html_page[HTML_MAX_SIZE]; +int html_page_size; + //main function int main() { //heartbeat.attach(&heart,HEARTBEAT_DELAY); //attach heartbeat ticker + t.start(); + // Reading webserver file + wait_ms(10); //Wait powerup + + html_file = fopen("/local/index.htm","r"); // Open "index.html" on the local file system for reading + if(html_file==NULL){ //If file doesnt exist + html_page_size = sprintf(html_page,"ERROR: File Not Found"); + ERROR_PRINTF("index.htm file not found at local file system!"); + fclose(html_file); //close html file + } + else + { //File exists + fseek(html_file, 0, SEEK_SET); + html_page_size = 0; + while (!feof(html_file)) + html_page[html_page_size++]= getc(html_file); + if(feof(html_file)) + html_page_size--; + fclose(html_file); //close html file + } amc_setup(); //Setup AMC7812B setup(); //Initialize LCD and variables @@ -190,6 +219,7 @@ else { clear_lcd(); display.printf("HW ERROR: eth conn"); //HW ethernet error - probably PHY broken + ERROR_PRINTF("Ethernet Connection Hardware Error!"); //Turn LED 1 Red and Green - ETH HW Error display.putc(0xFE); display.putc(0x5A); @@ -225,7 +255,7 @@ eth_led1 = 1; //turn on led1 if(server_init == 0) //initiate http server the first time { - httpsvr.init(); + httpsvr.init(html_page,html_page_size); server_init = 1; //turn flag on - Server initiated server_thread.start(server_loop); //run thread - monitoring port 80 } @@ -417,7 +447,7 @@ ch_msg_idx--; //decrement to index 0 to 7 if(socket_buffer[1]=='r') //read message { - n = sprintf(send_buffer,"OK>%d:\tV=%4.2f\tI=%3.2f\tC=%d\tIL=%3.2f\tF=%d\tOL=%d\tNL=%d\tE=%d\r\n",ch_msg_idx+1,\ + n = sprintf(send_buffer,"OK>%d:\tV=%4.2f\tI=%3.2f\tC=%.1f\tIL=%3.2f\tF=%d\tOL=%d\tNL=%d\tE=%d\r\n",ch_msg_idx+1,\ CH[ch_msg_idx].voltage,CH[ch_msg_idx].current,\ CH[ch_msg_idx].control,CH[ch_msg_idx].limit,\ CH[ch_msg_idx].failure,CH[ch_msg_idx].overload>ERROR_REP,\ @@ -616,14 +646,17 @@ fast_read_U4(); //Estimate control input (Duty cycle in %) - CH[i].control = FILTC*CH[i].control+FILTC2*(((rx.data*5.0/0xFFF))-VC_OFF)/VC_K; + CH[i].control = FILTC*CH[i].control+FILTC2*(rx.data*VC_K*5.0/0xFFF+VC_OFF); - //Verify limits - if(CH[i].control<0) - CH[i].control=0; - if(CH[i].control>100) - CH[i].control=100; + #ifndef CAL + //Verify limits + if(CH[i].control<0) + CH[i].control=0; + if(CH[i].control>100) + CH[i].control=100; + #endif } + DEBUG_PRINTF("Duty Cycle Calibration - Measured Voltage: %f",rx.data*5.0/0xFFF); } } } @@ -643,7 +676,7 @@ { while(1) { - httpsvr.run(&CH[0]); //wait for new client connection + httpsvr.run(&CH[0],dev_name); //wait for new client connection server_led = !server_led; //togle server led } } @@ -688,7 +721,7 @@ //Reset AMC7812B to make sure both are in the initial state amc_reset = 0; - wait_ms(1); + wait_ms(5); amc_reset = 1; // Setup the spi for 12 bit data, high steady state clock, @@ -696,7 +729,7 @@ spi.format(12,1); spi.frequency(10000000); - wait_ms(5); //Wait AMC7812B power up + wait_ms(10); //Wait AMC7812B power up //Disabling Power Down Register tx.data = 0x7FFE; @@ -955,6 +988,7 @@ fprintf(cfg_file,"%d %3.2f 1\n",i+1,DEFAULT_CURR_LIMIT); //Write to file CH[i].enable = 1; } + ERROR_PRINTF("lim.cfg file not found! Creating default file..."); } else //File exists :) { @@ -1039,7 +1073,7 @@ normal(); //Normal mode } clear_lcd(); //Clear LCD - display.printf("CH%d %5.2fV/%3.2fAC:%03d%% IL:%3.2fA",LCD_index+1,CH[LCD_index].voltage,CH[LCD_index].current,CH[LCD_index].control,CH[LCD_index].limit); + display.printf("CH%d %5.2fV/%3.2fAC:%03.0f%% IL:%3.2fA",LCD_index+1,CH[LCD_index].voltage,CH[LCD_index].current,CH[LCD_index].control,CH[LCD_index].limit); } //Heartbeat toogle MBED led function