/* ----------------------------------------------------------------------------- * function.c * * PMU Simulator - Phasor Measurement Unit Simulator * * Copyright (C) 2011-2012 Nitesh Pandit * Copyright (C) 2011-2012 Kedar V. Khandeparkar * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * Authors: * Nitesh Pandit * Kedar V. Khandeparkar * * ----------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------------------- */ /* Functions defined in function.c */ /* -------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */ /* */ /* 1. void B_copy(unsigned char main[],unsigned char tmp[],int ind,int n) */ /* 2. char* measurement_Return () */ /* 3. void H2S(char a[], unsigned char temp_6[]) */ /* 4. void i2c (int t, unsigned char temp[]) */ /* 5. void li2c (long int t1, unsigned char temp_1[]) */ /* 6. void f2c (float f, unsigned char temp_4[]) */ /* 7. int c2i (unsigned char temp_2[]) */ /* 8. long int c2li (unsigned char temp_3[]) */ /* 9. uint16_t compute_CRC(unsigned char *message,char length) */ /* 10.void sigchld_handler(int s) */ /* */ /* ---------------------------------------------------------------------------- */ #include #include #include #include #include #include #include "function.h" #include "ServerFunction.h" #define channel_name 100 /* ---------------------------------------------------------------------------- */ /* FUNCTION B_copy(unsigned char main[], unsigned char tmp[], int ind, int n): */ /* Function copies unsigned char or Bytes in a main array from tmp array. */ /* ---------------------------------------------------------------------------- */ void B_copy(unsigned char main[], unsigned char tmp[], int ind, int n) { int k; for(k=0; k0) { return l1; } fseek(fp_DataFile, 0, SEEK_SET); result = 1; } fclose(fp_DataFile); } /* ---------------------------------------------------------------------------- */ /* FUNCTION H2S(char a[], unsigned char temp_6[]): */ /* Function for unsigned/Hexa char to String Conversion. */ /* ---------------------------------------------------------------------------- */ void H2S(char a[], unsigned char temp_6[]) { int k; for(k=0; k<16; k++) { a[k] = temp_6[k]; } a[16] = '\0'; } /* ---------------------------------------------------------------------------- */ /* FUNCTION i2c (int t, unsigned char temp[]): */ /* Function for Integer to unsigned Character Conversion */ /* ---------------------------------------------------------------------------- */ void i2c (int t, unsigned char temp[]) { temp[0] = t>>8; temp[1] = t; } /* ---------------------------------------------------------------------------- */ /* FUNCTION li2c (long int t1, unsigned char temp_1[]): */ /* Function for Long Integer to unsigned Character Conversion. */ /* ---------------------------------------------------------------------------- */ void li2c (long int t1, unsigned char temp_1[]) { temp_1[0] = t1>>24; temp_1[1] = t1>>16; temp_1[2] = t1>>8; temp_1[3] = t1; } /* ---------------------------------------------------------------------------- */ /* FUNCTION li2c (long int t1, unsigned char temp_1[]): */ /* Function for float to unsigned Character Conversion */ /* ---------------------------------------------------------------------------- */ void f2c (float f, unsigned char temp_1[]) { int i, j; float fv; unsigned char a1[sizeof fv]; fv = f; memcpy(a1, &fv, sizeof fv); for (i=0, j=3; i>8)^message[i]; crc<<=8; quick=temp ^ ( temp >>4); crc ^=quick; quick<<=5; crc ^=quick; quick <<=7; crc ^= quick; } return crc; } /* ---------------------------------------------------------------------------- */ /* FUNCTION sigchld_handler(int s): */ /* Function for TCP connection signal handling */ /* ---------------------------------------------------------------------------- */ void sigchld_handler(int s) { while(wait(NULL) > 0); } /**************************************** End of File *******************************************************/