Advertisement
Pdevo

gestore_sistemi

Mar 3rd, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.71 KB | None | 0 0
  1. -- configurazione sistema
  2.  
  3. app = "gestore"
  4. cod = "sistemi"
  5. pro = "scgrc"
  6.  
  7. -- configurazione periferiche
  8.  
  9. modem = nil
  10.  for n,l in pairs(peripheral.getNames()) do
  11.   if peripheral.getType(l) == "modem" then
  12.   modem = l
  13.   break
  14.   end
  15.  end
  16.  
  17. drive = nil
  18.  for n,l in pairs(peripheral.getNames()) do
  19.   if peripheral.getType(l) == "drive" then
  20.   drive = l
  21.   break
  22.   end
  23.  end
  24.  
  25. -- inizializzazione settaggi
  26.  
  27. C = {}
  28. N = {}
  29. O = {}
  30. P = {}
  31. G = {}
  32. B = {}
  33. D = {}
  34.  
  35. -- catalogi
  36.  
  37. -- direttrice est
  38. C.de = "est"
  39. -- direttrice sud
  40. C.ds = "sud"
  41. -- direttrice ovest
  42. C.dw = "ovest"
  43. -- direttrice nord
  44. C.dn = "nord"
  45. -- binari passeggeri
  46. C.bp = "passeggeri"
  47. -- binari merci
  48. C.bm = "merci"
  49. -- binari servizi
  50. C.bs = "servizi"
  51. -- binari fermata
  52. C.bf = "fermata"
  53. -- binari transito
  54. C.bt = "transito"
  55.  
  56. -- norme
  57.  
  58. -- limite sistemi
  59. N.ls = 10000
  60. -- codice speciale
  61. N.cs = 0000
  62. -- codice direttrice
  63. N.cd = 1000
  64. -- direttrice est
  65. N.de = 1
  66. -- direttrice sud
  67. N.ds = 2
  68. -- direttrice ovest
  69. N.dw = 3
  70. -- direttrice nord
  71. N.dn = 4
  72. -- circolazione positiva
  73. N.cx = 1
  74. -- circolazione negativa
  75. N.cy = 2
  76. -- circolazione neutra
  77. N.cz = 3
  78. -- binari passeggeri
  79. N.bp = 100
  80. -- binari merci
  81. N.bm = 200
  82. -- binari servizi
  83. N.bs = 300
  84. -- binari fermata
  85. N.bf = 500
  86. -- binari transito
  87. N.bt = 600
  88.  
  89. -- operatori
  90.  
  91. -- fattore inclusione
  92. O.fi = 1/3
  93. -- fattore esclusione
  94. O.fe = 5/3
  95. -- fattore determinazione
  96. O.fl = 5
  97. -- fattore ciclico
  98. O.fc = 5
  99. -- fattore attivazione
  100. O.fa = 10
  101. -- fattore limite
  102. O.fl = 15
  103. -- fattore reiterazione
  104. O.fr = 25
  105. -- fattore sequenziale
  106. O.fs = 1/5
  107. -- fattore gerarchico
  108. O.fg = 1/10
  109.  
  110. -- parametri
  111.  
  112. -- binari passeggeri
  113. P.bp = 10
  114. -- binari merci
  115. P.bm = 10
  116. -- binari servizi
  117. P.bs = 10
  118. -- binari fermata
  119. P.bf = 10
  120. -- binari transito
  121. P.bt = 10
  122. -- direttrice est
  123. P.de = 2
  124. -- direttrice sud
  125. P.ds = 2
  126. -- direttrice ovest
  127. P.dw = 2
  128. -- direttrice nord
  129. P.dn = 2
  130.  
  131. -- gestioni
  132.  
  133. -- circolazione binata
  134. G.cb = "ammessa"
  135. -- circolazione deviatoi
  136. G.cd = "ammessa"
  137. -- circolazione segnali
  138. G.cs = "ammessa"
  139. -- direttrice est
  140. G.de = "ammessa"
  141. -- direttrice sud
  142. G.ds = "ammessa"
  143. -- direttrice ovest
  144. G.dw = "ammessa"
  145. -- direttrice nord
  146. G.dn = "ammessa"
  147. -- fermata parallela
  148. G.fp = "ammessa"
  149. -- fermata lineare
  150. G.fl = "ammessa"
  151. -- transito dedicato
  152. G.td = "ammessa"
  153. -- transito eccezionale
  154. G.te = "ammessa"
  155. -- transito passeggeri
  156. G.tp = "ammessa"
  157. -- transito merci
  158. G.tm = "ammessa"
  159. -- transito servizi
  160. G.ts = "ammessa"
  161.  
  162. -- binari
  163.  
  164. -- binari passeggeri
  165. if P.bp == 0 then
  166. B[C.bp] = nil
  167. end
  168. if P.bp > 0 then
  169. B[C.bp] = {}
  170. B[C.bp].vn,B[C.bp].vp,B[C.bp].bx,B[C.bp].by = N.bp,P.bp,N.bp+1,N.bp+P.bp
  171. end
  172. -- binari merci
  173. if P.bm == 0 then
  174. B[C.bm] = nil
  175. end
  176. if P.bm > 0 then
  177. B[C.bm] = {}
  178. B[C.bm].vn,B[C.bm].vp,B[C.bm].bx,B[C.bm].by = N.bm,P.bm,N.bm+1,N.bm+P.bm
  179. end
  180. -- binari servizi
  181. if P.bs == 0 then
  182. B[C.bs] = nil
  183. end
  184. if P.bs > 0 then
  185. B[C.bs] = {}
  186. B[C.bs].vn,B[C.bs].vp,B[C.bs].bx,B[C.bs].by = N.bs,P.bs,N.bs+1,N.bs+P.bs
  187. end
  188. -- binari fermata
  189. if P.bf == 0 then
  190. B[C.bf] = nil
  191. end
  192. if P.bf > 0 then
  193. B[C.bf] = {}
  194. B[C.bf].vn,B[C.bf].vp,B[C.bf].bx,B[C.bf].by = N.bf,P.bf,N.bf+1,N.bf+P.bf
  195. end
  196. -- binari transito
  197. if P.bt == 0 then
  198. B[C.bt] = nil
  199. end
  200. if P.bt > 0 then
  201. B[C.bt] = {}
  202. B[C.bt].vn,B[C.bt].vp,B[C.bt].bx,B[C.bt].by = N.bt,P.bt,N.bt+1,N.bt+P.bt
  203. end
  204.  
  205. -- direttrici
  206.  
  207. -- direttrice est
  208. if P.de == 0 then
  209. D[C.de] = nil
  210. end
  211. if P.de == 1 then
  212. D[C.de] = {}
  213. D[C.de].vg,D[C.de].lv,D[C.de].lw,D[C.de].kx,D[C.de].ky = G.de,N.de,C.dw,N.de*N.cd+N.cz,N.de*N.cd+N.cz
  214. end
  215. if P.de == 2 then
  216. D[C.de] = {}
  217. D[C.de].vg,D[C.de].lv,D[C.de].lw,D[C.de].kx,D[C.de].ky = G.de,N.de,C.dw,N.de*N.cd+N.cx,N.de*N.cd+N.cy
  218. end
  219. -- direttrice sud
  220. if P.ds == 0 then
  221. D[C.ds] = nil
  222. end
  223. if P.ds == 2 then
  224. D[C.ds] = {}
  225. D[C.ds].vg,D[C.ds].lv,D[C.ds].lw,D[C.ds].kx,D[C.ds].ky = G.ds,N.ds,C.dn,N.ds*N.cd+N.cz,N.ds*N.cd+N.cz
  226. end
  227. if P.ds == 2 then
  228. D[C.ds] = {}
  229. D[C.ds].vg,D[C.ds].lv,D[C.ds].lw,D[C.ds].kx,D[C.ds].ky = G.ds,N.ds,C.dn,N.ds*N.cd+N.cx,N.ds*N.cd+N.cy
  230. end
  231. -- direttrice ovest
  232. if P.dw == 0 then
  233. D[C.dw] = nil
  234. end
  235. if P.dw == 1  then
  236. D[C.dw] = {}
  237. D[C.dw].vg,D[C.dw].lv,D[C.dw].lw,D[C.dw].kx,D[C.dw].ky = G.dw,N.dw,C.de,N.dw*N.cd+N.cz,N.dw*N.cd+N.cz
  238. end
  239. if P.dw == 2  then
  240. D[C.dw] = {}
  241. D[C.dw].vg,D[C.dw].lv,D[C.dw].lw,D[C.dw].kx,D[C.dw].ky = G.dw,N.dw,C.de,N.dw*N.cd+N.cx,N.dw*N.cd+N.cy
  242. end
  243. -- direttrice nord
  244. if P.dn == 0 then
  245. D[C.dn] = nil
  246. end
  247. if P.dn == 1 then
  248. D[C.dn] = {}
  249. D[C.dn].vg,D[C.dn].lv,D[C.dn].lw,D[C.dn].kx,D[C.dn].ky = G.dn,N.dn,C.ds,N.dn*N.cd+N.cz,N.dn*N.cd+N.cz
  250. end
  251. if P.dn == 2 then
  252. D[C.dn] = {}
  253. D[C.dn].vg,D[C.dn].lv,D[C.dn].lw,D[C.dn].kx,D[C.dn].ky = G.dn,N.dn,C.ds,N.dn*N.cd+N.cx,N.dn*N.cd+N.cy
  254. end
  255.  
  256. -- inizializzazione dati
  257.  
  258. I = {}
  259. E = {}
  260. S = {}
  261. T = {}
  262. R = {}
  263. C = {}
  264. M = {}
  265.  
  266. -- itinerari
  267.  
  268. -- elenchi
  269.  
  270. E[2020] = {tt = "tratta",tl = "passeggeri",tc = "intercity",tb = 1,vx = 1,vy = 3,ox = 12.00,oy = 12.15,lx = "venezia",ly = "milano",lm = "verona"}
  271. E[4040] = {tt = "tratta",tl = "passeggeri",tc = "frecciabianca",tb = 2,vx = 1,vy = 3,ox = 13.30,oy = 13.45,lx = "venezia",ly = "firenze",lm = "verona"}
  272.  
  273. -- stati
  274.  
  275. -- treni
  276.  
  277. -- registri
  278.  
  279. -- compiti
  280.  
  281. -- media
  282.  
  283.  
  284. -- funzioni sistema
  285.  
  286. function sistema_struttura(tipo)
  287.  
  288. local path = disk.getMountPath(drive)
  289. fs.makeDir(path.."/"..tipo)
  290.  
  291. end
  292.  
  293. function sistema_configura(tabella,tipo,nome)
  294.  
  295. local path = disk.getMountPath(drive)
  296. local file = fs.open(path.."/"..tipo.."/"..nome,"w")
  297. local text = textutils.serialize(tabella)
  298. file.write(text)
  299. file.close()
  300.  
  301. end
  302.  
  303. -- codice sistema
  304.  
  305. sleep()
  306. print(app.."_"..cod)
  307. rednet.open(modem)
  308. rednet.host(pro,app.."_"..cod)
  309. rednet.broadcast({"avvio",app,cod})
  310.  
  311. while true do
  312. local id, scgrc = rednet.receive()
  313.  
  314.  if scgrc[1] == "sistemi" then
  315.  
  316.   if scgrc[2] == app then
  317.  
  318.    if scgrc[3] == cod then
  319.    
  320.     if scgrc[4] == "spegnimento" then
  321.     rednet.broadcast({"spegnimento",app,cod})
  322.     os.shutdown()
  323.     end
  324.     if scgrc[4] == "riavvio" then
  325.     rednet.broadcast({"riavvio",app,cod})
  326.     os.reboot()
  327.     end
  328.     if scgrc[4] == "configura" then
  329.     rednet.broadcast({"configura",app,cod})
  330.     sistema_configura(C,"settaggi","cataloghi")
  331.     sistema_configura(N,"settaggi","norme")
  332.     sistema_configura(O,"settaggi","operatori")
  333.     sistema_configura(P,"settaggi","parametri")
  334.     sistema_configura(G,"settaggi","gestioni")
  335.     sistema_configura(B,"settaggi","binari")
  336.     sistema_configura(D,"settaggi","direttrici")
  337.     sistema_configura(I,"dati","itinerari")
  338.     sistema_configura(E,"dati","elenchi")
  339.     sistema_configura(S,"dati","stati")
  340.     sistema_configura(T,"dati","treni")
  341.     sistema_configura(R,"dati","registri")
  342.     sistema_configura(C,"dati","compiti")
  343.     sistema_configura(M,"dati","media")
  344.     end
  345.    
  346.    end
  347.    
  348.   end
  349.  
  350.  end
  351.  
  352. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement