Commit a1880302 authored by Adrian Šiška's avatar Adrian Šiška
Browse files

"No compile errors, currently"

parent c28cc2d7
#!/usr/bin/env bash
gcc -Wall -Wextra -O2 view.c -oview
cat beshrunkt.uk2 | ./view out.pgm 640 480 &
sixiv out.pgm
......@@ -3,10 +3,11 @@ import struct
from datetime import datetime
import time
def main():
with open("logfile", "a+") as log:
with open("beshrukt.uk2", "wb+") as smolOut:
ser = serial.Serial('/dev/ttyUSB1', 19200)
ser = serial.Serial("/dev/ttyUSB1", 19200)
print(ser.name)
print("\033[2J")
......@@ -19,15 +20,14 @@ def main():
time.sleep(0.1)
print("\033[2H")
while 1:
byte = ser.read(1)
# print(byte)
if (byte == b'+'):
if byte == b"+":
count_plus += 1
else:
count_plus = 0
if (count_plus == 3):
if count_plus == 3:
print("[PACKET]", end="")
break
......@@ -35,7 +35,7 @@ def main():
# input_data = ser.read(177)
# input_data = open("example.dat", "rb").read()
if ((input_data[169] != 45) or (input_data[168] != 45)):
if (input_data[169] != 45) or (input_data[168] != 45):
print("[FAIL]", input_data[169], input_data[168], len(input_data))
continue
......@@ -59,18 +59,18 @@ def main():
print("TEMPERATURE:")
print("\x1b[14;12fT: %3.3f *C " % (rezultat[0]), end="")
# print(rezultat[3], rezultat[4], rezultat[5])
# print(len(input_data))
# print(math.sqrt(rezultat[6]**2 + rezultat[7]**2 + rezultat[8]**2))
# print(rezultat)
smolOut.write(input_data[-132:])
log.write(repr((rezultat, datetime.now(), input_data[-132:]))+ '\n')
logline = repr((rezultat, datetime.now(), input_data[-132:]))+ '\n'
smolOut.flush()
log.write(repr((rezultat, datetime.now(), input_data[-132:])) + "\n")
logline = repr((rezultat, datetime.now(), input_data[-132:])) + "\n"
# print(logline)
ser.close()
if __name__ == "__main__":
main()
#include <arpa/inet.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#define S0(x) (x ? x : "")
int main(int argc, char **argv) {
int r = 0;
if (argc != 1 + 3) {
fprintf(stderr, "uporaba: %s out.pgm 640 480\n", S0(argv[0]));
return 1;
}
#define OUT argv[1]
#define ŠIRINA atoi(argv[2])
#define VIŠINA atoi(argv[3])
int fd;
if ((fd = open(OUT, O_CREAT | O_RDWR | O_CLOEXEC | O_TRUNC, 00777)) == -1) {
perror("open");
return 2;
}
if (ftruncate(fd, ŠIRINA * VIŠINA * 32) == -1) {
perror("ftruncate");
r = 3;
goto r2;
}
char *file;
if ((file = mmap(NULL, ŠIRINA * VIŠINA + 32, PROT_WRITE, MAP_SHARED, fd,
0)) == NULL) {
perror("mmap");
r = 4;
goto r;
}
sprintf(file, "P5 %11d %11d 255\n", ŠIRINA, VIŠINA);
char *slika = file + 32;
while (!ferror(stdin)) {
uint32_t offset;
if (fread((char *)&offset, 4, 1, stdin) != 4) {
fprintf(stderr, "fread != 4\n");
r = 5;
goto r;
}
offset--;
int na_eni_sliki = offset % (VIŠINA * 5);
if (fread(slika + na_eni_sliki * 128, 128, 1, stdin) != 128) {
fprintf(stderr, "fread != 128\n");
r = 6;
goto r;
}
}
r:
if (munmap(file, ŠIRINA * VIŠINA + 32) == -1)
perror("munmap");
r2:
if (close(fd) == -1)
perror("close");
return r;
}
......@@ -35,7 +35,11 @@ int samomor = 0;
uint64_t vrsI = 0;
uint64_t seg = 5;
char vrs[];
char first_time = 1;
char vrs[ORIGX];
const char head[] = {'+', '+', '+'};
const char foot[] = {'-', '-'};
void handle_child(int s __attribute__((unused)), siginfo_t *i,
void *ctx __attribute__((unused))) {
......@@ -119,9 +123,19 @@ int main(int argc, char **argv) {
R(200)
R(300)
R(600)
R(1200) R(1800) R(2400) R(4800) R(9600) R(19200) R(38400) R(57600) R(115200)
R(230400) R(460800) R(500000) R(576000) R(921600) R(1000000) R(1152000)
R(1500000) R(2000000) if (!y) {
R(1200)
R(1800)
R(2400)
R(4800)
R(9600)
R(19200)
R(38400)
R(57600)
R(115200)
R(230400)
R(460800)
R(500000)
R(576000) R(921600) R(1000000) R(1152000) R(1500000) R(2000000) if (!y) {
fprintf(stderr, "podana hitrost pošiljanja ni podprta\nglej Line speed v "
"tcgetattr(3) za možne hitrosti\n");
r = 9;
......@@ -238,8 +252,8 @@ int main(int argc, char **argv) {
continue;
}
if (i == PIC) {
char buf[132];
int fd;
char buf[4 + 128];
int fd = -1;
if ((fd = open(IMG, O_RDONLY | O_NONBLOCK)) == -1) {
perror("open");
#ifdef INFORM_DOWNLINK
......@@ -257,10 +271,16 @@ int main(int argc, char **argv) {
#endif
goto e;
}
if (statbuf.st_size < raw_offset * 128 + 128) {
if ((uint64_t)statbuf.st_size <
(uint64_t)((vrsI * ORIGY / picY + 1) * ORIGS)) {
raw_offset = 0;
}
if (seg == 5) {
if (!first_time)
vrsI++;
else
first_time = 0;
if (lseek(fd, vrsI * ORIGY / picY * ORIGS, SEEK_SET) == -1) {
perror("lseek");
#ifdef INFORM_DOWNLINK
......@@ -281,15 +301,31 @@ int main(int argc, char **argv) {
#endif
goto e;
}
seg = 0;
}
*((uint32_t *)(buf)) = htonl(raw_offset);
*((uint32_t *)(buf)) = htonl(vrsI * 5 + seg);
for (int x = 0; x < 128; x++)
buf[x] = vrs[4 + (128 * seg + x * ORIGX / picX) * 5 / 4];
y = write(u, buf, 128 + 4);
// Send header
y = write(u, head, sizeof(head));
if (y == -1)
perror("write");
if (y != 128 + 4)
if (y != sizeof(head))
fprintf(stderr, "RAW wrote only %d\n", y);
// Send body
y = write(u, buf, sizeof(buf));
if (y == -1)
perror("write");
if (y != sizeof(buf))
fprintf(stderr, "RAW wrote only %d\n", y);
// Send footer
y = write(u, foot, sizeof(foot));
if (y == -1)
perror("write");
if (y != sizeof(foot))
fprintf(stderr, "RAW wrote only %d\n", y);
seg++;
e:
if (close(fd) == -1)
perror("close");
......@@ -332,7 +368,7 @@ int main(int argc, char **argv) {
sprintf(buf + 4, "L%d\n", errno);
write(u, buf, strlen(buf));
#endif
goto e;
goto e2;
}
y = read(fd, buf + 4, 128);
if (y == -1) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment