char airRemoteEncode_22(char* airData) { char i, length; char formLength; char dataLenFul; char dataLenOdd; char dataLen = 0; char len; char dataIndex = 0; LOGD("type 0x22 encode "); timeShift(airData, tempData); formLength = 19; length = 0; dataIndex = 29; dataLenFul = airData[25] / 8; dataLenOdd = airData[25] % 8; dataLen = 0; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + dataIndex]; } dataIndex += dataLen; bits[length] = 3; length++; len = airDataToBitsTypeR(bits, data, length, dataLenFul, dataLenOdd); length += len; bits[length] = 4; length++; dataLenFul = airData[26] / 8; dataLenOdd = airData[26] % 8; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + dataIndex]; } len = airDataToBitsTypeR(bits, data, length, dataLenFul, dataLenOdd); length += len; bits[length] = 1; length++; bits[length] = 0; length++; len = compressData(tempData, bits, length, formLength); length = len + formLength; //repeat times tempData[length] = 1; length++; #ifdef EETEST for (i = 0; i < length; i++) { LOGD("second tempData[%d] ============> 0x%x ", i, tempData[i]); } #endif return length = WrapUpSendData(airSendData, tempData, REMOTE_SEND_1, length); }
char airRemoteEncode_00(char* airData) { char i, length; char formLength; char dataLenFul; char dataLenOdd; char dataLen = 0; char len; timeShift(airData, tempData); formLength = 19; dataLenFul = airData[25] / 8; dataLenOdd = airData[25] % 8; dataLen = 0; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + 29]; } dataLen = airDataToBitsTypeR(bits, data, 1, dataLenFul, dataLenOdd); LOGD("type 0x00 encode "); bits[0] = 3; dataLen++; bits[dataLen] = 1; dataLen++; bits[dataLen] = 0; dataLen++; dataLen = compressData(tempData, bits, dataLen, formLength); length = dataLen + formLength; //repeat times tempData[length] = 1; length++; #ifdef EETEST for (i = 0; i < length; i++) { LOGD("second tempData[%d] ============> 0x%x ", i, tempData[i]); } #endif return length = WrapUpSendData(airSendData, tempData, REMOTE_SEND_1, length); }
void senddata(int new_fd, struct sockaddr_in clnt_addr, char *datafile) { FILE *infp; time_t now, start; struct tm starttime; char *data, ch; char *frame; int offset, dataLen, tOffset; int timeFlag; time(&start); memcpy(&starttime, gmtime(&start), sizeof(struct tm)); starttime.tm_sec = 0; starttime.tm_min = 0; starttime.tm_hour = 10; start = mktime(&starttime); infp = fopen(datafile , "r"); if (infp == NULL) { perror("Data File Open Failed"); exit(errno); } data = (char *)malloc(sizeof(char) * 512); frame = (char *)malloc(sizeof(char)*256); readdata(infp, data, 282); dataLen = compressData(data); memset(frame, 0, sizeof(frame)); frame[0] = 'D'; frame[1] = dataLen; memcpy(frame + 2, data, dataLen); if (send(new_fd, frame, 256, 0) == -1) { perror("send"); close(new_fd); exit(errno); } while (1) { updatelist(clnt_addr); sleep(2); time(&now); tOffset=(int)difftime(now,start); if(tOffset>9000) tOffset-=7200; offset = 246 * tOffset / 2 + 282 - ftell(infp); if (fseek(infp, offset, SEEK_CUR)) printf("fseek failed!\n"); timeFlag = 0; while (timeFlag != 2) { fread(&ch, sizeof(char), 1, infp); if (ch == ':') timeFlag++; } fseek(infp, -7, SEEK_CUR); readdata(infp, data, 246); dataLen = compressData(data); memset(frame, 0, sizeof(frame)); frame[0] = 'D'; frame[1] = dataLen; memcpy(frame + 2, data, dataLen); if (send(new_fd, frame, 256, 0) == -1) { perror("send"); close(new_fd); fclose(infp); exit(errno); } } }
void twodVec2CompressedByteArrays(vector< vector<string> > &dataVec, int row, int col, string dp, vector<Byte *> &byteArrays, vector<int> &lengthOfCompressedArrays) {//right row col here, use them //DEBUG:val int printHelper = 0; //convert the 2d vector data to byte array then compress col by col for (int x = 0; x< dp.length(); x++) { int pos = 0; int len; Byte * tempByteArray;// if (dp[x] == 'd') { len = row * sizeof(double); tempByteArray = new Byte[len]; Byte barr[sizeof(double)]; for(int i=0; i < row; i++) //change string in 2d vector, dataVec, to the right type here { toByteArray_htond((double) atof((dataVec[x][i]).c_str()), barr); //dataVec[a][b], a is the col in org file, b is the row in org file memcpy(tempByteArray + pos, barr, sizeof(double)); pos = pos + sizeof(double); } } else if (dp[x] == 'i') { len = row * sizeof(int); tempByteArray = new Byte[len]; Byte barr[sizeof(int)]; for(int i=0; i < row; i++) //change string in 2d vector, dataVec, to the right type here { toByteArray_htoni((int) atoi((dataVec[x][i]).c_str()), barr); memcpy(tempByteArray + pos, barr, sizeof(int)); pos = pos + sizeof(int); } } else if (dp[x] == 'l') { len = row * sizeof(long long); tempByteArray = new Byte[len]; Byte barr[sizeof(long long)]; for(int i=0; i < row; i++) //change string in 2d vector, dataVec, to the right type here { toByteArray_htonll((long long) atoll((dataVec[x][i]).c_str()), barr); memcpy(tempByteArray + pos, barr, sizeof(long long)); pos = pos + sizeof(long long); } } else if (dp[x] == 'f') { len = row * sizeof(float); tempByteArray = new Byte[len]; Byte barr[sizeof(float)]; for(int i=0; i < row; i++) //change string in 2d vector, dataVec, to the right type here { //atof return double so cast to float toByteArray_htonf((float) atof((dataVec[x][i]).c_str()), barr); memcpy(tempByteArray + pos, barr, sizeof(float)); pos = pos + sizeof(float); } } else {//string, s for string, t for text len = 0; if (dp[x] == 's') {//two bytes for the len //cal the len for this col and total col for all the string vector<int> stringLens(row); Byte barr[sizeof(short)]; for (int s=0; s<row;s++) { stringLens[s] = dataVec[x][s].length();//the length of string should be equal to the length of byte array len = len + stringLens[s] + sizeof(short); } tempByteArray = new Byte[len]; //byte array to be compressed for (int i=0; i<row;i++) { Byte * strBytes = (Byte *)(dataVec[x][i].data()); toByteArray_htons((short) stringLens[i], barr); memcpy(tempByteArray + pos, barr, sizeof(short)); pos = pos + sizeof(short); memcpy(tempByteArray + pos, strBytes, stringLens[i]); pos = pos + stringLens[i]; } } else {//four bytes for the len //cal the len for this col and total col for all the string vector<int> stringLens(row); Byte barr[sizeof(int)]; for (int s=0; s<row;s++) { stringLens[s] = dataVec[x][s].length();//the length of string should be equal to the length of byte array len = len + stringLens[s] + sizeof(int); } tempByteArray = new Byte[len]; //byte array to be compressed for (int i=0; i<row;i++) { Byte * strBytes = (Byte *)(dataVec[x][i].data()); toByteArray_htoni((int) stringLens[i], barr); memcpy(tempByteArray + pos, barr, sizeof(int)); pos = pos + sizeof(int); memcpy(tempByteArray + pos, strBytes, stringLens[i]); pos = pos + stringLens[i]; } } } //prepare to compress Byte* byteArray = new Byte[len+20]; // output stored here, delete outside int lengthOfCompressedByteArray; compressData(tempByteArray, len, byteArray, lengthOfCompressedByteArray); //add this col of compressed data to my buffer byteArrays.push_back(byteArray); lengthOfCompressedArrays.push_back(lengthOfCompressedByteArray); delete [] tempByteArray; } }
char airRemoteEncode_85(char* airData) { char i, length; char formLength; char dataLenFul; char dataLenOdd; char dataLen = 0; char len; char tData[100]; char dataIndex = 0; LOGD("type 0x06 encode "); timeShiftD(airData, tempData); length = 0; formLength = 27; dataIndex = 29; dataLenFul = airData[25] / 8; dataLenOdd = airData[25] % 8; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + dataIndex]; // LOGD(" data[%d] ============> 0x%x ", i, data[i]); } dataIndex += dataLen; bits[length] = 5; length++; memset(tData,0x00,100); len = TCL2data2bits(tData,data,dataLen); if (tData[0]==0x00){ LOGD(" fix head data"); fixHeadTime(tempData); } len = TCLEdgeShiftLevel(bits, tData,length, len); length += len; dataLenFul = airData[26] / 8; dataLenOdd = airData[26] % 8; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + dataIndex]; } dataIndex += dataLen; bits[length] = 5; length++; memset(tData,0x00,100); len = TCL2data2bits(tData,data,dataLen); len = TCLEdgeShiftLevel(bits, tData,length, len); length += len; dataLenFul = airData[27] / 8; dataLenOdd = airData[27] % 8; if (dataLenOdd > 0) { dataLen = dataLenFul + 1; } else { dataLen = dataLenFul; } for (i = 0; i < dataLen; i++) { data[i] = airData[i + dataIndex]; } dataIndex += dataLen; bits[length] = 5; length++; memset(tData,0x00,100); len = TCL2data2bits(tData,data,dataLen); if (bits[0]==0x01){ fixHeadTime(tempData); } len = TCLEdgeShiftLevel(bits, tData,length, len); length += len; bits[length] = 6; length++; bits[length] = 0; length++; len = compressData(tempData, bits, length, formLength); length = len + formLength; //repeat times tempData[length] = 1; length++; #ifdef EETEST for (i = 0; i < length; i++) { LOGD("second tempData[%d] ============> 0x%x ", i, tempData[i]); } #endif return length = WrapUpSendData(airSendData, tempData, REMOTE_SEND_1, length); }