reverted to _old and cnt to 11

pull/26/head
alanbjohnston 6 years ago committed by GitHub
parent bb177c6240
commit 3fea286394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -80,8 +80,8 @@ int lower_digit(int number);
#define BUF_SIZE (S_RATE*10) /* 2 second buffer */
/*
// BPSK Settings
#define BIT_RATE 1200 // 200 for DUV
#define FSK 0 // 1 for DUV
#define BIT_RATE 1200 // 200 for DUV
#define FSK 0 // 1 for DUV
#define RS_FRAMES 3 // 3 frames for BPSK, 1 for DUV
#define PAYLOADS 6 // 1 for DUV
#define DATA_LEN 78 // 56 for DUV
@ -92,7 +92,7 @@ int lower_digit(int number);
*/
// FSK Settings
#define BIT_RATE 200
#define FSK 1
#define FSK 1
#define RS_FRAMES 1
#define PAYLOADS 1
#define RS_FRAME_LEN 64
@ -111,12 +111,10 @@ int smaller;
int flip_ctr = 0;
int phase = 1;
int ctr = 0;
int sock = 0;
void write_to_buffer(int i, int symbol, int val);
void write_wave();
#define SAMPLES (S_RATE / BIT_RATE)
#define FRAME_CNT 11// //33 // Add 3 frames to the count
#define FRAME_CNT 11 //33 // Add 3 frames to the count
//#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (8 + 6 * DATA_LEN + 96)) * SAMPLES)
#define BUF_LEN (FRAME_CNT * (SYNC_BITS + 10 * (HEADER_LEN + RS_FRAMES * (RS_FRAME_LEN + PARITY_LEN))) * SAMPLES)
@ -196,9 +194,9 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) {
struct SensorConfig data;
if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing
printf("ERROR: %s bus not present \n", bus);
data.fd = OFF;
return (data);
printf("ERROR: %s bus not present \n", bus);
data.fd = OFF;
return (data);
}
data.fd = wiringPiI2CSetupInterface(bus, address);
@ -209,7 +207,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) {
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
if (milliAmps == 400) { // INA219 16V 400mA configuration
if (milliAmps == 400) { // INA219 16V 400mA configuration
data.calValue = 8192;
data.powerMultiplier = 1;
data.currentDivider = 20; // 40; in Adafruit config
@ -221,8 +219,8 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) {
}
#ifdef DEBUG_LOGGING
printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd,
data.config, data.calValue, data.currentDivider, data.powerMultiplier);
printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd,
data.config, data.calValue, data.currentDivider, data.powerMultiplier);
#endif
return data;
}
@ -237,7 +235,7 @@ char dest_addr[5] = "CQ";
int main(int argc, char *argv[]) {
if (argc > 1) {
strcpy(src_addr, argv[1]);
strcpy(src_addr, argv[1]);
}
wiringPiSetup ();
@ -252,9 +250,9 @@ int main(int argc, char *argv[]) {
{
printf("Creating config file.");
config_file = fopen("sim.cfg","w");
fprintf(config_file, "%s %d", "KU2Y", 100);
fclose(config_file);
config_file = fopen("sim.cfg","r");
fprintf(config_file, "%s %d", "KU2Y", 100);
fclose(config_file);
config_file = fopen("sim.cfg","r");
}
char* cfg_buf[100];
@ -291,37 +289,6 @@ int main(int argc, char *argv[]) {
AX25_PREAMBLE_LEN,
AX25_POSTAMBLE_LEN);
// socket open
int error = 0;
struct sockaddr_in address;
int valread;
struct sockaddr_in serv_addr;
// char *hello = "Hello from client";
// char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("\n Socket creation error \n");
error = 1;
}
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary form
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
{
printf("\nInvalid address/ Address not supported \n");
error = 1;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
printf("\nConnection Failed \n");
error = 1;
}
/* Infinite loop */
//for (;;)
@ -349,9 +316,9 @@ int main(int argc, char *argv[]) {
char cmdbuffer[1000];
FILE* transmit;
if (FSK == 1) {
transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r");
transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr gain_ff 7000 | csdr convert_f_samplerf 20833 | sudo /home/pi/CubeSatSim/rpitx/rpitx -i- -m RF -f 434.9e3 2>&1", "r");
} else {
transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r");
transmit = popen("sudo cat /home/pi/CubeSatSim/transmit.wav | csdr convert_i16_f | csdr fir_interpolate_cc 2 | csdr dsb_fc | csdr bandpass_fir_fft_cc 0.002 0.06 0.01 | csdr fastagc_ff | sudo /home/pi/CubeSatSim/rpitx/sendiq -i /dev/stdin -s 96000 -f 434.9e6 -t float 2>&1", "r");
}
fgets(cmdbuffer, 1000, transmit);
pclose(transmit);
@ -359,7 +326,7 @@ int main(int argc, char *argv[]) {
*/
// printf("%s \n", b);
// printf("%s \n", b);
/*
digitalWrite (0, LOW);
@ -408,24 +375,24 @@ static void init_rf() {
//
int lower_digit(int number) {
int digit = 0;
if (number < 100)
digit = number - ((int)(number/10) * 10);
else
fprintf(stderr,"ERROR: Not a digit in lower_digit!\n");
return digit;
int digit = 0;
if (number < 100)
digit = number - ((int)(number/10) * 10);
else
fprintf(stderr,"ERROR: Not a digit in lower_digit!\n");
return digit;
}
// Returns upper digit of a number which must be less than 99
//
int upper_digit(int number) {
int digit = 0;
if (number < 100)
digit = (int)(number/10);
else
fprintf(stderr,"ERROR: Not a digit in upper_digit!\n");
return digit;
int digit = 0;
if (number < 100)
digit = (int)(number/10);
else
fprintf(stderr,"ERROR: Not a digit in upper_digit!\n");
return digit;
}
int get_tlm(char *str) {
@ -440,18 +407,18 @@ int get_tlm(char *str) {
reading[count] = read_sensor_data(sensor[count]);
#ifdef DEBUG_LOGGING
printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n",
count, reading[count].voltage, reading[count].current, reading[count].power);
count, reading[count].voltage, reading[count].current, reading[count].power);
#endif
}
tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi
tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4]
tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10]
tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10]
tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7]
tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10]
tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10]
tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel
tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp)
tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp)
tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current
tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100);
@ -472,16 +439,16 @@ int get_tlm(char *str) {
FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (cpuTempSensor) {
double cpuTemp;
fscanf (cpuTempSensor, "%lf", &cpuTemp);
cpuTemp /= 1000;
double cpuTemp;
fscanf (cpuTempSensor, "%lf", &cpuTemp);
cpuTemp /= 1000;
#ifdef DEBUG_LOGGING
printf("CPU Temp Read: %6.1f\n", cpuTemp);
#endif
tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100;
fclose (cpuTempSensor);
fclose (cpuTempSensor);
}
tlm[6][B] = 0 ;
@ -492,7 +459,7 @@ int get_tlm(char *str) {
int k, j;
for (k = 1; k < 7; k++) {
for (j = 1; j < 5; j++) {
printf(" %2d ", tlm[k][j]);
printf(" %2d ", tlm[k][j]);
}
printf("\n");
}
@ -531,41 +498,41 @@ int get_tlm_fox() {
printf("Reset Count: %d Uptime since Reset: %ld \n", reset_count, uptime);
fclose(uptime_file);
int i;
long int sync = SYNC_WORD;
int i;
long int sync = SYNC_WORD;
smaller = S_RATE/(2 * freq_Hz);
smaller = S_RATE/(2 * freq_Hz);
/*
short int b[DATA_LEN] = {0x00,0x7E,0x03,
0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02,
0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00};
short int b[DATA_LEN] = {0x00,0x7E,0x03,
0x00,0x00,0x00,0x00,0xE6,0x01,0x00,0x27,0xD1,0x02,
0xE5,0x40,0x04,0x18,0xE1,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
short int h[HEADER_LEN] = {0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00};
*/
short int b[DATA_LEN];
memset(b, 0, sizeof(b));
short int b[DATA_LEN];
memset(b, 0, sizeof(b));
short int h[HEADER_LEN];
memset(h, 0, sizeof(h));
short int h[HEADER_LEN];
memset(h, 0, sizeof(h));
short int b10[DATA_LEN], h10[HEADER_LEN];
short int rs_frame[RS_FRAMES][223];
unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte;
short int b10[DATA_LEN], h10[HEADER_LEN];
short int rs_frame[RS_FRAMES][223];
unsigned char parities[RS_FRAMES][PARITY_LEN],inputByte;
/*
int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0;
int batt_a_v = 0, batt_b_v = 0, batt_c_v = 8.95 * 100, battCurr = 48.6 * 10;
int posXv = 296, negXv = 45, posYv = 220, negYv = 68,
posZv = 280, negZv = 78;
posZv = 280, negZv = 78;
*/
int id = 7, frm_type = 0x01, TxTemp = 0, IHUcpuTemp = 0;
int batt_a_v = 0, batt_b_v = 0, batt_c_v = 0, battCurr = 0;
int posXv = 0, negXv = 0, posYv = 0, negYv = 0,
posZv = 0, negZv = 0;
posZv = 0, negZv = 0;
int head_offset = 0;
for (int frames = 0; frames < FRAME_CNT; frames++)
@ -576,7 +543,7 @@ int get_tlm_fox() {
reading[count] = read_sensor_data(sensor[count]);
#ifdef DEBUG_LOGGING
printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n",
count, reading[count].voltage, reading[count].current, reading[count].power);
count, reading[count].voltage, reading[count].current, reading[count].power);
#endif
}
/*
@ -596,9 +563,9 @@ int get_tlm_fox() {
*/
FILE *cpuTempSensor = fopen("/sys/class/thermal/thermal_zone0/temp", "r");
if (cpuTempSensor) {
double cpuTemp;
fscanf (cpuTempSensor, "%lf", &cpuTemp);
cpuTemp /= 1000;
double cpuTemp;
fscanf (cpuTempSensor, "%lf", &cpuTemp);
cpuTemp /= 1000;
#ifdef DEBUG_LOGGING
printf("CPU Temp Read: %6.1f\n", cpuTemp);
@ -654,144 +621,141 @@ int get_tlm_fox() {
encodeA(b, 18 + head_offset,negYv);
encodeB(b, 19 + head_offset,negZv);
/* batt_c_v += 10;
battCurr -= 10;
encodeA(b, 3 + head_offset, batt_c_v);
encodeA(b, 9 + head_offset, battCurr);
/* batt_c_v += 10;
battCurr -= 10;
encodeA(b, 3 + head_offset, batt_c_v);
encodeA(b, 9 + head_offset, battCurr);
*/
int ctr1 = 0;
int ctr3 = 0;
for (i = 0; i < RS_FRAME_LEN; i++)
{
int ctr1 = 0;
int ctr3 = 0;
for (i = 0; i < RS_FRAME_LEN; i++)
{
for (int j = 0; j < RS_FRAMES ; j++)
{
if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK
{
if (ctr1 < HEADER_LEN)
{
rs_frame[j][i] = h[ctr1];
update_rs(parities[j], h[ctr1]);
// printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]);
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
}
else
{
rs_frame[j][i] = b[ctr3 % DATA_LEN];
update_rs(parities[j], b[ctr3 % DATA_LEN]);
// printf("%d rs_frame[%d][%d] = %x %d \n",
// ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN);
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
ctr3++;
}
}
}
}
printf("Parities ");
for (int m = 0; m < PARITY_LEN; m++) {
printf("%d ", parities[0][m]);
}
printf("\n");
int ctr2 = 0;
memset(data10,0,sizeof(data10));
int rd = 0;
int nrd;
{
if (!((i == (RS_FRAME_LEN - 1)) && (j == 2))) // skip last one for BPSK
{
if (ctr1 < HEADER_LEN)
{
rs_frame[j][i] = h[ctr1];
update_rs(parities[j], h[ctr1]);
// printf("header %d rs_frame[%d][%d] = %x \n", ctr1, j, i, h[ctr1]);
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
}
else
{
rs_frame[j][i] = b[ctr3 % DATA_LEN];
update_rs(parities[j], b[ctr3 % DATA_LEN]);
// printf("%d rs_frame[%d][%d] = %x %d \n",
// ctr1, j, i, b[ctr3 % DATA_LEN], ctr3 % DATA_LEN);
data8[ctr1++] = rs_frame[j][i];
// printf ("data8[%d] = %x \n", ctr1 - 1, rs_frame[j][i]);
ctr3++;
}
}
}
}
printf("Parities ");
for (int m = 0; m < PARITY_LEN; m++) {
printf("%d ", parities[0][m]);
}
printf("\n");
int ctr2 = 0;
memset(data10,0,sizeof(data10));
int rd = 0;
int nrd;
for (i = 0; i < DATA_LEN * PAYLOADS + HEADER_LEN; i++) // 476 for BPSK
{
data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1;
// printf ("data10[%d] = encoded data8[%d] = %x \n",
// ctr2, ctr2, data10[ctr2]);
{
data10[ctr2] = (Encode_8b10b[rd][((int)data8[ctr2])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int)data8[ctr2])] >> 10) & 1;
// printf ("data10[%d] = encoded data8[%d] = %x \n",
// ctr2, ctr2, data10[ctr2]);
rd = nrd; // ^ nrd;
ctr2++;
}
rd = nrd; // ^ nrd;
ctr2++;
}
for (i = 0; i < PARITY_LEN; i++)
{
for (int j = 0; j < RS_FRAMES; j++)
{
data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1;
// printf ("data10[%d] = encoded parities[%d][%d] = %x \n",
// ctr2 - 1, j, i, data10[ctr2 - 1]);
rd = nrd;
}
}
{
for (int j = 0; j < RS_FRAMES; j++)
{
data10[ctr2++] = (Encode_8b10b[rd][((int)parities[j][i])] & 0x3ff);
nrd = (Encode_8b10b[rd][((int)parities[j][i])] >> 10) & 1;
// printf ("data10[%d] = encoded parities[%d][%d] = %x \n",
// ctr2 - 1, j, i, data10[ctr2 - 1]);
rd = nrd;
}
}
int data;
int val;
int offset = 0;
ctr = 0;
flip_ctr = 0;
phase = 1;
for (i = 1; i <= SYNC_BITS * SAMPLES; i++)
{
write_wave(ctr);
if ( (i % SAMPLES) == 0) {
int bit = SYNC_BITS - i/SAMPLES + 1;
val = sync;
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d sync bit %d = %d \n",
// ctr/SAMPLES, i, frames, bit, (data > 0) );
if (FSK)
{
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
}
}
}
for (i = 1;
i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572
{
write_wave(ctr);
if ( (i % SAMPLES) == 0) {
int symbol = (int)((i - 1)/ (SAMPLES * 10));
int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1;
val = data10[symbol];
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n",
// ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) );
if (FSK)
{
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
for (int j = 1; j <= smaller; j ++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
}
}
}
}
// write_wav("transmit.wav", BUF_LEN, buffer, S_RATE);
for (i = 1; i <= SYNC_BITS * SAMPLES; i++)
{
write_wave(ctr);
if ( (i % SAMPLES) == 0) {
int bit = SYNC_BITS - i/SAMPLES + 1;
val = sync;
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d sync bit %d = %d \n",
// ctr/SAMPLES, i, frames, bit, (data > 0) );
if (FSK)
{
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
for (int j = 1; j <= smaller; j++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
}
}
}
for (i = 1;
i <= (10 * (HEADER_LEN + DATA_LEN * PAYLOADS + RS_FRAMES * PARITY_LEN) * SAMPLES); i++) // 572
{
write_wave(ctr);
if ( (i % SAMPLES) == 0) {
int symbol = (int)((i - 1)/ (SAMPLES * 10));
int bit = 10 - (i - symbol * SAMPLES * 10) / SAMPLES + 1;
val = data10[symbol];
data = val & 1 << (bit - 1);
// printf ("%d i: %d new frame %d data10[%d] = %x bit %d = %d \n",
// ctr/SAMPLES, i, frames, symbol, val, bit, (data > 0) );
if (FSK)
{
phase = ((data != 0) * 2) - 1;
// printf("Sending a %d\n", phase);
}
else
{
if (data == 0) {
phase *= -1;
if ( (ctr - smaller) > 0)
{
for (int j = 1; j <= smaller; j ++)
buffer[ctr - j] = buffer[ctr - j] * 0.4;
}
flip_ctr = ctr;
}
}
}
}
}
// write_wav("transmit.wav", BUF_LEN, buffer, S_RATE);
int error = 0;
int count;
@ -802,13 +766,40 @@ int get_tlm_fox() {
// socket write
if (!error)
struct sockaddr_in address;
int sock = 0, valread;
struct sockaddr_in serv_addr;
// char *hello = "Hello from client";
// char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
printf("Sending buffer over socket!\n");
send(sock, buffer, sizeof(buffer), 0);
printf("\n Socket creation error \n");
error = 1;
}
sleep(20);
memset(&serv_addr, '0', sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(PORT);
// Convert IPv4 and IPv6 addresses from text to binary form
if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
{
printf("\nInvalid address/ Address not supported \n");
error = 1;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
{
printf("\nConnection Failed \n");
error = 1;
}
if (!error)
{
printf("Sending buffer over socket!\n");
send(sock, buffer, sizeof(buffer), 0);
}
return 0;
}
@ -853,8 +844,8 @@ return 0;
//static int encodeB(short int *b, int index, int val);
//static int encodeA(short int *b, int index, int val);
static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff;
static int FRAME = /* 0fa */ ~0xfa & 0x3ff;
static int NOT_FRAME = /* 0fa */ 0xfa & 0x3ff;
static int FRAME = /* 0fa */ ~0xfa & 0x3ff;
/*
* TelemEncoding.c
@ -1012,13 +1003,13 @@ void update_rs(
void write_little_endian(unsigned int word, int num_bytes, FILE *wav_file)
{
unsigned buf;
while(num_bytes>0)
{ buf = word & 0xff;
fwrite(&buf, 1,1, wav_file);
num_bytes--;
word >>= 8;
}
unsigned buf;
while(num_bytes>0)
{ buf = word & 0xff;
fwrite(&buf, 1,1, wav_file);
num_bytes--;
word >>= 8;
}
}
/* information about the WAV file format from
@ -1029,48 +1020,48 @@ http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
void write_wav(char * filename, unsigned long num_samples, short int * data, int s_rate)
{
FILE* wav_file;
unsigned int sample_rate;
unsigned int num_channels;
unsigned int bytes_per_sample;
unsigned int byte_rate;
unsigned long i; /* counter for samples */
num_channels = 1; /* monoaural */
bytes_per_sample = 2;
if (s_rate<=0) sample_rate = 44100;
else sample_rate = (unsigned int) s_rate;
byte_rate = sample_rate*num_channels*bytes_per_sample;
wav_file = fopen(filename, "w");
assert(wav_file); /* make sure it opened */
/* write RIFF header */
fwrite("RIFF", 1, 4, wav_file);
write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file);
fwrite("WAVE", 1, 4, wav_file);
/* write fmt subchunk */
fwrite("fmt ", 1, 4, wav_file);
write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */
write_little_endian(1, 2, wav_file); /* PCM is format 1 */
write_little_endian(num_channels, 2, wav_file);
write_little_endian(sample_rate, 4, wav_file);
write_little_endian(byte_rate, 4, wav_file);
write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */
write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */
/* write data subchunk */
fwrite("data", 1, 4, wav_file);
write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file);
for (i=0; i< num_samples; i++)
{ write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file);
}
fclose(wav_file);
FILE* wav_file;
unsigned int sample_rate;
unsigned int num_channels;
unsigned int bytes_per_sample;
unsigned int byte_rate;
unsigned long i; /* counter for samples */
num_channels = 1; /* monoaural */
bytes_per_sample = 2;
if (s_rate<=0) sample_rate = 44100;
else sample_rate = (unsigned int) s_rate;
byte_rate = sample_rate*num_channels*bytes_per_sample;
wav_file = fopen(filename, "w");
assert(wav_file); /* make sure it opened */
/* write RIFF header */
fwrite("RIFF", 1, 4, wav_file);
write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file);
fwrite("WAVE", 1, 4, wav_file);
/* write fmt subchunk */
fwrite("fmt ", 1, 4, wav_file);
write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */
write_little_endian(1, 2, wav_file); /* PCM is format 1 */
write_little_endian(num_channels, 2, wav_file);
write_little_endian(sample_rate, 4, wav_file);
write_little_endian(byte_rate, 4, wav_file);
write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */
write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */
/* write data subchunk */
fwrite("data", 1, 4, wav_file);
write_little_endian(bytes_per_sample* num_samples*num_channels, 4, wav_file);
for (i=0; i< num_samples; i++)
{ write_little_endian((unsigned int)(data[i]),bytes_per_sample, wav_file);
}
fclose(wav_file);
}
@ -1078,28 +1069,28 @@ void write_wav(char * filename, unsigned long num_samples, short int * data, int
//int main(int argc, char * argv[])
//{
// return 0;
// return 0;
//}
void write_wave(int i)
{
if (FSK)
{
// if ((ctr - flip_ctr) < smaller)
// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller;
// else
buffer[ctr++] = 0.25 * amplitude * phase;
}
else
{
if ((ctr - flip_ctr) < smaller)
buffer[ctr++] = (int)(amplitude * 0.4 * phase *
sin((float)(2*M_PI*i*freq_Hz/S_RATE)));
else
buffer[ctr++] = (int)(amplitude * phase *
sin((float)(2*M_PI*i*freq_Hz/S_RATE)));
}
// printf("%d %d \n", i, buffer[ctr - 1]);
if (FSK)
{
// if ((ctr - flip_ctr) < smaller)
// buffer[ctr++] = 0.1 * phase * (ctr - flip_ctr) / smaller;
// else
buffer[ctr++] = 0.25 * amplitude * phase;
}
else
{
if ((ctr - flip_ctr) < smaller)
buffer[ctr++] = (int)(amplitude * 0.4 * phase *
sin((float)(2*M_PI*i*freq_Hz/S_RATE)));
else
buffer[ctr++] = (int)(amplitude * phase *
sin((float)(2*M_PI*i*freq_Hz/S_RATE)));
}
// printf("%d %d \n", i, buffer[ctr - 1]);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.