void HalUARTReadAndFormate(uint8 port, uint8 *buf, uint16 len) { (void)port; uint8 i; uint8 string[2]; for(i = 0; i < len; i++) { HalUARTRead(port, string, 2); *buf++ = CharToValue(string); } }
int useTestApp() { int sensor1; int sensor2; char buffer1[10]; char buffer2[10]; int nb1; int nb2; // Open sensor1. sensor1 = open("/sensor1", 0, 0); if (sensor1 < 0) { printf("\nCouldn't open sensor 1.\n"); return ERROR; } printf("\nOpened sensor1.\n"); // Open sensor2. sensor2 = open("/sensor2", 0, 0); if (sensor2 < 0) { printf("Couldn't open sensor 2.\n"); return ERROR; } printf("Opened sensor2.\n\n"); // Read the value from sensor1. nb1 = read(sensor1, buffer1, 10); if (nb1 >= 0) { printf("Resultat 1 :\n"); // Id printf("Id: "); printf("%d\n", CharToInt(buffer1)); // Time printf("Time: "); printf("%d\n", CharToLong(buffer1 + ID_SIZE)); // Value printf("Value: "); printf("%d\n\n", CharToValue(buffer1 + ID_SIZE + TIME_SIZE)); } else { printf("Nothing to read on sensor 1.\n\n"); } // Read the value from sensor2. nb2 = read(sensor2, buffer2, 10); if (nb2 >= 0) { printf("Resultat 2 :\n"); // Id printf("Id: "); printf("%d\n", CharToInt(buffer2)); // Time printf("Time: "); printf("%d\n", CharToLong(buffer2 + ID_SIZE)); // Value printf("Value: "); printf("%d\n\n", CharToValue(buffer2 + ID_SIZE + TIME_SIZE)); } else { printf("Nothing to read on sensor 2.\n\n"); } // Close sensor1. printf("Closing sensor1: %d\n", close(sensor1)); // Close sensor2. printf("Closing sensor2: %d\n\n", close(sensor2)); return OK; }
nsresult nsBasicUTF7Decoder::DecodeBase64( const char * aSrc, PRInt32 * aSrcLength, PRUnichar * aDest, PRInt32 * aDestLength) { const char * srcEnd = aSrc + *aSrcLength; const char * src = aSrc; PRUnichar * destEnd = aDest + *aDestLength; PRUnichar * dest = aDest; nsresult res = NS_OK; char ch; PRUint32 value; while (src < srcEnd) { ch = *src; // stop when we meet other chars or end of direct encoded seq. value = CharToValue(ch); if (value > 0xff) { res = NS_ERROR_UDEC_ILLEGALINPUT; break; } switch (mEncStep) { case 0: mEncBits = value << 10; break; case 1: mEncBits += value << 4; break; case 2: if (dest >= destEnd) { res = NS_OK_UDEC_MOREOUTPUT; break; } mEncBits += value >> 2; *(dest++) = (PRUnichar) mEncBits; mEncBits = (value & 0x03) << 14; break; case 3: mEncBits += value << 8; break; case 4: mEncBits += value << 2; break; case 5: if (dest >= destEnd) { res = NS_OK_UDEC_MOREOUTPUT; break; } mEncBits += value >> 4; *(dest++) = (PRUnichar) mEncBits; mEncBits = (value & 0x0f) << 12; break; case 6: mEncBits += value << 6; break; case 7: if (dest >= destEnd) { res = NS_OK_UDEC_MOREOUTPUT; break; } mEncBits += value; *(dest++) = (PRUnichar) mEncBits; mEncBits = 0; break; } if (res != NS_OK) break; src++; (++mEncStep)%=8; } *aSrcLength = src - aSrc; *aDestLength = dest - aDest; return res; }