MicroLog.MyPower.CZ

… designed for freedom of automation.

Uživatelské nástroje

Nástroje pro tento web


source

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Obě strany předchozí revizePředchozí verze
Následující verze
Předchozí verze
source [2013/08/29 23:11] mypower_czsource [2016/04/22 21:34] (aktuální) – upraveno mimo DokuWiki 127.0.0.1
Řádek 3: Řádek 3:
 ===== Info ===== ===== Info =====
  
-Tato verze je pracovní a nemusí být plně funkční.+Verze 2.04
  
 +===== Kompilace projektu =====
 +
 +**Pozor: Pro kompilaci je potřeba použít [[https://www.arduino.cc/en/Main/OldSoftwareReleases#previous|starší verzi Arduino IDE]], ideálně verzi 1.0.5**
 +
 +V nových verzích se můžete setkat s chybou
 +
 +  microlog2:897: error: 'WebServer_p' was not declared in this scope
 +
 +nebo
 +
 +  microlog2:899: error: 'WebServer_p' was not declared in this scope
 ===== Notes ===== ===== Notes =====
  
-  * přidáno manuální ovládání 16ti digitálních výstupů es www rozhraní+  * přidána podpora pro datum a čas, synchronizováno i přenosu na mypower.cz 
 +  * čítač sekund byl změněn na uint32_t 
 +  * mapa eprom byla přesunuta z kódu na [[mod:eprom|wiki]] 
 + 
 +  * [[http://microlog.mypower.cz/source?do=revisions|starší verze]]
  
 ===== Download ===== ===== Download =====
Řádek 19: Řádek 34:
 // ---[ INFO ]---------------------------------------- // ---[ INFO ]----------------------------------------
  
-// MyPower.CZ Microlog +// Program: MyPower.CZ Microlog2 
-// Version 2 +// License: free for non-commercial use 
-// Date08/2013 +// Details: info@mypower.cz
- +
-// created by MyPower.CZ +
-// Licence: free for non-commercial use+
  
 // ---[ VERSION ]------------------------------------- // ---[ VERSION ]-------------------------------------
  
-#define MPWMicroLogVersion     "2.02"+#define MPWMicroLogVersion     "2.04"
  
 // ---[ INCLUDE ]------------------------------------- // ---[ INCLUDE ]-------------------------------------
Řádek 54: Řádek 66:
 //                    [....... LED .....][.not used.][........... RELE .............] //                    [....... LED .....][.not used.][........... RELE .............]
 byte DPINmap[16]  = { 40, 42, 44, 46, 48, 0,  0,  0,  22, 23, 24, 25, 26, 27, 28, 29 }; byte DPINmap[16]  = { 40, 42, 44, 46, 48, 0,  0,  0,  22, 23, 24, 25, 26, 27, 28, 29 };
-uint16_t DPINstatus = 0x0000;+uint16_t DPINstatus    = 0x0000; 
 +//                         <15  08>          <07  >00                           
 +uint16_t DPINlogicmask = (B00000000 << 8) | B00000011;  // pin/bit  0 = standard logic 0 OFF 1 ON,   1 = negative logic 0 ON 1 OFF
  
 // ---[ MODS ]---------------------------------------- // ---[ MODS ]----------------------------------------
Řádek 73: Řádek 87:
  
 // mod WebServer // mod WebServer
-#define modWebServer     1         // 1=on 0=off +#define modWebServer       1         // 1=on 0=off 
-#define modWebServerPort 80        // default: 80+#define modWebServerPort   80        // default: 80
  
 // mod Display // mod Display
-#define modDisplay       1         // 1=on 0=off +#define modDisplay         1         // 1=on 0=off 
-#define modDisplayType   1602      // typ displaye+#define modDisplayType     1602      // typ displaye 
 + 
 +// mod DisplayEmulation 
 +#define modDisplayEmulation        // 1=display neni fyzicky pripojen - zobrazeni jen na www rozhrani  
 +                                     // 0=display pripojen - zobrazeni na fyzickem displayi i na www rozhrani
  
 // --------------------------------------------------- // ---------------------------------------------------
Řádek 84: Řádek 102:
 byte lxLed=0; byte lxLed=0;
 byte lxTime=0; byte lxTime=0;
-long lxSeconds=0; +uint32_t lxSeconds=0; 
-long lxSendIndex=0;+uint32_t lxSendIndex=0;
 byte lxHttpOk=0; byte lxHttpOk=0;
 byte lxHttpErrors=0; byte lxHttpErrors=0;
Řádek 118: Řádek 136:
 #define xpinOPTsampleG2  B00001000 #define xpinOPTsampleG2  B00001000
 #define xpinOPTsampleG3  B00001100 #define xpinOPTsampleG3  B00001100
- 
-// ---------------------------------------------------- 
- 
-// EEPROM 
-//      0 - 40  PIN0 CONF (41 bytes struct tPinConf) 
-//     41 - 81  PIN1 CONF 
-//    82 - 122  PIN2 CONF 
-//   123 - 163  PIN3 CONF 
-//   164 - 204  PIN4 CONF 
-//   205 - 245  PIN5 CONF 
-//   246 - 286  PIN6 CONF 
-//   287 - 327  PIN7 CONF 
-//   328 - 368  PIN8 CONF 
-//   369 - 409  PIN9 CONF 
-//   410 - 450  PIN10 CONF 
-//   451 - 491  PIN11 CONF 
-//   492 - 532  PIN12 CONF 
-//   533 - 573  PIN13 CONF 
-//   574 - 614  PIN14 CONF 
-//   615 - 656  PIN15 CONF 
-//   657 - 683  DeviceConf           (struct tDeviceConf) 
-//  684 - 2047  Display program      (char []) 
-// 2048 - 2067  DPIN Name 0          (char [20]) 
-// 2068 - 2087  DPIN Name 1 
-// 2088 - 2107  DPIN Name 2 
-// 2008 - 2127  DPIN Name 3 
-// 2028 - 2147  DPIN Name 4 
-// 2048 - 2167  DPIN Name 5 
-// 2068 - 2187  DPIN Name 6 
-// 2088 - 2207  DPIN Name 7 
-// 2008 - 2227  DPIN Name 8 
-// 2028 - 2247  DPIN Name 9 
-// 2048 - 2267  DPIN Name 10 
-// 2068 - 2287  DPIN Name 11 
-// 2088 - 2307  DPIN Name 12 
-// 2008 - 2327  DPIN Name 13 
-// 2028 - 2347  DPIN Name 14 
-// 2048 - 2367  DPIN Name 15 
-// 2368 ...     FREE 
  
 struct tPinConf { struct tPinConf {
Řádek 168: Řádek 147:
 }; };
  
-#define xComStatusNop        B00000000 +#define xComStatusNop               B00000000 
-#define xComStatusASchanged  B00000001 +#define xComStatusASchanged         B00000001 
-#define xComStatusDSchanged  B00000010+#define xComStatusDSchanged         B00000010 
 +#define xComStatusIsLastDayInMonth  B00000100 
 +#define xComStatusIsDST             B00001000 
 + 
 +#define xComStatusXXDaysMonthMask   B00110000 
 +#define xComStatus28DaysMonth       B00000000 
 +#define xComStatus29DaysMonth       B00010000 
 +#define xComStatus30DaysMonth       B00100000 
 +#define xComStatus31DaysMonth       B00110000 
 + 
 +struct tMpwAccess {  
 +  byte xComStatus;                    //  flags 
 +  uint16_t mpwremoteDateYear;         //  2013 ... 
 +   uint8_t mpwremoteDateMonth;        //  1-12 
 +   uint8_t mpwremoteDateDay;          //  1-31 
 +   uint8_t mpwremoteDateWeek;         //  1-53 
 +   uint8_t mpwremoteDateDayOfWeek;    //  1 (for Monday) through 7 (for Sunday) 
 +  signed long mpwremoteTimeS;         //  0-86400, -1 - not known 
 +  uint32_t mpwremoteCheckedAtS;       //  local timeS (seconds counter) 
 +  uint32_t mpwlogintimeS;             //  login local timeS  
 +  uint32_t mpwDeviceId;               //  your device ID on mpw server 
 +  uint32_t mpwAccessId;               //  your access ID on mpw server 
 +} xMpwAccess;
  
-struct tMpwAccess byte xComStatus; unsigned long mpwtime; unsigned long mpwtimeAtMS; } xMpwAccess;+struct tMpwDateTime  
 +  int xyear, xmonth, xday, xhour, xminute, xsecond 
 +  };
  
 #define xdcOptBuiltIn      0x00; #define xdcOptBuiltIn      0x00;
Řádek 209: Řádek 212:
 char * _lcdweblbuf1=NULL; char * _lcdweblbuf1=NULL;
 tDispStats * _lcdwebdispstats=NULL; tDispStats * _lcdwebdispstats=NULL;
 +
 +#if (modDisplayEmulation == 0)
 #include <LiquidCrystal.h> #include <LiquidCrystal.h>
 LiquidCrystal lcd(8, 9, 14, 5, 6, 7); LiquidCrystal lcd(8, 9, 14, 5, 6, 7);
 +void lcdClear() { lcd.clear(); }
 +void lcdInit() { lcd.begin(16, 2); lcdClear(); }
 +#else
 +void lcdClear() { }
 +void lcdInit() { lcdClear(); }
 +#endif
 +
 void lcdPrintRight(char * str) { int x=16-strlen(str); lcdPrintAt(str,(x<0?0:x)); } void lcdPrintRight(char * str) { int x=16-strlen(str); lcdPrintAt(str,(x<0?0:x)); }
 void lcdPrintCenter(char * str) { int x=8-(strlen(str)/2); lcdPrintAt(str,(x<0?0:x)); } void lcdPrintCenter(char * str) { int x=8-(strlen(str)/2); lcdPrintAt(str,(x<0?0:x)); }
Řádek 216: Řádek 228:
 void lcdPrintAt(char * str,int x) {  void lcdPrintAt(char * str,int x) { 
   int ix=strlen(str);for (int i=0;((i+x<sizeof(_lcdlbuf)-1) && (i<ix));i++) if (x>=0) _lcdlbuf[i+x]=str[i]; }   int ix=strlen(str);for (int i=0;((i+x<sizeof(_lcdlbuf)-1) && (i<ix));i++) if (x>=0) _lcdlbuf[i+x]=str[i]; }
-void lcdClear() { lcd.clear(); }+//  int ix=strlen(str);for (int i=0;((i+x<sizeof(_lcdlbuf)-1) && (i<ix));i++) if ((x+i)>=0_lcdlbuf[i+x]=str[i]; } ??????
 void lcdClearLine() { int i; for (i=0;i<sizeof(_lcdlbuf)-1;i++) _lcdlbuf[i]=32; _lcdlbuf[i]=0; } void lcdClearLine() { int i; for (i=0;i<sizeof(_lcdlbuf)-1;i++) _lcdlbuf[i]=32; _lcdlbuf[i]=0; }
 void lcdPrintLine(int y) {  void lcdPrintLine(int y) { 
   if ((_lcdweblbuf0!=NULL) && (_lcdweblbuf1!=NULL))   if ((_lcdweblbuf0!=NULL) && (_lcdweblbuf1!=NULL))
     { char * p=_lcdweblbuf0; if (y==1) p=_lcdweblbuf1;strcpy(p,_lcdlbuf); }     { char * p=_lcdweblbuf0; if (y==1) p=_lcdweblbuf1;strcpy(p,_lcdlbuf); }
-  else { lcd.setCursor(0,y); lcd.print(_lcdlbuf); } } +  else {  
-void lcdInit() { lcd.begin(16, 2); lcdClear(); }+#if (modDisplayEmulation == 0)  
 +  lcd.setCursor(0,y); lcd.print(_lcdlbuf);  
 +#endif 
 +} } 
 #endif #endif
  
Řádek 247: Řádek 263:
  
 #if (modSerialLog == 1) #if (modSerialLog == 1)
-XLog(sn1);XLog(sn2); +XLog(sn1);XLog(sn2);XLog(MPWMicroLogVersion); 
-XLog(MPWMicroLogVersion);+
 #if (modMyPowerLog == 1) #if (modMyPowerLog == 1)
-xMpwAccess.mpwtimeAtMS=0;+xMpwAccess.mpwremoteDateYear=0; 
 +xMpwAccess.mpwremoteDateMonth=0; 
 +xMpwAccess.mpwremoteDateDay=0; 
 +xMpwAccess.mpwremoteDateWeek=0; 
 +xMpwAccess.mpwremoteDateDayOfWeek=0; 
 +xMpwAccess.mpwremoteTimeS=-1; 
 +xMpwAccess.mpwremoteCheckedAtS=0; 
 +xMpwAccess.mpwlogintimeS=0; 
 +xMpwAccess.mpwDeviceId=0; 
 +xMpwAccess.mpwAccessId=0;
 xMpwAccess.xComStatus=xComStatusNop; xMpwAccess.xComStatus=xComStatusNop;
-XLog("+mpwlog");+char cx[50]="+mpwlog ";strcat(cx,modMyPowerHost);XLog(cx);
 #endif #endif
 +
 #if (modDisplay == 1) #if (modDisplay == 1)
-XLog("+disp");+char ccx[50]=""; 
 +#if (modDisplayEmulation == 1 ) 
 +sprintf(ccx,"+dispemu @ %04d",modDisplayType); 
 +#else 
 +sprintf(ccx,"+disp @ %04d",modDisplayType);
 #endif #endif
 +XLog(ccx);
 +#endif
 +
 #endif #endif
  
Řádek 268: Řádek 301:
  
 DPINResetHW(); DPINResetHW();
-pinMode(10, OUTPUT);digitalWrite(10,HIGH);+pinMode(53, OUTPUT);digitalWrite(53,HIGH);
  
 int xret=0; int xret=0;
Řádek 318: Řádek 351:
 server.begin(); server.begin();
 #if modSerialLog == 1 #if modSerialLog == 1
-char c[30]="";sprintf(c,"+www@%d",modWebServerPort);XLog(c);+char c[30]="";sprintf(c,"+www @ %d",modWebServerPort);XLog(c);
 #endif #endif
 #endif #endif
Řádek 408: Řádek 441:
 if (lxHttpOk==2) xsi=xsr; if (lxHttpOk==2) xsi=xsr;
 if (xsi<30) xsi=30; if (xsi<30) xsi=30;
-long qlxSendIndex=lxSeconds;+uint32_t qlxSendIndex=lxSeconds;
 if ((lxSendIndex+xsi<=qlxSendIndex) || (lxHttpOk==0)) if ((lxSendIndex+xsi<=qlxSendIndex) || (lxHttpOk==0))
   {   {
Řádek 427: Řádek 460:
     client.write((byte*)xtext,strlen(xtext));       client.write((byte*)xtext,strlen(xtext));  
  
-//struct tMpwAccess { unsigned long mpwtime; unsigned long mpwtimeAtMS; } xMpwAccess; +    boolean islogin=(xMpwAccess.mpwlogintimeS==0);
- +
-    boolean islogin=(xMpwAccess.mpwtimeAtMS==0);+
  
 if (islogin) if (islogin)
Řádek 441: Řádek 472:
   }   }
    
-      sprintf(xtext,"utime=%lu/%ld; ",millis(),lxSeconds);+      sprintf(xtext,"utime=%lu/%lu; ",millis(),lxSeconds);
       client.write((byte*)xtext,strlen(xtext));       client.write((byte*)xtext,strlen(xtext));
       sprintf(xtext,"AX=VSAMX; ");       sprintf(xtext,"AX=VSAMX; ");
Řádek 461: Řádek 492:
       if (isvalid)       if (isvalid)
         {          { 
-        sprintf(xtext,"AC%d=%X/%ld.%04d/%ld.%04d/",xp,pconf.xopt,pconf.xmin, +        char smin10k[30]="";sprint10k(smin10k,pconf.xmin,pconf.xmin10000); 
-          pconf.xmin10000,pconf.xmax,pconf.xmax10000);+        char smax10k[30]="";sprint10k(smax10k,pconf.xmax,pconf.xmax10000); 
 +//        sprintf(xtext,"AC%d=%X/%ld.%04d/%ld.%04d/",xp,pconf.xopt,pconf.xmin,pconf.xmin10000,pconf.xmax,pconf.xmax10000); 
 +        sprintf(xtext,"AC%d=%X/%s/%s/",xp,pconf.xopt,smin10k,smax10k);
         client.write((byte*)xtext,strlen(xtext));         client.write((byte*)xtext,strlen(xtext));
         xtext[0]=0;         xtext[0]=0;
Řádek 542: Řádek 575:
  
 void ParseHTTPResult(char * xtext) {  void ParseHTTPResult(char * xtext) { 
-xMpwAccess.mpwtimeAtMS=millis(); 
-if (strcmp(xtext,"result:OK")==0) lxHttpOk=1; 
 #if modSerialLog == 1 #if modSerialLog == 1
 XLog2(xtext,"# "); XLog2(xtext,"# ");
 #endif #endif
 +if (strcmp(xtext,"result:OK")==0) lxHttpOk=1; else
 +if (strncmp(xtext,"qid:",4)==0) ParseQID(xtext+4);
 +}
 +
 +void ParseQID(char * xtext) {
 +if (xMpwAccess.mpwlogintimeS==0) xMpwAccess.mpwlogintimeS=lxSeconds;
 +char * p=strchr(xtext,'.');
 +if (p!=NULL)
 +  {  
 +  p[0]=0;
 +  xMpwAccess.mpwDeviceId=atol(xtext);
 +  p++;
 +  char * px=strchr(p,'.');
 +  if (px!=NULL)
 +    {
 +    px[0]=0;
 +    px++;
 +    xMpwAccess.mpwAccessId=atol(p);
 +    if (strlen(px)==20)
 +      {
 +      char c[30]="";
 +      strncpy(c,px,4);c[4]=0;xMpwAccess.mpwremoteDateYear=atoi(c);px+=4;
 +      strncpy(c,px,2);c[2]=0;xMpwAccess.mpwremoteDateMonth=atoi(c);px+=2;
 +      strncpy(c,px,2);c[2]=0;xMpwAccess.mpwremoteDateDay=atoi(c);px+=2;
 +      strncpy(c,px,2);c[2]=0;signed long xhour=atoi(c);px+=2;
 +      strncpy(c,px,2);c[2]=0;signed long xminute=atoi(c);px+=2;
 +      strncpy(c,px,2);c[2]=0;signed long xsecond=atoi(c);px+=2;
 +      strncpy(c,px,2);c[2]=0;byte xdaysinmonth=atoi(c);px+=2;
 +      strncpy(c,px,1);c[1]=0;byte xisdst=atoi(c);px+=1;
 +      strncpy(c,px,1);c[1]=0;xMpwAccess.mpwremoteDateDayOfWeek=atoi(c);px+=1;
 +      strncpy(c,px,2);c[2]=0;xMpwAccess.mpwremoteDateWeek=atoi(c);px+=2;
 +
 +      if (xisdst==1)
 +        xMpwAccess.xComStatus|=xComStatusIsDST;
 +      else
 +        xMpwAccess.xComStatus&=~xComStatusIsDST;
 +
 +      if (xdaysinmonth==xMpwAccess.mpwremoteDateDay)
 +        xMpwAccess.xComStatus|=xComStatusIsLastDayInMonth;
 +      else
 +        xMpwAccess.xComStatus&=~xComStatusIsLastDayInMonth;
 +        
 +      xMpwAccess.xComStatus&=~xComStatusXXDaysMonthMask;
 +      if (xdaysinmonth==28) xMpwAccess.xComStatus|=xComStatus28DaysMonth;
 +      if (xdaysinmonth==29) xMpwAccess.xComStatus|=xComStatus29DaysMonth;
 +      if (xdaysinmonth==30) xMpwAccess.xComStatus|=xComStatus30DaysMonth;
 +      if (xdaysinmonth==31) xMpwAccess.xComStatus|=xComStatus31DaysMonth;
 +        
 +      xMpwAccess.mpwremoteTimeS=(xhour*3600)+(xminute*60)+(xsecond);
 +      xMpwAccess.mpwremoteCheckedAtS=lxSeconds;
 +      }
 +    }
 +  
 +  }
 +
 +/*  
 +char xstr[50]="";
 +tMpwDateTime xMpwDateTime;
 +GetCurrentDateTime(&xMpwDateTime);
 +FormatDateTimeStr(xstr, "j.n.Y H:i:s",&xMpwDateTime,sizeof(xstr));
 +Serial.println(xstr);
 +*/
 } }
 #endif #endif
 +
 +
 +
 +void FormatDateTimeStr(char * xstr, char * xfmt, struct tMpwDateTime * xMpwDateTime,int xmaxlen)
 +{
 +xstr[0]=0;
 +while (strlen(xfmt)>0)
 +  {
 +  char ch=xfmt[0];
 +  char cout[20]="";
 +  if (ch=='d') sprintf(cout,"%02d",xMpwDateTime->xday); else
 +  if (ch=='j') sprintf(cout,"%d",xMpwDateTime->xday); else
 +  if (ch=='m') sprintf(cout,"%02d",xMpwDateTime->xmonth); else
 +  if (ch=='n') sprintf(cout,"%d",xMpwDateTime->xmonth); else
 +  if (ch=='Y') sprintf(cout,"%d",xMpwDateTime->xyear); else
 +  if (ch=='y') sprintf(cout,"%d",xMpwDateTime->xyear%99); else
 +  if (ch=='g') sprintf(cout,"%d",((xMpwDateTime->xhour%12)+1)); else
 +  if (ch=='G') sprintf(cout,"%d",(xMpwDateTime->xhour)); else
 +  if (ch=='h') sprintf(cout,"%02d",((xMpwDateTime->xhour%12)+1)); else
 +  if (ch=='H') sprintf(cout,"%02d",(xMpwDateTime->xhour)); else
 +  if (ch=='i') sprintf(cout,"%02d",(xMpwDateTime->xminute)); else
 +  if (ch=='s') sprintf(cout,"%02d",(xMpwDateTime->xsecond)); else
 +    { cout[0]=ch;cout[1]=0; }
 +    
 +  xfmt++;
 +  if (strlen(xstr)+strlen(cout)<xmaxlen) strcat(xstr,cout); else break;
 +  }
 +}
 +
 +int GetCurrentDateTime_DaysInMonth()
 +{
 +int xret=28;
 +int xst=xMpwAccess.xComStatus&xComStatusXXDaysMonthMask;
 +if (xst==xComStatus28DaysMonth) xret=28; else
 +if (xst==xComStatus29DaysMonth) xret=29; else
 +if (xst==xComStatus30DaysMonth) xret=30; else
 +if (xst==xComStatus31DaysMonth) xret=31;
 +return xret;
 +}
 + 
 +void GetCurrentDateTime(struct tMpwDateTime * xMpwDateTime)
 +{
 +if (xMpwAccess.mpwremoteCheckedAtS>0)
 +  {
 +  xMpwDateTime->xyear=xMpwAccess.mpwremoteDateYear;
 +  xMpwDateTime->xmonth=xMpwAccess.mpwremoteDateMonth;
 +  xMpwDateTime->xday=xMpwAccess.mpwremoteDateDay;
 +  uint32_t xtime=lxSeconds-xMpwAccess.mpwremoteCheckedAtS+xMpwAccess.mpwremoteTimeS;
 +  if (xtime>=86400)
 +    {
 +    int xdaysover=xtime/86400UL;
 +    int xtimeover=xtime%86400UL;
 +
 +    if (xdaysover>25) // max 25 days without time sync
 +      {
 +      xMpwDateTime->xyear=0;
 +      xMpwDateTime->xmonth=0;
 +      xMpwDateTime->xday=0;
 +      }
 +    else
 +      { 
 +      int xdaysinmonth=GetCurrentDateTime_DaysInMonth();
 +      for (int i=0;i<xdaysover;i++)
 +        {
 +        if (xMpwDateTime->xday<xdaysinmonth)
 +          xMpwDateTime->xday++;  
 +        else
 +          {
 +          xMpwDateTime->xday=1;
 +          if (xMpwDateTime->xmonth<12)
 +            xMpwDateTime->xmonth++;
 +          else
 +            {
 +            xMpwDateTime->xmonth=1;
 +            xMpwDateTime->xyear++;
 +            }
 +          }
 +        }
 +      }
 +  
 +    xtime=xtimeover;
 +    }
 +  xMpwDateTime->xhour=(xtime/3600)%24;
 +  int xmod=(xtime%3600);
 +  xMpwDateTime->xminute=(xmod/60)%60;
 +  xMpwDateTime->xsecond=xmod%60;
 +  }
 +else
 +  {
 +  uint32_t xtime=lxSeconds;
 +  xMpwDateTime->xyear=0;
 +  xMpwDateTime->xmonth=0;
 +  xMpwDateTime->xday=(xtime/86400UL);
 +  xMpwDateTime->xhour=((xtime%86400UL)/3600)%24;
 +  signed long xmod=((xtime%86400L)%3600);
 +  xMpwDateTime->xminute=(xmod/60)%60;
 +  xMpwDateTime->xsecond=xmod%60;    
 +  }
 +}
 +
 +
 +
 +
  
 void FlashError(byte xcount) void FlashError(byte xcount)
Řádek 680: Řádek 876:
 #define xDPinSetStatus    0xE0 #define xDPinSetStatus    0xE0
  
-void WebServer_pf(char * xstr,signed long * xsl,int * xsl10000) { +void WebServer_pf(char * xstr,signed long * xsl,int * xsl10k) { 
-int im; *xsl=0;*xsl10000=0; char * p=xstr; char * p10k=p;+int im; *xsl=0;*xsl10k=0; char * p=xstr; char * p10k=p;
 for (int i=0;i<strlen(xstr);i++) if (p10k[0]=='.') { p10k[0]=0;p10k++;break; } else p10k++; for (int i=0;i<strlen(xstr);i++) if (p10k[0]=='.') { p10k[0]=0;p10k++;break; } else p10k++;
 boolean hm=(p[0]=='-'); if (hm) { p++; } im=strlen(p); boolean hm=(p[0]=='-'); if (hm) { p++; } im=strlen(p);
 for (int i=0;i<im;i++) { *xsl*=10; if ((p[i]>='0') && (p[i]<='9')) *xsl+=(p[i]-'0'); } for (int i=0;i<im;i++) { *xsl*=10; if ((p[i]>='0') && (p[i]<='9')) *xsl+=(p[i]-'0'); }
 im=strlen(p10k); im=strlen(p10k);
-for (int i=0;i<4;i++) { *xsl10000*=10; if ((i<im) && ((p10k[i]>='0') && (p10k[i]<='9')))  +for (int i=0;i<4;i++) { *xsl10k*=10; if ((i<im) && ((p10k[i]>='0') && (p10k[i]<='9')))  
-  *xsl10000+=(p10k[i]-'0'); }+  *xsl10k+=(p10k[i]-'0'); }
 if (hm) *xsl=0-*xsl; if (hm) *xsl=0-*xsl;
 +if (hm) *xsl10k=0-*xsl10k; // minus bugfix
 } }
  
Řádek 1018: Řádek 1215:
     if (strcmp(xstr,"dp")==0) *qsaction=xACTdp; else     if (strcmp(xstr,"dp")==0) *qsaction=xACTdp; else
     if (strcmp(xstr,"sp")==0) *qsaction=xACTsp; else     if (strcmp(xstr,"sp")==0) *qsaction=xACTsp; else
-    if (strcmp(xstr,"dd")==0) *qsaction=xACTdd; else +    if (strcmp(xstr,"dd")==0) *qsaction=xACTdd; else 
 +    if (strcmp(xstr,"ep")==0) *qsaction=xACTep; else
     if (strcmp(xstr,"db")==0) *qsaction=xACTdb;         if (strcmp(xstr,"db")==0) *qsaction=xACTdb;    
     }     }
Řádek 1049: Řádek 1247:
         byte qsaction=(xmode>>8)&0x0F;          byte qsaction=(xmode>>8)&0x0F; 
         if (c == '\n' && cl) {         if (c == '\n' && cl) {
-          client.write("HTTP/1.1 200 OK\nContent-Type: text/html\nConnnection: close\n\n");+          client.write("HTTP/1.1 200 OK\n"); 
 +          if (qsaction==xACTep) 
 +            { 
 +            client.write("Content-Disposition: attachment; filename=\""); 
 +            sprintf(xln,"ulog_eprom_%08lX.hex",millis()); 
 +            client.write((byte*)xln,strlen(xln)); 
 +            client.write("\"\n"); 
 +            client.write("Content-Type: text/plain\nConnnection: close\n\n");               
 +            } 
 +          else 
 +            client.write("Content-Type: text/html\nConnnection: close\n\n");
           if (qmode==xWEBpins) {           if (qmode==xWEBpins) {
             for (int ain = 0; ain < NUM_ANALOG_INPUTS; ain++) {             for (int ain = 0; ain < NUM_ANALOG_INPUTS; ain++) {
Řádek 1066: Řádek 1274:
             (int)lxHttpErrors,(int)modSerialLog,(int)modDisplay,(modDisplay==1)?(int)modDisplayType:(int)0);             (int)lxHttpErrors,(int)modSerialLog,(int)modDisplay,(modDisplay==1)?(int)modDisplayType:(int)0);
             client.write((byte*)xln,strlen(xln));             client.write((byte*)xln,strlen(xln));
-            sprintf(xln,".%lu\nf:%s\nh:%s\nx:%d\nr:",(long)lxSeconds,modMyPowerFVEID,modMyPowerHost,(int)modMyPowerLog);+            sprintf(xln,".%lu\nf:%s\nh:%s\nx:%d\nr:",(unsigned long)lxSeconds,modMyPowerFVEID,modMyPowerHost,(int)modMyPowerLog);
             client.write((byte*)xln,strlen(xln));             client.write((byte*)xln,strlen(xln));
             sprintf(xln,cq,(int)freeRam(),(int)ARDUINO,(int)RAMEND,(int)XRAMEND,             sprintf(xln,cq,(int)freeRam(),(int)ARDUINO,(int)RAMEND,(int)XRAMEND,
             (int)E2END,(int)FLASHEND,(int)SPM_PAGESIZE,(int)E2PAGESIZE);             (int)E2END,(int)FLASHEND,(int)SPM_PAGESIZE,(int)E2PAGESIZE);
             client.write((byte*)xln,strlen(xln));             client.write((byte*)xln,strlen(xln));
-            sprintf(xln,"\nv:%s\nm:%02X%02X%02X%02X%02X%02X\nn:",MPWMicroLogVersion,+            sprintf(xln,"\n\nv:%s\nm:%02X%02X%02X%02X%02X%02X\nn:",MPWMicroLogVersion,
             NETmac[0],NETmac[1],NETmac[2],NETmac[3],NETmac[4],NETmac[5],NETmac[6]);             NETmac[0],NETmac[1],NETmac[2],NETmac[3],NETmac[4],NETmac[5],NETmac[6]);
             client.write((byte*)xln,strlen(xln));                       client.write((byte*)xln,strlen(xln));          
Řádek 1086: Řádek 1294:
               client.write((byte*)xln,strlen(xln));                         client.write((byte*)xln,strlen(xln));          
               }               }
-            sprintf(xln,"\nw:%d/%ld",(int)modWebServer,(long)modWebServerPort);+            sprintf(xln,"\nw:%d/%ld\nde:%d",(int)modWebServer,(long)modWebServerPort,(int)modDisplayEmulation); 
 +            client.write((byte*)xln,strlen(xln)); 
 +            client.write("\nds:"); 
 +            for (int i=0;i<16;i++) 
 +              { 
 +              int qb=DPINmap[i]; 
 +              sprintf(xln,"%d",qb); 
 +              if (i<16) strcat(xln,","); 
 +              client.write((byte*)xln,strlen(xln)); 
 +              } 
 +            sprintf(xln,"/%04X/%04X\n",DPINstatus,DPINlogicmask); 
 +            client.write((byte*)xln,strlen(xln));           
 + 
 +char xstr[30]=""; 
 +tMpwDateTime xMpwDateTime; 
 +GetCurrentDateTime(&xMpwDateTime); 
 +FormatDateTimeStr(xstr, "j.n.Y@H:i:s",&xMpwDateTime,sizeof(xstr)); 
 + 
 + 
 +            sprintf(xln,"mpw:%s/%d.%d.%d.%ld/%lu/%lu/%lu/%lu/%d/%d/%d/%lu\n",xstr,(int)xMpwAccess.mpwremoteDateYear, 
 +              (int)xMpwAccess.mpwremoteDateMonth, 
 +              (int)xMpwAccess.mpwremoteDateDay, 
 +              (signed long)xMpwAccess.mpwremoteTimeS, 
 +              xMpwAccess.mpwremoteCheckedAtS, 
 +              xMpwAccess.mpwlogintimeS, 
 +              xMpwAccess.mpwDeviceId, 
 +              xMpwAccess.mpwAccessId, 
 +              (int)xMpwAccess.xComStatus, 
 +              (int)xMpwAccess.mpwremoteDateWeek, 
 +              (int)xMpwAccess.mpwremoteDateDayOfWeek, 
 +              (unsigned long)(lxSeconds-xMpwAccess.mpwremoteCheckedAtS));
             client.write((byte*)xln,strlen(xln));                       client.write((byte*)xln,strlen(xln));          
 +            
             }             }
           else           else
Řádek 1111: Řádek 1350:
               client.write((byte*)xln,strlen(xln));               client.write((byte*)xln,strlen(xln));
               }               }
