-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpower433send.c
More file actions
84 lines (68 loc) · 1.78 KB
/
power433send.c
File metadata and controls
84 lines (68 loc) · 1.78 KB
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
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sched.h>
#include <wiringPi.h>
#include "power433_lib.h"
#define CODE_REPEATS 8 /* at least POWER433_RETRANS times */
/* Show help */
void help(char *progname)
{
printf("Usage:\n\t%s {gpio} {code0} [code1] ...\n\n", progname);
puts("Where:");
puts("\tgpio\t - GPIO pin with external RF transmitter connected (mandatory)");
puts("\tcode\t - code(s) to send (at least one)");
}
/* change sheduling priority */
int changeSched(void)
{
struct sched_param s;
s.sched_priority = 0;
if(sched_setscheduler(0, SCHED_BATCH, &s))
return -1;
return 0;
}
/* ********** */
/* * MAIN * */
/* ********** */
int main(int argc, char *argv[])
{
int i, gpio, ncode;
unsigned int *codes;
/* show help */
if (argc < 3) {
help(argv[0]);
exit(0);
}
/* get parameters */
sscanf(argv[1], "%d", &gpio);
ncode = argc - 2;
codes = (unsigned int*)malloc(ncode * sizeof(unsigned int));
for(i = 0; i < ncode; i++)
sscanf(argv[i + 2], "%d", &codes[i]);
/* change scheduling priority */
if (changeSched()) {
fprintf(stderr, "Unable to change process scheduling priority: %s\n",
strerror (errno));
exit(-1);
}
/* initialize WiringPi library - use BCM GPIO numbers */
wiringPiSetupGpio();
/* set transmission only */
Power433_init(gpio, -1);
/* sending codes */
for(i = 0; i < ncode; i++) {
printf("Transmitting code %d (0x%08X) %d times... ", codes[i],
codes[i], CODE_REPEATS);
Power433_repeatCode(codes[i], CODE_REPEATS);
puts("done.");
}
free(codes);
}