-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINcodev1.xc
100 lines (84 loc) · 2.07 KB
/
INcodev1.xc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* INcodev1.xc
*
* Created on: 26 May 2016
* Author: dsdan
*/
#include <xs1.h>
#include <platform.h>
#include <print.h>
#include <stdio.h>
#include <stdlib.h>
#include <syscall.h>
#define BUFFER_SIZE 128
#define DATA_LENGTH 22
#define TRANSDUCER_COUNT 8
#define SOURCE "test.txt"
in port goLine = XS1_PORT_1I;
in port returnLine = XS1_PORT_1J;
int main() {
unsigned char readBuffer[BUFFER_SIZE];
int flagCount = 0;
unsigned int data[DATA_LENGTH];
unsigned int flags[BUFFER_SIZE];
for(size_t i = 0; i < DATA_LENGTH; ++i)
{
data[i] = 0;
}
unsigned int topRatio;
unsigned int testLength;
unsigned int burstLength;
unsigned int brf;
unsigned int pulseLength;
unsigned int prf;
unsigned int magRatio[TRANSDUCER_COUNT];
unsigned int phase[TRANSDUCER_COUNT];
int fd = _open(SOURCE, O_RDONLY, 0);
if (fd == -1) {
printstrln("Error: _open failed");
exit(1);
}
_read(fd, readBuffer, BUFFER_SIZE);
for(size_t i = 0; i < BUFFER_SIZE; ++i)
{
if(readBuffer[i] == '.')
{
flags[flagCount] = i;
flagCount++;
}
}
for(size_t i = 0; i < DATA_LENGTH; ++i)
{
for(size_t j = flags[i]+1; j < flags[i+1]; ++j)
{
data[i] = data[i] * 10 + (readBuffer[j] - '0');
}
printf("%d\n",data[i]); //debugging
}
topRatio = data[0];
testLength = data[1];
burstLength = data[2];
brf = data[3];
pulseLength = data[4];
prf = data[5];
for(size_t i = 0; i < TRANSDUCER_COUNT; ++i)
{
magRatio[i] = data[i + 6];
phase[i] = data[i + 14];
}
if (_close(fd) != 0)
{
printstrln("Error: _close failed.");
exit(1);
}
printstr("Data recieved and processed!");
select
{
case goLine when pinsneq(0) :> void:
break;
case returnLine when pinsneq(1) :> void:
//return with dataIn
break;
}
return 0;
}