-            sprintf(xln,"DX:%04X\n",DPINstatus);+            sprintf(xln,"DX:%04X/%04X\n",DPINstatus,DPINlogicmask);
             client.write((byte*)xln,strlen(xln));             client.write((byte*)xln,strlen(xln));
             }             }
Řádek 1129: Řádek 1368:
               else               else
                 {                  { 
-                sprintf(xln,"%X/%ld.%04d/%ld.%04d/",pconf.xopt,pconf.xmin, +                char smin10k[30]="";sprint10k(smin10k,pconf.xmin,pconf.xmin10000); 
-                  pconf.xmin10000,pconf.xmax,pconf.xmax10000);+                char smax10k[30]="";sprint10k(smax10k,pconf.xmax,pconf.xmax10000); 
 +                sprintf(xln,"%X/%s/%s/",pconf.xopt,smin10k,smax10k);
                 client.write((byte*)xln,strlen(xln));                 client.write((byte*)xln,strlen(xln));
                 xln[0]=0;                 xln[0]=0;
Řádek 1275: Řádek 1515:
           else           else
 #endif          #endif         
 +          if (qsaction==xACTep)
 +            {
 +            sprintf(xln,"uLog/%s/eprom.0-%d/@%08lX\n",MPWMicroLogVersion,E2END,millis());
 +            client.write((byte*)xln,strlen(xln));
 +            unsigned long xsum=0;
 +            char s[20]="";
 +            for (int i=0;i<=E2END;i++)
 +              {
 +              if ((i&15)==0) 
 +                {
 +                sprintf(xln,"%04X: ",i);
 +                client.write((byte*)xln,strlen(xln));
 +                }
 +              int v=EEPROM.read(i);
 +              sprintf(xln,"%02X",v);
 +              int xi=i&15;
 +              s[xi]=((v>32)&&(v<127))?v:'.';
 +              s[xi+1]=0;
 +              client.write((byte*)xln,strlen(xln));          
 +              xsum=(((xsum>>24)&0xFF)|(xsum<<8))+v+i;
 +              if ((i&15)==15) 
 +                {
 +                sprintf(xln," %s\n",s);
 +                client.write((byte*)xln,strlen(xln));
 +                s[0]=0;
 +                }
 +              else client.write(" ");
 +              }
 +            if (s[0]!=0)
 +              {
 +              sprintf(xln," %s\n",s);
 +              client.write((byte*)xln,strlen(xln));
 +              s[0]=0;
 +              }
 +            sprintf(xln,"S:%08lX",xsum);
 +            client.write((byte*)xln,strlen(xln));                      
 +            }
 +          else
           if (qmode==xWEBcfg)             if (qmode==xWEBcfg)  
             {             {
Řádek 1618: Řádek 1896:
         xvar->xval=0;         xvar->xval=0;
         xvar->xval10000=0;         xvar->xval10000=0;
-        DisplayFillVarByPinValue(xpin,xvar,r);+         
 +        if ( (xvar->xname[0]=='@') && (xvar->xname[1]=='T') ) 
 +          DisplayFillVarByTimeVar(xvar); 
 +        else 
 +          DisplayFillVarByPinValue(xpin,xvar,r); 
 +        
         }         }
       else       else
Řádek 1736: Řádek 2019:
 tDispVar xvar; tDispVar xvar;
 DisplayFillVarByPinValue(xpin,&xvar,xpintype); DisplayFillVarByPinValue(xpin,&xvar,xpintype);
-signed long xval=xvar.xval; +//signed long xval=xvar.xval; 
-int xval10k=xvar.xval10000; +//int xval10k=xvar.xval10000; 
-sprintf(xret,"%ld.%04d",xval,xval10k);+sprint10k(xret,xvar.xval,xvar.xval10000); //minus bugfix 
 +//sprintf(xret,"%ld.%04d",xval,xval10k);
 } }
  
