ToneMaps2.c.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. ToneMaps2.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='ToneMaps1.c.html' title=' ToneMaps1.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='Topology1.c.html' title=' Topology1.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * signed ToneMaps2 (struct plc * plc);
  64. *
  65. * amp.h
  66. *
  67. *
  68. * Contributor(s):
  69. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  70. *
  71. *--------------------------------------------------------------------*/
  72. #ifndef TONEMAPS2_SOURCE
  73. #define TONEMAPS2_SOURCE
  74. #include &lt;stdio.h&gt;
  75. #include &lt;stdint.h&gt;
  76. #include &quot;../tools/flags.h&quot;
  77. #include &quot;../tools/error.h&quot;
  78. #include &quot;../tools/endian.h&quot;
  79. #include &quot;../plc/plc.h&quot;
  80. #include &quot;../mme/mme.h&quot;
  81. #ifndef SIGNALTONOISE2_SOURCE
  82. static uint8_t const mod2bits [AMP_BITS] =
  83. {
  84. 0,
  85. 1,
  86. 2,
  87. 3,
  88. 4,
  89. 6,
  90. 8,
  91. 10,
  92. 12
  93. };
  94. #endif
  95. #ifndef SIGNALTONOISE2_SOURCE
  96. static uint8_t const mod2db [AMP_BITS] =
  97. {
  98. 0,
  99. 2,
  100. 4,
  101. 7,
  102. 10,
  103. 16,
  104. 22,
  105. 28,
  106. 36
  107. };
  108. #endif
  109. signed ToneMaps2 (struct plc * plc)
  110. {
  111. uint8_t tonemap [PLC_SLOTS + 1][AMP_CARRIERS &gt;&gt; 1];
  112. struct channel * channel = (struct channel *)(plc-&gt;channel);
  113. struct message * message = (struct message *)(plc-&gt;message);
  114. uint16_t extent = 0;
  115. uint16_t carriers = AMP_CARRIERS;
  116. uint16_t carrier = 0;
  117. uint8_t slots = PLC_SLOTS;
  118. uint8_t slot = 0;
  119. #ifndef __GNUC__
  120. #pragma pack (push,1)
  121. #endif
  122. struct __packed vs_tonemap_char_request
  123. {
  124. struct ethernet_hdr ethernet;
  125. struct qualcomm_fmi qualcomm;
  126. uint8_t MME_SUBVER;
  127. uint8_t Reserved1 [3];
  128. uint8_t MACADDRESS [ETHER_ADDR_LEN];
  129. uint8_t TMSLOT;
  130. uint8_t COUPLING;
  131. }
  132. * request = (struct vs_tonemap_char_request *) (message);
  133. struct __packed vs_tonemap_char_confirm
  134. {
  135. struct ethernet_hdr ethernet;
  136. struct qualcomm_fmi qualcomm;
  137. uint8_t MSTATUS;
  138. uint8_t Reserved1;
  139. uint16_t MME_LEN;
  140. struct __packed vs_tonemap_char_header
  141. {
  142. uint8_t MME_SUBVER;
  143. uint8_t Reserved2;
  144. uint8_t MACADDRESS [6];
  145. uint8_t TMSLOT;
  146. uint8_t COUPLING;
  147. uint8_t NUMTMS;
  148. uint8_t Reserved4;
  149. uint16_t TMNUMACTCARRIERS;
  150. uint16_t Reserved5;
  151. uint16_t NUMCARRIERS;
  152. uint16_t Reserved6;
  153. uint32_t Reserved7;
  154. }
  155. header;
  156. uint8_t MOD_CARRIER [1];
  157. }
  158. * confirm = (struct vs_tonemap_char_confirm *) (message);
  159. struct __packed vs_tonemap_char_fragment
  160. {
  161. struct ethernet_hdr ethernet;
  162. struct homeplug_fmi qualcomm;
  163. uint8_t MOD_CARRIER [1];
  164. }
  165. * fragment = (struct vs_tonemap_char_fragment *) (message);
  166. #ifndef __GNUC__
  167. #pragma pack (pop)
  168. #endif
  169. memset (tonemap, 0, sizeof (tonemap));
  170. for (carrier = slot = 0; slot &lt; slots; carrier = 0, slot++)
  171. {
  172. memset (message, 0, sizeof (* message));
  173. EthernetHeader (&amp;request-&gt;ethernet, channel-&gt;peer, channel-&gt;host, channel-&gt;type);
  174. QualcommHeader1 (&amp;request-&gt;qualcomm, 1, (VS_TONE_MAP_CHAR | MMTYPE_REQ));
  175. plc-&gt;packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
  176. memcpy (request-&gt;MACADDRESS, plc-&gt;RDA, sizeof (request-&gt;MACADDRESS));
  177. request-&gt;TMSLOT = slot;
  178. request-&gt;COUPLING = plc-&gt;coupling;
  179. if (SendMME (plc) &lt;= 0)
  180. {
  181. error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
  182. return (-1);
  183. }
  184. if (ReadMME (plc, 1, (VS_TONE_MAP_CHAR | MMTYPE_CNF)) &lt;= 0)
  185. {
  186. error (PLC_EXIT (plc), errno, CHANNEL_CANTREAD);
  187. return (-1);
  188. }
  189. if (confirm-&gt;MSTATUS)
  190. {
  191. error (1, 0, &quot;Device refused request for slot %d: %s&quot;, slot, MMECode (VS_TONE_MAP_CHAR | MMTYPE_CNF, confirm-&gt;MSTATUS));
  192. }
  193. carriers = LE16TOH (confirm-&gt;header.TMNUMACTCARRIERS);
  194. slots = confirm-&gt;header.NUMTMS;
  195. extent = LE16TOH (confirm-&gt;MME_LEN) - sizeof (struct vs_tonemap_char_header);
  196. if (extent &gt; (AMP_CARRIERS &gt;&gt; 1))
  197. {
  198. error (1, EOVERFLOW, &quot;Too many carriers&quot;);
  199. }
  200. plc-&gt;packetsize -= sizeof (struct vs_tonemap_char_confirm);
  201. plc-&gt;packetsize += sizeof (confirm-&gt;MOD_CARRIER);
  202. if (plc-&gt;packetsize &gt; extent)
  203. {
  204. plc-&gt;packetsize = extent;
  205. }
  206. memcpy (&amp;tonemap [slot] [carrier], &amp;confirm-&gt;MOD_CARRIER, plc-&gt;packetsize);
  207. carrier += plc-&gt;packetsize;
  208. extent -= plc-&gt;packetsize;
  209. while (extent)
  210. {
  211. if (ReadMME (plc, 1, (VS_TONE_MAP_CHAR | MMTYPE_CNF)) &lt;= 0)
  212. {
  213. error (1, errno, CHANNEL_CANTREAD);
  214. }
  215. plc-&gt;packetsize -= sizeof (struct vs_tonemap_char_fragment);
  216. plc-&gt;packetsize += sizeof (fragment-&gt;MOD_CARRIER);
  217. if (plc-&gt;packetsize &gt; extent)
  218. {
  219. plc-&gt;packetsize = extent;
  220. }
  221. memcpy (&amp;tonemap [slot] [carrier], fragment-&gt;MOD_CARRIER, plc-&gt;packetsize);
  222. carrier += plc-&gt;packetsize;
  223. extent -= plc-&gt;packetsize;
  224. }
  225. }
  226. for (carrier = 0; carrier &lt; carriers; carrier++)
  227. {
  228. uint16_t scale = 0;
  229. uint16_t value = 0;
  230. uint16_t index = carrier &gt;&gt; 1;
  231. printf (&quot;%04d&quot;, carrier);
  232. for (slot = 0; slot &lt; slots; slot++)
  233. {
  234. value = tonemap [slot][index];
  235. if ((carrier &amp; 1))
  236. {
  237. value &gt;&gt;= 4;
  238. }
  239. value &amp;= 0x0F;
  240. printf (&quot;,%02d&quot;, mod2bits [value]);
  241. value *= value;
  242. scale += value;
  243. }
  244. if (slots)
  245. {
  246. scale /= slots;
  247. }
  248. printf (&quot; %03d &quot;, scale);
  249. if (_anyset (plc-&gt;flags, PLC_GRAPH))
  250. {
  251. while (scale--)
  252. {
  253. printf (&quot;#&quot;);
  254. }
  255. }
  256. printf (&quot;\n&quot;);
  257. }
  258. return (0);
  259. }
  260. #endif
  261. </pre>
  262. <div class='footerlink'>
  263. [<a href='ToneMaps1.c.html' title=' ToneMaps1.c '>PREV</a>]
  264. [<a href='toolkit.html' title=' Index '>HOME</a>]
  265. [<a href='Topology1.c.html' title=' Topology1.c '>NEXT</a>]
  266. </div>
  267. </body>
  268. </html>