Changeset 67

Show
Ignore:
Timestamp:
09/04/10 17:14:00 (14 years ago)
Author:
phil
Message:

made 2 byte rx checksum check general (now used for wattage, voltage and time rx packets)
now reads and outputs the time stored in the SolarCount? via http.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c

    r66 r67  
    6868extern int solarReadErrors; 
    6969extern int solarReadCounter; 
     70extern unsigned char scDate[6]; /* date received from solar count */ 
    7071 
    7172HTTPD_CGI_CALL(file, "file-stats", file_stats); 
     
    248249 
    249250 
    250         sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\n</h2>", 
    251           correctVoltWattRx, failedVoltWattRx 
     251        sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d</h2>", 
     252          correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4] 
    252253         ); 
    253254        strcat( uip_appdata, cCountBuf ); 
  • webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h

    r66 r67  
    33 
    44portCHAR checkRxOneByteCheckSum(void); 
    5 portCHAR checkRxTwoByteCheckSum(void); 
     5portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 
    66 
    77unsigned long long getEpochTimeWithMs(void); 
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r66 r67  
    5353#define SOL_CHAN     2 /* querying channel currentChannel */ 
    5454#define SOL_CHAN_WAIT_REPLY 3 /* waiting for reply on channel currentChannel = 0; */ 
     55#define SOL_QUERY_TIME 4 /* querying the time on the SC */ 
     56#define SOL_WAIT_FOR_TIME_RSP 5 /* waiting for reply on time query */ 
    5557#define SOL_FINISHED 0xA /* finished */ 
    5658//#define SOL_ 
     
    8890int uart3_buf[50]; 
    8991 
     92unsigned char scDate[6]; /* date received from solar count */ 
     93 
     94 
     95const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen 
     96const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen 
     97const unsigned char query_sc_time_r_m[] = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; // Zeit abfragen 
    9098 
    9199//char init1[]  = "abcdef"; 
     
    421429      /* now ready to query channel 0 data in next state */ 
    422430      xLastSolarStateChangeTime = xTaskGetTickCount(); 
    423       solarState = SOL_CHAN
     431      solarState = SOL_QUERY_TIME
    424432    } 
    425433    else 
     
    427435      /* no match (yet), stay in state */ 
    428436    } 
    429  
    430  
    431437    break; 
     438 
     439 
     440    case SOL_QUERY_TIME: 
     441 
     442      resetUart3RxBuf(); /* init */ 
     443      currentChannel = 0; /* the channel we query first */ 
     444 
     445       /* send query_sc_time */ 
     446      send_uart3((unsigned char *)query_sc_time, sizeof(query_sc_time)); 
     447      xLastSolarStateChangeTime = xTaskGetTickCount(); 
     448      solarState = SOL_WAIT_FOR_TIME_RSP; /* query sent wait for response */ 
     449    break; 
     450 
     451 
     452    case SOL_WAIT_FOR_TIME_RSP: 
     453 
     454 
     455      cmpResult = checkUart3Received(query_sc_time_rsp, query_sc_time_r_m,  sizeof(query_sc_time_rsp)-1); 
     456      if (cmpResult == 0) 
     457      { 
     458        /* we have got a match! */ 
     459         
     460          if (checkRxTwoByteCheckSum(1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ 
     461          { 
     462 
     463            /* use data only if checksum correct */ 
     464     
     465            scDate[0] = rxUART3[6]; /* year */ 
     466            scDate[1] = rxUART3[7]; /* month */ 
     467            scDate[2] = rxUART3[8]; /* day */ 
     468            scDate[3] = rxUART3[9]; /* hour */ 
     469            scDate[4] = rxUART3[10]; /* min */ 
     470 
     471          } 
     472          else 
     473          { 
     474            ; 
     475          } 
     476 
     477        /* finally, discard data from buffer */ 
     478        resetUart3RxBuf(); 
     479 
     480 
     481        solarState = SOL_CHAN; /* change state: time response received, now query the channels */ 
     482      } 
     483      else 
     484      { 
     485        /* stay in state */ 
     486      } 
     487     
     488    break; 
     489 
    432490 
    433491    case SOL_CHAN: 
     
    512570        { 
    513571 
    514           if (checkRxTwoByteCheckSum() == 1) 
     572          if (checkRxTwoByteCheckSum(1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ 
    515573          { 
    516574            /* checksum correct */ 
     
    824882 
    825883 
    826 portCHAR checkRxTwoByteCheckSum(void
     884portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte
    827885{ 
    828886  unsigned short cmpValue; 
     
    832890  staticCRC = 0xFFFF; /* init 16 bit checksum CRC start value */ 
    833891 
    834   /* use bytes 1 to 13 for the checksum */ 
    835   for (x = 1; x <= 12; x++) 
     892  /* use bytes first to last for the checksum */ 
     893  for (x = firstByte; x <= lastByte; x++) 
    836894  { 
    837895 
     
    841899 
    842900 
    843   cmpValue = ((((unsigned short)rxUART3[14])<<8) | rxUART3[13]); 
     901  cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); 
    844902  if (cmpValue == (staticCRC & 0xFFFF)) 
    845903  {