Řádek 1799: Řádek 2083:
     {     {
     if (c=='.') { c=xsrc[i+1];     if (c=='.') { c=xsrc[i+1];
 +      if (c=='R') { xdecs=0xFE; i++; }  else
       if ((c>='0') && (c<='9')) { xdecs=c-'0';i++; }       if ((c>='0') && (c<='9')) { xdecs=c-'0';i++; }
       c='#';  }       c='#';  }
Řádek 1835: Řádek 2120:
         {         {
         char pxval[50]="";         char pxval[50]="";
-        char qsc[]=" kMGT"; +        if ( (xvar->xname[0]=='@') && (xvar->xname[1]=='T')
-        char *xsc=qsc; +
-        signed long xval=xvar->xval; +
-        int xval10k=xvar->xval10000; +
-        while (xval>1500)+
           {           {
-          if (xsc[1]==0) break; +          DisplayGetValueByTimeVar(pxval,xvar->xname,sizeof(pxval)); 
-          int64 xq,xr; word xmod; +          } 
-          i64x10k2int10k(&xq, xval,xval10k); +        else 
-          i64divW(&xr, &xmod, &xq, 1000); +          { 
-          i64int10k2x10k(&xval,&xval10k,&xr); +          char qsc[]=" kMGT"; 
-          xsc++;+          char *xsc=qsc; 
 +          signed long xval=xvar->xval; 
 +          int xval10k=xvar->xval10000; 
 + 
 +          if (xdecs==0xFE) 
 +            { 
 +            sprintf(pxval,"%ld",xval); 
 +            } 
 +          else 
 +            { 
 +            while (xval>1500) 
 +              { 
 +              if (xsc[1]==0) break; 
 +              int64 xq,xr; word xmod; 
 +              i64x10k2int10k(&xq, xval,xval10k); 
 +              i64divW(&xr, &xmod, &xq, 1000); 
 +              i64int10k2x10k(&xval,&xval10k,&xr); 
 +              xsc++; 
 +              } 
 +            sprint10k(pxval,xval,xval10k); // minus bugfix 
 +    //        sprintf(pxval,"%ld.%04d",xval,xval10k); 
 +            DisplayCorrectDecs(pxval,xdecs); 
 +            if ((xsc[0]!=' ') && (xsc[0]!=0)) { xsc[1]=0; strcat(pxval,xsc);
 +            }
           }           }
-        sprintf(pxval,"%ld.%04d",xval,xval10k); 
-        DisplayCorrectDecs(pxval,xdecs); 
-        if ((xsc[0]!=' ') && (xsc[0]!=0)) { xsc[1]=0; strcat(pxval,xsc); } 
         for (int cc=0;cc<strlen(pxval);cc++)         for (int cc=0;cc<strlen(pxval);cc++)
           if (ix<xmaxlen-1) { xdst[ix]=pxval[cc];ix++;xdst[ix]=0; }           if (ix<xmaxlen-1) { xdst[ix]=pxval[cc];ix++;xdst[ix]=0; }
Řádek 1865: Řádek 2166:
   hasvar=(c=='$');   hasvar=(c=='$');
   if ((!hasvar) && (ix<xmaxlen-1)) { xdst[ix]=c;ix++;xdst[ix]=0; }   if ((!hasvar) && (ix<xmaxlen-1)) { xdst[ix]=c;ix++;xdst[ix]=0; }
 +  }
 +}
 +
 +
 +void DisplayFillVarByTimeVar(struct tDispVar * xvar)
 +{
 +char px[30]="";
 +DisplayGetValueByTimeVar(px,xvar->xname,sizeof(px));
 +xvar->xval=atol(px);
 +xvar->xval10000=0;
 +}
 +
 +
 +void DisplayGetValueByTimeVar(char * xbuf,char * xvarname,int xbufmaxsize)
 +{
 +xbuf[0]=0;
 +if ((xvarname[0]=='@') && (xvarname[1]=='T'))
 +  {
 +  if (strlen(xvarname)>=3)
 +    {
 +char xfmt[5]="";xfmt[0]=xvarname[2];xfmt[1]=0;
 +tMpwDateTime xMpwDateTime;GetCurrentDateTime(&xMpwDateTime);
 +FormatDateTimeStr(xbuf,xfmt,&xMpwDateTime,xbufmaxsize);
 +    }
   }   }
 } }
Řádek 2129: Řádek 2454:
  
  
 +// -- [MATH10k] -------------------------------------------------
 +
 +boolean isnegative10k(signed long xval, int x10k) { 
 +  boolean xret=(xval<0);if (xval==0) xret=(x10k<0);return xret; 
 +}
 +
 +void sprint10k(char * xret, signed long xval, int x10k) {
 +char xsgn[5]="";if (isnegative10k(xval,x10k)) strcpy(xsgn,"-");
 +if (xval<0) xval=-xval; if (x10k<0) x10k=-x10k;
 +sprintf(xret,"%s%ld.%04d",xsgn,xval,x10k);
 +}
  
 // -- [MATH64] ------------------------------------------------- // -- [MATH64] -------------------------------------------------
Řádek 2210: Řádek 2546:
 word xmod=0;i64divW(&qret, &xmod, xint64, 10000);*x10k=xmod; word xmod=0;i64divW(&qret, &xmod, xint64, 10000);*x10k=xmod;
 signed long qval=(((unsigned long)qret.lh)<<16)+(unsigned long)qret.ll; signed long qval=(((unsigned long)qret.lh)<<16)+(unsigned long)qret.ll;
-*xval=msf?(-qval):qval;xint64->msf=msf;+*xval=msf?(-qval):qval; if (msf) *x10k=-(*x10k); // minus bugfix 
 +xint64->msf=msf;
 } }
  
 void i64x10k2int10k(struct int64 * xret, signed long xval, int x10k) { void i64x10k2int10k(struct int64 * xret, signed long xval, int x10k) {
 int64 q1;int64 q2;i64nul(xret);i64nul(&q1);i64nul(&q2); int64 q1;int64 q2;i64nul(xret);i64nul(&q1);i64nul(&q2);
-boolean msf=((xval)<0);if (msf) xval=-(xval);if (x10k<0) x10k=-(x10k);+/* boolean msf=((xval)<0); */ boolean msf=isnegative10k(xval,x10k); // minus bugfix 
 +if (msf) xval=-(xval);if (x10k<0) x10k=-(x10k);
 q2.ll=(x10k)&0xFFFF;i64mul(&q1, (unsigned long)(xval), 10000UL); q2.ll=(x10k)&0xFFFF;i64mul(&q1, (unsigned long)(xval), 10000UL);
 i64addS(xret, &q1, &q2);xret->msf=msf; i64addS(xret, &q1, &q2);xret->msf=msf;
Řádek 2222: Řádek 2560:
 void i64x10k2int10kH(struct int64 * xret, signed long xval, int x10k) { void i64x10k2int10kH(struct int64 * xret, signed long xval, int x10k) {
 int64 q1;int64 q2;i64nul(xret);i64nul(&q1);i64nul(&q2); int64 q1;int64 q2;i64nul(xret);i64nul(&q1);i64nul(&q2);
-boolean msf=((xval)<0);if (msf) xval=-(xval);if (x10k<0) x10k=-(x10k);+/* boolean msf=((xval)<0); */ boolean msf=isnegative10k(xval,x10k); // minus bugfix 
 +if (msf) xval=-(xval);if (x10k<0) x10k=-(x10k);
 q2.ll=(x10k/100)&0xFFFF;i64mul(&q1, (unsigned long)(xval), 100UL); q2.ll=(x10k/100)&0xFFFF;i64mul(&q1, (unsigned long)(xval), 100UL);
 i64addS(xret, &q1, &q2);xret->msf=msf; i64addS(xret, &q1, &q2);xret->msf=msf;
Řádek 2273: Řádek 2612:
  
 void DPINUpdateHW() { void DPINUpdateHW() {
 +uint16_t dstat=DPINstatus^DPINlogicmask;
 for (int i=0;i<16;i++) { byte xdpin=DPINmap[i]; for (int i=0;i<16;i++) { byte xdpin=DPINmap[i];
-  if ((xdpin>=22) && (xdpin<=49)) digitalWrite(xdpin, ((DPINstatus&(1<<i))==0)?LOW:HIGH);+  if ((xdpin>=22) && (xdpin<=49)) digitalWrite(xdpin, ((dstat&(1<<i))==0)?LOW:HIGH);
   }   }
 } }
Řádek 2282: Řádek 2622:
   if ((xdpin>=22) && (xdpin<=49)) { pinMode(xdpin, OUTPUT); digitalWrite(xdpin, LOW); }   if ((xdpin>=22) && (xdpin<=49)) { pinMode(xdpin, OUTPUT); digitalWrite(xdpin, LOW); }
   }   }
 +DPINUpdateHW();
 } }
 +
  
  
 </file> </file>
source.1377810678.txt.gz · Poslední úprava: 2013/08/30 05:11 (upraveno mimo DokuWiki)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki