15 #include "modules/wltune.h"
23 static bool _initialized =
false;
24 static int _timeout = 0;
25 static int32_t _lastTune = -1;
27 WrxTuneInfo wlTuneInfo;
28 WlTuneState wlTuneState;
32 static const char * MODES[] = {
"not possible",
"eoptolink",
"OESolutions",
"simulated" };
34 void wltune_show_info()
36 logInfo(
"Tuning procedure is %s (%d), state=%d, to=%d", MODES[wlTuneInfo.tuneproc], wlTuneInfo.tuneproc, wlTuneState, _timeout);
37 if (wlTuneInfo.tuneproc == 0)
return;
38 logInfo(
"Tuning value: %d, Laser temperature: %lu", wlTuneInfo.tuneword, wlTuneInfo.laserTmpWl);
43 if (wltune_update_info()) {
45 if (wlTuneInfo.tuneproc == 0)
return true;
46 wlTuneState = WL_TUNE_STATE_IDLE;
48 wlTuneState = WL_TUNE_STATE_ERROR;
61 bool wltune_update_info()
69 bool wltune_set_word(int32_t t)
75 _lastTune = wlTuneInfo.tuneword;
78 wlLastTuneNoAck =
false;
79 wlTuneState = WL_TUNE_STATE_BUSY;
83 wlTuneState = WL_TUNE_STATE_ERROR;
96 wlTuneState = WL_TUNE_STATE_IDLE;
106 bool wltune_periodic()
108 if (wlTuneState != WL_TUNE_STATE_IDLE)
logInfo(
"State=%d, To=%d\n", wlTuneState, _timeout);
109 if (_timeout > 0) _timeout--;
112 case WL_TUNE_STATE_BUSY:
113 wltune_update_info();
114 if (_timeout == 0 && wlTuneInfo.laserTmpWl != 65535)
118 uint16_t mint = wlTuneInfo.laserTmpWl > 256 ? wlTuneInfo.laserTmpWl - 256 : 0;
119 uint16_t maxt = wlTuneInfo.laserTmpWl < 65535-256 ? wlTuneInfo.laserTmpWl + 256 : 65535;
124 wrxSetSFPThreshold(WRX_SFP_LASER_TEMP_HIGH_ALARM, maxt);
125 wrxSetSFPThreshold(WRX_SFP_LASER_TEMP_HIGH_WARN, maxt);
126 wrxSetSFPThreshold(WRX_SFP_LASER_TEMP_LOW_ALARM, mint);
127 wrxSetSFPThreshold(WRX_SFP_LASER_TEMP_LOW_WARN, mint);
129 if (_lastTune == wlTuneInfo.tuneword)
132 wlTuneState = WL_TUNE_STATE_IDLE;
135 wlTuneState = WL_TUNE_STATE_WAITACK;
140 case WL_TUNE_STATE_WAITACK:
143 logError(
"No ack received, reverting DAC value");
145 wlTuneState = WL_TUNE_STATE_ERROR;
148 wlTuneState = WL_TUNE_STATE_BUSY;
150 wlLastTuneNoAck =
true;
bool wrxGetTuneInfo(WrxTuneInfo *info)
Sets the fields of the WrxTuneInfo structure.
#define E_INVSTATE
Generic error: Module is in a state in which.
Manages the global system error.
bool wrxSetTuneWord(int32_t tuneWord)
Sets the tune-word.
This module is responsible for distributing error codes.
#define logError(MSG,...)
Format a log message with fatal level.
#define LOG_DEF(NAME,...)
Define a logger for a module.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).
Implements a generic logger facility.
#define logInfo(MSG,...)
Write a log message with formatting on info level.
#define E_NOTSUPPORTED
Generic error: not supported.