Changeset 67
- Timestamp:
- 09/04/10 17:14:00 (14 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/EnergyMeters/ARM7_LPC2368_Rowley/webserver/httpd-cgi.c
r66 r67 68 68 extern int solarReadErrors; 69 69 extern int solarReadCounter; 70 extern unsigned char scDate[6]; /* date received from solar count */ 70 71 71 72 HTTPD_CGI_CALL(file, "file-stats", file_stats); … … 248 249 249 250 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] 252 253 ); 253 254 strcat( uip_appdata, cCountBuf ); webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h
r66 r67 3 3 4 4 portCHAR checkRxOneByteCheckSum(void); 5 portCHAR checkRxTwoByteCheckSum( void);5 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ); 6 6 7 7 unsigned long long getEpochTimeWithMs(void); webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c
r66 r67 53 53 #define SOL_CHAN 2 /* querying channel currentChannel */ 54 54 #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 */ 55 57 #define SOL_FINISHED 0xA /* finished */ 56 58 //#define SOL_ … … 88 90 int uart3_buf[50]; 89 91 92 unsigned char scDate[6]; /* date received from solar count */ 93 94 95 const unsigned char query_sc_time[] = "\x02\xB0\xF0\x03\x00\x04\xAB\xB9\x03"; // Zeit abfragen 96 const unsigned char query_sc_time_rsp[] = "\x02\xF0\xB0\x08\x00\x84\x00\x00\x00\x00\x00\x00\x00\x03"; // Zeit abfragen 97 const unsigned char query_sc_time_r_m[] = "\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff"; // Zeit abfragen 90 98 91 99 //char init1[] = "abcdef"; … … 421 429 /* now ready to query channel 0 data in next state */ 422 430 xLastSolarStateChangeTime = xTaskGetTickCount(); 423 solarState = SOL_ CHAN;431 solarState = SOL_QUERY_TIME; 424 432 } 425 433 else … … 427 435 /* no match (yet), stay in state */ 428 436 } 429 430 431 437 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 432 490 433 491 case SOL_CHAN: … … 512 570 { 513 571 514 if (checkRxTwoByteCheckSum( ) == 1)572 if (checkRxTwoByteCheckSum(1, 12, 13) == 1) /* checksum in bytes 13 and 14, check bytes 1 to 12 */ 515 573 { 516 574 /* checksum correct */ … … 824 882 825 883 826 portCHAR checkRxTwoByteCheckSum( void)884 portCHAR checkRxTwoByteCheckSum(unsigned char firstByte, unsigned char lastByte, unsigned charCheckSumStartByte ) 827 885 { 828 886 unsigned short cmpValue; … … 832 890 staticCRC = 0xFFFF; /* init 16 bit checksum CRC start value */ 833 891 834 /* use bytes 1 to 13for 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++) 836 894 { 837 895 … … 841 899 842 900 843 cmpValue = ((((unsigned short)rxUART3[ 14])<<8) | rxUART3[13]);901 cmpValue = ((((unsigned short)rxUART3[charCheckSumStartByte+1])<<8) | rxUART3[charCheckSumStartByte]); 844 902 if (cmpValue == (staticCRC & 0xFFFF)) 845 903 {