KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
msg_net.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 National Institute for Subatomic Physics Nikhef
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : msg_sys.c
11  * Created : 17 jul. 2013
12  * Author : Vincent van Beveren
13  */
14 
15 #include <stdbool.h>
16 #include <string.h>
17 #include <stdio.h>
18 #include "clbstate.h"
19 #include "net/msg.h"
20 #include "kernel/err.h"
21 #include "kernel/sys.h"
22 #include "net/network.h"
23 #include "errorcode.h"
24 #include "pv/vars.h"
25 #include "modules/wltune.h"
26 
27 bool _msgNetMuxDest(MsgId * msgId, DataBuffer * cmd)
28 {
29  uint8_t ip[4];
30  dbReadU8(cmd, &ip[0]);
31  dbReadU8(cmd, &ip[1]);
32  dbReadU8(cmd, &ip[2]);
33  dbReadU8(cmd, &ip[3]);
34  if (!msgRxBufCheck(cmd)) return false;
35 
36  // TODO: remove, should now be done by variables
37  net.ipmux_srv_ip = NET_IP_U32(ip[0], ip[1], ip[2], ip[3]);
38 
39  return msgTxReplyAck(msgId);
40 }
41 
42 
43 
44 /**
45  * Request the wavelength tuning subsystem state.
46  */
47 bool _msgNetWlTuneInfo(MsgId * msgId, DataBuffer * cmd)
48 {
49  if (!msgRxBufCheck(cmd)) return false;
50 
51  if (!wltune_update_info())
52  return msgTxCurError(msgId);
53 
54  uint8_t buf[8];
55 
56  DataBuffer db = DB_BUF_INIT(buf, sizeof(buf));
57 
58  // First byte, tune procedure
59  dbWriteU8(&db, wlTuneInfo.tuneproc);
60  // Tuning state
61  dbWriteU8(&db, wlTuneState);
62  // Laser temperature or wavelength
63  dbWriteU16(&db, wlTuneInfo.laserTmpWl);
64  // Tune word
65  dbWriteI32(&db, wlTuneInfo.tuneword);
66 
67  return msgTxReply(msgId, &db);
68 }
69 
70 /**
71  * Set the wavelength tuning word
72  */
73 bool _msgNetWlTuneSet(MsgId * msgId, DataBuffer * cmd)
74 {
75  int32_t tw;
76  bool relative = false;
77  dbReadBool(cmd, &relative);
78  dbReadI32(cmd, &tw);
79  if (!msgRxBufCheck(cmd)) return false;
80 
81  if (relative)
82  {
83  wltune_update_info();
84  tw = wlTuneInfo.tuneword + tw;
85  if (tw < 0) tw = 0;
86  if (tw > 65535) tw = 65535;
87  }
88 
89  if (!wltune_set_word(tw))
90  return msgTxCurError(msgId);
91 
92  return msgTxReplyAck(msgId);
93 }
94 
95 /**
96  * Acknowledge the wavelength tuning
97  */
98 bool _msgNetWlTuneAck(MsgId * msgId, DataBuffer * cmd)
99 {
100  if (!msgRxBufCheck(cmd)) return false;
101 
102  if (!wltune_ack())
103  return msgTxCurError(msgId);
104 
105  return msgTxReplyAck(msgId);
106 }
bool dbReadU8(DataBuffer *buf, uint8_t *byte)
Reads an unsigned byte.
Definition: databuffer.c:153
bool _msgNetWlTuneInfo(MsgId *id, DataBuffer *buf)
Request the wavelength tuning subsystem state.
Definition: msg_net.c:47
bool _msgNetWlTuneAck(MsgId *id, DataBuffer *buf)
Acknowledge the wavelength tuning.
Definition: msg_net.c:98
System start up and management.
#define NET_IP_U32(A, B, C, D)
Creates a U32 IP address from components.
Definition: net.h:40
bool dbWriteI32(DataBuffer *buf, int32_t i)
Writes an 32 bits signed integer.
Definition: databuffer.c:213
bool _msgNetWlTuneSet(MsgId *id, DataBuffer *buf)
Set the wavelength tuning word.
Definition: msg_net.c:73
static bool msgTxCurError(MsgId *id)
Invoke to reply the current global error.
Definition: msg.h:378
Defines a DataBuffer structure.
Definition: databuffer.h:45
static bool dbReadBool(DataBuffer *buf, bool *boolean)
Reads a boolean.
Definition: databuffer.h:263
Handles MCF packed messages from the higher protocol layer.
Manages the global system error.
bool msgTxReply(MsgId *id, DataBuffer *buf)
Invoke to send a reply.
Definition: msg.c:286
bool msgRxBufCheck(DataBuffer *buf)
Checks the received buffer, and logs an error if there is something wrong.
Definition: msg.c:141
This module is responsible for distributing error codes.
bool dbWriteU8(DataBuffer *buf, uint8_t byte)
Writes a unsigned byte.
Definition: databuffer.c:146
The CLB stare module tracks is responsible for state management of the various sub-systems on the CLB...
If defined, events will not require an acknowledge.
Definition: msg.h:274
bool dbReadI32(DataBuffer *buf, int32_t *i)
Reads an 32 bits signed integer.
Definition: databuffer.c:262
#define DB_BUF_INIT(PTR, LEN)
Simple buffer initialization.
Definition: databuffer.h:63
static bool msgTxReplyAck(MsgId *id)
Replies a simple ACK with no content.
Definition: msg.h:323
bool dbWriteU16(DataBuffer *buf, uint16_t u)
Writes a unsigned short (16 bits unsigned) integer.
Definition: databuffer.c:162