Changeset 77
- Timestamp:
- 10/31/10 13:36:00 (14 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
webserver/example/EnergyMeters/Source/EnergyMeters/MetersIncludes.h
r70 r77 1 1 2 2 void initMeterItems(void); 3 4 void convert_uchar_to_2_byte_hexencoding(unsigned char inValue, unsigned char * outMSB, unsigned char * outLSB); 5 unsigned char convertSingleDigit(unsigned char inValue); 6 3 7 4 8 portCHAR checkRxOneByteCheckSum(unsigned char* dataStart, unsigned char firstByte, unsigned char lastByte, unsigned char CheckSumStartByte); webserver/example/EnergyMeters/Source/EnergyMeters/SolarCountUART.c
r76 r77 1373 1373 1374 1374 1375 /* convert day to binary coded hex */ 1376 if (day > 15) 1377 { 1378 req_day_yield[8] = 0x31; /* hex MSB day is 1 */ 1379 day = day - 16; /* decrease day (is now remainder */ 1380 } 1381 else 1382 { 1383 req_day_yield[8] = 0x30; /* hex MSB day is 0 */ 1384 } 1385 req_day_yield[9] = 0x30 + day; /* hex LSB day */ 1375 convert_uchar_to_2_byte_hexencoding(day, &req_day_yield[8], &req_day_yield[9]); 1376 1377 1378 1386 1379 1387 1380 newChkSum = calculate_crc8( (&(req_day_yield[0])), (sizeof(req_day_yield)-1)); … … 1403 1396 req_hour_yield[5] = 0x30 + channel; // channel 1404 1397 1405 if (hour >= 0x10) /* >= 16 */ 1406 { 1407 hourMSB = 1; 1408 } 1409 else 1410 { 1411 hourMSB = 0; 1412 } 1413 hourLSB = hour - (hourMSB * 0x10); 1414 1415 if (hourLSB <= 9) 1416 { 1417 req_hour_yield[9] = 0x30 + hourLSB; // minute LSB (binary coded hex) 1418 } 1419 else 1420 { 1421 req_hour_yield[9] = 0x40 + hourLSB - 0xA; // minute LSB (binary coded hex, 0xA --> 0x40, 0xF -> 0x45) 1422 } 1423 1424 req_hour_yield[8] = 0x30 + hourMSB; // minute MSB (binary coded hex), 30 or 31 here. 1398 1399 convert_uchar_to_2_byte_hexencoding(hour, &req_hour_yield[8], &req_hour_yield[9]); 1400 1401 1402 1425 1403 1426 1404 … … 1463 1441 1464 1442 } /* prepare_yield_query_minute() */ 1443 1444 void convert_uchar_to_2_byte_hexencoding(unsigned char inValue, unsigned char * outMSB, unsigned char * outLSB) 1445 { 1446 1447 *outLSB = convertSingleDigit(inValue & 0xF); 1448 *outMSB = convertSingleDigit(((inValue >> 4) & 0xF)); 1449 } 1450 1451 unsigned char convertSingleDigit(unsigned char inValue) 1452 { 1453 unsigned char retVal; 1454 1455 switch (inValue) 1456 { 1457 case 0x0: 1458 retVal = 0x30 + 0; 1459 break; 1460 case 0x1: 1461 retVal = 0x30 + 1; 1462 break; 1463 case 0x2: 1464 retVal = 0x30 + 2; 1465 break; 1466 case 0x3: 1467 retVal = 0x30 + 3; 1468 break; 1469 case 0x4: 1470 retVal = 0x30 + 4; 1471 break; 1472 case 0x5: 1473 retVal = 0x30 + 5; 1474 break; 1475 case 0x6: 1476 retVal = 0x30 + 6; 1477 break; 1478 case 0x7: 1479 retVal = 0x30 + 7; 1480 break; 1481 case 0x8: 1482 retVal = 0x30 + 8; 1483 break; 1484 case 0x9: 1485 retVal = 0x30 + 9; 1486 break; 1487 1488 case 0xA: 1489 retVal = 0x41 + 0; 1490 break; 1491 case 0xB: 1492 retVal = 0x41 + 1; 1493 break; 1494 case 0xC: 1495 retVal = 0x41 + 2; 1496 break; 1497 case 0xD: 1498 retVal = 0x41 + 3; 1499 break; 1500 case 0xE: 1501 retVal = 0x41 + 4; 1502 break; 1503 case 0xF: 1504 retVal = 0x41 + 5; 1505 break; 1506 1507 default: 1508 retVal = 0x78; /* erro: 'x' */ 1509 1510 } 1511 return retVal; 1512 1513 } /* convertSingleDigit() */