summaryrefslogtreecommitdiff
path: root/src/pira32ctl/command.go
blob: 9291ef9ceb31fcba08df510d97e5457c9f1886eb (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
//  pira32ctl
//
//  Copyright (C) 2016 Christian Pointner <equinox@helsinki.at>
//
//  This file is part of pira32ctl.
//
//  pira32ctl 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 3 of the License, or
//  any later version.
//
//  pira32ctl 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 pira32ctl. If not, see <http://www.gnu.org/licenses/>.
//

package main

import (
	"time"
)

const (
	REQ_PERSISTANT = '*'

	RESP_OK          = '+'
	RESP_UNKNOWN_CMD = '!'
	RESP_INVALID_ARG = '-'
	RESP_PARTIAL     = '/'

	storeExecutionTime = 10 * time.Millisecond
)

type Command interface {
	AllowedMethods() (get, assign, store, assignstore bool)
}

type BasicCommand struct {
	code        string
	description string
	exec_time   time.Duration
	get         bool
	assign      bool
	store       bool
	assignStore bool
}

func (c BasicCommand) AllowedMethods() (bool, bool, bool, bool) {
	return c.get, c.assign, c.store, c.assignStore
}

type ParamCommand struct {
	code        string
	description string
	rangeMin    uint
	rangeMax    uint
	exec_time   time.Duration
	get         bool
	assign      bool
	store       bool
	assignStore bool
}

func (c ParamCommand) AllowedMethods() (bool, bool, bool, bool) {
	return c.get, c.assign, c.store, c.assignStore
}

type Param2Command struct {
	code        string
	description string
	rangeMin    uint
	rangeMax    uint
	exec_time   time.Duration
	get         bool
	assign      bool
	store       bool
	assignStore bool
}

func (c Param2Command) AllowedMethods() (bool, bool, bool, bool) {
	return c.get, c.assign, c.store, c.assignStore
}

var (
	// Basic:
	CMD_AF       = BasicCommand{"AF", "Alternative Frequencies", 0, true, true, true, true}
	CMD_AFCH     = BasicCommand{"AFCH", "Alternative Frequencies Channels", 0, true, true, true, false}
	CMD_DI       = BasicCommand{"DI", "Decoder Identification", 0, true, true, true, false}
	CMD_DPS1     = BasicCommand{"DPS1", "Dynamic PS1", 400 * time.Millisecond, true, true, true, false}
	CMD_DPS1ENQ  = BasicCommand{"DPS1ENQ", "Dynamic PS1 Enqueue", 400 * time.Millisecond, false, true, false, false}
	CMD_DPS2     = BasicCommand{"DPS2", "Dynamic PS2", 400 * time.Millisecond, true, true, true, false}
	CMD_DPS1MOD  = BasicCommand{"DPS1MOD", "Dynamic PS1 Mode", 400 * time.Millisecond, true, true, true, false}
	CMD_DPS2MOD  = BasicCommand{"DPS2MOD", "Dynamic PS2 Mode", 400 * time.Millisecond, true, true, true, false}
	CMD_DPS1REP  = BasicCommand{"DPS1REP", "Dynamic PS2 Number of Repeating", 400 * time.Millisecond, true, true, true, false}
	CMD_DPS2REP  = BasicCommand{"DPS2REP", "Dynamic PS2 Number of Repeating", 400 * time.Millisecond, true, true, true, false}
	CMD_DTTMOUT  = BasicCommand{"DTTMOUT", "Default Text Timeout", 0, true, true, true, false}
	CMD_EQTEXT1  = BasicCommand{"EQTEXT1", "Equal Text 1", 0, true, true, true, false}
	CMD_LABPER   = BasicCommand{"LABPER", "Label Period", 0, true, true, true, false}
	CMD_MS       = BasicCommand{"MS", "Music/Speech", 0, true, true, true, false}
	CMD_PI       = BasicCommand{"PI", "Program Identifaction", 0, true, true, true, false}
	CMD_PS       = BasicCommand{"PS", "Program Service name", 400 * time.Millisecond, true, true, true, false}
	CMD_PTY      = BasicCommand{"PTY", "Program Type number", 0, true, true, true, false}
	CMD_PTYN     = BasicCommand{"PTYN", "Program Type Name", 0, true, true, true, false}
	CMD_PTYNEN   = BasicCommand{"PTYNEN", "PTYN Enable", 0, true, true, true, false}
	CMD_RT1      = BasicCommand{"RT1", "Radiotext 1", 0, true, true, true, false}
	CMD_RT1EN    = BasicCommand{"RT1EN", "RT1 Enable", 0, true, true, true, false}
	CMD_RT2      = BasicCommand{"RT2", "Radiotext 2", 0, true, true, true, false}
	CMD_RT2EN    = BasicCommand{"RT2EN", "RT2 Enable", 0, true, true, true, false}
	CMD_RTPER    = BasicCommand{"RTPER", "Radiotext Switching Period", 0, true, true, true, false}
	CMD_RSTDPS   = BasicCommand{"RSTDPS", "Rerstart Dynamic PS", 0, true, true, true, false}
	CMD_SCRLSPD  = BasicCommand{"SCRLSPD", "Scrolling PS Speed", 0, true, true, true, false}
	CMD_SPSPER   = BasicCommand{"SPSPER", "Static PS Period", 0, true, true, true, false}
	CMD_TA       = BasicCommand{"TA", "Traffic Announcement", 0, true, true, true, false}
	CMD_TATMOUT  = BasicCommand{"TATMOUT", "TA TImeout", 0, true, true, true, false}
	CMD_TP       = BasicCommand{"TP", "Traffic Program", 0, true, true, true, false}
	CMD_TPS      = BasicCommand{"TPS", "Traffic PS", 400 * time.Millisecond, true, true, true, false}
	CMD_INIT     = BasicCommand{"INIT", "Initialization", 0, true, false, false, false}
	CMD_STOREALL = BasicCommand{"ALL", "Store All", 0, false, false, true, false}
	CMD_HELP     = BasicCommand{"HELP", "Help", 0, true, false, false, false}

	// EON:
	CMD_EON_AF   = ParamCommand{"EONxAF", "EON x Frequencies", 1, 4, 0, true, true, false, false}
	CMD_EON_AFCH = ParamCommand{"EONxAFCH", "EON x Frequency channels", 1, 4, 0, true, true, false, false}
	CMD_EON_EN   = ParamCommand{"EONxEN", "EON x Enable", 1, 4, 0, true, true, false, false}
	CMD_EON_PI   = ParamCommand{"EONxPI", "EON x Program Identification", 1, 4, 0, true, true, false, false}
	CMD_EON_PIN  = ParamCommand{"EONxPIN", "EON x Program Item Number", 1, 4, 0, true, true, false, false}
	CMD_EON_PS   = ParamCommand{"EONxPS", "EON x Program Service name", 1, 4, 0, true, true, false, false}
	CMD_EON_PTY  = ParamCommand{"EONxPTY", "EON x Program Type number", 1, 4, 0, true, true, false, false}
	CMD_EON_TA   = ParamCommand{"EONxTA", "EON x Traffic Announcement", 1, 4, 0, true, true, false, false}
	CMD_EON_TP   = ParamCommand{"EONxTA", "EON x Traffic Program", 1, 4, 0, true, true, false, false}
	CMD_EON      = ParamCommand{"EON", "Store all EON data into EEPROM", 1, 4, 50 * time.Millisecond, false, false, true, false}

	//Messages:
	CMD_MSG     = Param2Command{"MSGxx", "Text message", 1, 99, 0, true, false, false, true}
	CMD_MSG_D   = Param2Command{"MSGxxD", "Message Destination", 1, 99, 0, true, false, false, true}
	CMD_MSGLIST = BasicCommand{"MSGLIST", "List of Messages", 0, true, false, false, false}
	CMD_DPS2MSG = BasicCommand{"DPS2MSG", "Dynamic PS 2 Message Number", 0, true, true, true, false}
	CMD_RT2MSG  = BasicCommand{"RT2MSG", "Radiotext 2 Message NUmber", 0, true, true, true, false}

	//Scheduling:
	CMD_SLIST = BasicCommand{"SLIST", "List of Scheduling Items", 0, true, false, false, false}
	CMD_S_C   = Param2Command{"SxxC", "Scheduling Item Command", 1, 48, 0, true, false, false, true}
	CMD_S_D   = Param2Command{"SxxD", "Scheduling Item Days", 1, 48, 0, true, false, false, true}
	CMD_S_P   = Param2Command{"SxxP", "Scheduling Item PTY", 1, 48, 0, true, false, false, true}
	CMD_S_T   = Param2Command{"SxxT", "Scheduling Item Times", 1, 48, 0, true, false, false, true}
	CMD_SEN   = BasicCommand{"SEN", "Scheduling Enable", 0, true, true, true, false}

	// System:
	CMD_COMSPD  = BasicCommand{"COMSPD", "Com Port Speed", 0, true, true, true, false}
	CMD_CT      = BasicCommand{"CT", "CLock Time and Date", 0, true, true, true, false}
	CMD_DATE    = BasicCommand{"Date", "Date", 0, true, true, true, false}
	CMD_ECHO    = BasicCommand{"ECHO", "Terminal Echo", 0, true, true, true, false}
	CMD_EXTSYNC = BasicCommand{"EXTSYNC", "External Pilot Synchronisation", 0, true, true, true, false}
	CMD_LEVEL   = BasicCommand{"LEVEL", "RDS Signal Level", 0, true, true, true, false}
	CMD_LTO     = BasicCommand{"LTO", "Local Time Offset", 0, true, true, true, false}
	CMD_MJD     = BasicCommand{"MJD", "Modified Julian Day", 0, true, true, true, false}
	CMD_PHASE   = BasicCommand{"PHASE", "RDS Signal Phase", 0, true, true, true, false}
	CMD_PILOT   = BasicCommand{"PILOT", "Pilot Tone Present", 0, true, false, false, false}
	CMD_RDSGEN  = BasicCommand{"RDSGEN", "RDS Generator", 0, true, true, true, false}
	CMD_RESET   = BasicCommand{"RESET", "Reset", 0, true, false, false, false}
	CMD_SPEED   = BasicCommand{"SPEED", "Com Port Speed", 0, true, true, true, false}
	CMD_STATUS  = BasicCommand{"STATUS", "RDS Encoder Status", 0, true, false, false, false}
	CMD_TIME    = BasicCommand{"TIME", "Time", 0, true, true, true, false}
	CMD_VER     = BasicCommand{"VER", "Firmware Version", 0, true, false, false, false}

	// Advanved:
	CMD_ADR     = BasicCommand{"ADR", "Encoder Address List", 0, true, false, false, true}
	CMD_CC      = BasicCommand{"CC", "Conditional Command", 0, true, false, false, true}
	CMD_DSN     = ParamCommand{"DSNx", "Program x Data Set Number", 1, 2, 0, true, false, false, true}
	CMD_ECC     = BasicCommand{"ECC", "Extended Country Code", 0, true, true, true, false}
	CMD_ECCEN   = BasicCommand{"ECCEN", "ECC and LIC Enable", 0, true, true, true, false}
	CMD_G       = BasicCommand{"G", "Group", 200 * time.Millisecond, false, true, false, false}
	CMD_GRPSEQ  = BasicCommand{"GRPSEQ", "Group Sequeunce", 0, true, true, true, false}
	CMD_LIC     = BasicCommand{"LIC", "Language Identification Code", 0, true, true, true, false}
	CMD_NOHDR   = BasicCommand{"NOHDR", "No Header Communication", 0, true, false, false, true}
	CMD_PIN     = BasicCommand{"PIN", "Program Item Number", 0, true, true, true, false}
	CMD_PINEN   = BasicCommand{"PINEN", "PIN Enable", 0, true, true, true, false}
	CMD_PROGRAM = BasicCommand{"PROGRAM", "Program Set Selection", 0, true, true, true, false}
	CMD_PSN     = ParamCommand{"PSNx", "Program x Service Number", 1, 2, 0, true, false, false, true}
	CMD_PSW     = BasicCommand{"PSW", "PS Window", 0, true, false, false, false}
	CMD_RTP     = BasicCommand{"RTP", "Radiotext Plus Tagging Data", 0, true, true, false, false}
	CMD_RTPRUN  = BasicCommand{"RTPRUN", "Radiotext Plus Running Bit", 0, true, true, false, false}
	CMD_SEL     = BasicCommand{"SEL", "Select Encoder", 0, false, true, false, false}
	CMD_SHORTRT = BasicCommand{"SEL", "Short Radiotext", 0, true, true, true, false}
	CMD_SITE    = BasicCommand{"SITE", "Site Address List", 0, true, false, false, true}
	CMD_UDG1    = BasicCommand{"UDG1", "User Defined Groups 1", 0, true, true, true, false}
	CMD_UDG2    = BasicCommand{"UDG2", "User Defined Groups 2", 0, true, true, true, false}
	CMD_UECP    = BasicCommand{"UECP", "UECP Enable", 0, true, true, true, false}
)