Show
Ignore:
Timestamp:
09/18/10 13:47:23 (14 years ago)
Author:
phil
Message:

progress update: additional states. now reads sample month yield data

Files:

Legend:

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

    r68 r69  
    7070extern int solarReadCounter; 
    7171extern unsigned char scDate[6]; /* date received from solar count */ 
     72 
     73extern int resultValueRaw; /* last raw yield value */ 
    7274 
    7375extern int solarStateWhenFail; 
     
    253255 
    254256 
    255         sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d\r\nTimeQueries %d\r\nStateWhenFail=%u , chanWhenFail=%u</h2>", 
    256           correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4], queryTimeCounter, solarStateWhenFail, currentChannelWhenFail 
     257        sprintf( cCountBuf, "<h2>Watt_CRCok=%u\r\nWatt_CRCfail=%u\r\nSC_Date=20%02d-%02d-%02d_%02d:%02d\r\nTimeQueries %d\r\nStateWhenFail=%u , chanWhenFail=%u , resultValueRaw=%u</h2>", 
     258          correctVoltWattRx, failedVoltWattRx, scDate[0], scDate[1], scDate[2], scDate[3], scDate[4], queryTimeCounter, solarStateWhenFail, currentChannelWhenFail, resultValueRaw 
    257259         ); 
    258260        strcat( uip_appdata, cCountBuf ); 
  • webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h

    r67 r69  
    22void initMeterItems(void); 
    33 
    4 portCHAR checkRxOneByteCheckSum(void); 
    5 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 
     4portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte); 
     5portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 
     6 
     7int extractBinaryHexDigitString(unsigned char* srcDataStart,  
     8                                    unsigned char firstSrcByte,  
     9                                    unsigned char lastSrcByte 
     10                                    ); 
     11 
    612 
    713unsigned long long getEpochTimeWithMs(void); 
  • webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c

    r68 r69  
    4040unsigned long queryTimeCounter = 0;  /* counter attempted queries for the time */ 
    4141 
     42int resultValueRaw = 0; /* last yield result value (raw) */  
     43 
    4244static unsigned short staticCRC; 
    4345 
     46static unsigned short calculatedCrc2Byte; /* last calculated CRC (by checkRxTwoByteCheckSum() ) */ 
     47static unsigned char calculatedCrc1Byte; /* last calculated CRC (by checkRxOneByteCheckSum() ) */ 
    4448 
    4549// Pin I/O LED Control Maskbit 
     
    5963#define SOL_QUERY_TIME 4 /* querying the time on the SC */ 
    6064#define SOL_WAIT_FOR_TIME_RSP 5 /* waiting for reply on time query */ 
     65#define SOL_QUERY_YIELD 6 /* querying yield data */ 
     66#define SOL_QUERY_YIELD_WAIT_REPLY 7 /* waiting for yield data reply */ 
    6167#define SOL_FINISHED 0xA /* finished */ 
    6268//#define SOL_ 
     
    100106const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen 
    101107const unsigned char query_sc_time_r_m[] = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; // Zeit abfragen 
     108 
     109// Query month 
     110// Time Stamp:Year=10:Month=1 
     111// ---> 01-Jun-2010 14:41:21 : 02 31 3c 4d 30 31 30 30 30 31 b0 03 
     112// <--- 01-Jun-2010 14:41:21 : 02 31 4d 30 31 30 30 30 31 30 30 30 30 31 34 38 36 aa 03 03 
     113 
     114// tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year 
     115// cc (channel) values: x30 + channel number 
     116// m1: month BCD msb, m2: month BCD lsb 
     117// ck: checksum 
     118// ad: unit address 
     119//                                       ad      tt  cc  m1  m2  ck 
     120//specification: unsigned char req_month_yield[] = "\x02\x31\x3c\x4d\x30\x31\x30\x30\x03"; // Frame for querying the yield. Will be filled in by solQueryYield() 
     121 
     122//                                   02  31  3c  4d  30  30  30  30  30  31  fd  03 
     123unsigned char req_month_yield[] = "\x02\x31\x3c\x4d\x30\x30\x30\x30\x30\x31\xfd\x03"; // Frame for querying the yield. Will be filled in by solQueryYield() 
     124 
     125// tt (time) values: m=minute , h = hour, D = day, M = month (\x31), Y = year 
     126// cc (channel) values: x30 + channel number 
     127// m1: month BCD msb, m2: month BCD lsb 
     128// ck: checksum 
     129// ad: unit address 
     130// r1 to r7: result binary coded hex 
     131//                                                    ad  tt  cc  m1  m2  r1  r2  r3  r4  r5  r6  r7  ck  
     132//specification: unsigned char yield_month_rsp[] = "\x02\x31\x4d\x30\x00\x00\x09\x0c\x04\x0a\x26\x86\xcd\x00\x03"; /* exp. query yield response. Will be filled in by solQueryYield() */ 
     133//specification: unsigned char yield_month_r_m[] = "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; /* exp. query yield seq response mask. Will be filled in by solQueryYield() */ 
     134 
     135//                                   02  31  4d  30  30  30  30  30  31  30  30  30  30  31  35  44  43  9a  03  03 
     136//                                   00  01  02  03  04  05  06  07  08  09  10  11  12  13  14  15  16  17  18  19 
     137unsigned char yield_month_rsp[] = "\x02\x31\x4d\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03"; /* exp. query yield response. Will be filled in by solQueryYield() */ 
     138unsigned char yield_month_r_m[] = "\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; /* exp. query yield seq response mask. Will be filled in by solQueryYield() */ 
     139 
    102140 
    103141//char init1[]  = "abcdef"; 
     
    476514          /* we have got a match! */ 
    477515         
    478           if (checkRxTwoByteCheckSum(1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ 
     516          if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 10, 11) == 1) /* checksum in bytes 11 and 12, check bytes 1 to 10 */ 
    479517          { 
    480518 
     
    497535 
    498536        xLastSolarStateChangeTime = xTaskGetTickCount(); 
    499         solarState = SOL_NO_INIT; /* change state: time response received, now init and query the channels */ 
     537 
     538        currentChannel = 0; /* start yield scan on channel 0 */ 
     539        solarState = SOL_QUERY_YIELD; /* change state: time response received, now init and query the channels */ 
    500540      } 
    501541      else 
     
    505545     
    506546    break; 
     547 
     548    case SOL_QUERY_YIELD: 
     549 
     550        xLastSolarStateChangeTime = xTaskGetTickCount(); 
     551 
     552        /* first, fill in data for tx */ 
     553        // TODO 
     554   
     555 
     556//        req_month_yield[4] = 0x30 + 1; // channel 
     557//        req_month_yield[8] = 0x30 + 0; // month MSB (binary coded hex)  
     558//        req_month_yield[9] = 0x30 + 4; // month LSB (binary coded hex) 
     559 
     560        /* then, calculate the CRC for tx */ 
     561       (void)checkRxOneByteCheckSum(&(req_month_yield[0]), 1, 7, 8); 
     562       /* checksum now in calculatedCrc1Byte */ 
     563 
     564 
     565        // crc 
     566        //req_month_yield[7] = calculatedCrc1Byte; /* fill in checksum */ 
     567 
     568        resetUart3RxBuf(); 
     569        send_uart3((unsigned char *)req_month_yield, sizeof(req_month_yield)); 
     570 
     571        solarState = SOL_QUERY_YIELD_WAIT_REPLY; /* change state: now wait for response */ 
     572 
     573    break; /* end of case SOL_QUERY_YIELD */ 
     574 
     575    case SOL_QUERY_YIELD_WAIT_REPLY: 
     576 
     577 
     578 
     579       cmpResult = checkUart3Received(yield_month_rsp, yield_month_r_m,  sizeof(yield_month_rsp)-1); 
     580 
     581 
     582      /* wait for reply to request, check if full response has arrived */ 
     583      if (cmpResult == 0) 
     584      { 
     585        /* we have got a match! */ 
     586         
     587 
     588        resultValueRaw = extractBinaryHexDigitString( &(rxUART3[0]),  
     589                                    9, /* first byte of binary hex string */ 
     590                                    16 /* last byte of binary hex string */ 
     591                                    ); 
     592 
     593 
     594 
     595        solarState = SOL_NO_INIT; /* go ahead */ 
     596  
     597     } 
     598#if 0 
     599        currentChannel++; /* next channel */ 
     600 
     601        if (currentChannel >= 6) 
     602        { 
     603          solarState = SOL_NO_INIT; /* change state: last channel done */ 
     604        } /* if */ 
     605        else 
     606        { 
     607          solarState = SOL_QUERY_YIELD; /* scan next channel */ 
     608        } /* else */ 
     609#endif 
     610 
     611    break; /* end of case SOL_QUERY_YIELD_WAIT_REPLY */ 
    507612 
    508613 
     
    616721        { 
    617722 
    618           if (checkRxTwoByteCheckSum(1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ 
     723          if (checkRxTwoByteCheckSum(&(rxUART3[0]), 1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ 
    619724          { 
    620725            /* checksum correct */ 
     
    9071012 
    9081013 
    909 portCHAR checkRxOneByteCheckSum(void
     1014portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte
    9101015{ 
    9111016  portCHAR retVal; /* return value */ 
     
    9211026 
    9221027  /* use bytes 1 to 13 for the checksum */ 
    923   for (x = 1; x <= 13; x++) 
     1028  for (x = firstByte; x <= lastByte; x++) 
    9241029  { 
    9251030 
    9261031    /* overflow? */ 
    927  //   if (((portSHORT)crc + (portSHORT)(rxUART3[x])) > 0xFF) 
     1032 //   if (((portSHORT)crc + (portSHORT)(dataStart[x])) > 0xFF) 
    9281033 //   { 
    9291034 //     carry++; 
    9301035 //   } 
    9311036 
    932     crcLONG = (crcLONG + rxUART3[x]); /* add and truncate to 8 bit */ 
     1037    crcLONG = (crcLONG + dataStart[x]); /* add and truncate to 8 bit */ 
    9331038  } 
    9341039 
     
    9411046 
    9421047 
    943   if (crcCHARinv == rxUART3[14]) 
     1048  calculatedCrc1Byte = crcCHARinv; /* save calculated CRC (for use in case of checksum generation) */ 
     1049 
     1050  if (crcCHARinv == dataStart[charCheckSumStartByte]) 
    9441051  { 
    9451052    retVal = 1; /* checksum OK, data is valid */ 
     
    9531060 
    9541061 
    955 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) 
     1062portCHAR checkRxTwoByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) 
    9561063{ 
    9571064  unsigned short cmpValue; 
     
    9651072  { 
    9661073 
    967      crc16_ccitt(rxUART3[x]); 
    968   } 
    969  
    970  
    971  
    972   cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); 
     1074     crc16_ccitt(dataStart[x]); 
     1075  } 
     1076 
     1077 
     1078 
     1079  cmpValue = ((((unsigned short)dataStart[charCheckSumStartByte+1])<<8) | dataStart[charCheckSumStartByte]); 
     1080 
     1081  calculatedCrc2Byte = staticCRC; /* save calculated CRC (for use in case of checksum generation) */ 
     1082 
    9731083  if (cmpValue == (staticCRC & 0xFFFF)) 
    9741084  { 
     
    9961106 
    9971107 
     1108 
     1109 
     1110int extractBinaryHexDigitString(unsigned char* srcDataStart,  
     1111                                    unsigned char firstSrcByte,  
     1112                                    unsigned char lastSrcByte 
     1113                                    ) 
     1114{ 
     1115 
     1116  unsigned char x; 
     1117  int resultValue = 0; /* initial value */ 
     1118  unsigned char round = 0; /* which digit? 0 = LSB */ 
     1119  unsigned char currentCharValue; 
     1120 
     1121  /* go through the bytes backwards (least significant to most significant) */ 
     1122  for (x = lastSrcByte; x >= firstSrcByte; x--) 
     1123  { 
     1124 
     1125    currentCharValue = (srcDataStart[x]) - 0x30; 
     1126    resultValue = resultValue + (currentCharValue << (4 * round)); 
     1127 
     1128    round++; 
     1129  } /* for */ 
     1130 
     1131  return resultValue; 
     1132 
     1133 } /* extractBinaryHexDigitString() */